Skip to content

Commit 03b9a16

Browse files
authored
refactor: migrate AppMetadataController to @metamask/messenger (#6385)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR migrates the `AppMetadataController` class to the new `@metamask/messenger` comm system, as opposed to the one exported from `@metamask/base-controller`. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Related to #5626 ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 0f3227f commit 03b9a16

File tree

8 files changed

+47
-22
lines changed

8 files changed

+47
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ linkStyle default opacity:0.5
164164
announcement_controller --> base_controller;
165165
announcement_controller --> messenger;
166166
app_metadata_controller --> base_controller;
167+
app_metadata_controller --> messenger;
167168
approval_controller --> base_controller;
168169
assets_controllers --> base_controller;
169170
assets_controllers --> controller_utils;

packages/app-metadata-controller/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6385](https://github.com/MetaMask/core/pull/6385))
13+
- Previously, `AppMetadataController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
14+
- **BREAKING:** Metadata property `anonymous` renamed to `includeInDebugSnapshot` ([#6385](https://github.com/MetaMask/core/pull/6385))
15+
1016
## [1.1.1]
1117

1218
### Changed

packages/app-metadata-controller/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
4848
},
4949
"dependencies": {
50-
"@metamask/base-controller": "^8.4.2"
50+
"@metamask/base-controller": "^8.4.2",
51+
"@metamask/messenger": "^0.3.0"
5152
},
5253
"devDependencies": {
5354
"@metamask/auto-changelog": "^3.4.4",

packages/app-metadata-controller/src/AppMetadataController.test.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { Messenger, deriveStateFromMetadata } from '@metamask/base-controller';
1+
import { deriveStateFromMetadata } from '@metamask/base-controller/next';
2+
import {
3+
Messenger,
4+
MOCK_ANY_NAMESPACE,
5+
type MockAnyNamespace,
6+
} from '@metamask/messenger';
27

38
import {
49
AppMetadataController,
510
getDefaultAppMetadataControllerState,
611
type AppMetadataControllerOptions,
12+
type AppMetadataControllerActions,
13+
type AppMetadataControllerEvents,
714
} from './AppMetadataController';
815

916
describe('AppMetadataController', () => {
@@ -128,7 +135,7 @@ describe('AppMetadataController', () => {
128135
deriveStateFromMetadata(
129136
controller.state,
130137
controller.metadata,
131-
'anonymous',
138+
'includeInDebugSnapshot',
132139
),
133140
).toMatchInlineSnapshot(`
134141
Object {
@@ -219,12 +226,20 @@ function withController<ReturnValue>(
219226
): ReturnValue {
220227
const [options = {}, fn] = args.length === 2 ? args : [{}, args[0]];
221228

222-
const messenger = new Messenger<never, never>();
223-
224-
const appMetadataControllerMessenger = messenger.getRestricted({
225-
name: 'AppMetadataController',
226-
allowedActions: [],
227-
allowedEvents: [],
229+
const rootMessenger = new Messenger<
230+
MockAnyNamespace,
231+
AppMetadataControllerActions,
232+
AppMetadataControllerEvents
233+
>({ namespace: MOCK_ANY_NAMESPACE });
234+
235+
const appMetadataControllerMessenger = new Messenger<
236+
'AppMetadataController',
237+
AppMetadataControllerActions,
238+
AppMetadataControllerEvents,
239+
typeof rootMessenger
240+
>({
241+
namespace: 'AppMetadataController',
242+
parent: rootMessenger,
228243
});
229244

230245
return fn({

packages/app-metadata-controller/src/AppMetadataController.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { BaseController } from '@metamask/base-controller';
21
import type {
32
StateMetadata,
43
ControllerGetStateAction,
54
ControllerStateChangeEvent,
6-
RestrictedMessenger,
7-
} from '@metamask/base-controller';
5+
} from '@metamask/base-controller/next';
6+
import { BaseController } from '@metamask/base-controller/next';
7+
import type { Messenger } from '@metamask/messenger';
88

99
// Unique name for the controller
1010
const controllerName = 'AppMetadataController';
@@ -88,12 +88,10 @@ type AllowedEvents = never;
8888
* @returns A restricted messenger type that defines the allowed actions and events
8989
* for the AppMetadataController
9090
*/
91-
export type AppMetadataControllerMessenger = RestrictedMessenger<
91+
export type AppMetadataControllerMessenger = Messenger<
9292
typeof controllerName,
9393
AppMetadataControllerActions | AllowedActions,
94-
AppMetadataControllerEvents | AllowedEvents,
95-
AllowedActions['type'],
96-
AllowedEvents['type']
94+
AppMetadataControllerEvents | AllowedEvents
9795
>;
9896

9997
/**
@@ -105,25 +103,25 @@ const controllerMetadata = {
105103
currentAppVersion: {
106104
includeInStateLogs: true,
107105
persist: true,
108-
anonymous: true,
106+
includeInDebugSnapshot: true,
109107
usedInUi: false,
110108
},
111109
previousAppVersion: {
112110
includeInStateLogs: true,
113111
persist: true,
114-
anonymous: true,
112+
includeInDebugSnapshot: true,
115113
usedInUi: false,
116114
},
117115
previousMigrationVersion: {
118116
includeInStateLogs: true,
119117
persist: true,
120-
anonymous: true,
118+
includeInDebugSnapshot: true,
121119
usedInUi: false,
122120
},
123121
currentMigrationVersion: {
124122
includeInStateLogs: true,
125123
persist: true,
126-
anonymous: true,
124+
includeInDebugSnapshot: true,
127125
usedInUi: false,
128126
},
129127
} satisfies StateMetadata<AppMetadataControllerState>;

packages/app-metadata-controller/tsconfig.build.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"outDir": "./dist",
66
"rootDir": "./src"
77
},
8-
"references": [{ "path": "../base-controller/tsconfig.build.json" }],
8+
"references": [
9+
{ "path": "../base-controller/tsconfig.build.json" },
10+
{ "path": "../messenger/tsconfig.build.json" }
11+
],
912
"include": ["../../types", "./src"]
1013
}

packages/app-metadata-controller/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"compilerOptions": {
44
"baseUrl": "./"
55
},
6-
"references": [{ "path": "../base-controller" }],
6+
"references": [{ "path": "../base-controller" }, { "path": "../messenger" }],
77
"include": ["../../types", "./src"]
88
}

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,7 @@ __metadata:
27102710
dependencies:
27112711
"@metamask/auto-changelog": "npm:^3.4.4"
27122712
"@metamask/base-controller": "npm:^8.4.2"
2713+
"@metamask/messenger": "npm:^0.3.0"
27132714
"@types/jest": "npm:^27.4.1"
27142715
deepmerge: "npm:^4.2.2"
27152716
jest: "npm:^27.5.1"

0 commit comments

Comments
 (0)