All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- BREAKING: Remove deprecated messenger-related exports and simplify
RestrictedMessengerconstructor (#5260)- Remove
ControllerMessengerexport which was an alias forMessenger. Consumers should importMessengerdirectly - Remove
RestrictedControllerMessengerexport which was an alias forRestrictedMessenger. Consumers should importRestrictedMessengerdirectly - Remove
RestrictedControllerMessengerConstrainttype export which was an alias forRestrictedMessengerConstraint. Consumers should useRestrictedMessengerConstrainttype directly - Simplify
RestrictedMessengerconstructor by removing deprecatedcontrollerMessengerparameter. The messenger instance should now be passed using only themessengerparameter instead of supporting both options
- Remove
- Widen input parameter for type guard
isBaseControllerfromControllerInstancetounknown(#5018) - Bump
@metamask/json-rpc-enginefrom^10.0.2to^10.0.3(#5272) - Bump
@metamask/utilsfrom^11.0.1to^11.1.0(#5223)
- BREAKING: Remove class
BaseControllerV1and type guardisBaseControllerV1(#5018) - BREAKING: Remove types
BaseConfig,BaseControllerV1Instance,BaseState,ConfigConstraintV1,Listener,StateConstraintV1,LegacyControllerStateConstraint,ControllerInstance(#5018)
- Bump
@metamask/utilsfrom^10.0.0to^11.0.1(#5080)
- Rename
ControllerMessengertoMessenger(#5050)ControllerMessengerhas been renamed toMessengerRestrictedControllerMessengerConstrainthas been renamed toRestrictedMessengerConstraintRestrictedControllerMessengerhas been renamed toRestrictedMessenger- The
RestrictedMessengerconstructor parametercontrollerMessengerhas been renamed tomessenger, though the old name is still accepted - The old names remain exported as deprecated aliases of the new names, so this is not a breaking change.
- Bump
@metamask/utilsfrom^9.1.0to^10.0.0(#4831)
- Produce and export ESM-compatible TypeScript type declaration files in addition to CommonJS-compatible declaration files (#4648)
- Previously, this package shipped with only one variant of type declaration
files, and these files were only CommonJS-compatible, and the
exportsfield inpackage.jsonlinked to these files. This is an anti-pattern and was rightfully flagged by the "Are the Types Wrong?" tool as "masquerading as CJS". All of the ATTW checks now pass.
- Previously, this package shipped with only one variant of type declaration
files, and these files were only CommonJS-compatible, and the
- Remove chunk files (#4648).
- Previously, the build tool we used to generate JavaScript files extracted common code to "chunk" files. While this was intended to make this package more tree-shakeable, it also made debugging more difficult for our development teams. These chunk files are no longer present.
- Migrate from
@metamask/composable-controller@8.0.0into@metamask/base-controller: typesLegacyControllerStateConstraint,RestrictedControllerMessengerConstraintand type guard functionsisBaseController,isBaseControllerV1(#4581) - Add and export types
ControllerInstance,BaseControllerInstance,StateDeriverConstraint,StateMetadataConstraint,StatePropertyMetadataConstraint,BaseControllerV1Instance,ConfigConstraintV1,StateConstraintV1(#4581)
- BREAKING: Fix
StateMetadatatype so that it requires associated metadata for all optional and non-optional top-level state properties (#4612)- Fixes issue of runtime error being thrown during
BaseControllerinstantiation due to missing metadata for optional state properties.
- Fixes issue of runtime error being thrown during
- Bump TypeScript version to
~5.0.4and setmoduleResolutionoption toNode16(#3645) - Bump
@metamask/utilsfrom^9.0.0to^9.1.0(#4529)
- Bump
@metamask/rpc-errorsfrom6.2.1to^6.3.1(#4516) - Bump
@metamask/utilsfrom^8.3.0to^9.0.0(#4516)
- BREAKING: Bump minimum Node version to 18.18 (#3611)
- Bump TypeScript version to
~4.9.5(#4084)
- Fix
typesfield inpackage.json(#4047)
- BREAKING: Add ESM build (#3998)
- It's no longer possible to import files from
./distdirectly.
- It's no longer possible to import files from
- Add and export type
StateConstraint, which is an alias forRecord<string, Json>(#3949)- This type represents the narrowest supertype of the state of all controllers.
- Importing this type enables controllers to constrain state objects and types to be JSON-serializable without having to directly add
@metamask/utilsas a dependency.
- BREAKING: Narrow the return types of functions
getAnonymizedState<ControllerState>andgetPersistentState<ControllerState>fromRecord<string, Json>toRecord<keyof ControllerState, Json>. (#3949, #4040) - BREAKING: Align type-level and runtime behavior of
getRestrictedso that omitted or empty inputs consistently represent a set of empty allowlists (#4013)- If the
AllowedActionsandAllowedEventsgeneric parameters are omitted, they are always assumed to benever.- Previously, omission of these generic parameters resulted in the full allowlists for the controller being inferred as type constraints for the
allowedActionsandallowedEventsfunction parameters.
- Previously, omission of these generic parameters resulted in the full allowlists for the controller being inferred as type constraints for the
- If the function parameters
allowedActionsandallowedEventsare a non-empty array, their corresponding type names must be explicitly passed into generic parametersAllowedActionsandAllowedEventsto avoid type errors.- This may cause some duplication of allowlists between type-level and value-level code.
- This requirement is only relevant for TypeScript code. A JavaScript consumer only needs to pass in the correct value-level function parameters. Because of this, these changes should not affect downstream JavaScript code, but may be disruptive to TypeScript code.
getRestrictedis still able to flagAllowedActionsandAllowedEventsmembers that should not be included in the allowlists, based on theActionandEventgeneric arguments passed into theControllerMessengerinstance.
- If the
- BREAKING: The
RestrictedControllerMessengerclass constructor now expectsallowedActionsandallowedEventsas required options (#4013) - BREAKING: Add
stringas generic constraint to theNamegeneric parameter of the typesNamespacedByandNotNamespacedBy(#4036) - BREAKING: The
getRestrictedmethod of theControllerMessengerclass now expects bothallowedActionsandallowedEventsas required parameters.- An empty array is required if no allowed actions or events are desired.
- Convert interface
StatePropertyMetadatainto a type alias (#3949)
- BREAKING: Remove the deprecated
subscribeclass field fromBaseController(#3949)- This property was used to differentiate between
BaseControllerV1andBaseController(v2) controllers. It is no longer used.
- This property was used to differentiate between
- BREAKING: Narrow the generic constraint of the
ControllerStateparameter fromRecord<string, unknown>toRecord<string, Json>for typesControllerGetStateAction,ControllerStateChangeEvent,ControllerActions, andControllerEvents(#3949) - BREAKING: Fix
BaseControllerso that mutating state directly now results in a runtime error (#4011)- Directly modifying the state outside of an
updatecall may lead to parts of the application being out of sync, because such modifications do not result in thestateChangeevent being fired. - Instead of mutating the state of a controller after instantiation, consumers should either initialize that controller with the proper state via options or should use the
updatemethod to safely modify the state.
- Directly modifying the state outside of an
- BREAKING: Fix
subscribeonControllerMessengerandRestrictedControllerMessengerto infer correct types forselectorarguments (#4012)- Previously, the types of the arguments that the
selectorfunction received would always be inferred asnever, but now the types match those ofpublish(the "event payload"). This means that you shouldn't need to add use type annotations or assertions to type theselectorarguments.
- Previously, the types of the arguments that the
- Bump
@metamask/utilsto^8.3.0(#3769)
- Add
registerInitialEventPayloadtoControllerMessengerandRestrictedControllerMessenger(#3697)- This allows registering an event payload function for an event, which has the benefit of ensuring the "subscription selector" feature works correctly the first time the event is fired after subscribing.
- Fix
subscribemethod selector support on first publish (#3697)- An event with a registered initial event payload function will work better with selectors, in that it will correctly compare with the initial selected state and return the previous value the first time it's published. Without this, the initial published event will always return
undefinedas the previous value.
- An event with a registered initial event payload function will work better with selectors, in that it will correctly compare with the initial selected state and return the previous value the first time it's published. Without this, the initial published event will always return
- Subscribers to the
stateChangeevent of anyBaseControllerV2-based controllers will now correctly handle the initial state change event (#3702)- Previously the initial state change would always result in this event firing, even for subscriptions with selectors where the selected value has not changed. Additionally, the
previousValuereturned was always set toundefinedthe first time. BaseControllerV2has been updated to correctly compare with the previous value even for the first state change. The returnedpreviousValueis also now guaranteed to be correct even for the initial state change.
- Previously the initial state change would always result in this event firing, even for subscriptions with selectors where the selected value has not changed. Additionally, the
- Deprecate
subscribeproperty fromBaseControllerV2(#3590, #3698)- This property was used to differentiate between
BaseControllerV1andBaseControllerV2controllers. It is no longer used, so it has been marked as deprecated.
- This property was used to differentiate between
- Add
ControllerGetStateActionandControllerStateChangeEventtypes (#1890, #2029) - Add
NamespacedNametype (#1890)- This is the narrowest supertype of all names defined within a given namespace.
- Add
NotNamespacedBytype, which matches an action/event name if and only if it is not prefixed by a given namespace (#2051)
- BREAKING: Alter controller messenger
ActionHandlertype soActiontype parameter must satisfy (updated)ActionConstraint(#1890) - BREAKING: Alter controller messenger
ExtractActionParametersutility type soActiontype parameter must satisfy (updated)ActionConstraint(#1890) - BREAKING: Alter controller messenger
ExtractEventHandlerutility type soEventtype parameter must satisfyEventConstraint(#1890) - BREAKING: Alter controller messenger
ExtractEventPayloadutility type soEventtype parameter must satisfyEventConstraintandEvent['payload']must be an array (to match behavior ofExtractEventHandler) (#1890) - BREAKING: Alter controller messenger
SelectorFunctiontype so that its generic parameterArgsis replaced byEvent, which must satisfyEventConstraint, and it returns a function whose arguments satisfy the event payload type specified byEvent(#1890) - BREAKING:
BaseControlleris now renamed toBaseControllerV1and has been deprecated;BaseControllernow points to what was previously calledBaseControllerV2(#2078)- This should encourage use of
BaseControllerv2 for new controllers going forward. - If your controller is importing
BaseControllerV2, you will need to importBaseControllerinstead. - If your controller is still importing
BaseControllerv1, you will need to import and useBaseControllerV1instead. That said, please consider migrating your controller to v2.
- This should encourage use of
- BREAKING: The restricted controller messenger now allows calling all internal events and actions by default and prohibits explicitly allowlisting any of them (#2050, #2051)
- Previously internal events and actions were only usable if they were listed as "allowed" via the
allowedActionsorallowedEventsoptions to theRestrictedControllerMessengerconstructor orControllerMessenger.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.
- Previously internal events and actions were only usable if they were listed as "allowed" via the
- BREAKING: Rename
Namespacedtype toNamespacedBy(#2051) - Alter controller messenger
ActionConstraint['handler']type to remove usage ofany(#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/utilsto ^8.2.0 (#1957)
- Bump dependency on
@metamask/utilsto ^8.1.0 (#1639)
- Update TypeScript to v4.8.x (#1718)
- There are no consumer-facing changes to this package. This version is a part of a synchronized release across all packages in our monorepo.
- When deriving state, skip properties with invalid metadata (#1529)
- The previous behavior was to throw an error
- An error is thrown in a timeout handler so that it can still be captured in the console, and by global unhandled error handlers.
- Update
@metamask/utilsto^6.2.0(#1514)
- Prevent event publish from throwing error (#1475)
- The controller messenger will no longer throw when an event subscriber throws an error. Calls to
publish(either within controllers or on a messenger instance directly) will no longer throw errors. - Errors are thrown in a timeout handler so that they can still be logged and captured.
- The controller messenger will no longer throw when an event subscriber throws an error. Calls to
- BREAKING: Bump to Node 16 (#1262)
- Replace
@metamask/controller-utilsdependency with@metamask/utils(#1370)
- BREAKING: Remove
isomorphic-fetch(#1106)- Consumers must now import
isomorphic-fetchor another polyfill themselves if they are running in an environment withoutfetch
- Consumers must now import
- Relax dependency on
@metamask/controller-utils(use^instead of~) (#998)
- Add
applyPatchesfunction to BaseControllerV2 (#980)
- Action and event handler types are now exported (#987)
- Update
updatefunction to expose patches (#980)
-
Initial release
-
As a result of converting our shared controllers repo into a monorepo (#831), we've created this package from select parts of
@metamask/controllersv33.0.0, namely:src/BaseController.tssrc/BaseController.test.tssrc/BaseControllerV2.tssrc/BaseControllerV2.test.tssrc/ComposableController.tssrc/ComposableController.test.tssrc/ControllerMessenger.tssrc/ControllerMessenger.test.ts
All changes listed after this point were applied to this package following the monorepo conversion.
-