Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@metamask/composable-controller

Package Overview
Dependencies
Maintainers
12
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/composable-controller - npm Package Compare versions

Comparing version 5.0.1 to 6.0.0

dist/chunk-EN3DCJ7Q.mjs

56

CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.

@@ -9,11 +10,41 @@

## [6.0.0]
### Added
- **BREAKING**: Add ESM build ([#3998](https://github.com/MetaMask/core/pull/3998))
- It's no longer possible to import files from `./dist` directly.
- Add and export functions `isBaseControllerV1` and `isBaseController`, which are type guards for validating controller instances ([#3904](https://github.com/MetaMask/core/pull/3904))
- `ComposableController` now accommodates `BaseControllerV1` controllers that use a messenger (specifically, which have a `messagingSystem` property which is an instance of `RestrictedControllerMessenger`), by subscribing to the `stateChange` event of the messenger instead of using the `subscribe` method on the controller ([#3964](https://github.com/MetaMask/core/pull/3964))
### Changed
- **BREAKING:** Passing a non-controller into `controllers` constructor option now throws an error ([#3904](https://github.com/MetaMask/core/pull/3904))
- **BREAKING:** The `AllowedAction` parameter of the `ComposableControllerMessenger` type is narrowed from `string` to `never`, as `ComposableController` does not use any external controller actions ([#3904](https://github.com/MetaMask/core/pull/3904))
- **BREAKING:** Bump `@metamask/base-controller` to `^5.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
- This version has a number of breaking changes. See the changelog for more.
- Relax `payload` in `ComposableControllerStateChangeEvent` to use `Record<string, any>` rather than `Record<string, unknown>` ([#3949](https://github.com/MetaMask/core/pull/3949))
- Bump `@metamask/json-rpc-engine` to `^8.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
### Removed
- **BREAKING:** Remove `flatState` getter from `ComposableController` ([#3877](https://github.com/MetaMask/core/pull/3877))
- This method was confusing to use in practice. Consumers should use the `ComposableController` state directly.
- **BREAKING:** Remove `ControllerList` as an exported type ([#3904](https://github.com/MetaMask/core/pull/3904))
- There is no replacement.
## [5.0.1]
### Changed
- Bump `@metamask/base-controller` to `^4.1.1` ([#3760](https://github.com/MetaMask/core/pull/3760), [#3821](https://github.com/MetaMask/core/pull/3821))
## [5.0.0]
### Added
- Add types `ComposableControllerState`, `ComposableControllerStateChangeEvent`, `ComposableControllerEvents`, `ComposableControllerMessenger` ([#3590](https://github.com/MetaMask/core/pull/3590))
### Changed
- **BREAKING:** `ComposableController` is upgraded to extend `BaseControllerV2` ([#3590](https://github.com/MetaMask/core/pull/3590))

@@ -26,3 +57,5 @@ - The constructor now expects an options object with required properties `controllers` and `messenger` as its only argument.

## [4.0.0]
### Changed
- **BREAKING:** Bump `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))

@@ -32,19 +65,29 @@ - This is breaking because the type of the `messenger` has backward-incompatible changes. See the changelog for this package for more.

## [3.0.3]
### Changed
- Bump dependency on `@metamask/base-controller` to ^3.2.3 ([#1747](https://github.com/MetaMask/core/pull/1747))
## [3.0.2]
### Changed
- Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
## [3.0.1]
### Changed
- Bump dependency on `@metamask/base-controller` to ^3.2.1
## [3.0.0]
### Changed
- **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
## [2.0.0]
### Removed
- **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))

@@ -54,14 +97,22 @@ - Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`

## [1.0.2]
### Changed
- Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
- Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
- Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
## [1.0.1]
### Changed
- Relax dependency on `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
## [1.0.0]
### Added
- Initial release
- 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:
- `src/ComposableController.ts`

@@ -72,3 +123,4 @@ - `src/ComposableController.test.ts`

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@5.0.1...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@6.0.0...HEAD
[6.0.0]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@5.0.1...@metamask/composable-controller@6.0.0
[5.0.1]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@5.0.0...@metamask/composable-controller@5.0.1

@@ -75,0 +127,0 @@ [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/composable-controller@4.0.0...@metamask/composable-controller@5.0.0

97

dist/ComposableController.js

@@ -1,84 +0,15 @@

"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
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");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _ComposableController_instances, _ComposableController_controllers, _ComposableController_updateChildController;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComposableController = exports.controllerName = void 0;
const base_controller_1 = require("@metamask/base-controller");
exports.controllerName = 'ComposableController';
/**
* Determines if the given controller is an instance of BaseControllerV1
* @param controller - Controller instance to check
* @returns True if the controller is an instance of BaseControllerV1
*/
function isBaseControllerV1(controller) {
return controller instanceof base_controller_1.BaseControllerV1;
}
/**
* Controller that can be used to compose multiple controllers together.
*/
class ComposableController extends base_controller_1.BaseController {
/**
* Creates a ComposableController instance.
*
* @param options - Initial options used to configure this controller
* @param options.controllers - List of child controller instances to compose.
* @param options.messenger - A restricted controller messenger.
*/
constructor({ controllers, messenger, }) {
if (messenger === undefined) {
throw new Error(`Messaging system is required`);
}
super({
name: exports.controllerName,
metadata: {},
state: controllers.reduce((state, controller) => {
return Object.assign(Object.assign({}, state), { [controller.name]: controller.state });
}, {}),
messenger,
});
_ComposableController_instances.add(this);
_ComposableController_controllers.set(this, []);
__classPrivateFieldSet(this, _ComposableController_controllers, controllers, "f");
__classPrivateFieldGet(this, _ComposableController_controllers, "f").forEach((controller) => __classPrivateFieldGet(this, _ComposableController_instances, "m", _ComposableController_updateChildController).call(this, controller));
}
/**
* Flat state representation, one that isn't keyed
* of controller name. Instead, all child controller state is merged
* together into a single, flat object.
*
* @returns Merged state representation of all child controllers.
*/
get flatState() {
let flatState = {};
for (const controller of __classPrivateFieldGet(this, _ComposableController_controllers, "f")) {
flatState = Object.assign(Object.assign({}, flatState), controller.state);
}
return flatState;
}
}
exports.ComposableController = ComposableController;
_ComposableController_controllers = new WeakMap(), _ComposableController_instances = new WeakSet(), _ComposableController_updateChildController = function _ComposableController_updateChildController(controller) {
const { name } = controller;
if (isBaseControllerV1(controller)) {
controller.subscribe((childState) => {
this.update((state) => (Object.assign(Object.assign({}, state), { [name]: childState })));
});
}
else {
this.messagingSystem.subscribe(`${String(name)}:stateChange`, (childState) => {
this.update((state) => (Object.assign(Object.assign({}, state), { [name]: childState })));
});
}
};
exports.default = ComposableController;
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunkK4UHO4GXjs = require('./chunk-K4UHO4GX.js');
exports.ComposableController = _chunkK4UHO4GXjs.ComposableController; exports.controllerName = _chunkK4UHO4GXjs.controllerName; exports.default = _chunkK4UHO4GXjs.ComposableController_default; exports.isBaseController = _chunkK4UHO4GXjs.isBaseController; exports.isBaseControllerV1 = _chunkK4UHO4GXjs.isBaseControllerV1;
//# sourceMappingURL=ComposableController.js.map

@@ -1,6 +0,11 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComposableController = void 0;
var ComposableController_1 = require("./ComposableController");
Object.defineProperty(exports, "ComposableController", { enumerable: true, get: function () { return ComposableController_1.ComposableController; } });
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunkK4UHO4GXjs = require('./chunk-K4UHO4GX.js');
exports.ComposableController = _chunkK4UHO4GXjs.ComposableController; exports.isBaseController = _chunkK4UHO4GXjs.isBaseController; exports.isBaseControllerV1 = _chunkK4UHO4GXjs.isBaseControllerV1;
//# sourceMappingURL=index.js.map
{
"name": "@metamask/composable-controller",
"version": "5.0.1",
"version": "6.0.0",
"description": "Consolidates the state from multiple controllers into one",

@@ -18,2 +18,11 @@ "keywords": [

"license": "MIT",
"sideEffects": false,
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/types/index.d.ts"
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",

@@ -25,2 +34,3 @@ "types": "./dist/index.d.ts",

"scripts": {
"build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean",
"build:docs": "typedoc",

@@ -36,6 +46,7 @@ "changelog:update": "../../scripts/update-changelog.sh @metamask/composable-controller",

"dependencies": {
"@metamask/base-controller": "^4.1.1"
"@metamask/base-controller": "^5.0.0"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/json-rpc-engine": "^8.0.0",
"@types/jest": "^27.4.1",

@@ -42,0 +53,0 @@ "deepmerge": "^4.2.2",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc