@metamask-previews/sample-controllers 5.0.6-preview-3866c0ff1 → 5.0.6-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 (72) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/index.cjs +12 -0
  3. package/dist/{index.js.map → index.cjs.map} +1 -1
  4. package/dist/{index.d.ts → index.d.cts} +10 -10
  5. package/dist/index.d.cts.map +1 -0
  6. package/dist/index.d.mts +10 -0
  7. package/dist/index.d.mts.map +1 -0
  8. package/dist/index.mjs +4 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/sample-gas-prices-controller-method-action-types.cjs +7 -0
  11. package/dist/sample-gas-prices-controller-method-action-types.cjs.map +1 -0
  12. package/dist/{sample-gas-prices-controller-method-action-types.d.ts → sample-gas-prices-controller-method-action-types.d.cts} +2 -2
  13. package/dist/sample-gas-prices-controller-method-action-types.d.cts.map +1 -0
  14. package/dist/sample-gas-prices-controller-method-action-types.d.mts +21 -0
  15. package/dist/sample-gas-prices-controller-method-action-types.d.mts.map +1 -0
  16. package/dist/{sample-gas-prices-controller-method-action-types.js → sample-gas-prices-controller-method-action-types.mjs} +1 -1
  17. package/dist/sample-gas-prices-controller-method-action-types.mjs.map +1 -0
  18. package/dist/sample-gas-prices-controller.cjs +179 -0
  19. package/dist/sample-gas-prices-controller.cjs.map +1 -0
  20. package/dist/{sample-gas-prices-controller.d.ts → sample-gas-prices-controller.d.cts} +8 -8
  21. package/dist/sample-gas-prices-controller.d.cts.map +1 -0
  22. package/dist/sample-gas-prices-controller.d.mts +184 -0
  23. package/dist/sample-gas-prices-controller.d.mts.map +1 -0
  24. package/dist/{sample-gas-prices-controller.js → sample-gas-prices-controller.mjs} +29 -22
  25. package/dist/sample-gas-prices-controller.mjs.map +1 -0
  26. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs +7 -0
  27. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.cjs.map +1 -0
  28. package/dist/sample-gas-prices-service/{sample-gas-prices-service-method-action-types.d.ts → sample-gas-prices-service-method-action-types.d.cts} +2 -2
  29. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.cts.map +1 -0
  30. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts +21 -0
  31. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.mts.map +1 -0
  32. package/dist/sample-gas-prices-service/{sample-gas-prices-service-method-action-types.js → sample-gas-prices-service-method-action-types.mjs} +1 -1
  33. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.mjs.map +1 -0
  34. package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs +121 -0
  35. package/dist/sample-gas-prices-service/sample-gas-prices-service.cjs.map +1 -0
  36. package/dist/sample-gas-prices-service/{sample-gas-prices-service.d.ts → sample-gas-prices-service.d.cts} +9 -9
  37. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.cts.map +1 -0
  38. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts +139 -0
  39. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.mts.map +1 -0
  40. package/dist/sample-gas-prices-service/{sample-gas-prices-service.js → sample-gas-prices-service.mjs} +4 -4
  41. package/dist/sample-gas-prices-service/sample-gas-prices-service.mjs.map +1 -0
  42. package/dist/sample-petnames-controller-method-action-types.cjs +7 -0
  43. package/dist/sample-petnames-controller-method-action-types.cjs.map +1 -0
  44. package/dist/{sample-petnames-controller-method-action-types.d.ts → sample-petnames-controller-method-action-types.d.cts} +2 -2
  45. package/dist/sample-petnames-controller-method-action-types.d.cts.map +1 -0
  46. package/dist/sample-petnames-controller-method-action-types.d.mts +22 -0
  47. package/dist/sample-petnames-controller-method-action-types.d.mts.map +1 -0
  48. package/dist/{sample-petnames-controller-method-action-types.js → sample-petnames-controller-method-action-types.mjs} +1 -1
  49. package/dist/sample-petnames-controller-method-action-types.mjs.map +1 -0
  50. package/dist/sample-petnames-controller.cjs +130 -0
  51. package/dist/sample-petnames-controller.cjs.map +1 -0
  52. package/dist/{sample-petnames-controller.d.ts → sample-petnames-controller.d.cts} +6 -6
  53. package/dist/sample-petnames-controller.d.cts.map +1 -0
  54. package/dist/sample-petnames-controller.d.mts +136 -0
  55. package/dist/sample-petnames-controller.d.mts.map +1 -0
  56. package/dist/{sample-petnames-controller.js → sample-petnames-controller.mjs} +5 -4
  57. package/dist/sample-petnames-controller.mjs.map +1 -0
  58. package/package.json +16 -12
  59. package/dist/index.d.ts.map +0 -1
  60. package/dist/index.js +0 -4
  61. package/dist/sample-gas-prices-controller-method-action-types.d.ts.map +0 -1
  62. package/dist/sample-gas-prices-controller-method-action-types.js.map +0 -1
  63. package/dist/sample-gas-prices-controller.d.ts.map +0 -1
  64. package/dist/sample-gas-prices-controller.js.map +0 -1
  65. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.d.ts.map +0 -1
  66. package/dist/sample-gas-prices-service/sample-gas-prices-service-method-action-types.js.map +0 -1
  67. package/dist/sample-gas-prices-service/sample-gas-prices-service.d.ts.map +0 -1
  68. package/dist/sample-gas-prices-service/sample-gas-prices-service.js.map +0 -1
  69. package/dist/sample-petnames-controller-method-action-types.d.ts.map +0 -1
  70. package/dist/sample-petnames-controller-method-action-types.js.map +0 -1
  71. package/dist/sample-petnames-controller.d.ts.map +0 -1
  72. package/dist/sample-petnames-controller.js.map +0 -1
@@ -1,4 +1,16 @@
1
- import { BaseController } from '@metamask/base-controller';
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
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ 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");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _SampleGasPricesController_instances, _SampleGasPricesController_selectedChainId, _SampleGasPricesController_onSelectedNetworkClientIdChange;
13
+ import { BaseController } from "@metamask/base-controller";
2
14
  // === GENERAL ===
3
15
  /**
4
16
  * The name of the {@link SampleGasPricesController}, used to namespace the
@@ -107,10 +119,6 @@ const MESSENGER_EXPOSED_METHODS = ['updateGasPrices'];
107
119
  * ```
108
120
  */
109
121
  export class SampleGasPricesController extends BaseController {
110
- /**
111
- * The globally selected chain ID.
112
- */
113
- #selectedChainId;
114
122
  /**
115
123
  * Constructs a new {@link SampleGasPricesController}.
116
124
  *
@@ -129,8 +137,13 @@ export class SampleGasPricesController extends BaseController {
129
137
  ...state,
130
138
  },
131
139
  });
140
+ _SampleGasPricesController_instances.add(this);
141
+ /**
142
+ * The globally selected chain ID.
143
+ */
144
+ _SampleGasPricesController_selectedChainId.set(this, void 0);
132
145
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
133
- this.messenger.subscribe('NetworkController:stateChange', this.#onSelectedNetworkClientIdChange.bind(this), (networkControllerState) => networkControllerState.selectedNetworkClientId);
146
+ this.messenger.subscribe('NetworkController:stateChange', __classPrivateFieldGet(this, _SampleGasPricesController_instances, "m", _SampleGasPricesController_onSelectedNetworkClientIdChange).bind(this), (networkControllerState) => networkControllerState.selectedNetworkClientId);
134
147
  }
135
148
  /**
136
149
  * Fetches the latest gas prices for the given chain and persists them to
@@ -148,20 +161,14 @@ export class SampleGasPricesController extends BaseController {
148
161
  };
149
162
  });
150
163
  }
151
- /**
152
- * Callback to call when the globally selected network client ID changes,
153
- * ensuring that gas prices get updated.
154
- *
155
- * @param selectedNetworkClientId - The globally selected network client ID.
156
- */
157
- #onSelectedNetworkClientIdChange(selectedNetworkClientId) {
158
- const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
159
- if (chainId !== this.#selectedChainId) {
160
- this.#selectedChainId = chainId;
161
- this.updateGasPrices({ chainId }).catch((error) => {
162
- this.messenger.captureException?.(error);
163
- });
164
- }
165
- }
166
164
  }
167
- //# sourceMappingURL=sample-gas-prices-controller.js.map
165
+ _SampleGasPricesController_selectedChainId = new WeakMap(), _SampleGasPricesController_instances = new WeakSet(), _SampleGasPricesController_onSelectedNetworkClientIdChange = function _SampleGasPricesController_onSelectedNetworkClientIdChange(selectedNetworkClientId) {
166
+ const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
167
+ if (chainId !== __classPrivateFieldGet(this, _SampleGasPricesController_selectedChainId, "f")) {
168
+ __classPrivateFieldSet(this, _SampleGasPricesController_selectedChainId, chainId, "f");
169
+ this.updateGasPrices({ chainId }).catch((error) => {
170
+ this.messenger.captureException?.(error);
171
+ });
172
+ }
173
+ };
174
+ //# sourceMappingURL=sample-gas-prices-controller.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-controller.mjs","sourceRoot":"","sources":["../src/sample-gas-prices-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAY3D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAsCpD;;GAEG;AACH,MAAM,2BAA2B,GAAG;IAClC,kBAAkB,EAAE;QAClB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;CACsD,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,UAAU,wCAAwC;IACtD,OAAO;QACL,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aAAa,EAAE,EAAE,OAAO,EAAE,GAC3B,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACrB,wCAAwC,EACxC,uBAAuB,CACxB,CAAC;IAEF,IAAI,OAAO,KAAK,uBAAA,IAAI,kDAAiB,EAAE,CAAC;QACtC,uBAAA,IAAI,8CAAoB,OAAO,MAAA,CAAC;QAChC,IAAI,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAChD,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { SampleGasPricesControllerMethodActions } from './sample-gas-prices-controller-method-action-types.js';\nimport type { SampleGasPricesServiceFetchGasPricesAction } from './sample-gas-prices-service/sample-gas-prices-service-method-action-types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link SampleGasPricesController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nconst CONTROLLER_NAME = 'SampleGasPricesController';\n\n// === STATE ===\n\n/**\n * The collection of gas price data fetched periodically.\n */\ntype GasPrices = {\n /**\n * The total estimated gas in the \"low\" bucket.\n */\n low: number;\n /**\n * The total estimated gas in the \"average\" bucket.\n */\n average: number;\n /**\n * The total estimated gas in the \"high\" bucket.\n */\n high: number;\n /**\n * The date/time (in ISO-8601 format) when prices were fetched.\n */\n fetchedDate: string;\n};\n\n/**\n * Describes the shape of the state object for {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerState = {\n /**\n * Fetched gas prices categorized by chain ID.\n */\n gasPricesByChainId: {\n [chainId: Hex]: GasPrices;\n };\n};\n\n/**\n * The metadata for each property in {@link SampleGasPricesControllerState}.\n */\nconst gasPricesControllerMetadata = {\n gasPricesByChainId: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<SampleGasPricesControllerState>;\n\n/**\n * Constructs the default {@link SampleGasPricesController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link SampleGasPricesController} state.\n */\nexport function getDefaultSampleGasPricesControllerState(): SampleGasPricesControllerState {\n return {\n gasPricesByChainId: {},\n };\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['updateGasPrices'] as const;\n\n/**\n * Retrieves the state of the {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n SampleGasPricesControllerState\n>;\n\n/**\n * Actions that {@link SampleGasPricesMessenger} exposes to other consumers.\n */\nexport type SampleGasPricesControllerActions =\n | SampleGasPricesControllerGetStateAction\n | SampleGasPricesControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link SampleGasPricesMessenger} calls.\n */\ntype AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | SampleGasPricesServiceFetchGasPricesAction;\n\n/**\n * Published when the state of {@link SampleGasPricesController} changes.\n */\nexport type SampleGasPricesControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n SampleGasPricesControllerState\n >;\n\n/**\n * Events that {@link SampleGasPricesMessenger} exposes to other consumers.\n */\nexport type SampleGasPricesControllerEvents =\n SampleGasPricesControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link SampleGasPricesMessenger} subscribes\n * to.\n */\ntype AllowedEvents = NetworkControllerStateChangeEvent;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link SampleGasPricesController}.\n */\nexport type SampleGasPricesControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n SampleGasPricesControllerActions | AllowedActions,\n SampleGasPricesControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `SampleGasPricesController` fetches and persists gas prices for various chains.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * NetworkControllerActions,\n * NetworkControllerEvents,\n * } from '@metamask/network-controller';\n * import type {\n * SampleGasPricesControllerActions,\n * SampleGasPricesControllerEvents,\n * SampleGasPricesServiceActions,\n * SampleGasPricesServiceEvents,\n * } from '@metamask/sample-controllers';\n * import {\n * SampleGasPricesController,\n * SampleGasPricesService,\n * selectGasPrices,\n * } from '@metamask/sample-controllers';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * SampleGasPricesServiceActions\n * | SampleGasPricesControllerActions\n * | NetworkControllerActions,\n * SampleGasPricesServiceEvents\n * | SampleGasPricesControllerEvents\n * | NetworkControllerEvents\n * >({ namespace: 'Root' });\n * const gasPricesServiceMessenger = new Messenger<\n * 'SampleGasPricesService',\n * SampleGasPricesServiceActions,\n * SampleGasPricesServiceEvents,\n * typeof rootMessenger,\n * >({\n * namespace: 'SampleGasPricesService',\n * parent: rootMessenger,\n * });\n * // Instantiate the service to register its actions on the messenger\n * new SampleGasPricesService({\n * messenger: gasPricesServiceMessenger,\n * // We assume you're using this in the browser.\n * fetch,\n * });\n * const gasPricesControllerMessenger = new Messenger<\n * 'SampleGasPricesController',\n * SampleGasPricesControllerActions | NetworkControllerGetNetworkClientByIdAction,\n * SampleGasPricesControllerEvents | NetworkControllerStateChangeEvent,\n * typeof rootMessenger,\n * >({\n * namespace: 'SampleGasPricesController',\n * parent: rootMessenger,\n * });\n * // Instantiate the controller to register its actions on the messenger\n * new SampleGasPricesController({\n * messenger: gasPricesControllerMessenger,\n * });\n *\n * // Later...\n * await rootMessenger.call(\n * 'SampleGasPricesController:updateGasPrices',\n * { chainId: '0x42' },\n * );\n * const gasPricesControllerState = await rootMessenger.call(\n * 'SampleGasPricesController:getState',\n * );\n * gasPricesControllerState.gasPricesByChainId\n * // => { '0x42': { low: 5, average: 10, high: 15, fetchedDate: '2024-01-02T00:00:00.000Z' } }\n * ```\n */\nexport class SampleGasPricesController extends BaseController<\n typeof CONTROLLER_NAME,\n SampleGasPricesControllerState,\n SampleGasPricesControllerMessenger\n> {\n /**\n * The globally selected chain ID.\n */\n #selectedChainId: Hex | undefined;\n\n /**\n * Constructs a new {@link SampleGasPricesController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to initialize this\n * controller. Missing properties will be filled in with defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: SampleGasPricesControllerMessenger;\n state?: Partial<SampleGasPricesControllerState>;\n }) {\n super({\n messenger,\n metadata: gasPricesControllerMetadata,\n name: CONTROLLER_NAME,\n state: {\n ...getDefaultSampleGasPricesControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.messenger.subscribe(\n 'NetworkController:stateChange',\n this.#onSelectedNetworkClientIdChange.bind(this),\n (networkControllerState) =>\n networkControllerState.selectedNetworkClientId,\n );\n }\n\n /**\n * Fetches the latest gas prices for the given chain and persists them to\n * state.\n *\n * @param args - The arguments to the function.\n * @param args.chainId - The chain ID for which to fetch gas prices.\n */\n async updateGasPrices({ chainId }: { chainId: Hex }): Promise<void> {\n const gasPricesResponse = await this.messenger.call(\n 'SampleGasPricesService:fetchGasPrices',\n chainId,\n );\n\n this.update((state) => {\n state.gasPricesByChainId[chainId] = {\n ...gasPricesResponse,\n fetchedDate: new Date().toISOString(),\n };\n });\n }\n\n /**\n * Callback to call when the globally selected network client ID changes,\n * ensuring that gas prices get updated.\n *\n * @param selectedNetworkClientId - The globally selected network client ID.\n */\n #onSelectedNetworkClientIdChange(\n selectedNetworkClientId: NetworkClientId,\n ): void {\n const {\n configuration: { chainId },\n } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n if (chainId !== this.#selectedChainId) {\n this.#selectedChainId = chainId;\n this.updateGasPrices({ chainId }).catch((error) => {\n this.messenger.captureException?.(error);\n });\n }\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=sample-gas-prices-service-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-service-method-action-types.cjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SampleGasPricesService } from './sample-gas-prices-service.js';\n\n/**\n * Makes a request to the API in order to retrieve gas prices for a particular\n * chain.\n *\n * @param chainId - The chain ID for which you want to fetch gas prices.\n * @returns The gas prices for the given chain.\n */\nexport type SampleGasPricesServiceFetchGasPricesAction = {\n type: `SampleGasPricesService:fetchGasPrices`;\n handler: SampleGasPricesService['fetchGasPrices'];\n};\n\n/**\n * Union of all SampleGasPricesService action types.\n */\nexport type SampleGasPricesServiceMethodActions =\n SampleGasPricesServiceFetchGasPricesAction;\n"]}
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { SampleGasPricesService } from './sample-gas-prices-service.js';
5
+ import type { SampleGasPricesService } from "./sample-gas-prices-service.cjs";
6
6
  /**
7
7
  * Makes a request to the API in order to retrieve gas prices for a particular
8
8
  * chain.
@@ -18,4 +18,4 @@ export type SampleGasPricesServiceFetchGasPricesAction = {
18
18
  * Union of all SampleGasPricesService action types.
19
19
  */
20
20
  export type SampleGasPricesServiceMethodActions = SampleGasPricesServiceFetchGasPricesAction;
21
- //# sourceMappingURL=sample-gas-prices-service-method-action-types.d.ts.map
21
+ //# sourceMappingURL=sample-gas-prices-service-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-service-method-action-types.d.cts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAuC;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC7C,0CAA0C,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { SampleGasPricesService } from "./sample-gas-prices-service.mjs";
6
+ /**
7
+ * Makes a request to the API in order to retrieve gas prices for a particular
8
+ * chain.
9
+ *
10
+ * @param chainId - The chain ID for which you want to fetch gas prices.
11
+ * @returns The gas prices for the given chain.
12
+ */
13
+ export type SampleGasPricesServiceFetchGasPricesAction = {
14
+ type: `SampleGasPricesService:fetchGasPrices`;
15
+ handler: SampleGasPricesService['fetchGasPrices'];
16
+ };
17
+ /**
18
+ * Union of all SampleGasPricesService action types.
19
+ */
20
+ export type SampleGasPricesServiceMethodActions = SampleGasPricesServiceFetchGasPricesAction;
21
+ //# sourceMappingURL=sample-gas-prices-service-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-service-method-action-types.d.mts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAuC;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC7C,0CAA0C,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=sample-gas-prices-service-method-action-types.js.map
6
+ //# sourceMappingURL=sample-gas-prices-service-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-service-method-action-types.mjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SampleGasPricesService } from './sample-gas-prices-service.js';\n\n/**\n * Makes a request to the API in order to retrieve gas prices for a particular\n * chain.\n *\n * @param chainId - The chain ID for which you want to fetch gas prices.\n * @returns The gas prices for the given chain.\n */\nexport type SampleGasPricesServiceFetchGasPricesAction = {\n type: `SampleGasPricesService:fetchGasPrices`;\n handler: SampleGasPricesService['fetchGasPrices'];\n};\n\n/**\n * Union of all SampleGasPricesService action types.\n */\nexport type SampleGasPricesServiceMethodActions =\n SampleGasPricesServiceFetchGasPricesAction;\n"]}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SampleGasPricesService = exports.serviceName = void 0;
4
+ const base_data_service_1 = require("@metamask/base-data-service");
5
+ const controller_utils_1 = require("@metamask/controller-utils");
6
+ const superstruct_1 = require("@metamask/superstruct");
7
+ // === GENERAL ===
8
+ /**
9
+ * The name of the {@link SampleGasPricesService}, used to namespace the
10
+ * service's actions and events.
11
+ */
12
+ exports.serviceName = 'SampleGasPricesService';
13
+ // === MESSENGER ===
14
+ /**
15
+ * All of the methods within {@link SampleGasPricesService} that are exposed via
16
+ * the messenger.
17
+ */
18
+ const MESSENGER_EXPOSED_METHODS = ['fetchGasPrices'];
19
+ // === SERVICE DEFINITION ===
20
+ /**
21
+ * Struct to validate what the API endpoint returns.
22
+ */
23
+ const GasPricesResponseStruct = (0, superstruct_1.type)({
24
+ data: (0, superstruct_1.type)({
25
+ low: (0, superstruct_1.number)(),
26
+ average: (0, superstruct_1.number)(),
27
+ high: (0, superstruct_1.number)(),
28
+ }),
29
+ });
30
+ /**
31
+ * The base URL of the API that the service represents.
32
+ */
33
+ const BASE_URL = 'https://api.example.com';
34
+ /**
35
+ * This service object is responsible for fetching gas prices via an API.
36
+ *
37
+ * @example
38
+ *
39
+ * ``` ts
40
+ * import type { MessengerActions, MessengerEvents } from '@metamask/messenger';
41
+ * import { Messenger } from '@metamask/messenger';
42
+ * import type {
43
+ * SampleGasPricesServiceMessenger,
44
+ * } from '@metamask/sample-controllers';
45
+ *
46
+ * const rootMessenger = new Messenger<
47
+ * 'Root',
48
+ * SampleGasPricesServiceActions
49
+ * SampleGasPricesServiceEvents
50
+ * >({ namespace: 'Root' });
51
+ * const gasPricesServiceMessenger = new Messenger<
52
+ * 'SampleGasPricesService',
53
+ * MessengerActions<SampleGasPricesServiceMessenger>,
54
+ * MessengerEvents<SampleGasPricesServiceMessenger>,
55
+ * typeof rootMessenger,
56
+ * >({
57
+ * namespace: 'SampleGasPricesService',
58
+ * parent: rootMessenger,
59
+ * });
60
+ * // Instantiate the service to register its actions on the messenger
61
+ * new SampleGasPricesService({
62
+ * messenger: gasPricesServiceMessenger,
63
+ * });
64
+ *
65
+ * // Later...
66
+ * // Fetch gas prices for Mainnet
67
+ * const gasPrices = await rootMessenger.call(
68
+ * 'SampleGasPricesService:fetchGasPrices',
69
+ * '0x1',
70
+ * );
71
+ * // ... Do something with the gas prices ...
72
+ * ```
73
+ */
74
+ class SampleGasPricesService extends base_data_service_1.BaseDataService {
75
+ /**
76
+ * Constructs a new SampleGasPricesService object.
77
+ *
78
+ * @param args - The constructor arguments.
79
+ * @param args.messenger - The messenger suited for this service.
80
+ * @param args.queryClientConfig - Configuration for the underlying TanStack
81
+ * Query client.
82
+ * @param args.policyOptions - Options to pass to `createServicePolicy`, which
83
+ * is used to wrap each request. See {@link CreateServicePolicyOptions}.
84
+ */
85
+ constructor({ messenger, queryClientConfig = {}, policyOptions = {}, }) {
86
+ super({
87
+ name: exports.serviceName,
88
+ messenger,
89
+ queryClientConfig,
90
+ policyOptions,
91
+ });
92
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
93
+ }
94
+ /**
95
+ * Makes a request to the API in order to retrieve gas prices for a particular
96
+ * chain.
97
+ *
98
+ * @param chainId - The chain ID for which you want to fetch gas prices.
99
+ * @returns The gas prices for the given chain.
100
+ */
101
+ async fetchGasPrices(chainId) {
102
+ const url = new URL('/gas-prices', BASE_URL);
103
+ url.searchParams.append('chainId', `eip155:${(0, controller_utils_1.fromHex)(chainId).toString()}`);
104
+ const jsonResponse = await this.fetchQuery({
105
+ queryKey: [`${this.name}:fetchGasPrices`, chainId],
106
+ queryFn: async () => {
107
+ const response = await fetch(url);
108
+ if (!response.ok) {
109
+ throw new controller_utils_1.HttpError(response.status, `Gas prices API failed with status '${response.status}'`);
110
+ }
111
+ return response.json();
112
+ },
113
+ });
114
+ if (!(0, superstruct_1.is)(jsonResponse, GasPricesResponseStruct)) {
115
+ throw new Error('Malformed response received from gas prices API');
116
+ }
117
+ return jsonResponse.data;
118
+ }
119
+ }
120
+ exports.SampleGasPricesService = SampleGasPricesService;
121
+ //# sourceMappingURL=sample-gas-prices-service.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-service.cjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":";;;AAAA,mEAA8D;AAO9D,iEAAgE;AAGhE,uDAAyD;AAMzD,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,wBAAwB,CAAC;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GAAG,CAAC,CAAC;gBAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,4BAAS,CACjB,QAAQ,CAAC,MAAM,EACf,sCAAsC,QAAQ,CAAC,MAAM,GAAG,CACzD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,IAAA,gBAAE,EAAC,YAAY,EAAE,uBAAuB,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF;AArED,wDAqEC","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError, fromHex } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Infer } from '@metamask/superstruct';\nimport { is, number, type } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { SampleGasPricesServiceMethodActions } from './sample-gas-prices-service-method-action-types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link SampleGasPricesService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'SampleGasPricesService';\n\n// === MESSENGER ===\n\n/**\n * All of the methods within {@link SampleGasPricesService} that are exposed via\n * the messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = ['fetchGasPrices'] as const;\n\n/**\n * Invalidates cached queries for {@link SampleGasPricesService}.\n */\nexport type SampleGasPricesServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link SampleGasPricesService} exposes to other consumers.\n */\nexport type SampleGasPricesServiceActions =\n | SampleGasPricesServiceMethodActions\n | SampleGasPricesServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link SampleGasPricesService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when {@link SampleGasPricesService}'s cache is updated.\n */\nexport type SampleGasPricesServiceCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link SampleGasPricesService}'s cache is\n * updated.\n */\nexport type SampleGasPricesServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link SampleGasPricesService} exposes to other consumers.\n */\nexport type SampleGasPricesServiceEvents =\n | SampleGasPricesServiceCacheUpdatedEvent\n | SampleGasPricesServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link SampleGasPricesService} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link SampleGasPricesService}.\n */\nexport type SampleGasPricesServiceMessenger = Messenger<\n typeof serviceName,\n SampleGasPricesServiceActions | AllowedActions,\n SampleGasPricesServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Struct to validate what the API endpoint returns.\n */\nconst GasPricesResponseStruct = type({\n data: type({\n low: number(),\n average: number(),\n high: number(),\n }),\n});\n\n/**\n * What the API endpoint returns.\n */\ntype GasPricesResponse = Infer<typeof GasPricesResponseStruct>;\n\n/**\n * The base URL of the API that the service represents.\n */\nconst BASE_URL = 'https://api.example.com';\n\n/**\n * This service object is responsible for fetching gas prices via an API.\n *\n * @example\n *\n * ``` ts\n * import type { MessengerActions, MessengerEvents } from '@metamask/messenger';\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * SampleGasPricesServiceMessenger,\n * } from '@metamask/sample-controllers';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * SampleGasPricesServiceActions\n * SampleGasPricesServiceEvents\n * >({ namespace: 'Root' });\n * const gasPricesServiceMessenger = new Messenger<\n * 'SampleGasPricesService',\n * MessengerActions<SampleGasPricesServiceMessenger>,\n * MessengerEvents<SampleGasPricesServiceMessenger>,\n * typeof rootMessenger,\n * >({\n * namespace: 'SampleGasPricesService',\n * parent: rootMessenger,\n * });\n * // Instantiate the service to register its actions on the messenger\n * new SampleGasPricesService({\n * messenger: gasPricesServiceMessenger,\n * });\n *\n * // Later...\n * // Fetch gas prices for Mainnet\n * const gasPrices = await rootMessenger.call(\n * 'SampleGasPricesService:fetchGasPrices',\n * '0x1',\n * );\n * // ... Do something with the gas prices ...\n * ```\n */\nexport class SampleGasPricesService extends BaseDataService<\n typeof serviceName,\n SampleGasPricesServiceMessenger\n> {\n /**\n * Constructs a new SampleGasPricesService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.queryClientConfig - Configuration for the underlying TanStack\n * Query client.\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n queryClientConfig = {},\n policyOptions = {},\n }: {\n messenger: SampleGasPricesServiceMessenger;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions,\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Makes a request to the API in order to retrieve gas prices for a particular\n * chain.\n *\n * @param chainId - The chain ID for which you want to fetch gas prices.\n * @returns The gas prices for the given chain.\n */\n async fetchGasPrices(chainId: Hex): Promise<GasPricesResponse['data']> {\n const url = new URL('/gas-prices', BASE_URL);\n url.searchParams.append('chainId', `eip155:${fromHex(chainId).toString()}`);\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchGasPrices`, chainId],\n queryFn: async () => {\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Gas prices API failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n if (!is(jsonResponse, GasPricesResponseStruct)) {\n throw new Error('Malformed response received from gas prices API');\n }\n\n return jsonResponse.data;\n }\n}\n"]}
@@ -1,11 +1,11 @@
1
- import { BaseDataService } from '@metamask/base-data-service';
2
- import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from '@metamask/base-data-service';
3
- import type { CreateServicePolicyOptions } from '@metamask/controller-utils';
4
- import type { Messenger } from '@metamask/messenger';
5
- import type { Infer } from '@metamask/superstruct';
6
- import type { Hex } from '@metamask/utils';
7
- import type { QueryClientConfig } from '@tanstack/query-core';
8
- import type { SampleGasPricesServiceMethodActions } from './sample-gas-prices-service-method-action-types.js';
1
+ import { BaseDataService } from "@metamask/base-data-service";
2
+ import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from "@metamask/base-data-service";
3
+ import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
4
+ import type { Messenger } from "@metamask/messenger";
5
+ import type { Infer } from "@metamask/superstruct";
6
+ import type { Hex } from "@metamask/utils";
7
+ import type { QueryClientConfig } from "@tanstack/query-core";
8
+ import type { SampleGasPricesServiceMethodActions } from "./sample-gas-prices-service-method-action-types.cjs";
9
9
  /**
10
10
  * The name of the {@link SampleGasPricesService}, used to namespace the
11
11
  * service's actions and events.
@@ -136,4 +136,4 @@ export declare class SampleGasPricesService extends BaseDataService<typeof servi
136
136
  fetchGasPrices(chainId: Hex): Promise<GasPricesResponse['data']>;
137
137
  }
138
138
  export {};
139
- //# sourceMappingURL=sample-gas-prices-service.d.ts.map
139
+ //# sourceMappingURL=sample-gas-prices-service.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-service.d.cts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,E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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,sBAAuB,SAAQ,eAAe,CACzD,OAAO,WAAW,EAClB,+BAA+B,CAChC;IACC;;;;;;;;;OASG;gBACS,EACV,SAAS,EACT,iBAAsB,EACtB,aAAkB,GACnB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;QACtC,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C;IAcD;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CA0BvE"}
@@ -0,0 +1,139 @@
1
+ import { BaseDataService } from "@metamask/base-data-service";
2
+ import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from "@metamask/base-data-service";
3
+ import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
4
+ import type { Messenger } from "@metamask/messenger";
5
+ import type { Infer } from "@metamask/superstruct";
6
+ import type { Hex } from "@metamask/utils";
7
+ import type { QueryClientConfig } from "@tanstack/query-core";
8
+ import type { SampleGasPricesServiceMethodActions } from "./sample-gas-prices-service-method-action-types.mjs";
9
+ /**
10
+ * The name of the {@link SampleGasPricesService}, used to namespace the
11
+ * service's actions and events.
12
+ */
13
+ export declare const serviceName = "SampleGasPricesService";
14
+ /**
15
+ * Invalidates cached queries for {@link SampleGasPricesService}.
16
+ */
17
+ export type SampleGasPricesServiceInvalidateQueriesAction = DataServiceInvalidateQueriesAction<typeof serviceName>;
18
+ /**
19
+ * Actions that {@link SampleGasPricesService} exposes to other consumers.
20
+ */
21
+ export type SampleGasPricesServiceActions = SampleGasPricesServiceMethodActions | SampleGasPricesServiceInvalidateQueriesAction;
22
+ /**
23
+ * Actions from other messengers that {@link SampleGasPricesService} calls.
24
+ */
25
+ type AllowedActions = never;
26
+ /**
27
+ * Published when {@link SampleGasPricesService}'s cache is updated.
28
+ */
29
+ export type SampleGasPricesServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<typeof serviceName>;
30
+ /**
31
+ * Published when a key within {@link SampleGasPricesService}'s cache is
32
+ * updated.
33
+ */
34
+ export type SampleGasPricesServiceGranularCacheUpdatedEvent = DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
35
+ /**
36
+ * Events that {@link SampleGasPricesService} exposes to other consumers.
37
+ */
38
+ export type SampleGasPricesServiceEvents = SampleGasPricesServiceCacheUpdatedEvent | SampleGasPricesServiceGranularCacheUpdatedEvent;
39
+ /**
40
+ * Events from other messengers that {@link SampleGasPricesService} subscribes
41
+ * to.
42
+ */
43
+ type AllowedEvents = never;
44
+ /**
45
+ * The messenger which is restricted to actions and events accessed by
46
+ * {@link SampleGasPricesService}.
47
+ */
48
+ export type SampleGasPricesServiceMessenger = Messenger<typeof serviceName, SampleGasPricesServiceActions | AllowedActions, SampleGasPricesServiceEvents | AllowedEvents>;
49
+ /**
50
+ * Struct to validate what the API endpoint returns.
51
+ */
52
+ declare const GasPricesResponseStruct: import("@metamask/superstruct").Struct<{
53
+ data: {
54
+ low: number;
55
+ average: number;
56
+ high: number;
57
+ };
58
+ }, {
59
+ data: import("@metamask/superstruct").Struct<{
60
+ low: number;
61
+ average: number;
62
+ high: number;
63
+ }, {
64
+ low: import("@metamask/superstruct").Struct<number, null>;
65
+ average: import("@metamask/superstruct").Struct<number, null>;
66
+ high: import("@metamask/superstruct").Struct<number, null>;
67
+ }>;
68
+ }>;
69
+ /**
70
+ * What the API endpoint returns.
71
+ */
72
+ type GasPricesResponse = Infer<typeof GasPricesResponseStruct>;
73
+ /**
74
+ * This service object is responsible for fetching gas prices via an API.
75
+ *
76
+ * @example
77
+ *
78
+ * ``` ts
79
+ * import type { MessengerActions, MessengerEvents } from '@metamask/messenger';
80
+ * import { Messenger } from '@metamask/messenger';
81
+ * import type {
82
+ * SampleGasPricesServiceMessenger,
83
+ * } from '@metamask/sample-controllers';
84
+ *
85
+ * const rootMessenger = new Messenger<
86
+ * 'Root',
87
+ * SampleGasPricesServiceActions
88
+ * SampleGasPricesServiceEvents
89
+ * >({ namespace: 'Root' });
90
+ * const gasPricesServiceMessenger = new Messenger<
91
+ * 'SampleGasPricesService',
92
+ * MessengerActions<SampleGasPricesServiceMessenger>,
93
+ * MessengerEvents<SampleGasPricesServiceMessenger>,
94
+ * typeof rootMessenger,
95
+ * >({
96
+ * namespace: 'SampleGasPricesService',
97
+ * parent: rootMessenger,
98
+ * });
99
+ * // Instantiate the service to register its actions on the messenger
100
+ * new SampleGasPricesService({
101
+ * messenger: gasPricesServiceMessenger,
102
+ * });
103
+ *
104
+ * // Later...
105
+ * // Fetch gas prices for Mainnet
106
+ * const gasPrices = await rootMessenger.call(
107
+ * 'SampleGasPricesService:fetchGasPrices',
108
+ * '0x1',
109
+ * );
110
+ * // ... Do something with the gas prices ...
111
+ * ```
112
+ */
113
+ export declare class SampleGasPricesService extends BaseDataService<typeof serviceName, SampleGasPricesServiceMessenger> {
114
+ /**
115
+ * Constructs a new SampleGasPricesService object.
116
+ *
117
+ * @param args - The constructor arguments.
118
+ * @param args.messenger - The messenger suited for this service.
119
+ * @param args.queryClientConfig - Configuration for the underlying TanStack
120
+ * Query client.
121
+ * @param args.policyOptions - Options to pass to `createServicePolicy`, which
122
+ * is used to wrap each request. See {@link CreateServicePolicyOptions}.
123
+ */
124
+ constructor({ messenger, queryClientConfig, policyOptions, }: {
125
+ messenger: SampleGasPricesServiceMessenger;
126
+ queryClientConfig?: QueryClientConfig;
127
+ policyOptions?: CreateServicePolicyOptions;
128
+ });
129
+ /**
130
+ * Makes a request to the API in order to retrieve gas prices for a particular
131
+ * chain.
132
+ *
133
+ * @param chainId - The chain ID for which you want to fetch gas prices.
134
+ * @returns The gas prices for the given chain.
135
+ */
136
+ fetchGasPrices(chainId: Hex): Promise<GasPricesResponse['data']>;
137
+ }
138
+ export {};
139
+ //# sourceMappingURL=sample-gas-prices-service.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-service.d.mts","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B;AAE9D,OAAO,KAAK,EAAE,mCAAmC,EAAE,4DAA2D;AAI9G;;;GAGG;AACH,eAAO,MAAM,WAAW,2BAA2B,CAAC;AAUpD;;GAEG;AACH,MAAM,MAAM,6CAA6C,GACvD,kCAAkC,CAAC,OAAO,WAAW,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,mCAAmC,GACnC,6CAA6C,CAAC;AAElD;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,uCAAuC,GACjD,4BAA4B,CAAC,OAAO,WAAW,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,+CAA+C,GACzD,oCAAoC,CAAC,OAAO,WAAW,CAAC,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACpC,uCAAuC,GACvC,+CAA+C,CAAC;AAEpD;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,WAAW,EAClB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC;AAIF;;GAEG;AACH,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;;;EAM3B,CAAC;AAEH;;GAEG;AACH,KAAK,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAO/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,sBAAuB,SAAQ,eAAe,CACzD,OAAO,WAAW,EAClB,+BAA+B,CAChC;IACC;;;;;;;;;OASG;gBACS,EACV,SAAS,EACT,iBAAsB,EACtB,aAAkB,GACnB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;QACtC,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C;IAcD;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CA0BvE"}
@@ -1,6 +1,6 @@
1
- import { BaseDataService } from '@metamask/base-data-service';
2
- import { HttpError, fromHex } from '@metamask/controller-utils';
3
- import { is, number, type } from '@metamask/superstruct';
1
+ import { BaseDataService } from "@metamask/base-data-service";
2
+ import { HttpError, fromHex } from "@metamask/controller-utils";
3
+ import { is, number, type } from "@metamask/superstruct";
4
4
  // === GENERAL ===
5
5
  /**
6
6
  * The name of the {@link SampleGasPricesService}, used to namespace the
@@ -114,4 +114,4 @@ export class SampleGasPricesService extends BaseDataService {
114
114
  return jsonResponse.data;
115
115
  }
116
116
  }
117
- //# sourceMappingURL=sample-gas-prices-service.js.map
117
+ //# sourceMappingURL=sample-gas-prices-service.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-gas-prices-service.mjs","sourceRoot":"","sources":["../../src/sample-gas-prices-service/sample-gas-prices-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAO9D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,mCAAmC;AAGhE,OAAO,EAAE,EAAE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AClD,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;gBAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,SAAS,CACjB,QAAQ,CAAC,MAAM,EACf,sCAAsC,QAAQ,CAAC,MAAM,GAAG,CACzD,CAAC;gBACJ,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,uBAAuB,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError, fromHex } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Infer } from '@metamask/superstruct';\nimport { is, number, type } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport type { QueryClientConfig } from '@tanstack/query-core';\n\nimport type { SampleGasPricesServiceMethodActions } from './sample-gas-prices-service-method-action-types.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link SampleGasPricesService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'SampleGasPricesService';\n\n// === MESSENGER ===\n\n/**\n * All of the methods within {@link SampleGasPricesService} that are exposed via\n * the messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = ['fetchGasPrices'] as const;\n\n/**\n * Invalidates cached queries for {@link SampleGasPricesService}.\n */\nexport type SampleGasPricesServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link SampleGasPricesService} exposes to other consumers.\n */\nexport type SampleGasPricesServiceActions =\n | SampleGasPricesServiceMethodActions\n | SampleGasPricesServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link SampleGasPricesService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when {@link SampleGasPricesService}'s cache is updated.\n */\nexport type SampleGasPricesServiceCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link SampleGasPricesService}'s cache is\n * updated.\n */\nexport type SampleGasPricesServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link SampleGasPricesService} exposes to other consumers.\n */\nexport type SampleGasPricesServiceEvents =\n | SampleGasPricesServiceCacheUpdatedEvent\n | SampleGasPricesServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link SampleGasPricesService} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link SampleGasPricesService}.\n */\nexport type SampleGasPricesServiceMessenger = Messenger<\n typeof serviceName,\n SampleGasPricesServiceActions | AllowedActions,\n SampleGasPricesServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Struct to validate what the API endpoint returns.\n */\nconst GasPricesResponseStruct = type({\n data: type({\n low: number(),\n average: number(),\n high: number(),\n }),\n});\n\n/**\n * What the API endpoint returns.\n */\ntype GasPricesResponse = Infer<typeof GasPricesResponseStruct>;\n\n/**\n * The base URL of the API that the service represents.\n */\nconst BASE_URL = 'https://api.example.com';\n\n/**\n * This service object is responsible for fetching gas prices via an API.\n *\n * @example\n *\n * ``` ts\n * import type { MessengerActions, MessengerEvents } from '@metamask/messenger';\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * SampleGasPricesServiceMessenger,\n * } from '@metamask/sample-controllers';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * SampleGasPricesServiceActions\n * SampleGasPricesServiceEvents\n * >({ namespace: 'Root' });\n * const gasPricesServiceMessenger = new Messenger<\n * 'SampleGasPricesService',\n * MessengerActions<SampleGasPricesServiceMessenger>,\n * MessengerEvents<SampleGasPricesServiceMessenger>,\n * typeof rootMessenger,\n * >({\n * namespace: 'SampleGasPricesService',\n * parent: rootMessenger,\n * });\n * // Instantiate the service to register its actions on the messenger\n * new SampleGasPricesService({\n * messenger: gasPricesServiceMessenger,\n * });\n *\n * // Later...\n * // Fetch gas prices for Mainnet\n * const gasPrices = await rootMessenger.call(\n * 'SampleGasPricesService:fetchGasPrices',\n * '0x1',\n * );\n * // ... Do something with the gas prices ...\n * ```\n */\nexport class SampleGasPricesService extends BaseDataService<\n typeof serviceName,\n SampleGasPricesServiceMessenger\n> {\n /**\n * Constructs a new SampleGasPricesService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.queryClientConfig - Configuration for the underlying TanStack\n * Query client.\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n queryClientConfig = {},\n policyOptions = {},\n }: {\n messenger: SampleGasPricesServiceMessenger;\n queryClientConfig?: QueryClientConfig;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({\n name: serviceName,\n messenger,\n queryClientConfig,\n policyOptions,\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Makes a request to the API in order to retrieve gas prices for a particular\n * chain.\n *\n * @param chainId - The chain ID for which you want to fetch gas prices.\n * @returns The gas prices for the given chain.\n */\n async fetchGasPrices(chainId: Hex): Promise<GasPricesResponse['data']> {\n const url = new URL('/gas-prices', BASE_URL);\n url.searchParams.append('chainId', `eip155:${fromHex(chainId).toString()}`);\n\n const jsonResponse = await this.fetchQuery({\n queryKey: [`${this.name}:fetchGasPrices`, chainId],\n queryFn: async () => {\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Gas prices API failed with status '${response.status}'`,\n );\n }\n\n return response.json();\n },\n });\n\n if (!is(jsonResponse, GasPricesResponseStruct)) {\n throw new Error('Malformed response received from gas prices API');\n }\n\n return jsonResponse.data;\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=sample-petnames-controller-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-petnames-controller-method-action-types.cjs","sourceRoot":"","sources":["../src/sample-petnames-controller-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SamplePetnamesController } from './sample-petnames-controller.js';\n\n/**\n * Registers the given name with the given address (relative to the given\n * chain).\n *\n * @param chainId - The chain ID that the address belongs to.\n * @param address - The account address to name.\n * @param name - The name to assign to the address.\n */\nexport type SamplePetnamesControllerAssignPetnameAction = {\n type: `SamplePetnamesController:assignPetname`;\n handler: SamplePetnamesController['assignPetname'];\n};\n\n/**\n * Union of all SamplePetnamesController action types.\n */\nexport type SamplePetnamesControllerMethodActions =\n SamplePetnamesControllerAssignPetnameAction;\n"]}
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { SamplePetnamesController } from './sample-petnames-controller.js';
5
+ import type { SamplePetnamesController } from "./sample-petnames-controller.cjs";
6
6
  /**
7
7
  * Registers the given name with the given address (relative to the given
8
8
  * chain).
@@ -19,4 +19,4 @@ export type SamplePetnamesControllerAssignPetnameAction = {
19
19
  * Union of all SamplePetnamesController action types.
20
20
  */
21
21
  export type SamplePetnamesControllerMethodActions = SamplePetnamesControllerAssignPetnameAction;
22
- //# sourceMappingURL=sample-petnames-controller-method-action-types.d.ts.map
22
+ //# sourceMappingURL=sample-petnames-controller-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-petnames-controller-method-action-types.d.cts","sourceRoot":"","sources":["../src/sample-petnames-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,yCAAwC;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC;CACpD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC/C,2CAA2C,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { SamplePetnamesController } from "./sample-petnames-controller.mjs";
6
+ /**
7
+ * Registers the given name with the given address (relative to the given
8
+ * chain).
9
+ *
10
+ * @param chainId - The chain ID that the address belongs to.
11
+ * @param address - The account address to name.
12
+ * @param name - The name to assign to the address.
13
+ */
14
+ export type SamplePetnamesControllerAssignPetnameAction = {
15
+ type: `SamplePetnamesController:assignPetname`;
16
+ handler: SamplePetnamesController['assignPetname'];
17
+ };
18
+ /**
19
+ * Union of all SamplePetnamesController action types.
20
+ */
21
+ export type SamplePetnamesControllerMethodActions = SamplePetnamesControllerAssignPetnameAction;
22
+ //# sourceMappingURL=sample-petnames-controller-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-petnames-controller-method-action-types.d.mts","sourceRoot":"","sources":["../src/sample-petnames-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,yCAAwC;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC;CACpD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC/C,2CAA2C,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=sample-petnames-controller-method-action-types.js.map
6
+ //# sourceMappingURL=sample-petnames-controller-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-petnames-controller-method-action-types.mjs","sourceRoot":"","sources":["../src/sample-petnames-controller-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SamplePetnamesController } from './sample-petnames-controller.js';\n\n/**\n * Registers the given name with the given address (relative to the given\n * chain).\n *\n * @param chainId - The chain ID that the address belongs to.\n * @param address - The account address to name.\n * @param name - The name to assign to the address.\n */\nexport type SamplePetnamesControllerAssignPetnameAction = {\n type: `SamplePetnamesController:assignPetname`;\n handler: SamplePetnamesController['assignPetname'];\n};\n\n/**\n * Union of all SamplePetnamesController action types.\n */\nexport type SamplePetnamesControllerMethodActions =\n SamplePetnamesControllerAssignPetnameAction;\n"]}