@metamask-previews/polling-controller 16.0.9-preview-3866c0ff1 → 16.0.9-preview-e3275932a

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/AbstractPollingController.cjs +84 -0
  3. package/dist/AbstractPollingController.cjs.map +1 -0
  4. package/dist/{AbstractPollingController.d.ts → AbstractPollingController.d.cts} +5 -5
  5. package/dist/AbstractPollingController.d.cts.map +1 -0
  6. package/dist/AbstractPollingController.d.mts +21 -0
  7. package/dist/AbstractPollingController.d.mts.map +1 -0
  8. package/dist/AbstractPollingController.mjs +83 -0
  9. package/dist/AbstractPollingController.mjs.map +1 -0
  10. package/dist/StaticIntervalPollingController.cjs +84 -0
  11. package/dist/StaticIntervalPollingController.cjs.map +1 -0
  12. package/dist/{StaticIntervalPollingController.d.ts → StaticIntervalPollingController.d.cts} +19 -19
  13. package/dist/StaticIntervalPollingController.d.cts.map +1 -0
  14. package/dist/StaticIntervalPollingController.d.mts +37 -0
  15. package/dist/StaticIntervalPollingController.d.mts.map +1 -0
  16. package/dist/StaticIntervalPollingController.mjs +79 -0
  17. package/dist/StaticIntervalPollingController.mjs.map +1 -0
  18. package/dist/index.cjs +10 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +4 -0
  21. package/dist/index.d.cts.map +1 -0
  22. package/dist/index.d.mts +4 -0
  23. package/dist/index.d.mts.map +1 -0
  24. package/dist/index.mjs +3 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/types.cjs +3 -0
  27. package/dist/types.cjs.map +1 -0
  28. package/dist/{types.d.ts → types.d.cts} +2 -2
  29. package/dist/types.d.cts.map +1 -0
  30. package/dist/types.d.mts +21 -0
  31. package/dist/types.d.mts.map +1 -0
  32. package/dist/types.mjs +2 -0
  33. package/dist/types.mjs.map +1 -0
  34. package/package.json +16 -12
  35. package/dist/AbstractPollingController.d.ts.map +0 -1
  36. package/dist/AbstractPollingController.js +0 -73
  37. package/dist/AbstractPollingController.js.map +0 -1
  38. package/dist/StaticIntervalPollingController.d.ts.map +0 -1
  39. package/dist/StaticIntervalPollingController.js +0 -71
  40. package/dist/StaticIntervalPollingController.js.map +0 -1
  41. package/dist/index.d.ts +0 -4
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.js +0 -3
  44. package/dist/index.js.map +0 -1
  45. package/dist/types.d.ts.map +0 -1
  46. package/dist/types.js +0 -2
  47. package/dist/types.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -13,7 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
 
14
14
  ### Changed
15
15
 
16
- - **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
17
16
  - Bump `@metamask/network-controller` from `^35.0.0` to `^35.0.1` ([#9758](https://github.com/MetaMask/core/pull/9758))
18
17
 
19
18
  ### Removed
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.AbstractPollingControllerBaseMixin = exports.getKey = void 0;
12
+ const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
13
+ const uuid_1 = require("uuid");
14
+ const getKey = (input) => (0, fast_json_stable_stringify_1.default)(input);
15
+ exports.getKey = getKey;
16
+ /**
17
+ * AbstractPollingControllerBaseMixin
18
+ *
19
+ * @param Base - The base class to mix onto.
20
+ * @returns The composed class.
21
+ */
22
+ function AbstractPollingControllerBaseMixin(Base) {
23
+ var _AbstractPollingControllerBase_pollingTokenSets, _AbstractPollingControllerBase_callbacks;
24
+ class AbstractPollingControllerBase extends Base {
25
+ constructor() {
26
+ super(...arguments);
27
+ _AbstractPollingControllerBase_pollingTokenSets.set(this, new Map());
28
+ _AbstractPollingControllerBase_callbacks.set(this, new Map());
29
+ }
30
+ startPolling(input) {
31
+ const pollToken = (0, uuid_1.v4)();
32
+ const key = (0, exports.getKey)(input);
33
+ const pollingTokenSet = __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").get(key) ?? new Set();
34
+ pollingTokenSet.add(pollToken);
35
+ __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").set(key, pollingTokenSet);
36
+ if (pollingTokenSet.size === 1) {
37
+ this._startPolling(input);
38
+ }
39
+ return pollToken;
40
+ }
41
+ stopAllPolling() {
42
+ __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").forEach((tokenSet, _key) => {
43
+ tokenSet.forEach((token) => {
44
+ this.stopPollingByPollingToken(token);
45
+ });
46
+ });
47
+ }
48
+ stopPollingByPollingToken(pollingToken) {
49
+ if (!pollingToken) {
50
+ throw new Error('pollingToken required');
51
+ }
52
+ let keyToDelete = null;
53
+ for (const [key, tokenSet] of __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f")) {
54
+ if (tokenSet.delete(pollingToken)) {
55
+ if (tokenSet.size === 0) {
56
+ keyToDelete = key;
57
+ }
58
+ break;
59
+ }
60
+ }
61
+ if (keyToDelete) {
62
+ this._stopPollingByPollingTokenSetId(keyToDelete);
63
+ __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").delete(keyToDelete);
64
+ const callbacks = __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").get(keyToDelete);
65
+ if (callbacks) {
66
+ for (const callback of callbacks) {
67
+ callback(JSON.parse(keyToDelete));
68
+ }
69
+ callbacks.clear();
70
+ }
71
+ }
72
+ }
73
+ onPollingComplete(input, callback) {
74
+ const key = (0, exports.getKey)(input);
75
+ const callbacks = __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").get(key) ?? new Set();
76
+ callbacks.add(callback);
77
+ __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").set(key, callbacks);
78
+ }
79
+ }
80
+ _AbstractPollingControllerBase_pollingTokenSets = new WeakMap(), _AbstractPollingControllerBase_callbacks = new WeakMap();
81
+ return AbstractPollingControllerBase;
82
+ }
83
+ exports.AbstractPollingControllerBaseMixin = AbstractPollingControllerBaseMixin;
84
+ //# sourceMappingURL=AbstractPollingController.cjs.map
@@ -0,0 +1 @@
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,SAAgB,kCAAkC,CAGhD,IAAW;;IACX,MAAe,6BACb,SAAQ,IAAI;QADd;;YAIW,0DAAyD,IAAI,GAAG,EAAE,EAAC;YAEnE,mDAGL,IAAI,GAAG,EAAE,EAAC;QAoEhB,CAAC;QA5DC,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,CA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AQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;oBACpC,CAAC;oBACD,SAAS,CAAC,KAAK,EAAE,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC;QAED,iBAAiB,CACf,KAAmB,EACnB,QAAuC;YAEvC,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,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;AAnFD,gFAmFC","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.js';\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 */\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 readonly #callbacks: Map<\n PollingTokenSetId,\n 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 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,5 +1,5 @@
1
- import type { Json } from '@metamask/utils';
2
- import type { Constructor, PollingTokenSetId } from './types.js';
1
+ import type { Json } from "@metamask/utils";
2
+ import type { Constructor, PollingTokenSetId } from "./types.cjs";
3
3
  export declare const getKey: <PollingInput>(input: PollingInput) => PollingTokenSetId;
4
4
  /**
5
5
  * AbstractPollingControllerBaseMixin
@@ -8,8 +8,8 @@ export declare const getKey: <PollingInput>(input: PollingInput) => PollingToken
8
8
  * @returns The composed class.
9
9
  */
10
10
  export declare function AbstractPollingControllerBaseMixin<TBase extends Constructor, PollingInput extends Json>(Base: TBase): (abstract new (...args: any[]) => {
11
- readonly _pollingTokenSets: Map<PollingTokenSetId, Set<string>>;
12
- readonly _callbacks: Map<PollingTokenSetId, Set<(input: PollingInput) => void>>;
11
+ readonly "__#3@#pollingTokenSets": Map<PollingTokenSetId, Set<string>>;
12
+ readonly "__#3@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
13
13
  _executePoll(input: PollingInput): Promise<void>;
14
14
  _startPolling(input: PollingInput): void;
15
15
  _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
@@ -18,4 +18,4 @@ export declare function AbstractPollingControllerBaseMixin<TBase extends Constru
18
18
  stopPollingByPollingToken(pollingToken: string): void;
19
19
  onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
20
20
  }) & TBase;
21
- //# sourceMappingURL=AbstractPollingController.d.ts.map
21
+ //# sourceMappingURL=AbstractPollingController.d.cts.map
@@ -0,0 +1 @@
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,oBAAmB;AAEpB,eAAO,MAAM,MAAM,yCAAwC,iBACzC,CAAC;AAEnB;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,KAAK,SAAS,WAAW,EACzB,YAAY,SAAS,IAAI,EACzB,IAAI,EAAE,KAAK;uCAKmB,IAAI,iBAAiB,EAAE,IAAI,MAAM,CAAC,CAAC;wDAIjD,YAAY,KAAK,IAAI;wBAGN,YAAY,GAAG,QAAQ,IAAI,CAAC;yBAE3B,YAAY,GAAG,IAAI;yCAEH,iBAAiB,GAAG,IAAI;wBAElD,YAAY,GAAG,MAAM;;4CAuBD,MAAM;6BA6BrC,YAAY,oBACD,YAAY,KAAK,IAAI;WAS5C"}
@@ -0,0 +1,21 @@
1
+ import type { Json } from "@metamask/utils";
2
+ import type { Constructor, PollingTokenSetId } from "./types.mjs";
3
+ export declare const getKey: <PollingInput>(input: PollingInput) => PollingTokenSetId;
4
+ /**
5
+ * AbstractPollingControllerBaseMixin
6
+ *
7
+ * @param Base - The base class to mix onto.
8
+ * @returns The composed class.
9
+ */
10
+ export declare function AbstractPollingControllerBaseMixin<TBase extends Constructor, PollingInput extends Json>(Base: TBase): (abstract new (...args: any[]) => {
11
+ readonly "__#3@#pollingTokenSets": Map<PollingTokenSetId, Set<string>>;
12
+ readonly "__#3@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
13
+ _executePoll(input: PollingInput): Promise<void>;
14
+ _startPolling(input: PollingInput): void;
15
+ _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
16
+ startPolling(input: PollingInput): string;
17
+ stopAllPolling(): void;
18
+ stopPollingByPollingToken(pollingToken: string): void;
19
+ onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
20
+ }) & TBase;
21
+ //# sourceMappingURL=AbstractPollingController.d.mts.map
@@ -0,0 +1 @@
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,oBAAmB;AAEpB,eAAO,MAAM,MAAM,yCAAwC,iBACzC,CAAC;AAEnB;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,KAAK,SAAS,WAAW,EACzB,YAAY,SAAS,IAAI,EACzB,IAAI,EAAE,KAAK;uCAKmB,IAAI,iBAAiB,EAAE,IAAI,MAAM,CAAC,CAAC;wDAIjD,YAAY,KAAK,IAAI;wBAGN,YAAY,GAAG,QAAQ,IAAI,CAAC;yBAE3B,YAAY,GAAG,IAAI;yCAEH,iBAAiB,GAAG,IAAI;wBAElD,YAAY,GAAG,MAAM;;4CAuBD,MAAM;6BA6BrC,YAAY,oBACD,YAAY,KAAK,IAAI;WAS5C"}
@@ -0,0 +1,83 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ function $importDefault(module) {
7
+ if (module?.__esModule) {
8
+ return module.default;
9
+ }
10
+ return module;
11
+ }
12
+ import $stringify from "fast-json-stable-stringify";
13
+ const stringify = $importDefault($stringify);
14
+ import { v4 as random } from "uuid";
15
+ export const getKey = (input) => stringify(input);
16
+ /**
17
+ * AbstractPollingControllerBaseMixin
18
+ *
19
+ * @param Base - The base class to mix onto.
20
+ * @returns The composed class.
21
+ */
22
+ export function AbstractPollingControllerBaseMixin(Base) {
23
+ var _AbstractPollingControllerBase_pollingTokenSets, _AbstractPollingControllerBase_callbacks;
24
+ class AbstractPollingControllerBase extends Base {
25
+ constructor() {
26
+ super(...arguments);
27
+ _AbstractPollingControllerBase_pollingTokenSets.set(this, new Map());
28
+ _AbstractPollingControllerBase_callbacks.set(this, new Map());
29
+ }
30
+ startPolling(input) {
31
+ const pollToken = random();
32
+ const key = getKey(input);
33
+ const pollingTokenSet = __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").get(key) ?? new Set();
34
+ pollingTokenSet.add(pollToken);
35
+ __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").set(key, pollingTokenSet);
36
+ if (pollingTokenSet.size === 1) {
37
+ this._startPolling(input);
38
+ }
39
+ return pollToken;
40
+ }
41
+ stopAllPolling() {
42
+ __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").forEach((tokenSet, _key) => {
43
+ tokenSet.forEach((token) => {
44
+ this.stopPollingByPollingToken(token);
45
+ });
46
+ });
47
+ }
48
+ stopPollingByPollingToken(pollingToken) {
49
+ if (!pollingToken) {
50
+ throw new Error('pollingToken required');
51
+ }
52
+ let keyToDelete = null;
53
+ for (const [key, tokenSet] of __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f")) {
54
+ if (tokenSet.delete(pollingToken)) {
55
+ if (tokenSet.size === 0) {
56
+ keyToDelete = key;
57
+ }
58
+ break;
59
+ }
60
+ }
61
+ if (keyToDelete) {
62
+ this._stopPollingByPollingTokenSetId(keyToDelete);
63
+ __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").delete(keyToDelete);
64
+ const callbacks = __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").get(keyToDelete);
65
+ if (callbacks) {
66
+ for (const callback of callbacks) {
67
+ callback(JSON.parse(keyToDelete));
68
+ }
69
+ callbacks.clear();
70
+ }
71
+ }
72
+ }
73
+ onPollingComplete(input, callback) {
74
+ const key = getKey(input);
75
+ const callbacks = __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").get(key) ?? new Set();
76
+ callbacks.add(callback);
77
+ __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").set(key, callbacks);
78
+ }
79
+ }
80
+ _AbstractPollingControllerBase_pollingTokenSets = new WeakMap(), _AbstractPollingControllerBase_callbacks = new WeakMap();
81
+ return AbstractPollingControllerBase;
82
+ }
83
+ //# sourceMappingURL=AbstractPollingController.mjs.map
@@ -0,0 +1 @@
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,MAAM,UAAU,kCAAkC,CAGhD,IAAW;;IACX,MAAe,6BACb,SAAQ,IAAI;QADd;;YAIW,0DAAyD,IAAI,GAAG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AAG,CAAC;oBACpB,CAAC;oBACD,MAAM;gBACR,CAAC;YACH,CAAC;YAED,IAAI,WAAW,EAAE,CAAC;gBAChB,IAAI,CAAC,+BAA+B,CAAC,WAAW,CAAC,CAAC;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,CAAC;oBACd,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;wBACjC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;oBACpC,CAAC;oBACD,SAAS,CAAC,KAAK,EAAE,CAAC;gBACpB,CAAC;YACH,CAAC;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.js';\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 */\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 readonly #callbacks: Map<\n PollingTokenSetId,\n 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 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"]}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.StaticIntervalPollingController = exports.StaticIntervalPollingControllerOnly = void 0;
15
+ const base_controller_1 = require("@metamask/base-controller");
16
+ const AbstractPollingController_js_1 = require("./AbstractPollingController.cjs");
17
+ /**
18
+ * StaticIntervalPollingControllerMixin
19
+ * A polling controller that polls on a static interval.
20
+ *
21
+ * @param Base - The base class to mix onto.
22
+ * @returns The composed class.
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
27
+ function StaticIntervalPollingControllerMixin(Base) {
28
+ var _StaticIntervalPollingController_intervalIds, _StaticIntervalPollingController_intervalLength;
29
+ class StaticIntervalPollingController extends (0, AbstractPollingController_js_1.AbstractPollingControllerBaseMixin)(Base) {
30
+ constructor() {
31
+ super(...arguments);
32
+ _StaticIntervalPollingController_intervalIds.set(this, {});
33
+ _StaticIntervalPollingController_intervalLength.set(this, 1000);
34
+ }
35
+ setIntervalLength(intervalLength) {
36
+ __classPrivateFieldSet(this, _StaticIntervalPollingController_intervalLength, intervalLength, "f");
37
+ }
38
+ getIntervalLength() {
39
+ return __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f");
40
+ }
41
+ _startPolling(input) {
42
+ if (!__classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f")) {
43
+ throw new Error('intervalLength must be defined and greater than 0');
44
+ }
45
+ const key = (0, AbstractPollingController_js_1.getKey)(input);
46
+ const existingInterval = __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key];
47
+ this._stopPollingByPollingTokenSetId(key);
48
+ // eslint-disable-next-line no-multi-assign
49
+ const intervalId = (__classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key] = setTimeout(
50
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
51
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
52
+ async () => {
53
+ try {
54
+ await this._executePoll(input);
55
+ }
56
+ catch (error) {
57
+ console.error(error);
58
+ }
59
+ if (intervalId === __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key]) {
60
+ this._startPolling(input);
61
+ }
62
+ }, existingInterval ? __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f") : 0));
63
+ }
64
+ _stopPollingByPollingTokenSetId(key) {
65
+ const intervalId = __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key];
66
+ if (intervalId) {
67
+ clearTimeout(intervalId);
68
+ delete __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key];
69
+ }
70
+ }
71
+ }
72
+ _StaticIntervalPollingController_intervalIds = new WeakMap(), _StaticIntervalPollingController_intervalLength = new WeakMap();
73
+ return StaticIntervalPollingController;
74
+ }
75
+ class Empty {
76
+ }
77
+ const StaticIntervalPollingControllerOnly = () => StaticIntervalPollingControllerMixin(Empty);
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
82
+ const StaticIntervalPollingController = () => StaticIntervalPollingControllerMixin(base_controller_1.BaseController);
83
+ exports.StaticIntervalPollingController = StaticIntervalPollingController;
84
+ //# sourceMappingURL=StaticIntervalPollingController.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StaticIntervalPollingController.cjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAA2D;AAG3D,kFAGwC;AAOxC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,SAAS,oCAAoC,CAG3C,IAAW;;IACX,MAAe,+BACb,SAAQ,IAAA,iEAAkC,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,qCAAM,EAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,gBAAgB,GAAG,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAChD,IAAI,CAAC,+BAA+B,CAAC,GAAG,CAAC,CAAC;YAE1C,2CAA2C;YAC3C,MAAM,UAAU,GAAG,CAAC,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,GAAG,UAAU;YACrD,gFAAgF;YAChF,kEAAkE;YAClE,KAAK,IAAI,EAAE;gBACT,IAAI,CAAC;oBACH,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;gBACjC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC;gBACD,IAAI,UAAU,KAAK,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC1C,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC,EACD,gBAAgB,CAAC,CAAC,CAAC,uBAAA,IAAI,uDAAgB,CAAC,CAAC,CAAC,CAAC,CAC5C,CAAC,CAAC;QACL,CAAC;QAED,+BAA+B,CAAC,GAAsB;YACpD,MAAM,UAAU,GAAG,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,UAAU,EAAE,CAAC;gBACf,YAAY,CAAC,UAAU,CAAC,CAAC;gBACzB,OAAO,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;KACF;;IAED,OAAO,+BAA+B,CAAC;AACzC,CAAC;AAED,MAAM,KAAK;CAAG;AAEP,MAAM,mCAAmC,GAAG,GAK/C,EAAE,CAAC,oCAAoC,CAA6B,KAAK,CAAC,CAAC;AALlE,QAAA,mCAAmC,uCAK+B;AAE/E,yEAAyE;AACzE,wCAAwC;AACxC,4EAA4E;AACrE,MAAM,+BAA+B,GAAG,GAA8B,EAAE,CAC7E,oCAAoC,CAClC,gCAAc,CACf,CAAC;AAHS,QAAA,+BAA+B,mCAGxC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController.js';\nimport type {\n Constructor,\n IPollingController,\n PollingTokenSetId,\n} from './types.js';\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,37 +1,37 @@
1
- import { BaseController } from '@metamask/base-controller';
2
- import type { Json } from '@metamask/utils';
3
- import type { PollingTokenSetId } from './types.js';
1
+ import { BaseController } from "@metamask/base-controller";
2
+ import type { Json } from "@metamask/utils";
3
+ import type { PollingTokenSetId } from "./types.cjs";
4
4
  declare class Empty {
5
5
  }
6
6
  export declare const StaticIntervalPollingControllerOnly: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
7
- readonly _callbacks: Map<string, Set<(input: PollingInput) => void>>;
8
- _executePoll(input: PollingInput): Promise<void>;
9
- startPolling(input: PollingInput): string;
10
- stopAllPolling(): void;
11
- stopPollingByPollingToken(pollingToken: string): void;
12
- readonly _intervalIds: Record<PollingTokenSetId, NodeJS.Timeout>;
13
- _intervalLength: number | undefined;
7
+ readonly "__#6@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
8
+ "__#6@#intervalLength": number | undefined;
14
9
  setIntervalLength(intervalLength: number): void;
15
10
  getIntervalLength(): number | undefined;
16
11
  _startPolling(input: PollingInput): void;
17
12
  _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
18
- readonly _pollingTokenSets: Map<PollingTokenSetId, Set<string>>;
19
- onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
20
- }) & typeof Empty;
21
- export declare const StaticIntervalPollingController: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
22
- readonly _callbacks: Map<string, Set<(input: PollingInput) => void>>;
13
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
14
+ readonly "__#3@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
23
15
  _executePoll(input: PollingInput): Promise<void>;
24
16
  startPolling(input: PollingInput): string;
25
17
  stopAllPolling(): void;
26
18
  stopPollingByPollingToken(pollingToken: string): void;
27
- readonly _intervalIds: Record<PollingTokenSetId, NodeJS.Timeout>;
28
- _intervalLength: number | undefined;
19
+ onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
20
+ }) & typeof Empty;
21
+ export declare const StaticIntervalPollingController: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
22
+ readonly "__#6@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
23
+ "__#6@#intervalLength": number | undefined;
29
24
  setIntervalLength(intervalLength: number): void;
30
25
  getIntervalLength(): number | undefined;
31
26
  _startPolling(input: PollingInput): void;
32
27
  _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
33
- readonly _pollingTokenSets: Map<PollingTokenSetId, Set<string>>;
28
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
29
+ readonly "__#3@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
30
+ _executePoll(input: PollingInput): Promise<void>;
31
+ startPolling(input: PollingInput): string;
32
+ stopAllPolling(): void;
33
+ stopPollingByPollingToken(pollingToken: string): void;
34
34
  onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
35
35
  }) & typeof BaseController;
36
36
  export {};
37
- //# sourceMappingURL=StaticIntervalPollingController.d.ts.map
37
+ //# sourceMappingURL=StaticIntervalPollingController.d.cts.map
@@ -0,0 +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,oBAAmB;AAuEpB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC;kCArDrB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;4BAE/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;kCA/DjB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;4BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM,GAAG,IAAI;yBAI1B,MAAM,GAAG,SAAS;wCAIH,IAAI;yCA2BH,iBAAiB,GAAG,IAAI;;;;;;;;0BA2B9D,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { BaseController } from "@metamask/base-controller";
2
+ import type { Json } from "@metamask/utils";
3
+ import type { PollingTokenSetId } from "./types.mjs";
4
+ declare class Empty {
5
+ }
6
+ export declare const StaticIntervalPollingControllerOnly: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
7
+ readonly "__#6@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
8
+ "__#6@#intervalLength": number | undefined;
9
+ setIntervalLength(intervalLength: number): void;
10
+ getIntervalLength(): number | undefined;
11
+ _startPolling(input: PollingInput): void;
12
+ _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
13
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
14
+ readonly "__#3@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
15
+ _executePoll(input: PollingInput): Promise<void>;
16
+ startPolling(input: PollingInput): string;
17
+ stopAllPolling(): void;
18
+ stopPollingByPollingToken(pollingToken: string): void;
19
+ onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
20
+ }) & typeof Empty;
21
+ export declare const StaticIntervalPollingController: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
22
+ readonly "__#6@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
23
+ "__#6@#intervalLength": number | undefined;
24
+ setIntervalLength(intervalLength: number): void;
25
+ getIntervalLength(): number | undefined;
26
+ _startPolling(input: PollingInput): void;
27
+ _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
28
+ readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
29
+ readonly "__#3@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
30
+ _executePoll(input: PollingInput): Promise<void>;
31
+ startPolling(input: PollingInput): string;
32
+ stopAllPolling(): void;
33
+ stopPollingByPollingToken(pollingToken: string): void;
34
+ onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
35
+ }) & typeof BaseController;
36
+ export {};
37
+ //# sourceMappingURL=StaticIntervalPollingController.d.mts.map
@@ -0,0 +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,oBAAmB;AAuEpB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC;kCArDrB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;4BAE/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;kCA/DjB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;4BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM,GAAG,IAAI;yBAI1B,MAAM,GAAG,SAAS;wCAIH,IAAI;yCA2BH,iBAAiB,GAAG,IAAI;;;;;;;;0BA2B9D,CAAC"}
@@ -0,0 +1,79 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ import { BaseController } from "@metamask/base-controller";
13
+ import { AbstractPollingControllerBaseMixin, getKey } from "./AbstractPollingController.mjs";
14
+ /**
15
+ * StaticIntervalPollingControllerMixin
16
+ * A polling controller that polls on a static interval.
17
+ *
18
+ * @param Base - The base class to mix onto.
19
+ * @returns The composed class.
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
24
+ function StaticIntervalPollingControllerMixin(Base) {
25
+ var _StaticIntervalPollingController_intervalIds, _StaticIntervalPollingController_intervalLength;
26
+ class StaticIntervalPollingController extends AbstractPollingControllerBaseMixin(Base) {
27
+ constructor() {
28
+ super(...arguments);
29
+ _StaticIntervalPollingController_intervalIds.set(this, {});
30
+ _StaticIntervalPollingController_intervalLength.set(this, 1000);
31
+ }
32
+ setIntervalLength(intervalLength) {
33
+ __classPrivateFieldSet(this, _StaticIntervalPollingController_intervalLength, intervalLength, "f");
34
+ }
35
+ getIntervalLength() {
36
+ return __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f");
37
+ }
38
+ _startPolling(input) {
39
+ if (!__classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f")) {
40
+ throw new Error('intervalLength must be defined and greater than 0');
41
+ }
42
+ const key = getKey(input);
43
+ const existingInterval = __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key];
44
+ this._stopPollingByPollingTokenSetId(key);
45
+ // eslint-disable-next-line no-multi-assign
46
+ const intervalId = (__classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key] = setTimeout(
47
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
48
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
49
+ async () => {
50
+ try {
51
+ await this._executePoll(input);
52
+ }
53
+ catch (error) {
54
+ console.error(error);
55
+ }
56
+ if (intervalId === __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key]) {
57
+ this._startPolling(input);
58
+ }
59
+ }, existingInterval ? __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f") : 0));
60
+ }
61
+ _stopPollingByPollingTokenSetId(key) {
62
+ const intervalId = __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key];
63
+ if (intervalId) {
64
+ clearTimeout(intervalId);
65
+ delete __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key];
66
+ }
67
+ }
68
+ }
69
+ _StaticIntervalPollingController_intervalIds = new WeakMap(), _StaticIntervalPollingController_intervalLength = new WeakMap();
70
+ return StaticIntervalPollingController;
71
+ }
72
+ class Empty {
73
+ }
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
78
+ export const StaticIntervalPollingController = () => StaticIntervalPollingControllerMixin(BaseController);
79
+ //# sourceMappingURL=StaticIntervalPollingController.mjs.map
@@ -0,0 +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,wCAAuC;AAOxC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,SAAS,oCAAoC,CAG3C,IAAW;;IACX,MAAe,+BACb,SAA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,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.js';\nimport type {\n Constructor,\n IPollingController,\n PollingTokenSetId,\n} from './types.js';\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/dist/index.cjs ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getKey = exports.AbstractPollingControllerBaseMixin = exports.StaticIntervalPollingController = exports.StaticIntervalPollingControllerOnly = void 0;
4
+ var StaticIntervalPollingController_js_1 = require("./StaticIntervalPollingController.cjs");
5
+ Object.defineProperty(exports, "StaticIntervalPollingControllerOnly", { enumerable: true, get: function () { return StaticIntervalPollingController_js_1.StaticIntervalPollingControllerOnly; } });
6
+ Object.defineProperty(exports, "StaticIntervalPollingController", { enumerable: true, get: function () { return StaticIntervalPollingController_js_1.StaticIntervalPollingController; } });
7
+ var AbstractPollingController_js_1 = require("./AbstractPollingController.cjs");
8
+ Object.defineProperty(exports, "AbstractPollingControllerBaseMixin", { enumerable: true, get: function () { return AbstractPollingController_js_1.AbstractPollingControllerBaseMixin; } });
9
+ Object.defineProperty(exports, "getKey", { enumerable: true, get: function () { return AbstractPollingController_js_1.getKey; } });
10
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4FAG8C;AAF5C,yJAAA,mCAAmC,OAAA;AACnC,qJAAA,+BAA+B,OAAA;AAGjC,gFAGwC;AAFtC,kJAAA,kCAAkC,OAAA;AAClC,sHAAA,MAAM,OAAA","sourcesContent":["export {\n StaticIntervalPollingControllerOnly,\n StaticIntervalPollingController,\n} from './StaticIntervalPollingController.js';\n\nexport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController.js';\n\nexport type {\n IPollingController,\n Constructor,\n PollingTokenSetId,\n} from './types.js';\n"]}
@@ -0,0 +1,4 @@
1
+ export { StaticIntervalPollingControllerOnly, StaticIntervalPollingController, } from "./StaticIntervalPollingController.cjs";
2
+ export { AbstractPollingControllerBaseMixin, getKey, } from "./AbstractPollingController.cjs";
3
+ export type { IPollingController, Constructor, PollingTokenSetId, } from "./types.cjs";
4
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EACnC,+BAA+B,GAChC,8CAA6C;AAE9C,OAAO,EACL,kCAAkC,EAClC,MAAM,GACP,wCAAuC;AAExC,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,iBAAiB,GAClB,oBAAmB"}
@@ -0,0 +1,4 @@
1
+ export { StaticIntervalPollingControllerOnly, StaticIntervalPollingController, } from "./StaticIntervalPollingController.mjs";
2
+ export { AbstractPollingControllerBaseMixin, getKey, } from "./AbstractPollingController.mjs";
3
+ export type { IPollingController, Constructor, PollingTokenSetId, } from "./types.mjs";
4
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EACnC,+BAA+B,GAChC,8CAA6C;AAE9C,OAAO,EACL,kCAAkC,EAClC,MAAM,GACP,wCAAuC;AAExC,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,iBAAiB,GAClB,oBAAmB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export { StaticIntervalPollingControllerOnly, StaticIntervalPollingController } from "./StaticIntervalPollingController.mjs";
2
+ export { AbstractPollingControllerBaseMixin, getKey } from "./AbstractPollingController.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EACnC,+BAA+B,EAChC,8CAA6C;AAE9C,OAAO,EACL,kCAAkC,EAClC,MAAM,EACP,wCAAuC","sourcesContent":["export {\n StaticIntervalPollingControllerOnly,\n StaticIntervalPollingController,\n} from './StaticIntervalPollingController.js';\n\nexport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController.js';\n\nexport type {\n IPollingController,\n Constructor,\n PollingTokenSetId,\n} from './types.js';\n"]}
package/dist/types.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
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"]}
@@ -1,4 +1,4 @@
1
- import type { Json } from '@metamask/utils';
1
+ import type { Json } from "@metamask/utils";
2
2
  export type PollingTokenSetId = string;
3
3
  export type IPollingController<PollingInput extends Json> = {
4
4
  startPolling(input: PollingInput): string;
@@ -18,4 +18,4 @@ export type IPollingController<PollingInput extends Json> = {
18
18
  * A potential future refactor that removes the mixin pattern may be able to fix this.
19
19
  */
20
20
  export type Constructor = new (...args: any[]) => object;
21
- //# sourceMappingURL=types.d.ts.map
21
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,21 @@
1
+ import type { Json } from "@metamask/utils";
2
+ export type PollingTokenSetId = string;
3
+ export type IPollingController<PollingInput extends Json> = {
4
+ startPolling(input: PollingInput): string;
5
+ stopAllPolling(): void;
6
+ stopPollingByPollingToken(pollingToken: string): void;
7
+ onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
8
+ _executePoll(input: PollingInput): Promise<void>;
9
+ _startPolling(input: PollingInput): void;
10
+ _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
11
+ };
12
+ /**
13
+ * TypeScript enforces this type for mixin constructors.
14
+ *
15
+ * Removing the `any` type results in the following error:
16
+ * 'A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)'
17
+ *
18
+ * A potential future refactor that removes the mixin pattern may be able to fix this.
19
+ */
20
+ export type Constructor = new (...args: any[]) => object;
21
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
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-previews/polling-controller",
3
- "version": "16.0.9-preview-3866c0ff1",
3
+ "version": "16.0.9-preview-e3275932a",
4
4
  "description": "Polling Controller is the base for controllers that polling by networkClientId",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -18,12 +18,19 @@
18
18
  "files": [
19
19
  "dist/"
20
20
  ],
21
- "type": "module",
22
21
  "sideEffects": false,
22
+ "main": "./dist/index.cjs",
23
+ "types": "./dist/index.d.cts",
23
24
  "exports": {
24
25
  ".": {
25
- "types": "./dist/index.d.ts",
26
- "default": "./dist/index.js"
26
+ "import": {
27
+ "types": "./dist/index.d.mts",
28
+ "default": "./dist/index.mjs"
29
+ },
30
+ "require": {
31
+ "types": "./dist/index.d.cts",
32
+ "default": "./dist/index.cjs"
33
+ }
27
34
  },
28
35
  "./package.json": "./package.json"
29
36
  },
@@ -32,11 +39,9 @@
32
39
  "registry": "https://registry.npmjs.org/"
33
40
  },
34
41
  "scripts": {
35
- "build": "tsc --project tsconfig.build.json",
36
- "build:all": "tsc --build tsconfig.build.json --verbose",
37
- "build:clean": "yarn build:only-clean && yarn build",
42
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
43
+ "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
38
44
  "build:docs": "typedoc",
39
- "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
40
45
  "changelog:update": "../../scripts/update-changelog.sh @metamask/polling-controller",
41
46
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/polling-controller",
42
47
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
@@ -57,18 +62,17 @@
57
62
  "devDependencies": {
58
63
  "@metamask/auto-changelog": "^6.1.0",
59
64
  "@metamask/messenger": "^2.0.0",
65
+ "@ts-bridge/cli": "^0.6.4",
60
66
  "@types/jest": "^30.0.0",
61
- "@typescript/native": "npm:typescript@^7.0.2",
62
67
  "deepmerge": "^4.2.2",
63
68
  "jest": "^30.4.2",
64
- "rimraf": "^5.0.5",
65
69
  "ts-jest": "^29.4.11",
66
70
  "tsx": "^4.20.5",
67
71
  "typedoc": "^0.25.13",
68
72
  "typedoc-plugin-missing-exports": "^2.0.0",
69
- "typescript": "npm:@typescript/typescript6@^6.0.2"
73
+ "typescript": "~5.3.3"
70
74
  },
71
75
  "engines": {
72
- "node": "^22.14.0 || ^24"
76
+ "node": "^18.18 || >=20"
73
77
  }
74
78
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbstractPollingController.d.ts","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,MAAM,GAAI,YAAY,SAAS,YAAY,KAAG,iBACzC,CAAC;AAEnB;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,KAAK,SAAS,WAAW,EACzB,YAAY,SAAS,IAAI,EACzB,IAAI,EAAE,KAAK;gCAYmB,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;yBAE1C,GAAG,CACtB,iBAAiB,EACjB,GAAG,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC,CACnC;wBAE4B,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;yBAE3B,YAAY,GAAG,IAAI;yCAEH,iBAAiB,GAAG,IAAI;wBAElD,YAAY,GAAG,MAAM;;4CAuBD,MAAM;6BA6BrC,YAAY,YACT,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI;WAS5C"}
@@ -1,73 +0,0 @@
1
- import stringify from 'fast-json-stable-stringify';
2
- import { v4 as random } from 'uuid';
3
- export const getKey = (input) => stringify(input);
4
- /**
5
- * AbstractPollingControllerBaseMixin
6
- *
7
- * @param Base - The base class to mix onto.
8
- * @returns The composed class.
9
- */
10
- export function AbstractPollingControllerBaseMixin(Base) {
11
- class AbstractPollingControllerBase extends Base {
12
- // These fields are public (rather than using `#`) so that declaration
13
- // emission can describe them. Private/protected members on the class
14
- // returned by an exported mixin function trigger TS4094, and giving the
15
- // mixin an explicit return type to work around that breaks consumers
16
- // that supply the base class's own type arguments via
17
- // `SomeMixin()<Name, State, Messenger>`. The leading underscore signals
18
- // "internal, do not use" without needing true privacy.
19
- _pollingTokenSets = new Map();
20
- _callbacks = new Map();
21
- startPolling(input) {
22
- const pollToken = random();
23
- const key = getKey(input);
24
- const pollingTokenSet = this._pollingTokenSets.get(key) ?? new Set();
25
- pollingTokenSet.add(pollToken);
26
- this._pollingTokenSets.set(key, pollingTokenSet);
27
- if (pollingTokenSet.size === 1) {
28
- this._startPolling(input);
29
- }
30
- return pollToken;
31
- }
32
- stopAllPolling() {
33
- this._pollingTokenSets.forEach((tokenSet, _key) => {
34
- tokenSet.forEach((token) => {
35
- this.stopPollingByPollingToken(token);
36
- });
37
- });
38
- }
39
- stopPollingByPollingToken(pollingToken) {
40
- if (!pollingToken) {
41
- throw new Error('pollingToken required');
42
- }
43
- let keyToDelete = null;
44
- for (const [key, tokenSet] of this._pollingTokenSets) {
45
- if (tokenSet.delete(pollingToken)) {
46
- if (tokenSet.size === 0) {
47
- keyToDelete = key;
48
- }
49
- break;
50
- }
51
- }
52
- if (keyToDelete) {
53
- this._stopPollingByPollingTokenSetId(keyToDelete);
54
- this._pollingTokenSets.delete(keyToDelete);
55
- const callbacks = this._callbacks.get(keyToDelete);
56
- if (callbacks) {
57
- for (const callback of callbacks) {
58
- callback(JSON.parse(keyToDelete));
59
- }
60
- callbacks.clear();
61
- }
62
- }
63
- }
64
- onPollingComplete(input, callback) {
65
- const key = getKey(input);
66
- const callbacks = this._callbacks.get(key) ?? new Set();
67
- callbacks.add(callback);
68
- this._callbacks.set(key, callbacks);
69
- }
70
- }
71
- return AbstractPollingControllerBase;
72
- }
73
- //# sourceMappingURL=AbstractPollingController.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbstractPollingController.js","sourceRoot":"","sources":["../src/AbstractPollingController.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,4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ACF;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.js';\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 */\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 // These fields are public (rather than using `#`) so that declaration\n // emission can describe them. Private/protected members on the class\n // returned by an exported mixin function trigger TS4094, and giving the\n // mixin an explicit return type to work around that breaks consumers\n // that supply the base class's own type arguments via\n // `SomeMixin()<Name, State, Messenger>`. The leading underscore signals\n // \"internal, do not use\" without needing true privacy.\n readonly _pollingTokenSets: Map<PollingTokenSetId, Set<string>> = new Map();\n\n readonly _callbacks: Map<\n PollingTokenSetId,\n 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 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 +0,0 @@
1
- {"version":3,"file":"StaticIntervalPollingController.d.ts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAM5C,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AA+EpB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC,GAC9C,YAAY,SAAS,IAAI;;;;;;2BAtDA,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC;qBAE/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,GAAI,YAAY,SAAS,IAAI;;;;;;2BA/D9C,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC;qBAE/C,MAAM,GAAG,SAAS;sCAED,MAAM,GAAG,IAAI;yBAI1B,MAAM,GAAG,SAAS;wCAIH,IAAI;yCA2BH,iBAAiB,GAAG,IAAI;;;0BA2B9D,CAAC"}
@@ -1,71 +0,0 @@
1
- import { BaseController } from '@metamask/base-controller';
2
- import { AbstractPollingControllerBaseMixin, getKey, } from './AbstractPollingController.js';
3
- /**
4
- * StaticIntervalPollingControllerMixin
5
- * A polling controller that polls on a static interval.
6
- *
7
- * @param Base - The base class to mix onto.
8
- * @returns The composed class.
9
- */
10
- // This is a function that's used as class, and the return type is inferred from
11
- // the class defined inside the function scope, so this can't be easily typed.
12
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
13
- function StaticIntervalPollingControllerMixin(Base) {
14
- class StaticIntervalPollingController extends AbstractPollingControllerBaseMixin(Base) {
15
- // These fields are public (rather than using `#`) so that declaration
16
- // emission can describe them. Private/protected members on the class
17
- // returned by an exported mixin function trigger TS4094, and giving the
18
- // mixin an explicit return type to work around that breaks consumers
19
- // that supply the base class's own type arguments via
20
- // `StaticIntervalPollingController()<Name, State, Messenger>`. The
21
- // leading underscore signals "internal, do not use" without needing
22
- // true privacy.
23
- _intervalIds = {};
24
- _intervalLength = 1000;
25
- setIntervalLength(intervalLength) {
26
- this._intervalLength = intervalLength;
27
- }
28
- getIntervalLength() {
29
- return this._intervalLength;
30
- }
31
- _startPolling(input) {
32
- if (!this._intervalLength) {
33
- throw new Error('intervalLength must be defined and greater than 0');
34
- }
35
- const key = getKey(input);
36
- const existingInterval = this._intervalIds[key];
37
- this._stopPollingByPollingTokenSetId(key);
38
- // eslint-disable-next-line no-multi-assign
39
- const intervalId = (this._intervalIds[key] = setTimeout(
40
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
41
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
42
- async () => {
43
- try {
44
- await this._executePoll(input);
45
- }
46
- catch (error) {
47
- console.error(error);
48
- }
49
- if (intervalId === this._intervalIds[key]) {
50
- this._startPolling(input);
51
- }
52
- }, existingInterval ? this._intervalLength : 0));
53
- }
54
- _stopPollingByPollingTokenSetId(key) {
55
- const intervalId = this._intervalIds[key];
56
- if (intervalId) {
57
- clearTimeout(intervalId);
58
- delete this._intervalIds[key];
59
- }
60
- }
61
- }
62
- return StaticIntervalPollingController;
63
- }
64
- class Empty {
65
- }
66
- export const StaticIntervalPollingControllerOnly = () => StaticIntervalPollingControllerMixin(Empty);
67
- // The return type is inferred from the class defined inside the function
68
- // scope, so this can't be easily typed.
69
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
70
- export const StaticIntervalPollingController = () => StaticIntervalPollingControllerMixin(BaseController);
71
- //# sourceMappingURL=StaticIntervalPollingController.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StaticIntervalPollingController.js","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EACL,kCAAkC,EAClC,MAAM,GACP,MAAM,gCAAgC,CAAC;AAOxC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,SAAS,oCAAoC,CAG3C,IAAW;IACX,MAAe,+BACb,SAAQ,kCAAkC,CAAsB,IAAI,CAAC;QAGrE,sEAAsE;QACtE,qEAAqE;QACrE,wEAAwE;QACxE,qEAAqE;QACrE,sDAAsD;QACtD,mEAAmE;QACnE,oEAAoE;QACpE,gBAAgB;QACP,YAAY,GAA8C,EAAE,CAAC;QAEtE,eAAe,GAAuB,IAAI,CAAC;QAE3C,iBAAiB,CAAC,cAAsB;YACtC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACxC,CAAC;QAED,iBAAiB;YACf,OAAO,IAAI,CAAC,eAAe,CAAC;QAC9B,CAAC;QAED,aAAa,CAAC,KAAmB;YAC/B,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACvE,CAAC;YAED,MAAM,GAAG,GAAG,MAAM,CAAC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AAc,CACf,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController.js';\nimport type {\n Constructor,\n IPollingController,\n PollingTokenSetId,\n} from './types.js';\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 // These fields are public (rather than using `#`) so that declaration\n // emission can describe them. Private/protected members on the class\n // returned by an exported mixin function trigger TS4094, and giving the\n // mixin an explicit return type to work around that breaks consumers\n // that supply the base class's own type arguments via\n // `StaticIntervalPollingController()<Name, State, Messenger>`. The\n // leading underscore signals \"internal, do not use\" without needing\n // true privacy.\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/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { StaticIntervalPollingControllerOnly, StaticIntervalPollingController, } from './StaticIntervalPollingController.js';
2
- export { AbstractPollingControllerBaseMixin, getKey, } from './AbstractPollingController.js';
3
- export type { IPollingController, Constructor, PollingTokenSetId, } from './types.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EACnC,+BAA+B,GAChC,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,kCAAkC,EAClC,MAAM,GACP,MAAM,gCAAgC,CAAC;AAExC,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { StaticIntervalPollingControllerOnly, StaticIntervalPollingController, } from './StaticIntervalPollingController.js';
2
- export { AbstractPollingControllerBaseMixin, getKey, } from './AbstractPollingController.js';
3
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mCAAmC,EACnC,+BAA+B,GAChC,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,kCAAkC,EAClC,MAAM,GACP,MAAM,gCAAgC,CAAC","sourcesContent":["export {\n StaticIntervalPollingControllerOnly,\n StaticIntervalPollingController,\n} from './StaticIntervalPollingController.js';\n\nexport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController.js';\n\nexport type {\n IPollingController,\n Constructor,\n PollingTokenSetId,\n} from './types.js';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;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.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","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"]}