@metamask-previews/composable-controller 5.0.0-preview.d357889 → 5.0.1-preview.08978bf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
|
|
2
3
|
All notable changes to this project will be documented in this file.
|
|
3
4
|
|
|
4
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
@@ -6,11 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
7
|
|
|
7
8
|
## [Unreleased]
|
|
8
9
|
|
|
10
|
+
## [5.0.1]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Bump `@metamask/base-controller` to `^4.1.1` ([#3760](https://github.com/MetaMask/core/pull/3760), [#3821](https://github.com/MetaMask/core/pull/3821))
|
|
15
|
+
|
|
9
16
|
## [5.0.0]
|
|
17
|
+
|
|
10
18
|
### Added
|
|
19
|
+
|
|
11
20
|
- Add types `ComposableControllerState`, `ComposableControllerStateChangeEvent`, `ComposableControllerEvents`, `ComposableControllerMessenger` ([#3590](https://github.com/MetaMask/core/pull/3590))
|
|
12
21
|
|
|
13
22
|
### Changed
|
|
23
|
+
|
|
14
24
|
- **BREAKING:** `ComposableController` is upgraded to extend `BaseControllerV2` ([#3590](https://github.com/MetaMask/core/pull/3590))
|
|
15
25
|
- The constructor now expects an options object with required properties `controllers` and `messenger` as its only argument.
|
|
16
26
|
- `ComposableController` no longer has a `subscribe` method. Instead, listeners for `ComposableController` events must be registered to the controller messenger that generated the restricted messenger assigned to the instance's `messagingSystem` class field.
|
|
@@ -18,50 +28,71 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
18
28
|
- Bump `@metamask/base-controller` to `^4.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
|
|
19
29
|
|
|
20
30
|
## [4.0.0]
|
|
31
|
+
|
|
21
32
|
### Changed
|
|
33
|
+
|
|
22
34
|
- **BREAKING:** Bump `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
|
|
23
35
|
- This is breaking because the type of the `messenger` has backward-incompatible changes. See the changelog for this package for more.
|
|
24
36
|
|
|
25
37
|
## [3.0.3]
|
|
38
|
+
|
|
26
39
|
### Changed
|
|
40
|
+
|
|
27
41
|
- Bump dependency on `@metamask/base-controller` to ^3.2.3 ([#1747](https://github.com/MetaMask/core/pull/1747))
|
|
28
42
|
|
|
29
43
|
## [3.0.2]
|
|
44
|
+
|
|
30
45
|
### Changed
|
|
46
|
+
|
|
31
47
|
- Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
|
|
32
48
|
|
|
33
49
|
## [3.0.1]
|
|
50
|
+
|
|
34
51
|
### Changed
|
|
52
|
+
|
|
35
53
|
- Bump dependency on `@metamask/base-controller` to ^3.2.1
|
|
36
54
|
|
|
37
55
|
## [3.0.0]
|
|
56
|
+
|
|
38
57
|
### Changed
|
|
58
|
+
|
|
39
59
|
- **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
|
|
40
60
|
|
|
41
61
|
## [2.0.0]
|
|
62
|
+
|
|
42
63
|
### Removed
|
|
64
|
+
|
|
43
65
|
- **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
|
|
44
66
|
- Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
|
|
45
67
|
|
|
46
68
|
## [1.0.2]
|
|
69
|
+
|
|
47
70
|
### Changed
|
|
71
|
+
|
|
48
72
|
- Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
|
|
49
|
-
- Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
|
|
73
|
+
- Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
|
|
50
74
|
|
|
51
75
|
## [1.0.1]
|
|
76
|
+
|
|
52
77
|
### Changed
|
|
78
|
+
|
|
53
79
|
- Relax dependency on `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
|
|
54
80
|
|
|
55
81
|
## [1.0.0]
|
|
82
|
+
|
|
56
83
|
### Added
|
|
84
|
+
|
|
57
85
|
- Initial release
|
|
86
|
+
|
|
58
87
|
- As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely:
|
|
88
|
+
|
|
59
89
|
- `src/ComposableController.ts`
|
|
60
90
|
- `src/ComposableController.test.ts`
|
|
61
91
|
|
|
62
92
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
63
93
|
|
|
64
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@5.0.
|
|
94
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@5.0.1...HEAD
|
|
95
|
+
[5.0.1]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@5.0.0...@metamask/composable-controller@5.0.1
|
|
65
96
|
[5.0.0]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@4.0.0...@metamask/composable-controller@5.0.0
|
|
66
97
|
[4.0.0]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@3.0.3...@metamask/composable-controller@4.0.0
|
|
67
98
|
[3.0.3]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@3.0.2...@metamask/composable-controller@3.0.3
|
|
@@ -31,14 +31,6 @@ export declare class ComposableController extends BaseController<typeof controll
|
|
|
31
31
|
controllers: ControllerList;
|
|
32
32
|
messenger: ComposableControllerMessenger;
|
|
33
33
|
});
|
|
34
|
-
/**
|
|
35
|
-
* Flat state representation, one that isn't keyed
|
|
36
|
-
* of controller name. Instead, all child controller state is merged
|
|
37
|
-
* together into a single, flat object.
|
|
38
|
-
*
|
|
39
|
-
* @returns Merged state representation of all child controllers.
|
|
40
|
-
*/
|
|
41
|
-
get flatState(): {};
|
|
42
34
|
}
|
|
43
35
|
export default ComposableController;
|
|
44
36
|
//# sourceMappingURL=ComposableController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposableController.d.ts","sourceRoot":"","sources":["../src/ComposableController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EACV,0BAA0B,EAC1B,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,cAAc,yBAAyB,CAAC;AASrD,aAAK,kBAAkB,GAGrB,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAEhF;;GAEG;AACH,oBAAY,cAAc,GAAG,kBAAkB,EAAE,CAAC;AAelD,oBAAY,yBAAyB,GAAG;IACtC,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;CAC7C,CAAC;AAEF,oBAAY,oCAAoC,GAAG,0BAA0B,CAC3E,OAAO,cAAc,EACrB,yBAAyB,CAC1B,CAAC;AAEF,oBAAY,0BAA0B,GAAG,oCAAoC,CAAC;AAE9E,oBAAY,6BAA6B,GAAG,6BAA6B,CACvE,OAAO,cAAc,EACrB,KAAK,EACL,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC3D,MAAM,EACN,MAAM,CACP,CAAC;AAEF;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;;IAGC;;;;;;OAMG;gBAES,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AC1C;CA8CF;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -51,20 +51,6 @@ class ComposableController extends base_controller_1.BaseController {
|
|
|
51
51
|
__classPrivateFieldSet(this, _ComposableController_controllers, controllers, "f");
|
|
52
52
|
__classPrivateFieldGet(this, _ComposableController_controllers, "f").forEach((controller) => __classPrivateFieldGet(this, _ComposableController_instances, "m", _ComposableController_updateChildController).call(this, controller));
|
|
53
53
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Flat state representation, one that isn't keyed
|
|
56
|
-
* of controller name. Instead, all child controller state is merged
|
|
57
|
-
* together into a single, flat object.
|
|
58
|
-
*
|
|
59
|
-
* @returns Merged state representation of all child controllers.
|
|
60
|
-
*/
|
|
61
|
-
get flatState() {
|
|
62
|
-
let flatState = {};
|
|
63
|
-
for (const controller of __classPrivateFieldGet(this, _ComposableController_controllers, "f")) {
|
|
64
|
-
flatState = Object.assign(Object.assign({}, flatState), controller.state);
|
|
65
|
-
}
|
|
66
|
-
return flatState;
|
|
67
|
-
}
|
|
68
54
|
}
|
|
69
55
|
exports.ComposableController = ComposableController;
|
|
70
56
|
_ComposableController_controllers = new WeakMap(), _ComposableController_instances = new WeakSet(), _ComposableController_updateChildController = function _ComposableController_updateChildController(controller) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposableController.js","sourceRoot":"","sources":["../src/ComposableController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAA6E;AAMhE,QAAA,cAAc,GAAG,sBAAsB,CAAC;AAmBrD;;;;GAIG;AACH,SAAS,kBAAkB,CACzB,UAA8B;IAI9B,OAAO,UAAU,YAAY,kCAAgB,CAAC;AAChD,CAAC;AAqBD;;GAEG;AACH,MAAa,oBAAqB,SAAQ,gCAIzC;IAGC;;;;;;OAMG;IAEH,YAAY,EACV,WAAW,EACX,SAAS,GAIV;QACC,IAAI,SAAS,KAAK,SAAS,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,8BAA8B,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3D,CAAC,EAAE,EAA+B,CAAC;YACnC,SAAS;SACV,CAAC,CAAC;;QA5BL,4CAAwC,EAAE,EAAC;QA8BzC,uBAAA,IAAI,qCAAgB,WAAW,MAAA,CAAC;QAChC,uBAAA,IAAI,yCAAa,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CACvC,uBAAA,IAAI,oFAAuB,MAA3B,IAAI,EAAwB,UAAU,CAAC,CACxC,CAAC;IACJ,CAAC;CA4BF;AAnED,oDAmEC;uMArBwB,UAA8B;IACnD,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IAC5B,IAAI,kBAAkB,CAAC,UAAU,CAAC,EAAE;QAClC,UAAU,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCAClB,KAAK,KACR,CAAC,IAAI,CAAC,EAAE,UAAU,IAClB,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,IAAI,CAAC,eAAe,CAAC,SAAS,CAC5B,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,EAC7B,CAAC,UAAmC,EAAE,EAAE;YACtC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCAClB,KAAK,KACR,CAAC,IAAI,CAAC,EAAE,UAAU,IAClB,CAAC,CAAC;QACN,CAAC,CACF,CAAC;KACH;AACH,CAAC;AAGH,kBAAe,oBAAoB,CAAC","sourcesContent":["import { BaseController, BaseControllerV1 } from '@metamask/base-controller';\nimport type {\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\n\nexport const controllerName = 'ComposableController';\n\n/*\n * This type encompasses controllers based on either BaseControllerV1 or\n * BaseController. The BaseController type can't be included directly\n * because the generic parameters it expects require knowing the exact state\n * shape, so instead we look for an object with the BaseController properties\n * that we use in the ComposableController (name and state).\n */\ntype ControllerInstance =\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n BaseControllerV1<any, any> | { name: string; state: Record<string, unknown> };\n\n/**\n * List of child controller instances\n */\nexport type ControllerList = ControllerInstance[];\n\n/**\n * Determines if the given controller is an instance of BaseControllerV1\n * @param controller - Controller instance to check\n * @returns True if the controller is an instance of BaseControllerV1\n */\nfunction isBaseControllerV1(\n controller: ControllerInstance,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): controller is BaseControllerV1<any, any> {\n return controller instanceof BaseControllerV1;\n}\n\nexport type ComposableControllerState = {\n [name: string]: ControllerInstance['state'];\n};\n\nexport type ComposableControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ComposableControllerState\n>;\n\nexport type ComposableControllerEvents = ComposableControllerStateChangeEvent;\n\nexport type ComposableControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n never,\n ControllerStateChangeEvent<string, Record<string, unknown>>,\n string,\n string\n>;\n\n/**\n * Controller that can be used to compose multiple controllers together.\n */\nexport class ComposableController extends BaseController<\n typeof controllerName,\n ComposableControllerState,\n ComposableControllerMessenger\n> {\n readonly #controllers: ControllerList = [];\n\n /**\n * Creates a ComposableController instance.\n *\n * @param options - Initial options used to configure this controller\n * @param options.controllers - List of child controller instances to compose.\n * @param options.messenger - A restricted controller messenger.\n */\n\n constructor({\n controllers,\n messenger,\n }: {\n controllers: ControllerList;\n messenger: ComposableControllerMessenger;\n }) {\n if (messenger === undefined) {\n throw new Error(`Messaging system is required`);\n }\n\n super({\n name: controllerName,\n metadata: {},\n state: controllers.reduce((state, controller) => {\n return { ...state, [controller.name]: controller.state };\n }, {} as ComposableControllerState),\n messenger,\n });\n\n this.#controllers = controllers;\n this.#controllers.forEach((controller) =>\n this.#updateChildController(controller),\n );\n }\n\n /**\n * Adds a child controller instance to composable controller state,\n * or updates the state of a child controller.\n * @param controller - Controller instance to update\n */\n #updateChildController(controller: ControllerInstance): void {\n const { name } = controller;\n if (isBaseControllerV1(controller)) {\n controller.subscribe((childState) => {\n this.update((state) => ({\n ...state,\n [name]: childState,\n }));\n });\n } else {\n this.messagingSystem.subscribe(\n `${String(name)}:stateChange`,\n (childState: Record<string, unknown>) => {\n this.update((state) => ({\n ...state,\n [name]: childState,\n }));\n },\n );\n }\n }\n}\n\nexport default ComposableController;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/composable-controller",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1-preview.08978bf",
|
|
4
4
|
"description": "Consolidates the state from multiple controllers into one",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test:watch": "jest --watch"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@metamask/base-controller": "^4.1.
|
|
34
|
+
"@metamask/base-controller": "^4.1.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@metamask/auto-changelog": "^3.4.4",
|