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

@metamask-previews/composable-controller

Package Overview
Dependencies
Maintainers
2
Versions
393
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask-previews/composable-controller - npm Package Compare versions

Comparing version 5.0.1-preview.e5c396b to 5.0.1-preview.eb2135e

dist/chunk-EN3DCJ7Q.mjs

3

CHANGELOG.md

@@ -13,3 +13,2 @@ # Changelog

- Add and export functions `isBaseControllerV1` and `isBaseController`, which are type guards for validating controller instances ([#3904](https://github.com/MetaMask/core/pull/3904))
- Add and export types `BaseControllerV1Instance`, `BaseControllerV2Instance`, `ControllerInstance` which are the narrowest supertypes for all controllers extending from, respectively, `BaseControllerV1`, `BaseController`, and both ([#3904](https://github.com/MetaMask/core/pull/3904))

@@ -20,3 +19,3 @@ ### Changed

- **BREAKING:** The `AllowedActions` 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))
- Add `@metamask/utils` ^8.3.0 as a dependency. ([#3904](https://github.com/MetaMask/core/pull/3904))
- Subscribe to the `stateChange` events of `BaseControllerV1` controllers that have a `messagingSystem` class field with an assigned instance of the `RestrictedControllerMessenger` class. ([#3964](https://github.com/MetaMask/core/pull/3964))

@@ -23,0 +22,0 @@ ### Removed

@@ -1,93 +0,15 @@

"use strict";
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_updateChildController;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComposableController = exports.isBaseController = exports.isBaseControllerV1 = exports.controllerName = void 0;
const base_controller_1 = require("@metamask/base-controller");
const utils_1 = require("@metamask/utils");
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
* TODO: Deprecate once `BaseControllerV2` migrations are completed for all controllers.
*/
function isBaseControllerV1(controller) {
return ('name' in controller &&
typeof controller.name === 'string' &&
'defaultConfig' in controller &&
typeof controller.defaultConfig === 'object' &&
'defaultState' in controller &&
typeof controller.defaultState === 'object' &&
'disabled' in controller &&
typeof controller.disabled === 'boolean' &&
controller instanceof base_controller_1.BaseControllerV1);
}
exports.isBaseControllerV1 = isBaseControllerV1;
/**
* Determines if the given controller is an instance of BaseController
* @param controller - Controller instance to check
* @returns True if the controller is an instance of BaseController
*/
function isBaseController(controller) {
return ('name' in controller &&
typeof controller.name === 'string' &&
'state' in controller &&
typeof controller.state === 'object' &&
controller instanceof base_controller_1.BaseController);
}
exports.isBaseController = isBaseController;
/**
* 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: controllers.reduce((metadata, controller) => (Object.assign(Object.assign({}, metadata), { [controller.name]: isBaseController(controller)
? controller.metadata
: { persist: true, anonymous: true } })), {}),
state: controllers.reduce((state, controller) => {
return Object.assign(Object.assign({}, state), { [controller.name]: controller.state });
}, {}),
messenger,
});
_ComposableController_instances.add(this);
controllers.forEach((controller) => __classPrivateFieldGet(this, _ComposableController_instances, "m", _ComposableController_updateChildController).call(this, controller));
}
}
exports.ComposableController = ComposableController;
_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 if (isBaseController(controller)) {
this.messagingSystem.subscribe(`${name}:stateChange`, (childState) => {
if ((0, utils_1.isValidJson)(childState)) {
this.update((state) => (Object.assign(Object.assign({}, state), { [name]: childState })));
}
});
}
else {
throw new Error('Invalid controller: controller must extend from BaseController or BaseControllerV1');
}
};
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,8 +0,11 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBaseControllerV1 = exports.isBaseController = exports.ComposableController = void 0;
var ComposableController_1 = require("./ComposableController");
Object.defineProperty(exports, "ComposableController", { enumerable: true, get: function () { return ComposableController_1.ComposableController; } });
Object.defineProperty(exports, "isBaseController", { enumerable: true, get: function () { return ComposableController_1.isBaseController; } });
Object.defineProperty(exports, "isBaseControllerV1", { enumerable: true, get: function () { return ComposableController_1.isBaseControllerV1; } });
"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-previews/composable-controller",
"version": "5.0.1-preview.e5c396b",
"version": "5.0.1-preview.eb2135e",
"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,4 +46,3 @@ "changelog:update": "../../scripts/update-changelog.sh @metamask/composable-controller",

"dependencies": {
"@metamask/base-controller": "^4.1.1",
"@metamask/utils": "^8.3.0"
"@metamask/base-controller": "^4.1.1"
},

@@ -40,0 +49,0 @@ "devDependencies": {

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