Skip to content

Commit dac2789

Browse files
authored
feat: Make breaking changes to next base-controller metadata (#6593)
## Explanation Make the planned breaking changes to controller metadata. This includes renaming `anonymous` to `includeInDebugSnapshot`, and it includes making the two new metadata properties required. ## References Relates to #6443 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] 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 b4cdb12 commit dac2789

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed

packages/base-controller/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111

1212
- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))
13+
- In experimental `next` export, rename `anonymous` metadata property to `includeInDebugSnapshot` ([#6593](https://github.com/MetaMask/core/pull/6593))
14+
- In experimental `next` export, make `includeInStateLogs` and `usedInUi` metadata properties required ([#6593](https://github.com/MetaMask/core/pull/6593))
1315

1416
## [8.3.0]
1517

packages/base-controller/src/next/BaseController.test.ts

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type CountControllerEvent = ControllerStateChangeEvent<
3636

3737
export const countControllerStateMetadata = {
3838
count: {
39-
anonymous: true,
39+
includeInDebugSnapshot: true,
4040
includeInStateLogs: true,
4141
persist: true,
4242
usedInUi: true,
@@ -109,7 +109,7 @@ type MessagesControllerEvent = ControllerStateChangeEvent<
109109

110110
const messagesControllerStateMetadata = {
111111
messages: {
112-
anonymous: true,
112+
includeInDebugSnapshot: true,
113113
includeInStateLogs: true,
114114
persist: true,
115115
usedInUi: true,
@@ -609,7 +609,7 @@ describe('BaseController', () => {
609609

610610
const visitorControllerStateMetadata = {
611611
visitors: {
612-
anonymous: true,
612+
includeInDebugSnapshot: true,
613613
includeInStateLogs: true,
614614
persist: true,
615615
usedInUi: true,
@@ -679,7 +679,7 @@ describe('BaseController', () => {
679679

680680
const visitorOverflowControllerMetadata = {
681681
maxVisitors: {
682-
anonymous: true,
682+
includeInDebugSnapshot: true,
683683
includeInStateLogs: true,
684684
persist: false,
685685
usedInUi: true,
@@ -794,7 +794,7 @@ describe('getAnonymizedState', () => {
794794
{ count: 1 },
795795
{
796796
count: {
797-
anonymous: false,
797+
includeInDebugSnapshot: false,
798798
includeInStateLogs: false,
799799
persist: false,
800800
usedInUi: false,
@@ -814,25 +814,25 @@ describe('getAnonymizedState', () => {
814814
},
815815
{
816816
password: {
817-
anonymous: false,
817+
includeInDebugSnapshot: false,
818818
includeInStateLogs: false,
819819
persist: false,
820820
usedInUi: false,
821821
},
822822
privateKey: {
823-
anonymous: false,
823+
includeInDebugSnapshot: false,
824824
includeInStateLogs: false,
825825
persist: false,
826826
usedInUi: false,
827827
},
828828
network: {
829-
anonymous: true,
829+
includeInDebugSnapshot: true,
830830
includeInStateLogs: false,
831831
persist: false,
832832
usedInUi: false,
833833
},
834834
tokens: {
835-
anonymous: true,
835+
includeInDebugSnapshot: true,
836836
includeInStateLogs: false,
837837
persist: false,
838838
usedInUi: false,
@@ -856,7 +856,7 @@ describe('getAnonymizedState', () => {
856856
},
857857
{
858858
transactionHash: {
859-
anonymous: anonymizeTransactionHash,
859+
includeInDebugSnapshot: anonymizeTransactionHash,
860860
includeInStateLogs: false,
861861
persist: false,
862862
usedInUi: false,
@@ -881,7 +881,7 @@ describe('getAnonymizedState', () => {
881881
},
882882
{
883883
txMeta: {
884-
anonymous: anonymizeTxMeta,
884+
includeInDebugSnapshot: anonymizeTxMeta,
885885
includeInStateLogs: false,
886886
persist: false,
887887
usedInUi: false,
@@ -921,7 +921,7 @@ describe('getAnonymizedState', () => {
921921
},
922922
{
923923
txMeta: {
924-
anonymous: anonymizeTxMeta,
924+
includeInDebugSnapshot: anonymizeTxMeta,
925925
includeInStateLogs: false,
926926
persist: false,
927927
usedInUi: false,
@@ -941,7 +941,7 @@ describe('getAnonymizedState', () => {
941941
},
942942
{
943943
count: {
944-
anonymous: (count) => Number(count),
944+
includeInDebugSnapshot: (count) => Number(count),
945945
includeInStateLogs: false,
946946
persist: false,
947947
usedInUi: false,
@@ -963,13 +963,13 @@ describe('getAnonymizedState', () => {
963963
// @ts-expect-error Intentionally testing invalid state
964964
{
965965
privateKey: {
966-
anonymous: true,
966+
includeInDebugSnapshot: true,
967967
includeInStateLogs: true,
968968
persist: true,
969969
usedInUi: true,
970970
},
971971
network: {
972-
anonymous: false,
972+
includeInDebugSnapshot: false,
973973
includeInStateLogs: false,
974974
persist: false,
975975
usedInUi: false,
@@ -999,7 +999,7 @@ describe('getPersistentState', () => {
999999
{ count: 1 },
10001000
{
10011001
count: {
1002-
anonymous: false,
1002+
includeInDebugSnapshot: false,
10031003
includeInStateLogs: false,
10041004
persist: false,
10051005
usedInUi: false,
@@ -1019,25 +1019,25 @@ describe('getPersistentState', () => {
10191019
},
10201020
{
10211021
password: {
1022-
anonymous: false,
1022+
includeInDebugSnapshot: false,
10231023
includeInStateLogs: false,
10241024
persist: true,
10251025
usedInUi: false,
10261026
},
10271027
privateKey: {
1028-
anonymous: false,
1028+
includeInDebugSnapshot: false,
10291029
includeInStateLogs: false,
10301030
persist: true,
10311031
usedInUi: false,
10321032
},
10331033
network: {
1034-
anonymous: false,
1034+
includeInDebugSnapshot: false,
10351035
includeInStateLogs: false,
10361036
persist: false,
10371037
usedInUi: false,
10381038
},
10391039
tokens: {
1040-
anonymous: false,
1040+
includeInDebugSnapshot: false,
10411041
includeInStateLogs: false,
10421042
persist: false,
10431043
usedInUi: false,
@@ -1061,7 +1061,7 @@ describe('getPersistentState', () => {
10611061
},
10621062
{
10631063
transactionHash: {
1064-
anonymous: false,
1064+
includeInDebugSnapshot: false,
10651065
includeInStateLogs: false,
10661066
persist: normalizeTransacitonHash,
10671067
usedInUi: false,
@@ -1086,7 +1086,7 @@ describe('getPersistentState', () => {
10861086
},
10871087
{
10881088
txMeta: {
1089-
anonymous: false,
1089+
includeInDebugSnapshot: false,
10901090
includeInStateLogs: false,
10911091
persist: getPersistentTxMeta,
10921092
usedInUi: false,
@@ -1126,7 +1126,7 @@ describe('getPersistentState', () => {
11261126
},
11271127
{
11281128
txMeta: {
1129-
anonymous: false,
1129+
includeInDebugSnapshot: false,
11301130
includeInStateLogs: false,
11311131
persist: getPersistentTxMeta,
11321132
usedInUi: false,
@@ -1146,7 +1146,7 @@ describe('getPersistentState', () => {
11461146
},
11471147
{
11481148
count: {
1149-
anonymous: false,
1149+
includeInDebugSnapshot: false,
11501150
includeInStateLogs: false,
11511151
persist: (count) => Number(count),
11521152
usedInUi: false,
@@ -1168,13 +1168,13 @@ describe('getPersistentState', () => {
11681168
// @ts-expect-error Intentionally testing invalid state
11691169
{
11701170
privateKey: {
1171-
anonymous: false,
1171+
includeInDebugSnapshot: false,
11721172
includeInStateLogs: false,
11731173
persist: true,
11741174
usedInUi: false,
11751175
},
11761176
network: {
1177-
anonymous: false,
1177+
includeInDebugSnapshot: false,
11781178
includeInStateLogs: false,
11791179
persist: false,
11801180
usedInUi: true,
@@ -1200,20 +1200,21 @@ describe('deriveStateFromMetadata', () => {
12001200
{ count: 1 },
12011201
{
12021202
count: {
1203-
anonymous: false,
1203+
includeInDebugSnapshot: false,
12041204
includeInStateLogs: false,
12051205
persist: false,
1206-
// usedInUi is not set
1206+
usedInUi: false,
12071207
},
12081208
},
1209-
'usedInUi',
1209+
// @ts-expect-error Intentionally passing in fake unset property
1210+
'unset',
12101211
);
12111212

12121213
expect(derivedState).toStrictEqual({});
12131214
});
12141215

12151216
describe.each([
1216-
'anonymous',
1217+
'includeInDebugSnapshot',
12171218
'includeInStateLogs',
12181219
'persist',
12191220
'usedInUi',
@@ -1227,7 +1228,7 @@ describe('deriveStateFromMetadata', () => {
12271228
{ count: 1 },
12281229
{
12291230
count: {
1230-
anonymous: false,
1231+
includeInDebugSnapshot: false,
12311232
includeInStateLogs: false,
12321233
persist: false,
12331234
usedInUi: false,
@@ -1250,28 +1251,28 @@ describe('deriveStateFromMetadata', () => {
12501251
},
12511252
{
12521253
password: {
1253-
anonymous: false,
1254+
includeInDebugSnapshot: false,
12541255
includeInStateLogs: false,
12551256
persist: false,
12561257
usedInUi: false,
12571258
[property]: true,
12581259
},
12591260
privateKey: {
1260-
anonymous: false,
1261+
includeInDebugSnapshot: false,
12611262
includeInStateLogs: false,
12621263
persist: false,
12631264
usedInUi: false,
12641265
[property]: true,
12651266
},
12661267
network: {
1267-
anonymous: false,
1268+
includeInDebugSnapshot: false,
12681269
includeInStateLogs: false,
12691270
persist: false,
12701271
usedInUi: false,
12711272
[property]: false,
12721273
},
12731274
tokens: {
1274-
anonymous: false,
1275+
includeInDebugSnapshot: false,
12751276
includeInStateLogs: false,
12761277
persist: false,
12771278
usedInUi: false,
@@ -1299,7 +1300,7 @@ describe('deriveStateFromMetadata', () => {
12991300
},
13001301
{
13011302
transactionHash: {
1302-
anonymous: false,
1303+
includeInDebugSnapshot: false,
13031304
includeInStateLogs: false,
13041305
persist: false,
13051306
usedInUi: false,
@@ -1326,7 +1327,7 @@ describe('deriveStateFromMetadata', () => {
13261327
},
13271328
{
13281329
txMeta: {
1329-
anonymous: false,
1330+
includeInDebugSnapshot: false,
13301331
includeInStateLogs: false,
13311332
persist: false,
13321333
usedInUi: false,
@@ -1368,7 +1369,7 @@ describe('deriveStateFromMetadata', () => {
13681369
},
13691370
{
13701371
txMeta: {
1371-
anonymous: false,
1372+
includeInDebugSnapshot: false,
13721373
includeInStateLogs: false,
13731374
persist: false,
13741375
usedInUi: false,
@@ -1390,7 +1391,7 @@ describe('deriveStateFromMetadata', () => {
13901391
},
13911392
{
13921393
count: {
1393-
anonymous: false,
1394+
includeInDebugSnapshot: false,
13941395
includeInStateLogs: false,
13951396
persist: false,
13961397
usedInUi: false,
@@ -1415,14 +1416,14 @@ describe('deriveStateFromMetadata', () => {
14151416
// @ts-expect-error Intentionally testing invalid state
14161417
{
14171418
privateKey: {
1418-
anonymous: false,
1419+
includeInDebugSnapshot: false,
14191420
includeInStateLogs: false,
14201421
persist: false,
14211422
usedInUi: false,
14221423
[property]: true,
14231424
},
14241425
network: {
1425-
anonymous: false,
1426+
includeInDebugSnapshot: false,
14261427
includeInStateLogs: false,
14271428
persist: false,
14281429
usedInUi: false,

packages/base-controller/src/next/BaseController.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export type StatePropertyMetadata<ControllerState extends Json> = {
6767
* Set this to false if the state may contain personally identifiable information, or if it's
6868
* too large to include in a debug snapshot.
6969
*/
70-
anonymous: boolean | StateDeriver<ControllerState>;
70+
includeInDebugSnapshot: boolean | StateDeriver<ControllerState>;
7171
/**
7272
* Indicates whether this property should be included in state logs.
7373
*
@@ -78,7 +78,7 @@ export type StatePropertyMetadata<ControllerState extends Json> = {
7878
* diagnosing errors (e.g. transaction hashes, addresses), but we still attempt to limit the
7979
* data we expose to what is most useful for helping users.
8080
*/
81-
includeInStateLogs?: boolean | StateDeriver<ControllerState>;
81+
includeInStateLogs: boolean | StateDeriver<ControllerState>;
8282
/**
8383
* Indicates whether this property should be persisted.
8484
*
@@ -98,7 +98,7 @@ export type StatePropertyMetadata<ControllerState extends Json> = {
9898
* Note that we disallow the use of a state derivation function here to preserve type information
9999
* for the UI (the state deriver type always returns `Json`).
100100
*/
101-
usedInUi?: boolean;
101+
usedInUi: boolean;
102102
};
103103

104104
/**
@@ -377,7 +377,7 @@ export function getAnonymizedState<ControllerState extends StateConstraint>(
377377
state: ControllerState,
378378
metadata: StateMetadata<ControllerState>,
379379
): Record<keyof ControllerState, Json> {
380-
return deriveStateFromMetadata(state, metadata, 'anonymous');
380+
return deriveStateFromMetadata(state, metadata, 'includeInDebugSnapshot');
381381
}
382382

383383
/**

0 commit comments

Comments
 (0)