@metamask/polling-controller 10.0.1 → 11.0.0
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 +10 -1
- package/dist/AbstractPollingController.cjs +7 -7
- package/dist/AbstractPollingController.cjs.map +1 -1
- package/dist/AbstractPollingController.d.cts +8 -9
- package/dist/AbstractPollingController.d.cts.map +1 -1
- package/dist/AbstractPollingController.d.mts +8 -9
- package/dist/AbstractPollingController.d.mts.map +1 -1
- package/dist/AbstractPollingController.mjs +7 -7
- package/dist/AbstractPollingController.mjs.map +1 -1
- package/dist/BlockTrackerPollingController.cjs +12 -9
- package/dist/BlockTrackerPollingController.cjs.map +1 -1
- package/dist/BlockTrackerPollingController.d.cts +31 -24
- package/dist/BlockTrackerPollingController.d.cts.map +1 -1
- package/dist/BlockTrackerPollingController.d.mts +31 -24
- package/dist/BlockTrackerPollingController.d.mts.map +1 -1
- package/dist/BlockTrackerPollingController.mjs +9 -9
- package/dist/BlockTrackerPollingController.mjs.map +1 -1
- package/dist/StaticIntervalPollingController.cjs +10 -7
- package/dist/StaticIntervalPollingController.cjs.map +1 -1
- package/dist/StaticIntervalPollingController.d.cts +27 -28
- package/dist/StaticIntervalPollingController.d.cts.map +1 -1
- package/dist/StaticIntervalPollingController.d.mts +27 -28
- package/dist/StaticIntervalPollingController.d.mts.map +1 -1
- package/dist/StaticIntervalPollingController.mjs +7 -7
- package/dist/StaticIntervalPollingController.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -7
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -7
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [11.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING**: `AbstractPollingController` now accepts a generic type parameter `PollingInput` which is polymorphic, unlike the previous monomorphic required input of a network client id ([#4752](https://github.com/MetaMask/core/pull/4752))
|
|
15
|
+
- **BREAKING:** The `AbstractPollingController` method `startPollingByNetworkClientId` has been renamed to `startPolling` ([#4752](https://github.com/MetaMask/core/pull/4752))
|
|
16
|
+
- **BREAKING:** The `AbstractPollingController` method `onPollingComplete` now returns the entire input object of type `PollingInput`, instead of a network client id ([#4752](https://github.com/MetaMask/core/pull/4752))
|
|
17
|
+
|
|
10
18
|
## [10.0.1]
|
|
11
19
|
|
|
12
20
|
### Fixed
|
|
@@ -187,7 +195,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
187
195
|
|
|
188
196
|
- Initial release
|
|
189
197
|
|
|
190
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@
|
|
198
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@11.0.0...HEAD
|
|
199
|
+
[11.0.0]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@10.0.1...@metamask/polling-controller@11.0.0
|
|
191
200
|
[10.0.1]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@10.0.0...@metamask/polling-controller@10.0.1
|
|
192
201
|
[10.0.0]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@9.0.1...@metamask/polling-controller@10.0.0
|
|
193
202
|
[9.0.1]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@9.0.0...@metamask/polling-controller@9.0.1
|
|
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.AbstractPollingControllerBaseMixin = exports.getKey = void 0;
|
|
12
12
|
const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
|
|
13
13
|
const uuid_1 = require("uuid");
|
|
14
|
-
const getKey = (
|
|
14
|
+
const getKey = (input) => (0, fast_json_stable_stringify_1.default)(input);
|
|
15
15
|
exports.getKey = getKey;
|
|
16
16
|
/**
|
|
17
17
|
* AbstractPollingControllerBaseMixin
|
|
@@ -29,14 +29,14 @@ function AbstractPollingControllerBaseMixin(Base) {
|
|
|
29
29
|
_AbstractPollingControllerBase_pollingTokenSets.set(this, new Map());
|
|
30
30
|
_AbstractPollingControllerBase_callbacks.set(this, new Map());
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
startPolling(input) {
|
|
33
33
|
const pollToken = (0, uuid_1.v4)();
|
|
34
|
-
const key = (0, exports.getKey)(
|
|
34
|
+
const key = (0, exports.getKey)(input);
|
|
35
35
|
const pollingTokenSet = __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").get(key) ?? new Set();
|
|
36
36
|
pollingTokenSet.add(pollToken);
|
|
37
37
|
__classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").set(key, pollingTokenSet);
|
|
38
38
|
if (pollingTokenSet.size === 1) {
|
|
39
|
-
this.
|
|
39
|
+
this._startPolling(input);
|
|
40
40
|
}
|
|
41
41
|
return pollToken;
|
|
42
42
|
}
|
|
@@ -67,14 +67,14 @@ function AbstractPollingControllerBaseMixin(Base) {
|
|
|
67
67
|
if (callbacks) {
|
|
68
68
|
for (const callback of callbacks) {
|
|
69
69
|
// eslint-disable-next-line n/callback-return
|
|
70
|
-
callback(keyToDelete);
|
|
70
|
+
callback(JSON.parse(keyToDelete));
|
|
71
71
|
}
|
|
72
72
|
callbacks.clear();
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
const key = (0, exports.getKey)(
|
|
76
|
+
onPollingComplete(input, callback) {
|
|
77
|
+
const key = (0, exports.getKey)(input);
|
|
78
78
|
const callbacks = __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").get(key) ?? new Set();
|
|
79
79
|
callbacks.add(callback);
|
|
80
80
|
__classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").set(key, callbacks);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractPollingController.cjs","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"AbstractPollingController.cjs","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,4FAAmD;AACnD,+BAAoC;AAQ7B,MAAM,MAAM,GAAG,CAAe,KAAmB,EAAqB,EAAE,CAC7E,IAAA,oCAAS,EAAC,KAAK,CAAC,CAAC;AADN,QAAA,MAAM,UACA;AAEnB;;;;;GAKG;AACH,gFAAgF;AAChF,gEAAgE;AAChE,SAAgB,kCAAkC,CAGhD,IAAW;;IACX,MAAe,6BACb,SAAQ,IAAI;QADd;;YAIW,0DAAyD,IAAI,GAAG,EAAE,EAAC;YAE5E,mDACE,IAAI,GAAG,EAAE,EAAC;QAqEd,CAAC;QA7DC,YAAY,CAAC,KAAmB;YAC9B,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,eAAe,GACnB,uBAAA,IAAI,uDAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,EAAU,CAAC;YACvD,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAC/B,uBAAA,IAAI,uDAAkB,CAAC,GAAG,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;YAEjD,IAAI,eAAe,CAAC,IAAI,KAAK,CAAC,EAAE;gBAC9B,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;aAC3B;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,cAAc;YACZ,uBAAA,IAAI,uDAAkB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,IAAI,EAA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E,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,uBAAA,IAAI,gDAAW,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACtC,CAAC;KACF;;IACD,OAAO,6BAA6B,CAAC;AACvC,CAAC;AAlFD,gFAkFC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport stringify from 'fast-json-stable-stringify';\nimport { v4 as random } from 'uuid';\n\nimport type {\n Constructor,\n PollingTokenSetId,\n IPollingController,\n} from './types';\n\nexport const getKey = <PollingInput>(input: PollingInput): PollingTokenSetId =>\n stringify(input);\n\n/**\n * AbstractPollingControllerBaseMixin\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function AbstractPollingControllerBaseMixin<\n TBase extends Constructor,\n PollingInput extends Json,\n>(Base: TBase) {\n abstract class AbstractPollingControllerBase\n extends Base\n implements IPollingController<PollingInput>\n {\n readonly #pollingTokenSets: Map<PollingTokenSetId, Set<string>> = new Map();\n\n #callbacks: Map<PollingTokenSetId, Set<(input: PollingInput) => void>> =\n new Map();\n\n abstract _executePoll(input: PollingInput): Promise<void>;\n\n abstract _startPolling(input: PollingInput): void;\n\n abstract _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;\n\n startPolling(input: PollingInput): string {\n const pollToken = random();\n const key = getKey(input);\n const pollingTokenSet =\n this.#pollingTokenSets.get(key) ?? new Set<string>();\n pollingTokenSet.add(pollToken);\n this.#pollingTokenSets.set(key, pollingTokenSet);\n\n if (pollingTokenSet.size === 1) {\n this._startPolling(input);\n }\n\n return pollToken;\n }\n\n stopAllPolling() {\n this.#pollingTokenSets.forEach((tokenSet, _key) => {\n tokenSet.forEach((token) => {\n this.stopPollingByPollingToken(token);\n });\n });\n }\n\n stopPollingByPollingToken(pollingToken: string) {\n if (!pollingToken) {\n throw new Error('pollingToken required');\n }\n\n let keyToDelete: PollingTokenSetId | null = null;\n for (const [key, tokenSet] of this.#pollingTokenSets) {\n if (tokenSet.delete(pollingToken)) {\n if (tokenSet.size === 0) {\n keyToDelete = key;\n }\n break;\n }\n }\n\n if (keyToDelete) {\n this._stopPollingByPollingTokenSetId(keyToDelete);\n this.#pollingTokenSets.delete(keyToDelete);\n const callbacks = this.#callbacks.get(keyToDelete);\n if (callbacks) {\n for (const callback of callbacks) {\n // eslint-disable-next-line n/callback-return\n callback(JSON.parse(keyToDelete));\n }\n callbacks.clear();\n }\n }\n }\n\n onPollingComplete(\n input: PollingInput,\n callback: (input: PollingInput) => void,\n ) {\n const key = getKey(input);\n const callbacks = this.#callbacks.get(key) ?? new Set<typeof callback>();\n callbacks.add(callback);\n this.#callbacks.set(key, callbacks);\n }\n }\n return AbstractPollingControllerBase;\n}\n"]}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import type { NetworkClientId } from "@metamask/network-controller";
|
|
2
1
|
import type { Json } from "@metamask/utils";
|
|
3
2
|
import type { Constructor, PollingTokenSetId } from "./types.cjs";
|
|
4
|
-
export declare const getKey: (
|
|
3
|
+
export declare const getKey: <PollingInput>(input: PollingInput) => PollingTokenSetId;
|
|
5
4
|
/**
|
|
6
5
|
* AbstractPollingControllerBaseMixin
|
|
7
6
|
*
|
|
8
7
|
* @param Base - The base class to mix onto.
|
|
9
8
|
* @returns The composed class.
|
|
10
9
|
*/
|
|
11
|
-
export declare function AbstractPollingControllerBaseMixin<TBase extends Constructor>(Base: TBase): (abstract new (...args: any[]) => {
|
|
12
|
-
readonly "__#
|
|
13
|
-
"__#
|
|
14
|
-
_executePoll(
|
|
15
|
-
|
|
10
|
+
export declare function AbstractPollingControllerBaseMixin<TBase extends Constructor, PollingInput extends Json>(Base: TBase): (abstract new (...args: any[]) => {
|
|
11
|
+
readonly "__#784834@#pollingTokenSets": Map<PollingTokenSetId, Set<string>>;
|
|
12
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
13
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
14
|
+
_startPolling(input: PollingInput): void;
|
|
16
15
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
17
|
-
|
|
16
|
+
startPolling(input: PollingInput): string;
|
|
18
17
|
stopAllPolling(): void;
|
|
19
18
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
20
|
-
|
|
19
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
21
20
|
}) & TBase;
|
|
22
21
|
//# sourceMappingURL=AbstractPollingController.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractPollingController.d.cts","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"AbstractPollingController.d.cts","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAElB,oBAAgB;AAEjB,eAAO,MAAM,MAAM,yCAAwC,iBACzC,CAAC;AAEnB;;;;;GAKG;AAGH,wBAAgB,kCAAkC,CAChD,KAAK,SAAS,WAAW,EACzB,YAAY,SAAS,IAAI,EACzB,IAAI,EAAE,KAAK;4CAKmB,IAAI,iBAAiB,EAAE,IAAI,MAAM,CAAC,CAAC;oDAEhB,YAAY,KAAK,IAAI;wBAGvC,YAAY,GAAG,QAAQ,IAAI,CAAC;yBAE3B,YAAY,GAAG,IAAI;yCAEH,iBAAiB,GAAG,IAAI;wBAElD,YAAY,GAAG,MAAM;;4CAuBD,MAAM;6BA8BrC,YAAY,oBACD,YAAY,KAAK,IAAI;WAS5C"}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import type { NetworkClientId } from "@metamask/network-controller";
|
|
2
1
|
import type { Json } from "@metamask/utils";
|
|
3
2
|
import type { Constructor, PollingTokenSetId } from "./types.mjs";
|
|
4
|
-
export declare const getKey: (
|
|
3
|
+
export declare const getKey: <PollingInput>(input: PollingInput) => PollingTokenSetId;
|
|
5
4
|
/**
|
|
6
5
|
* AbstractPollingControllerBaseMixin
|
|
7
6
|
*
|
|
8
7
|
* @param Base - The base class to mix onto.
|
|
9
8
|
* @returns The composed class.
|
|
10
9
|
*/
|
|
11
|
-
export declare function AbstractPollingControllerBaseMixin<TBase extends Constructor>(Base: TBase): (abstract new (...args: any[]) => {
|
|
12
|
-
readonly "__#
|
|
13
|
-
"__#
|
|
14
|
-
_executePoll(
|
|
15
|
-
|
|
10
|
+
export declare function AbstractPollingControllerBaseMixin<TBase extends Constructor, PollingInput extends Json>(Base: TBase): (abstract new (...args: any[]) => {
|
|
11
|
+
readonly "__#784834@#pollingTokenSets": Map<PollingTokenSetId, Set<string>>;
|
|
12
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
13
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
14
|
+
_startPolling(input: PollingInput): void;
|
|
16
15
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
17
|
-
|
|
16
|
+
startPolling(input: PollingInput): string;
|
|
18
17
|
stopAllPolling(): void;
|
|
19
18
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
20
|
-
|
|
19
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
21
20
|
}) & TBase;
|
|
22
21
|
//# sourceMappingURL=AbstractPollingController.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractPollingController.d.mts","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"AbstractPollingController.d.mts","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAI5C,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAElB,oBAAgB;AAEjB,eAAO,MAAM,MAAM,yCAAwC,iBACzC,CAAC;AAEnB;;;;;GAKG;AAGH,wBAAgB,kCAAkC,CAChD,KAAK,SAAS,WAAW,EACzB,YAAY,SAAS,IAAI,EACzB,IAAI,EAAE,KAAK;4CAKmB,IAAI,iBAAiB,EAAE,IAAI,MAAM,CAAC,CAAC;oDAEhB,YAAY,KAAK,IAAI;wBAGvC,YAAY,GAAG,QAAQ,IAAI,CAAC;yBAE3B,YAAY,GAAG,IAAI;yCAEH,iBAAiB,GAAG,IAAI;wBAElD,YAAY,GAAG,MAAM;;4CAuBD,MAAM;6BA8BrC,YAAY,oBACD,YAAY,KAAK,IAAI;WAS5C"}
|
|
@@ -12,7 +12,7 @@ function $importDefault(module) {
|
|
|
12
12
|
import $stringify from "fast-json-stable-stringify";
|
|
13
13
|
const stringify = $importDefault($stringify);
|
|
14
14
|
import { v4 as random } from "uuid";
|
|
15
|
-
export const getKey = (
|
|
15
|
+
export const getKey = (input) => stringify(input);
|
|
16
16
|
/**
|
|
17
17
|
* AbstractPollingControllerBaseMixin
|
|
18
18
|
*
|
|
@@ -29,14 +29,14 @@ export function AbstractPollingControllerBaseMixin(Base) {
|
|
|
29
29
|
_AbstractPollingControllerBase_pollingTokenSets.set(this, new Map());
|
|
30
30
|
_AbstractPollingControllerBase_callbacks.set(this, new Map());
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
startPolling(input) {
|
|
33
33
|
const pollToken = random();
|
|
34
|
-
const key = getKey(
|
|
34
|
+
const key = getKey(input);
|
|
35
35
|
const pollingTokenSet = __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").get(key) ?? new Set();
|
|
36
36
|
pollingTokenSet.add(pollToken);
|
|
37
37
|
__classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").set(key, pollingTokenSet);
|
|
38
38
|
if (pollingTokenSet.size === 1) {
|
|
39
|
-
this.
|
|
39
|
+
this._startPolling(input);
|
|
40
40
|
}
|
|
41
41
|
return pollToken;
|
|
42
42
|
}
|
|
@@ -67,14 +67,14 @@ export function AbstractPollingControllerBaseMixin(Base) {
|
|
|
67
67
|
if (callbacks) {
|
|
68
68
|
for (const callback of callbacks) {
|
|
69
69
|
// eslint-disable-next-line n/callback-return
|
|
70
|
-
callback(keyToDelete);
|
|
70
|
+
callback(JSON.parse(keyToDelete));
|
|
71
71
|
}
|
|
72
72
|
callbacks.clear();
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
const key = getKey(
|
|
76
|
+
onPollingComplete(input, callback) {
|
|
77
|
+
const key = getKey(input);
|
|
78
78
|
const callbacks = __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").get(key) ?? new Set();
|
|
79
79
|
callbacks.add(callback);
|
|
80
80
|
__classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").set(key, callbacks);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractPollingController.mjs","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"AbstractPollingController.mjs","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,OAAO,UAAS,mCAAmC;;AACnD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAQpC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAe,KAAmB,EAAqB,EAAE,CAC7E,SAAS,CAAC,KAAK,CAAC,CAAC;AAEnB;;;;;GAKG;AACH,gFAAgF;AAChF,gEAAgE;AAChE,MAAM,UAAU,kCAAkC,CAGhD,IAAW;;IACX,MAAe,6BACb,SAAQ,IAAI;QADd;;YAIW,0DAAyD,IAAI,GAAG,EAAE,EAAC;YAE5E,mDACE,IAAI,GAAG,EAAE,EAAC;QAqEd,CAAC;Q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AAC;gBAClD,uBAAA,IAAI,uDAAkB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;gBAC3C,MAAM,SAAS,GAAG,uBAAA,IAAI,gDAAW,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBACnD,IAAI,SAAS,EAAE;oBACb,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;wBAChC,6CAA6C;wBAC7C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;qBACnC;oBACD,SAAS,CAAC,KAAK,EAAE,CAAC;iBACnB;aACF;QACH,CAAC;QAED,iBAAiB,CACf,KAAmB,EACnB,QAAuC;YAEvC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,SAAS,GAAG,uBAAA,IAAI,gDAAW,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,EAAmB,CAAC;YACzE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,uBAAA,IAAI,gDAAW,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACtC,CAAC;KACF;;IACD,OAAO,6BAA6B,CAAC;AACvC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport stringify from 'fast-json-stable-stringify';\nimport { v4 as random } from 'uuid';\n\nimport type {\n Constructor,\n PollingTokenSetId,\n IPollingController,\n} from './types';\n\nexport const getKey = <PollingInput>(input: PollingInput): PollingTokenSetId =>\n stringify(input);\n\n/**\n * AbstractPollingControllerBaseMixin\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function AbstractPollingControllerBaseMixin<\n TBase extends Constructor,\n PollingInput extends Json,\n>(Base: TBase) {\n abstract class AbstractPollingControllerBase\n extends Base\n implements IPollingController<PollingInput>\n {\n readonly #pollingTokenSets: Map<PollingTokenSetId, Set<string>> = new Map();\n\n #callbacks: Map<PollingTokenSetId, Set<(input: PollingInput) => void>> =\n new Map();\n\n abstract _executePoll(input: PollingInput): Promise<void>;\n\n abstract _startPolling(input: PollingInput): void;\n\n abstract _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;\n\n startPolling(input: PollingInput): string {\n const pollToken = random();\n const key = getKey(input);\n const pollingTokenSet =\n this.#pollingTokenSets.get(key) ?? new Set<string>();\n pollingTokenSet.add(pollToken);\n this.#pollingTokenSets.set(key, pollingTokenSet);\n\n if (pollingTokenSet.size === 1) {\n this._startPolling(input);\n }\n\n return pollToken;\n }\n\n stopAllPolling() {\n this.#pollingTokenSets.forEach((tokenSet, _key) => {\n tokenSet.forEach((token) => {\n this.stopPollingByPollingToken(token);\n });\n });\n }\n\n stopPollingByPollingToken(pollingToken: string) {\n if (!pollingToken) {\n throw new Error('pollingToken required');\n }\n\n let keyToDelete: PollingTokenSetId | null = null;\n for (const [key, tokenSet] of this.#pollingTokenSets) {\n if (tokenSet.delete(pollingToken)) {\n if (tokenSet.size === 0) {\n keyToDelete = key;\n }\n break;\n }\n }\n\n if (keyToDelete) {\n this._stopPollingByPollingTokenSetId(keyToDelete);\n this.#pollingTokenSets.delete(keyToDelete);\n const callbacks = this.#callbacks.get(keyToDelete);\n if (callbacks) {\n for (const callback of callbacks) {\n // eslint-disable-next-line n/callback-return\n callback(JSON.parse(keyToDelete));\n }\n callbacks.clear();\n }\n }\n }\n\n onPollingComplete(\n input: PollingInput,\n callback: (input: PollingInput) => void,\n ) {\n const key = getKey(input);\n const callbacks = this.#callbacks.get(key) ?? new Set<typeof callback>();\n callbacks.add(callback);\n this.#callbacks.set(key, callbacks);\n }\n }\n return AbstractPollingControllerBase;\n}\n"]}
|
|
@@ -24,14 +24,14 @@ function BlockTrackerPollingControllerMixin(Base) {
|
|
|
24
24
|
super(...arguments);
|
|
25
25
|
_BlockTrackerPollingController_activeListeners.set(this, {});
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
const key = (0, AbstractPollingController_1.getKey)(
|
|
27
|
+
_startPolling(input) {
|
|
28
|
+
const key = (0, AbstractPollingController_1.getKey)(input);
|
|
29
29
|
if (__classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const networkClient = this._getNetworkClientById(networkClientId);
|
|
32
|
+
const networkClient = this._getNetworkClientById(input.networkClientId);
|
|
33
33
|
if (networkClient) {
|
|
34
|
-
const updateOnNewBlock = this._executePoll.bind(this,
|
|
34
|
+
const updateOnNewBlock = this._executePoll.bind(this, input);
|
|
35
35
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
37
37
|
networkClient.blockTracker.addListener('latest', updateOnNewBlock);
|
|
@@ -41,11 +41,11 @@ function BlockTrackerPollingControllerMixin(Base) {
|
|
|
41
41
|
throw new Error(
|
|
42
42
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
43
43
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
44
|
-
`Unable to retrieve blockTracker for networkClientId ${networkClientId}`);
|
|
44
|
+
`Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
_stopPollingByPollingTokenSetId(key) {
|
|
48
|
-
const
|
|
48
|
+
const { networkClientId } = JSON.parse(key);
|
|
49
49
|
const networkClient = this._getNetworkClientById(networkClientId);
|
|
50
50
|
if (networkClient && __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]) {
|
|
51
51
|
const listener = __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key];
|
|
@@ -63,7 +63,10 @@ function BlockTrackerPollingControllerMixin(Base) {
|
|
|
63
63
|
}
|
|
64
64
|
class Empty {
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
exports.
|
|
68
|
-
|
|
66
|
+
const BlockTrackerPollingControllerOnly = () => BlockTrackerPollingControllerMixin(Empty);
|
|
67
|
+
exports.BlockTrackerPollingControllerOnly = BlockTrackerPollingControllerOnly;
|
|
68
|
+
const BlockTrackerPollingController = () => BlockTrackerPollingControllerMixin(base_controller_1.BaseController);
|
|
69
|
+
exports.BlockTrackerPollingController = BlockTrackerPollingController;
|
|
70
|
+
const BlockTrackerPollingControllerV1 = () => BlockTrackerPollingControllerMixin(base_controller_1.BaseControllerV1);
|
|
71
|
+
exports.BlockTrackerPollingControllerV1 = BlockTrackerPollingControllerV1;
|
|
69
72
|
//# sourceMappingURL=BlockTrackerPollingController.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockTrackerPollingController.cjs","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;;;;AAAA,+DAA6E;AAO7E,+EAGqC;
|
|
1
|
+
{"version":3,"file":"BlockTrackerPollingController.cjs","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;;;;AAAA,+DAA6E;AAO7E,+EAGqC;AAWrC;;;;;;GAMG;AACH,gFAAgF;AAChF,gEAAgE;AAChE,SAAS,kCAAkC,CAGzC,IAAW;;IACX,MAAe,6BAA8B,SAAQ,IAAA,8DAAkC,EAGrF,IAAI,CAAC;QAHP;;YAIE,yDAAqE,EAAE,EAAC;QA6C1E,CAAC;QAvCC,aAAa,CAAC,KAAmB;YAC/B,MAAM,GAAG,GAAG,IAAA,kCAAM,EAAC,KAAK,CAAC,CAAC;YAE1B,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE;gBAC9B,OAAO;aACR;YAED,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACxE,IAAI,aAAa,EAAE;gBACjB,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI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jB,CAAC;AALS,QAAA,+BAA+B,mCAKxC","sourcesContent":["import { BaseController, BaseControllerV1 } 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// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @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) {\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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\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\nexport const BlockTrackerPollingControllerV1 = <\n PollingInput extends BlockTrackerPollingInput,\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseControllerV1, PollingInput>(\n BaseControllerV1,\n );\n"]}
|
|
@@ -2,46 +2,53 @@ import { BaseController, BaseControllerV1 } from "@metamask/base-controller";
|
|
|
2
2
|
import type { NetworkClientId, NetworkClient } from "@metamask/network-controller";
|
|
3
3
|
import type { Json } from "@metamask/utils";
|
|
4
4
|
import type { PollingTokenSetId } from "./types.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* The minimum input required to start polling for a {@link BlockTrackerPollingController}.
|
|
7
|
+
* Implementing classes may provide additional properties.
|
|
8
|
+
*/
|
|
9
|
+
export type BlockTrackerPollingInput = {
|
|
10
|
+
networkClientId: NetworkClientId;
|
|
11
|
+
};
|
|
5
12
|
declare class Empty {
|
|
6
13
|
}
|
|
7
|
-
export declare const BlockTrackerPollingControllerOnly: (abstract new (...args: any[]) => {
|
|
8
|
-
"__#
|
|
14
|
+
export declare const BlockTrackerPollingControllerOnly: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
|
|
15
|
+
"__#784841@#activeListeners": Record<string, (options: Json) => Promise<void>>;
|
|
9
16
|
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
10
|
-
|
|
17
|
+
_startPolling(input: PollingInput): void;
|
|
11
18
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
12
|
-
readonly "__#
|
|
13
|
-
"__#
|
|
14
|
-
_executePoll(
|
|
15
|
-
|
|
19
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
20
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
21
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
22
|
+
startPolling(input: PollingInput): string;
|
|
16
23
|
stopAllPolling(): void;
|
|
17
24
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
18
|
-
|
|
25
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
19
26
|
}) & typeof Empty;
|
|
20
|
-
export declare const BlockTrackerPollingController: (abstract new (...args: any[]) => {
|
|
21
|
-
"__#
|
|
27
|
+
export declare const BlockTrackerPollingController: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
|
|
28
|
+
"__#784841@#activeListeners": Record<string, (options: Json) => Promise<void>>;
|
|
22
29
|
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
23
|
-
|
|
30
|
+
_startPolling(input: PollingInput): void;
|
|
24
31
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
25
|
-
readonly "__#
|
|
26
|
-
"__#
|
|
27
|
-
_executePoll(
|
|
28
|
-
|
|
32
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
33
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
34
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
35
|
+
startPolling(input: PollingInput): string;
|
|
29
36
|
stopAllPolling(): void;
|
|
30
37
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
31
|
-
|
|
38
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
32
39
|
}) & typeof BaseController;
|
|
33
|
-
export declare const BlockTrackerPollingControllerV1: (abstract new (...args: any[]) => {
|
|
34
|
-
"__#
|
|
40
|
+
export declare const BlockTrackerPollingControllerV1: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
|
|
41
|
+
"__#784841@#activeListeners": Record<string, (options: Json) => Promise<void>>;
|
|
35
42
|
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
36
|
-
|
|
43
|
+
_startPolling(input: PollingInput): void;
|
|
37
44
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
38
|
-
readonly "__#
|
|
39
|
-
"__#
|
|
40
|
-
_executePoll(
|
|
41
|
-
|
|
45
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
46
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
47
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
48
|
+
startPolling(input: PollingInput): string;
|
|
42
49
|
stopAllPolling(): void;
|
|
43
50
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
44
|
-
|
|
51
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
45
52
|
}) & typeof BaseControllerV1;
|
|
46
53
|
export {};
|
|
47
54
|
//# sourceMappingURL=BlockTrackerPollingController.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockTrackerPollingController.d.cts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAC7E,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAAe,iBAAiB,EAAE,oBAAgB;
|
|
1
|
+
{"version":3,"file":"BlockTrackerPollingController.d.cts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAC7E,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;AAqEF,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,iCAAiC;2DApDC,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAyBS,iBAAiB;;;;;;;;iBAyBkB,CAAC;AAE7E,eAAO,MAAM,6BAA6B;2DAxDK,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAyBS,iBAAiB;;;;;;;;0BAgCvD,CAAC;AAEJ,eAAO,MAAM,+BAA+B;2DA/DG,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAyBS,iBAAiB;;;;;;;;4BAuCvD,CAAC"}
|
|
@@ -2,46 +2,53 @@ import { BaseController, BaseControllerV1 } from "@metamask/base-controller";
|
|
|
2
2
|
import type { NetworkClientId, NetworkClient } from "@metamask/network-controller";
|
|
3
3
|
import type { Json } from "@metamask/utils";
|
|
4
4
|
import type { PollingTokenSetId } from "./types.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* The minimum input required to start polling for a {@link BlockTrackerPollingController}.
|
|
7
|
+
* Implementing classes may provide additional properties.
|
|
8
|
+
*/
|
|
9
|
+
export type BlockTrackerPollingInput = {
|
|
10
|
+
networkClientId: NetworkClientId;
|
|
11
|
+
};
|
|
5
12
|
declare class Empty {
|
|
6
13
|
}
|
|
7
|
-
export declare const BlockTrackerPollingControllerOnly: (abstract new (...args: any[]) => {
|
|
8
|
-
"__#
|
|
14
|
+
export declare const BlockTrackerPollingControllerOnly: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
|
|
15
|
+
"__#784841@#activeListeners": Record<string, (options: Json) => Promise<void>>;
|
|
9
16
|
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
10
|
-
|
|
17
|
+
_startPolling(input: PollingInput): void;
|
|
11
18
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
12
|
-
readonly "__#
|
|
13
|
-
"__#
|
|
14
|
-
_executePoll(
|
|
15
|
-
|
|
19
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
20
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
21
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
22
|
+
startPolling(input: PollingInput): string;
|
|
16
23
|
stopAllPolling(): void;
|
|
17
24
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
18
|
-
|
|
25
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
19
26
|
}) & typeof Empty;
|
|
20
|
-
export declare const BlockTrackerPollingController: (abstract new (...args: any[]) => {
|
|
21
|
-
"__#
|
|
27
|
+
export declare const BlockTrackerPollingController: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
|
|
28
|
+
"__#784841@#activeListeners": Record<string, (options: Json) => Promise<void>>;
|
|
22
29
|
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
23
|
-
|
|
30
|
+
_startPolling(input: PollingInput): void;
|
|
24
31
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
25
|
-
readonly "__#
|
|
26
|
-
"__#
|
|
27
|
-
_executePoll(
|
|
28
|
-
|
|
32
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
33
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
34
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
35
|
+
startPolling(input: PollingInput): string;
|
|
29
36
|
stopAllPolling(): void;
|
|
30
37
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
31
|
-
|
|
38
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
32
39
|
}) & typeof BaseController;
|
|
33
|
-
export declare const BlockTrackerPollingControllerV1: (abstract new (...args: any[]) => {
|
|
34
|
-
"__#
|
|
40
|
+
export declare const BlockTrackerPollingControllerV1: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
|
|
41
|
+
"__#784841@#activeListeners": Record<string, (options: Json) => Promise<void>>;
|
|
35
42
|
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
36
|
-
|
|
43
|
+
_startPolling(input: PollingInput): void;
|
|
37
44
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
38
|
-
readonly "__#
|
|
39
|
-
"__#
|
|
40
|
-
_executePoll(
|
|
41
|
-
|
|
45
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
46
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
47
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
48
|
+
startPolling(input: PollingInput): string;
|
|
42
49
|
stopAllPolling(): void;
|
|
43
50
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
44
|
-
|
|
51
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
45
52
|
}) & typeof BaseControllerV1;
|
|
46
53
|
export {};
|
|
47
54
|
//# sourceMappingURL=BlockTrackerPollingController.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockTrackerPollingController.d.mts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAC7E,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAAe,iBAAiB,EAAE,oBAAgB;
|
|
1
|
+
{"version":3,"file":"BlockTrackerPollingController.d.mts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAC7E,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;AAqEF,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,iCAAiC;2DApDC,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAyBS,iBAAiB;;;;;;;;iBAyBkB,CAAC;AAE7E,eAAO,MAAM,6BAA6B;2DAxDK,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAyBS,iBAAiB;;;;;;;;0BAgCvD,CAAC;AAEJ,eAAO,MAAM,+BAA+B;2DA/DG,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAyBS,iBAAiB;;;;;;;;4BAuCvD,CAAC"}
|
|
@@ -21,14 +21,14 @@ function BlockTrackerPollingControllerMixin(Base) {
|
|
|
21
21
|
super(...arguments);
|
|
22
22
|
_BlockTrackerPollingController_activeListeners.set(this, {});
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
const key = getKey(
|
|
24
|
+
_startPolling(input) {
|
|
25
|
+
const key = getKey(input);
|
|
26
26
|
if (__classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
const networkClient = this._getNetworkClientById(networkClientId);
|
|
29
|
+
const networkClient = this._getNetworkClientById(input.networkClientId);
|
|
30
30
|
if (networkClient) {
|
|
31
|
-
const updateOnNewBlock = this._executePoll.bind(this,
|
|
31
|
+
const updateOnNewBlock = this._executePoll.bind(this, input);
|
|
32
32
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
33
33
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
34
34
|
networkClient.blockTracker.addListener('latest', updateOnNewBlock);
|
|
@@ -38,11 +38,11 @@ function BlockTrackerPollingControllerMixin(Base) {
|
|
|
38
38
|
throw new Error(
|
|
39
39
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
41
|
-
`Unable to retrieve blockTracker for networkClientId ${networkClientId}`);
|
|
41
|
+
`Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
_stopPollingByPollingTokenSetId(key) {
|
|
45
|
-
const
|
|
45
|
+
const { networkClientId } = JSON.parse(key);
|
|
46
46
|
const networkClient = this._getNetworkClientById(networkClientId);
|
|
47
47
|
if (networkClient && __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]) {
|
|
48
48
|
const listener = __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key];
|
|
@@ -60,7 +60,7 @@ function BlockTrackerPollingControllerMixin(Base) {
|
|
|
60
60
|
}
|
|
61
61
|
class Empty {
|
|
62
62
|
}
|
|
63
|
-
export const BlockTrackerPollingControllerOnly = BlockTrackerPollingControllerMixin(Empty);
|
|
64
|
-
export const BlockTrackerPollingController = BlockTrackerPollingControllerMixin(BaseController);
|
|
65
|
-
export const BlockTrackerPollingControllerV1 = BlockTrackerPollingControllerMixin(BaseControllerV1);
|
|
63
|
+
export const BlockTrackerPollingControllerOnly = () => BlockTrackerPollingControllerMixin(Empty);
|
|
64
|
+
export const BlockTrackerPollingController = () => BlockTrackerPollingControllerMixin(BaseController);
|
|
65
|
+
export const BlockTrackerPollingControllerV1 = () => BlockTrackerPollingControllerMixin(BaseControllerV1);
|
|
66
66
|
//# sourceMappingURL=BlockTrackerPollingController.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockTrackerPollingController.mjs","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAO7E,OAAO,EACL,kCAAkC,EAClC,MAAM,EACP,wCAAoC;
|
|
1
|
+
{"version":3,"file":"BlockTrackerPollingController.mjs","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAO7E,OAAO,EACL,kCAAkC,EAClC,MAAM,EACP,wCAAoC;AAWrC;;;;;;GAMG;AACH,gFAAgF;AAChF,gEAAgE;AAChE,SAAS,kCAAkC,CAGzC,IAAW;;IACX,MAAe,6BAA8B,SAAQ,kCAAkC,CAGrF,IAAI,CAAC;QAHP;;YAIE,yDAAqE,EAAE,EAAC;QA6C1E,CAAC;QAvCC,aAAa,CAAC,KAAmB;YAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAE1B,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE;gBAC9B,OAAO;aACR;YAED,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACxE,IA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AM,+BAA+B,GAAG,GAE3C,EAAE,CACJ,kCAAkC,CAChC,gBAAgB,CACjB,CAAC","sourcesContent":["import { BaseController, BaseControllerV1 } 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// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @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) {\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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\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\nexport const BlockTrackerPollingControllerV1 = <\n PollingInput extends BlockTrackerPollingInput,\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseControllerV1, PollingInput>(\n BaseControllerV1,\n );\n"]}
|
|
@@ -37,11 +37,11 @@ function StaticIntervalPollingControllerMixin(Base) {
|
|
|
37
37
|
getIntervalLength() {
|
|
38
38
|
return __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f");
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
_startPolling(input) {
|
|
41
41
|
if (!__classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f")) {
|
|
42
42
|
throw new Error('intervalLength must be defined and greater than 0');
|
|
43
43
|
}
|
|
44
|
-
const key = (0, AbstractPollingController_1.getKey)(
|
|
44
|
+
const key = (0, AbstractPollingController_1.getKey)(input);
|
|
45
45
|
const existingInterval = __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key];
|
|
46
46
|
this._stopPollingByPollingTokenSetId(key);
|
|
47
47
|
// eslint-disable-next-line no-multi-assign
|
|
@@ -50,13 +50,13 @@ function StaticIntervalPollingControllerMixin(Base) {
|
|
|
50
50
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
51
51
|
async () => {
|
|
52
52
|
try {
|
|
53
|
-
await this._executePoll(
|
|
53
|
+
await this._executePoll(input);
|
|
54
54
|
}
|
|
55
55
|
catch (error) {
|
|
56
56
|
console.error(error);
|
|
57
57
|
}
|
|
58
58
|
if (intervalId === __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key]) {
|
|
59
|
-
this.
|
|
59
|
+
this._startPolling(input);
|
|
60
60
|
}
|
|
61
61
|
}, existingInterval ? __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f") : 0));
|
|
62
62
|
}
|
|
@@ -73,7 +73,10 @@ function StaticIntervalPollingControllerMixin(Base) {
|
|
|
73
73
|
}
|
|
74
74
|
class Empty {
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
exports.
|
|
78
|
-
|
|
76
|
+
const StaticIntervalPollingControllerOnly = () => StaticIntervalPollingControllerMixin(Empty);
|
|
77
|
+
exports.StaticIntervalPollingControllerOnly = StaticIntervalPollingControllerOnly;
|
|
78
|
+
const StaticIntervalPollingController = () => StaticIntervalPollingControllerMixin(base_controller_1.BaseController);
|
|
79
|
+
exports.StaticIntervalPollingController = StaticIntervalPollingController;
|
|
80
|
+
const StaticIntervalPollingControllerV1 = () => StaticIntervalPollingControllerMixin(base_controller_1.BaseControllerV1);
|
|
81
|
+
exports.StaticIntervalPollingControllerV1 = StaticIntervalPollingControllerV1;
|
|
79
82
|
//# sourceMappingURL=StaticIntervalPollingController.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StaticIntervalPollingController.cjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAA6E;
|
|
1
|
+
{"version":3,"file":"StaticIntervalPollingController.cjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;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C,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;gBACd,YAAY,CAAC,UAAU,CAAC,CAAC;gBACzB,OAAO,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;aAC/B;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;AAEG,MAAM,iCAAiC,GAAG,GAE7C,EAAE,CACJ,oCAAoC,CAClC,kCAAgB,CACjB,CAAC;AALS,QAAA,iCAAiC,qCAK1C","sourcesContent":["import { BaseController, BaseControllerV1 } 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// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @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) {\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\nexport const StaticIntervalPollingControllerV1 = <\n PollingInput extends Json,\n>() =>\n StaticIntervalPollingControllerMixin<typeof BaseControllerV1, PollingInput>(\n BaseControllerV1,\n );\n"]}
|
|
@@ -1,53 +1,52 @@
|
|
|
1
1
|
import { BaseController, BaseControllerV1 } from "@metamask/base-controller";
|
|
2
|
-
import type { NetworkClientId } from "@metamask/network-controller";
|
|
3
2
|
import type { Json } from "@metamask/utils";
|
|
4
3
|
import type { PollingTokenSetId } from "./types.cjs";
|
|
5
4
|
declare class Empty {
|
|
6
5
|
}
|
|
7
|
-
export declare const StaticIntervalPollingControllerOnly: (abstract new (...args: any[]) => {
|
|
8
|
-
readonly "__#
|
|
9
|
-
"__#
|
|
6
|
+
export declare const StaticIntervalPollingControllerOnly: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
|
|
7
|
+
readonly "__#784842@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
|
|
8
|
+
"__#784842@#intervalLength": number | undefined;
|
|
10
9
|
setIntervalLength(intervalLength: number): void;
|
|
11
10
|
getIntervalLength(): number | undefined;
|
|
12
|
-
|
|
11
|
+
_startPolling(input: PollingInput): void;
|
|
13
12
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
14
|
-
readonly "__#
|
|
15
|
-
"__#
|
|
16
|
-
_executePoll(
|
|
17
|
-
|
|
13
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
14
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
15
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
16
|
+
startPolling(input: PollingInput): string;
|
|
18
17
|
stopAllPolling(): void;
|
|
19
18
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
20
|
-
|
|
19
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
21
20
|
}) & typeof Empty;
|
|
22
|
-
export declare const StaticIntervalPollingController: (abstract new (...args: any[]) => {
|
|
23
|
-
readonly "__#
|
|
24
|
-
"__#
|
|
21
|
+
export declare const StaticIntervalPollingController: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
|
|
22
|
+
readonly "__#784842@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
|
|
23
|
+
"__#784842@#intervalLength": number | undefined;
|
|
25
24
|
setIntervalLength(intervalLength: number): void;
|
|
26
25
|
getIntervalLength(): number | undefined;
|
|
27
|
-
|
|
26
|
+
_startPolling(input: PollingInput): void;
|
|
28
27
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
29
|
-
readonly "__#
|
|
30
|
-
"__#
|
|
31
|
-
_executePoll(
|
|
32
|
-
|
|
28
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
29
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
30
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
31
|
+
startPolling(input: PollingInput): string;
|
|
33
32
|
stopAllPolling(): void;
|
|
34
33
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
35
|
-
|
|
34
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
36
35
|
}) & typeof BaseController;
|
|
37
|
-
export declare const StaticIntervalPollingControllerV1: (abstract new (...args: any[]) => {
|
|
38
|
-
readonly "__#
|
|
39
|
-
"__#
|
|
36
|
+
export declare const StaticIntervalPollingControllerV1: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
|
|
37
|
+
readonly "__#784842@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
|
|
38
|
+
"__#784842@#intervalLength": number | undefined;
|
|
40
39
|
setIntervalLength(intervalLength: number): void;
|
|
41
40
|
getIntervalLength(): number | undefined;
|
|
42
|
-
|
|
41
|
+
_startPolling(input: PollingInput): void;
|
|
43
42
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
44
|
-
readonly "__#
|
|
45
|
-
"__#
|
|
46
|
-
_executePoll(
|
|
47
|
-
|
|
43
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
44
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
45
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
46
|
+
startPolling(input: PollingInput): string;
|
|
48
47
|
stopAllPolling(): void;
|
|
49
48
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
50
|
-
|
|
49
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
51
50
|
}) & typeof BaseControllerV1;
|
|
52
51
|
export {};
|
|
53
52
|
//# sourceMappingURL=StaticIntervalPollingController.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StaticIntervalPollingController.d.cts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAC7E,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"StaticIntervalPollingController.d.cts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAC7E,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAGV,iBAAiB,EAClB,oBAAgB;AAsEjB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC;uCArDrB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;iCAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;iBAgBoB,CAAC;AAE/E,eAAO,MAAM,+BAA+B;uCAzDjB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;iCAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;0BAqBvD,CAAC;AAEJ,eAAO,MAAM,iCAAiC;uCA9DnB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;iCAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;4BA4BvD,CAAC"}
|
|
@@ -1,53 +1,52 @@
|
|
|
1
1
|
import { BaseController, BaseControllerV1 } from "@metamask/base-controller";
|
|
2
|
-
import type { NetworkClientId } from "@metamask/network-controller";
|
|
3
2
|
import type { Json } from "@metamask/utils";
|
|
4
3
|
import type { PollingTokenSetId } from "./types.mjs";
|
|
5
4
|
declare class Empty {
|
|
6
5
|
}
|
|
7
|
-
export declare const StaticIntervalPollingControllerOnly: (abstract new (...args: any[]) => {
|
|
8
|
-
readonly "__#
|
|
9
|
-
"__#
|
|
6
|
+
export declare const StaticIntervalPollingControllerOnly: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
|
|
7
|
+
readonly "__#784842@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
|
|
8
|
+
"__#784842@#intervalLength": number | undefined;
|
|
10
9
|
setIntervalLength(intervalLength: number): void;
|
|
11
10
|
getIntervalLength(): number | undefined;
|
|
12
|
-
|
|
11
|
+
_startPolling(input: PollingInput): void;
|
|
13
12
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
14
|
-
readonly "__#
|
|
15
|
-
"__#
|
|
16
|
-
_executePoll(
|
|
17
|
-
|
|
13
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
14
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
15
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
16
|
+
startPolling(input: PollingInput): string;
|
|
18
17
|
stopAllPolling(): void;
|
|
19
18
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
20
|
-
|
|
19
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
21
20
|
}) & typeof Empty;
|
|
22
|
-
export declare const StaticIntervalPollingController: (abstract new (...args: any[]) => {
|
|
23
|
-
readonly "__#
|
|
24
|
-
"__#
|
|
21
|
+
export declare const StaticIntervalPollingController: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
|
|
22
|
+
readonly "__#784842@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
|
|
23
|
+
"__#784842@#intervalLength": number | undefined;
|
|
25
24
|
setIntervalLength(intervalLength: number): void;
|
|
26
25
|
getIntervalLength(): number | undefined;
|
|
27
|
-
|
|
26
|
+
_startPolling(input: PollingInput): void;
|
|
28
27
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
29
|
-
readonly "__#
|
|
30
|
-
"__#
|
|
31
|
-
_executePoll(
|
|
32
|
-
|
|
28
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
29
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
30
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
31
|
+
startPolling(input: PollingInput): string;
|
|
33
32
|
stopAllPolling(): void;
|
|
34
33
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
35
|
-
|
|
34
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
36
35
|
}) & typeof BaseController;
|
|
37
|
-
export declare const StaticIntervalPollingControllerV1: (abstract new (...args: any[]) => {
|
|
38
|
-
readonly "__#
|
|
39
|
-
"__#
|
|
36
|
+
export declare const StaticIntervalPollingControllerV1: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
|
|
37
|
+
readonly "__#784842@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
|
|
38
|
+
"__#784842@#intervalLength": number | undefined;
|
|
40
39
|
setIntervalLength(intervalLength: number): void;
|
|
41
40
|
getIntervalLength(): number | undefined;
|
|
42
|
-
|
|
41
|
+
_startPolling(input: PollingInput): void;
|
|
43
42
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
44
|
-
readonly "__#
|
|
45
|
-
"__#
|
|
46
|
-
_executePoll(
|
|
47
|
-
|
|
43
|
+
readonly "__#784834@#pollingTokenSets": Map<string, Set<string>>;
|
|
44
|
+
"__#784834@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
|
|
45
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
46
|
+
startPolling(input: PollingInput): string;
|
|
48
47
|
stopAllPolling(): void;
|
|
49
48
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
50
|
-
|
|
49
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
51
50
|
}) & typeof BaseControllerV1;
|
|
52
51
|
export {};
|
|
53
52
|
//# sourceMappingURL=StaticIntervalPollingController.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StaticIntervalPollingController.d.mts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAC7E,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"StaticIntervalPollingController.d.mts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAC7E,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAGV,iBAAiB,EAClB,oBAAgB;AAsEjB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC;uCArDrB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;iCAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;iBAgBoB,CAAC;AAE/E,eAAO,MAAM,+BAA+B;uCAzDjB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;iCAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;0BAqBvD,CAAC;AAEJ,eAAO,MAAM,iCAAiC;uCA9DnB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;iCAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;4BA4BvD,CAAC"}
|
|
@@ -34,11 +34,11 @@ function StaticIntervalPollingControllerMixin(Base) {
|
|
|
34
34
|
getIntervalLength() {
|
|
35
35
|
return __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f");
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
_startPolling(input) {
|
|
38
38
|
if (!__classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f")) {
|
|
39
39
|
throw new Error('intervalLength must be defined and greater than 0');
|
|
40
40
|
}
|
|
41
|
-
const key = getKey(
|
|
41
|
+
const key = getKey(input);
|
|
42
42
|
const existingInterval = __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key];
|
|
43
43
|
this._stopPollingByPollingTokenSetId(key);
|
|
44
44
|
// eslint-disable-next-line no-multi-assign
|
|
@@ -47,13 +47,13 @@ function StaticIntervalPollingControllerMixin(Base) {
|
|
|
47
47
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
48
48
|
async () => {
|
|
49
49
|
try {
|
|
50
|
-
await this._executePoll(
|
|
50
|
+
await this._executePoll(input);
|
|
51
51
|
}
|
|
52
52
|
catch (error) {
|
|
53
53
|
console.error(error);
|
|
54
54
|
}
|
|
55
55
|
if (intervalId === __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key]) {
|
|
56
|
-
this.
|
|
56
|
+
this._startPolling(input);
|
|
57
57
|
}
|
|
58
58
|
}, existingInterval ? __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f") : 0));
|
|
59
59
|
}
|
|
@@ -70,7 +70,7 @@ function StaticIntervalPollingControllerMixin(Base) {
|
|
|
70
70
|
}
|
|
71
71
|
class Empty {
|
|
72
72
|
}
|
|
73
|
-
export const StaticIntervalPollingControllerOnly = StaticIntervalPollingControllerMixin(Empty);
|
|
74
|
-
export const StaticIntervalPollingController = StaticIntervalPollingControllerMixin(BaseController);
|
|
75
|
-
export const StaticIntervalPollingControllerV1 = StaticIntervalPollingControllerMixin(BaseControllerV1);
|
|
73
|
+
export const StaticIntervalPollingControllerOnly = () => StaticIntervalPollingControllerMixin(Empty);
|
|
74
|
+
export const StaticIntervalPollingController = () => StaticIntervalPollingControllerMixin(BaseController);
|
|
75
|
+
export const StaticIntervalPollingControllerV1 = () => StaticIntervalPollingControllerMixin(BaseControllerV1);
|
|
76
76
|
//# sourceMappingURL=StaticIntervalPollingController.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StaticIntervalPollingController.mjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"StaticIntervalPollingController.mjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kCAAkC;AAG7E,OAAO,EACL,kCAAkC,EAClC,MAAM,EACP,wCAAoC;AAOrC;;;;;;GAMG;AACH,gFAAgF;AAChF,gEAAgE;AAChE,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;gBACzB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;aACtE;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;oBACF,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;iBAChC;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACtB;gBACD,IAAI,UAAU,KAAK,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,EAAE;oBACzC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;iBAC3B;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;gBACd,YAAY,CAAC,UAAU,CAAC,CAAC;gBACzB,OAAO,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;aAC/B;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;AAEJ,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAE7C,EAAE,CACJ,oCAAoC,CAClC,gBAAgB,CACjB,CAAC","sourcesContent":["import { BaseController, BaseControllerV1 } 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// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @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) {\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\nexport const StaticIntervalPollingControllerV1 = <\n PollingInput extends Json,\n>() =>\n StaticIntervalPollingControllerMixin<typeof BaseControllerV1, PollingInput>(\n BaseControllerV1,\n );\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/utils';\n\nexport type PollingTokenSetId = string;\n\nexport type IPollingController<PollingInput extends Json> = {\n startPolling(input: PollingInput): string;\n\n stopAllPolling(): void;\n\n stopPollingByPollingToken(pollingToken: string): void;\n\n onPollingComplete(\n input: PollingInput,\n callback: (input: PollingInput) => void,\n ): void;\n\n _executePoll(input: PollingInput): Promise<void>;\n _startPolling(input: PollingInput): void;\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;\n};\n\n/**\n * TypeScript enforces this type for mixin constructors.\n *\n * Removing the `any` type results in the following error:\n * 'A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)'\n *\n * A potential future refactor that removes the mixin pattern may be able to fix this.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Constructor = new (...args: any[]) => object;\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type { NetworkClientId } from "@metamask/network-controller";
|
|
2
1
|
import type { Json } from "@metamask/utils";
|
|
3
|
-
export type PollingTokenSetId =
|
|
4
|
-
export type IPollingController = {
|
|
5
|
-
|
|
2
|
+
export type PollingTokenSetId = string;
|
|
3
|
+
export type IPollingController<PollingInput extends Json> = {
|
|
4
|
+
startPolling(input: PollingInput): string;
|
|
6
5
|
stopAllPolling(): void;
|
|
7
6
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
8
|
-
|
|
9
|
-
_executePoll(
|
|
10
|
-
|
|
7
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
8
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
9
|
+
_startPolling(input: PollingInput): void;
|
|
11
10
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
12
11
|
};
|
|
13
12
|
/**
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEvC,MAAM,MAAM,kBAAkB,CAAC,YAAY,SAAS,IAAI,IAAI;IAC1D,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC;IAE1C,cAAc,IAAI,IAAI,CAAC;IAEvB,yBAAyB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtD,iBAAiB,CACf,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GACtC,IAAI,CAAC;IAER,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACzC,+BAA+B,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC/D,CAAC;AAEF;;;;;;;GAOG;AAEH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type { NetworkClientId } from "@metamask/network-controller";
|
|
2
1
|
import type { Json } from "@metamask/utils";
|
|
3
|
-
export type PollingTokenSetId =
|
|
4
|
-
export type IPollingController = {
|
|
5
|
-
|
|
2
|
+
export type PollingTokenSetId = string;
|
|
3
|
+
export type IPollingController<PollingInput extends Json> = {
|
|
4
|
+
startPolling(input: PollingInput): string;
|
|
6
5
|
stopAllPolling(): void;
|
|
7
6
|
stopPollingByPollingToken(pollingToken: string): void;
|
|
8
|
-
|
|
9
|
-
_executePoll(
|
|
10
|
-
|
|
7
|
+
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
8
|
+
_executePoll(input: PollingInput): Promise<void>;
|
|
9
|
+
_startPolling(input: PollingInput): void;
|
|
11
10
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
12
11
|
};
|
|
13
12
|
/**
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEvC,MAAM,MAAM,kBAAkB,CAAC,YAAY,SAAS,IAAI,IAAI;IAC1D,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC;IAE1C,cAAc,IAAI,IAAI,CAAC;IAEvB,yBAAyB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtD,iBAAiB,CACf,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GACtC,IAAI,CAAC;IAER,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACzC,+BAA+B,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC/D,CAAC;AAEF;;;;;;;GAOG;AAEH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/utils';\n\nexport type PollingTokenSetId = string;\n\nexport type IPollingController<PollingInput extends Json> = {\n startPolling(input: PollingInput): string;\n\n stopAllPolling(): void;\n\n stopPollingByPollingToken(pollingToken: string): void;\n\n onPollingComplete(\n input: PollingInput,\n callback: (input: PollingInput) => void,\n ): void;\n\n _executePoll(input: PollingInput): Promise<void>;\n _startPolling(input: PollingInput): void;\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;\n};\n\n/**\n * TypeScript enforces this type for mixin constructors.\n *\n * Removing the `any` type results in the following error:\n * 'A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)'\n *\n * A potential future refactor that removes the mixin pattern may be able to fix this.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Constructor = new (...args: any[]) => object;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/polling-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "Polling Controller is the base for controllers that polling by networkClientId",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@metamask/auto-changelog": "^3.4.4",
|
|
59
|
-
"@metamask/network-controller": "^21.0
|
|
59
|
+
"@metamask/network-controller": "^21.1.0",
|
|
60
60
|
"@types/jest": "^27.4.1",
|
|
61
61
|
"deepmerge": "^4.2.2",
|
|
62
62
|
"jest": "^27.5.1",
|