@metamask-previews/base-controller
Advanced tools
Comparing version 3.2.3-preview.eb58a59 to 4.0.0-preview.3fbb6b41
@@ -9,2 +9,27 @@ # Changelog | ||
## [4.0.0] | ||
### Added | ||
- Add `ControllerGetStateAction` and `ControllerStateChangeEvent` types ([#1890](https://github.com/MetaMask/core/pull/1890), [#2029](https://github.com/MetaMask/core/pull/2029)) | ||
- Add `NamespacedName` type ([#1890](https://github.com/MetaMask/core/pull/1890)) | ||
- This is the narrowest supertype of all names defined within a given namespace. | ||
- Add `NotNamespacedBy` type, which matches an action/event name if and only if it is not prefixed by a given namespace ([#2051](https://github.com/MetaMask/core/pull/2051)) | ||
### Changed | ||
- **BREAKING:** Alter controller messenger `ActionHandler` type so `Action` type parameter must satisfy (updated) `ActionConstraint` ([#1890](https://github.com/MetaMask/core/pull/1890)) | ||
- **BREAKING:** Alter controller messenger `ExtractActionParameters` utility type so `Action` type parameter must satisfy (updated) `ActionConstraint` ([#1890](https://github.com/MetaMask/core/pull/1890)) | ||
- **BREAKING:** Alter controller messenger `ExtractEventHandler` utility type so `Event` type parameter must satisfy `EventConstraint` ([#1890](https://github.com/MetaMask/core/pull/1890)) | ||
- **BREAKING:** Alter controller messenger `ExtractEventPayload` utility type so `Event` type parameter must satisfy `EventConstraint` and `Event['payload']` must be an array (to match behavior of `ExtractEventHandler`) ([#1890](https://github.com/MetaMask/core/pull/1890)) | ||
- **BREAKING:** Alter controller messenger `SelectorFunction` type so that its generic parameter `Args` is replaced by `Event`, which must satisfy `EventConstraint`, and it returns a function whose arguments satisfy the event payload type specified by `Event` ([#1890](https://github.com/MetaMask/core/pull/1890)) | ||
- **BREAKING:** `BaseController` is now renamed to `BaseControllerV1` and has been deprecated; `BaseController` now points to what was previously called `BaseControllerV2` ([#2078](https://github.com/MetaMask/core/pull/2078)) | ||
- This should encourage use of `BaseController` v2 for new controllers going forward. | ||
- If your controller is importing `BaseControllerV2`, you will need to import `BaseController` instead. | ||
- If your controller is still importing `BaseController` v1, you will need to import and use `BaseControllerV1` instead. That said, please consider migrating your controller to v2. | ||
- **BREAKING:** The restricted controller messenger now allows calling all internal events and actions by default and prohibits explicitly allowlisting any of them ([#2050](https://github.com/MetaMask/core/pull/2050), [#2051](https://github.com/MetaMask/core/pull/2051)) | ||
- Previously internal events and actions were only usable if they were listed as "allowed" via the `allowedActions` or `allowedEvents` options to the `RestrictedControllerMessenger` constructor or `ControllerMessenger.getRestricted()`. Now this works implicitly. | ||
- In fact, attempting to allowlist any of them will raise a type error, as otherwise, it would be possible to specify a partial list of allowed actions or events, and that would be misleading, since all of them are allowed anyway. | ||
- **BREAKING:** Rename `Namespaced` type to `NamespacedBy` ([#2051](https://github.com/MetaMask/core/pull/2051)) | ||
- Alter controller messenger `ActionConstraint['handler']` type to remove usage of `any` ([#1890](https://github.com/MetaMask/core/pull/1890)) | ||
- This type is now defined as the universal supertype of all functions, meaning any function can be safely assigned as an action handler, regardless of argument types, number of arguments, or return value type. | ||
- Bump `@metamask/utils` to ^8.2.0 ([#1957](https://github.com/MetaMask/core/pull/1957)) | ||
## [3.2.3] | ||
@@ -77,3 +102,4 @@ ### Changed | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/base-controller@3.2.3...HEAD | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/base-controller@4.0.0...HEAD | ||
[4.0.0]: https://github.com/MetaMask/core/compare/@metamask/base-controller@3.2.3...@metamask/base-controller@4.0.0 | ||
[3.2.3]: https://github.com/MetaMask/core/compare/@metamask/base-controller@3.2.2...@metamask/base-controller@3.2.3 | ||
@@ -80,0 +106,0 @@ [3.2.2]: https://github.com/MetaMask/core/compare/@metamask/base-controller@3.2.1...@metamask/base-controller@3.2.2 |
@@ -38,3 +38,4 @@ import { RestrictedControllerMessenger } from './RestrictedControllerMessenger'; | ||
*/ | ||
export declare type Namespaced<Namespace extends string, Name> = Name extends `${Namespace}:${string}` ? Name : never; | ||
export declare type NamespacedBy<Namespace extends string, Name> = Name extends `${Namespace}:${string}` ? Name : never; | ||
export declare type NotNamespacedBy<Namespace extends string, Name> = Name extends `${Namespace}:${string}` ? never : Name; | ||
export declare type NamespacedName<Namespace extends string = string> = `${Namespace}:${string}`; | ||
@@ -190,9 +191,11 @@ declare type NarrowToNamespace<Name, Namespace extends string> = Name extends { | ||
* @template AllowedAction - A type union of the 'type' string for any allowed actions. | ||
* This must not include internal actions that are in the messenger's namespace. | ||
* @template AllowedEvent - A type union of the 'type' string for any allowed events. | ||
* This must not include internal events that are in the messenger's namespace. | ||
* @returns The restricted controller messenger. | ||
*/ | ||
getRestricted<Namespace extends string, AllowedAction extends string, AllowedEvent extends string>({ name, allowedActions, allowedEvents, }: { | ||
getRestricted<Namespace extends string, AllowedAction extends NotNamespacedBy<Namespace, Action['type']>, AllowedEvent extends NotNamespacedBy<Namespace, Event['type']>>({ name, allowedActions, allowedEvents, }: { | ||
name: Namespace; | ||
allowedActions?: Extract<Action['type'], AllowedAction>[]; | ||
allowedEvents?: Extract<Event['type'], AllowedEvent>[]; | ||
allowedActions?: NotNamespacedBy<Namespace, Extract<Action['type'], AllowedAction>>[]; | ||
allowedEvents?: NotNamespacedBy<Namespace, Extract<Event['type'], AllowedEvent>>[]; | ||
}): RestrictedControllerMessenger<Namespace, NarrowToNamespace<Action, Namespace> | NarrowToAllowed<Action, AllowedAction>, NarrowToNamespace<Event, Namespace> | NarrowToAllowed<Event, AllowedEvent>, AllowedAction, AllowedEvent>; | ||
@@ -199,0 +202,0 @@ } |
@@ -195,3 +195,5 @@ "use strict"; | ||
* @template AllowedAction - A type union of the 'type' string for any allowed actions. | ||
* This must not include internal actions that are in the messenger's namespace. | ||
* @template AllowedEvent - A type union of the 'type' string for any allowed events. | ||
* This must not include internal events that are in the messenger's namespace. | ||
* @returns The restricted controller messenger. | ||
@@ -198,0 +200,0 @@ */ |
@@ -1,7 +0,7 @@ | ||
export type { BaseConfig, BaseState, Listener } from './BaseController'; | ||
export { BaseController } from './BaseController'; | ||
export type { Listener as ListenerV2, StateDeriver, StateMetadata, StatePropertyMetadata, } from './BaseControllerV2'; | ||
export { BaseController as BaseControllerV2, getAnonymizedState, getPersistentState, type ControllerGetStateAction, type ControllerStateChangeEvent, } from './BaseControllerV2'; | ||
export type { BaseConfig, BaseState, Listener } from './BaseControllerV1'; | ||
export { BaseControllerV1 } from './BaseControllerV1'; | ||
export type { Listener as ListenerV2, StateDeriver, StateMetadata, StatePropertyMetadata, ControllerGetStateAction, ControllerStateChangeEvent, } from './BaseControllerV2'; | ||
export { BaseController, getAnonymizedState, getPersistentState, } from './BaseControllerV2'; | ||
export * from './ControllerMessenger'; | ||
export * from './RestrictedControllerMessenger'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,7 +17,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPersistentState = exports.getAnonymizedState = exports.BaseControllerV2 = exports.BaseController = void 0; | ||
var BaseController_1 = require("./BaseController"); | ||
Object.defineProperty(exports, "BaseController", { enumerable: true, get: function () { return BaseController_1.BaseController; } }); | ||
exports.getPersistentState = exports.getAnonymizedState = exports.BaseController = exports.BaseControllerV1 = void 0; | ||
var BaseControllerV1_1 = require("./BaseControllerV1"); | ||
Object.defineProperty(exports, "BaseControllerV1", { enumerable: true, get: function () { return BaseControllerV1_1.BaseControllerV1; } }); | ||
var BaseControllerV2_1 = require("./BaseControllerV2"); | ||
Object.defineProperty(exports, "BaseControllerV2", { enumerable: true, get: function () { return BaseControllerV2_1.BaseController; } }); | ||
Object.defineProperty(exports, "BaseController", { enumerable: true, get: function () { return BaseControllerV2_1.BaseController; } }); | ||
Object.defineProperty(exports, "getAnonymizedState", { enumerable: true, get: function () { return BaseControllerV2_1.getAnonymizedState; } }); | ||
@@ -24,0 +24,0 @@ Object.defineProperty(exports, "getPersistentState", { enumerable: true, get: function () { return BaseControllerV2_1.getPersistentState; } }); |
@@ -1,2 +0,2 @@ | ||
import type { ActionConstraint, ActionHandler, ControllerMessenger, EventConstraint, ExtractActionParameters, ExtractActionResponse, ExtractEventHandler, ExtractEventPayload, NamespacedName, SelectorEventHandler, SelectorFunction } from './ControllerMessenger'; | ||
import type { ActionConstraint, ActionHandler, ControllerMessenger, EventConstraint, ExtractActionParameters, ExtractActionResponse, ExtractEventHandler, ExtractEventPayload, NamespacedName, NotNamespacedBy, SelectorEventHandler, SelectorFunction } from './ControllerMessenger'; | ||
/** | ||
@@ -14,3 +14,5 @@ * A restricted controller messenger. | ||
* @template AllowedAction - A type union of the 'type' string for any allowed actions. | ||
* This must not include internal actions that are in the messenger's namespace. | ||
* @template AllowedEvent - A type union of the 'type' string for any allowed events. | ||
* This must not include internal events that are in the messenger's namespace. | ||
*/ | ||
@@ -40,4 +42,4 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Action extends ActionConstraint, Event extends EventConstraint, AllowedAction extends string, AllowedEvent extends string> { | ||
name: Namespace; | ||
allowedActions?: AllowedAction[]; | ||
allowedEvents?: AllowedEvent[]; | ||
allowedActions?: NotNamespacedBy<Namespace, AllowedAction>[]; | ||
allowedEvents?: NotNamespacedBy<Namespace, AllowedEvent>[]; | ||
}); | ||
@@ -57,3 +59,3 @@ /** | ||
*/ | ||
registerActionHandler<ActionType extends Action['type']>(action: ActionType, handler: ActionHandler<Action, ActionType>): void; | ||
registerActionHandler<ActionType extends Action['type'] & NamespacedName<Namespace>>(action: ActionType, handler: ActionHandler<Action, ActionType>): void; | ||
/** | ||
@@ -66,6 +68,7 @@ * Unregister an action handler. | ||
* | ||
* @param action - The action type. This is a unqiue identifier for this action. | ||
* @param action - The action type. This is a unique identifier for this action. | ||
* @throws Will throw if an action handler that is not in the current namespace is being unregistered. | ||
* @template ActionType - A type union of Action type strings that are namespaced by Namespace. | ||
*/ | ||
unregisterActionHandler<ActionType extends NamespacedName<Namespace>>(action: ActionType): void; | ||
unregisterActionHandler<ActionType extends Action['type'] & NamespacedName<Namespace>>(action: ActionType): void; | ||
/** | ||
@@ -79,3 +82,3 @@ * Call an action. | ||
* | ||
* @param action - The action type. This is a unqiue identifier for this action. | ||
* @param actionType - The action type. This is a unqiue identifier for this action. | ||
* @param params - The action parameters. These must match the type of the parameters of the | ||
@@ -87,3 +90,3 @@ * registered action handler. | ||
*/ | ||
call<ActionType extends AllowedAction & NamespacedName>(action: ActionType, ...params: ExtractActionParameters<Action, ActionType>): ExtractActionResponse<Action, ActionType>; | ||
call<ActionType extends AllowedAction | (Action['type'] & NamespacedName<Namespace>)>(actionType: ActionType, ...params: ExtractActionParameters<Action, ActionType>): ExtractActionResponse<Action, ActionType>; | ||
/** | ||
@@ -99,5 +102,6 @@ * Publish an event. | ||
* match the type of this payload. | ||
* @throws Will throw if an event that is not in the current namespace is being published. | ||
* @template EventType - A type union of Event type strings that are namespaced by Namespace. | ||
*/ | ||
publish<EventType extends NamespacedName<Namespace>>(event: EventType, ...payload: ExtractEventPayload<Event, EventType>): void; | ||
publish<EventType extends Event['type'] & NamespacedName<Namespace>>(event: EventType, ...payload: ExtractEventPayload<Event, EventType>): void; | ||
/** | ||
@@ -113,5 +117,6 @@ * Subscribe to an event. | ||
* match the type of the payload for this event type. | ||
* @throws Will throw if the given event is not an allowed event for this controller messenger. | ||
* @template EventType - A type union of Event type strings. | ||
*/ | ||
subscribe<EventType extends AllowedEvent & NamespacedName>(eventType: EventType, handler: ExtractEventHandler<Event, EventType>): void; | ||
subscribe<EventType extends AllowedEvent | (Event['type'] & NamespacedName<Namespace>)>(eventType: EventType, handler: ExtractEventHandler<Event, EventType>): void; | ||
/** | ||
@@ -133,6 +138,7 @@ * Subscribe to an event, with a selector. | ||
* the type of the payload for this event type. | ||
* @throws Will throw if the given event is not an allowed event for this controller messenger. | ||
* @template EventType - A type union of Event type strings. | ||
* @template SelectorReturnValue - The selector return value. | ||
*/ | ||
subscribe<EventType extends AllowedEvent & NamespacedName, SelectorReturnValue>(eventType: EventType, handler: SelectorEventHandler<SelectorReturnValue>, selector: SelectorFunction<ExtractEventPayload<Event, EventType>, SelectorReturnValue>): void; | ||
subscribe<EventType extends AllowedEvent | (Event['type'] & NamespacedName<Namespace>), SelectorReturnValue>(eventType: EventType, handler: SelectorEventHandler<SelectorReturnValue>, selector: SelectorFunction<ExtractEventPayload<Event, EventType>, SelectorReturnValue>): void; | ||
/** | ||
@@ -147,6 +153,6 @@ * Unsubscribe from an event. | ||
* @param handler - The event handler to unregister. | ||
* @throws Will throw when the given event handler is not registered for this event. | ||
* @throws Will throw if the given event is not an allowed event for this controller messenger. | ||
* @template EventType - A type union of allowed Event type strings. | ||
*/ | ||
unsubscribe<EventType extends AllowedEvent & NamespacedName>(event: EventType, handler: ExtractEventHandler<Event, EventType>): void; | ||
unsubscribe<EventType extends AllowedEvent | (Event['type'] & NamespacedName<Namespace>)>(event: EventType, handler: ExtractEventHandler<Event, EventType>): void; | ||
/** | ||
@@ -160,6 +166,7 @@ * Clear subscriptions for a specific event. | ||
* @param event - The event type. This is a unique identifier for this event. | ||
* @throws Will throw if a subscription for an event that is not in the current namespace is being cleared. | ||
* @template EventType - A type union of Event type strings that are namespaced by Namespace. | ||
*/ | ||
clearEventSubscriptions<EventType extends NamespacedName<Namespace>>(event: EventType): void; | ||
clearEventSubscriptions<EventType extends Event['type'] & NamespacedName<Namespace>>(event: EventType): void; | ||
} | ||
//# sourceMappingURL=RestrictedControllerMessenger.d.ts.map |
@@ -13,3 +13,3 @@ "use strict"; | ||
}; | ||
var _RestrictedControllerMessenger_controllerMessenger, _RestrictedControllerMessenger_controllerName, _RestrictedControllerMessenger_allowedActions, _RestrictedControllerMessenger_allowedEvents; | ||
var _RestrictedControllerMessenger_instances, _RestrictedControllerMessenger_controllerMessenger, _RestrictedControllerMessenger_controllerName, _RestrictedControllerMessenger_allowedActions, _RestrictedControllerMessenger_allowedEvents, _RestrictedControllerMessenger_isAllowedEvent, _RestrictedControllerMessenger_isAllowedAction, _RestrictedControllerMessenger_isInCurrentNamespace; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -29,3 +29,5 @@ exports.RestrictedControllerMessenger = void 0; | ||
* @template AllowedAction - A type union of the 'type' string for any allowed actions. | ||
* This must not include internal actions that are in the messenger's namespace. | ||
* @template AllowedEvent - A type union of the 'type' string for any allowed events. | ||
* This must not include internal events that are in the messenger's namespace. | ||
*/ | ||
@@ -52,2 +54,3 @@ class RestrictedControllerMessenger { | ||
constructor({ controllerMessenger, name, allowedActions, allowedEvents, }) { | ||
_RestrictedControllerMessenger_instances.add(this); | ||
_RestrictedControllerMessenger_controllerMessenger.set(this, void 0); | ||
@@ -59,4 +62,4 @@ _RestrictedControllerMessenger_controllerName.set(this, void 0); | ||
__classPrivateFieldSet(this, _RestrictedControllerMessenger_controllerName, name, "f"); | ||
__classPrivateFieldSet(this, _RestrictedControllerMessenger_allowedActions, allowedActions || null, "f"); | ||
__classPrivateFieldSet(this, _RestrictedControllerMessenger_allowedEvents, allowedEvents || null, "f"); | ||
__classPrivateFieldSet(this, _RestrictedControllerMessenger_allowedActions, allowedActions !== null && allowedActions !== void 0 ? allowedActions : null, "f"); | ||
__classPrivateFieldSet(this, _RestrictedControllerMessenger_allowedEvents, allowedEvents !== null && allowedEvents !== void 0 ? allowedEvents : null, "f"); | ||
} | ||
@@ -78,3 +81,3 @@ /** | ||
/* istanbul ignore if */ // Branch unreachable with valid types | ||
if (!action.startsWith(`${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:`)) { | ||
if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, action)) { | ||
throw new Error(`Only allowed registering action handlers prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`); | ||
@@ -91,3 +94,4 @@ } | ||
* | ||
* @param action - The action type. This is a unqiue identifier for this action. | ||
* @param action - The action type. This is a unique identifier for this action. | ||
* @throws Will throw if an action handler that is not in the current namespace is being unregistered. | ||
* @template ActionType - A type union of Action type strings that are namespaced by Namespace. | ||
@@ -97,3 +101,3 @@ */ | ||
/* istanbul ignore if */ // Branch unreachable with valid types | ||
if (!action.startsWith(`${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:`)) { | ||
if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, action)) { | ||
throw new Error(`Only allowed unregistering action handlers prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`); | ||
@@ -111,3 +115,3 @@ } | ||
* | ||
* @param action - The action type. This is a unqiue identifier for this action. | ||
* @param actionType - The action type. This is a unqiue identifier for this action. | ||
* @param params - The action parameters. These must match the type of the parameters of the | ||
@@ -119,11 +123,8 @@ * registered action handler. | ||
*/ | ||
call(action, ...params) { | ||
/* istanbul ignore next */ // Branches unreachable with valid types | ||
if (__classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedActions, "f") === null) { | ||
throw new Error('No actions allowed'); | ||
call(actionType, ...params) { | ||
if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isAllowedAction).call(this, actionType)) { | ||
throw new Error(`Action missing from allow list: ${actionType}`); | ||
} | ||
else if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedActions, "f").includes(action)) { | ||
throw new Error(`Action missing from allow list: ${action}`); | ||
} | ||
return __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").call(action, ...params); | ||
const response = __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").call(actionType, ...params); | ||
return response; | ||
} | ||
@@ -140,2 +141,3 @@ /** | ||
* match the type of this payload. | ||
* @throws Will throw if an event that is not in the current namespace is being published. | ||
* @template EventType - A type union of Event type strings that are namespaced by Namespace. | ||
@@ -145,3 +147,3 @@ */ | ||
/* istanbul ignore if */ // Branch unreachable with valid types | ||
if (!event.startsWith(`${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:`)) { | ||
if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, event)) { | ||
throw new Error(`Only allowed publishing events prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`); | ||
@@ -152,7 +154,3 @@ } | ||
subscribe(event, handler, selector) { | ||
/* istanbul ignore next */ // Branches unreachable with valid types | ||
if (__classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedEvents, "f") === null) { | ||
throw new Error('No events allowed'); | ||
} | ||
else if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedEvents, "f").includes(event)) { | ||
if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isAllowedEvent).call(this, event)) { | ||
throw new Error(`Event missing from allow list: ${event}`); | ||
@@ -174,11 +172,7 @@ } | ||
* @param handler - The event handler to unregister. | ||
* @throws Will throw when the given event handler is not registered for this event. | ||
* @throws Will throw if the given event is not an allowed event for this controller messenger. | ||
* @template EventType - A type union of allowed Event type strings. | ||
*/ | ||
unsubscribe(event, handler) { | ||
/* istanbul ignore next */ // Branches unreachable with valid types | ||
if (__classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedEvents, "f") === null) { | ||
throw new Error('No events allowed'); | ||
} | ||
else if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedEvents, "f").includes(event)) { | ||
if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isAllowedEvent).call(this, event)) { | ||
throw new Error(`Event missing from allow list: ${event}`); | ||
@@ -196,7 +190,7 @@ } | ||
* @param event - The event type. This is a unique identifier for this event. | ||
* @throws Will throw if a subscription for an event that is not in the current namespace is being cleared. | ||
* @template EventType - A type union of Event type strings that are namespaced by Namespace. | ||
*/ | ||
clearEventSubscriptions(event) { | ||
/* istanbul ignore if */ // Branch unreachable with valid types | ||
if (!event.startsWith(`${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:`)) { | ||
if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, event)) { | ||
throw new Error(`Only allowed clearing events prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`); | ||
@@ -208,3 +202,15 @@ } | ||
exports.RestrictedControllerMessenger = RestrictedControllerMessenger; | ||
_RestrictedControllerMessenger_controllerMessenger = new WeakMap(), _RestrictedControllerMessenger_controllerName = new WeakMap(), _RestrictedControllerMessenger_allowedActions = new WeakMap(), _RestrictedControllerMessenger_allowedEvents = new WeakMap(); | ||
_RestrictedControllerMessenger_controllerMessenger = new WeakMap(), _RestrictedControllerMessenger_controllerName = new WeakMap(), _RestrictedControllerMessenger_allowedActions = new WeakMap(), _RestrictedControllerMessenger_allowedEvents = new WeakMap(), _RestrictedControllerMessenger_instances = new WeakSet(), _RestrictedControllerMessenger_isAllowedEvent = function _RestrictedControllerMessenger_isAllowedEvent(eventType) { | ||
// Safely upcast to allow runtime check | ||
const allowedEvents = __classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedEvents, "f"); | ||
return (__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, eventType) || | ||
(allowedEvents !== null && allowedEvents.includes(eventType))); | ||
}, _RestrictedControllerMessenger_isAllowedAction = function _RestrictedControllerMessenger_isAllowedAction(actionType) { | ||
// Safely upcast to allow runtime check | ||
const allowedActions = __classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedActions, "f"); | ||
return (__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, actionType) || | ||
(allowedActions !== null && allowedActions.includes(actionType))); | ||
}, _RestrictedControllerMessenger_isInCurrentNamespace = function _RestrictedControllerMessenger_isInCurrentNamespace(name) { | ||
return name.startsWith(`${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:`); | ||
}; | ||
//# sourceMappingURL=RestrictedControllerMessenger.js.map |
{ | ||
"name": "@metamask-previews/base-controller", | ||
"version": "3.2.3-preview.eb58a59", | ||
"version": "4.0.0-preview.3fbb6b41", | ||
"description": "Provides scaffolding for controllers as well a communication system for all controllers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
149560
1383