@metamask-previews/base-controller 8.4.2-preview-9fa15fd0 → 9.0.0-preview-46d2c977
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 +18 -4
- package/dist/BaseController.cjs +23 -57
- package/dist/BaseController.cjs.map +1 -1
- package/dist/BaseController.d.cts +16 -45
- package/dist/BaseController.d.cts.map +1 -1
- package/dist/BaseController.d.mts +16 -45
- package/dist/BaseController.d.mts.map +1 -1
- package/dist/BaseController.mjs +22 -53
- package/dist/BaseController.mjs.map +1 -1
- package/dist/index.cjs +1 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -14
- package/dist/Messenger.cjs +0 -279
- package/dist/Messenger.cjs.map +0 -1
- package/dist/Messenger.d.cts +0 -231
- package/dist/Messenger.d.cts.map +0 -1
- package/dist/Messenger.d.mts +0 -231
- package/dist/Messenger.d.mts.map +0 -1
- package/dist/Messenger.mjs +0 -275
- package/dist/Messenger.mjs.map +0 -1
- package/dist/RestrictedMessenger.cjs +0 -242
- package/dist/RestrictedMessenger.cjs.map +0 -1
- package/dist/RestrictedMessenger.d.cts +0 -200
- package/dist/RestrictedMessenger.d.cts.map +0 -1
- package/dist/RestrictedMessenger.d.mts +0 -200
- package/dist/RestrictedMessenger.d.mts.map +0 -1
- package/dist/RestrictedMessenger.mjs +0 -238
- package/dist/RestrictedMessenger.mjs.map +0 -1
- package/dist/next/BaseController.cjs +0 -168
- package/dist/next/BaseController.cjs.map +0 -1
- package/dist/next/BaseController.d.cts +0 -206
- package/dist/next/BaseController.d.cts.map +0 -1
- package/dist/next/BaseController.d.mts +0 -206
- package/dist/next/BaseController.d.mts.map +0 -1
- package/dist/next/BaseController.mjs +0 -163
- package/dist/next/BaseController.mjs.map +0 -1
- package/dist/next/index.cjs +0 -7
- package/dist/next/index.cjs.map +0 -1
- package/dist/next/index.d.cts +0 -3
- package/dist/next/index.d.cts.map +0 -1
- package/dist/next/index.d.mts +0 -3
- package/dist/next/index.d.mts.map +0 -1
- package/dist/next/index.mjs +0 -2
- package/dist/next/index.mjs.map +0 -1
- package/next.d.ts +0 -7
- package/next.js +0 -3
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RestrictedMessenger.mjs","sourceRoot":"","sources":["../src/RestrictedMessenger.ts"],"names":[],"mappings":";;;;;;;;;;;;AA+BA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,mBAAmB;IAe9B;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,EACV,SAAS,EACT,IAAI,EACJ,cAAc,EACd,aAAa,GAMd;;QApCQ,iDAAyD;QAEzD,iDAAsB;QAEtB,sDAA6D;QAE7D,qDAA2D;QA+BlE,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;SAC3C;QACD,uEAAuE;QACvE,uBAAA,IAAI,kCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,kCAAc,IAAI,MAAA,CAAC;QACvB,uBAAA,IAAI,uCAAmB,cAAc,MAAA,CAAC;QACtC,uBAAA,IAAI,sCAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,qBAAqB,CAEnB,MAAkB,EAAE,OAA0C;QAC9D,wBAAwB,CAAC,sCAAsC;QAC/D,IAAI,CAAC,uBAAA,IAAI,iFAAsB,MAA1B,IAAI,EAAuB,MAAM,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CACb,yDACE,uBAAA,IAAI,sCACN,IAAI,CACL,CAAC;SACH;QACD,uBAAA,IAAI,sCAAW,CAAC,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;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AAuB,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;CAqDF;4UA1CG,SAAwB;IAIxB,uCAAuC;IACvC,MAAM,aAAa,GAAoB,uBAAA,IAAI,0CAAe,CAAC;IAC3D,OAAO,CACL,uBAAA,IAAI,iFAAsB,MAA1B,IAAI,EAAuB,SAAS,CAAC;QACrC,CAAC,aAAa,KAAK,IAAI,IAAI,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAC9D,CAAC;AACJ,CAAC,uFAWC,UAA0B;IAI1B,uCAAuC;IACvC,MAAM,cAAc,GAAoB,uBAAA,IAAI,2CAAgB,CAAC;IAC7D,OAAO,CACL,uBAAA,IAAI,iFAAsB,MAA1B,IAAI,EAAuB,UAAU,CAAC;QACtC,CAAC,cAAc,KAAK,IAAI,IAAI,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CACjE,CAAC;AACJ,CAAC,iGAQqB,IAAY;IAChC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,uBAAA,IAAI,sCAAW,GAAG,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type {\n ActionConstraint,\n ActionHandler,\n Messenger,\n EventConstraint,\n ExtractActionParameters,\n ExtractActionResponse,\n ExtractEventHandler,\n ExtractEventPayload,\n NamespacedName,\n NotNamespacedBy,\n SelectorEventHandler,\n SelectorFunction,\n} from './Messenger';\n\n/**\n * A universal supertype of all `RestrictedMessenger` instances. This type can be assigned to any\n * `RestrictedMessenger` type.\n *\n * @template Namespace - Name of the module this messenger is for. Optionally can be used to\n * narrow this type to a constraint for the messenger of a specific module.\n */\nexport type RestrictedMessengerConstraint<Namespace extends string = string> =\n RestrictedMessenger<\n Namespace,\n ActionConstraint,\n EventConstraint,\n string,\n string\n >;\n\n/**\n * A restricted messenger.\n *\n * This acts as a wrapper around the messenger instance that restricts access to actions\n * and events.\n *\n * @template Namespace - The namespace for this messenger. Typically this is the name of the controller or\n * module that this messenger has been created for. The authority to publish events and register\n * actions under this namespace is granted to this restricted messenger instance.\n * @template Action - A type union of all Action types.\n * @template Event - A type union of all Event types.\n * @template AllowedAction - A type union of the 'type' string for any allowed actions.\n * This must not include internal actions that are in the messenger's namespace.\n * @template AllowedEvent - A type union of the 'type' string for any allowed events.\n * This must not include internal events that are in the messenger's namespace.\n */\nexport class RestrictedMessenger<\n Namespace extends string,\n Action extends ActionConstraint,\n Event extends EventConstraint,\n AllowedAction extends string,\n AllowedEvent extends string,\n> {\n readonly #messenger: Messenger<ActionConstraint, EventConstraint>;\n\n readonly #namespace: Namespace;\n\n readonly #allowedActions: NotNamespacedBy<Namespace, AllowedAction>[];\n\n readonly #allowedEvents: NotNamespacedBy<Namespace, AllowedEvent>[];\n\n /**\n * Constructs a restricted messenger\n *\n * The provided allowlists grant the ability to call the listed actions and subscribe to the\n * listed events. The \"name\" provided grants ownership of any actions and events under that\n * namespace. Ownership allows registering actions and publishing events, as well as\n * unregistering actions and clearing event subscriptions.\n *\n * @param options - Options.\n * @param options.messenger - The messenger instance that is being wrapped.\n * @param options.name - The name of the thing this messenger will be handed to (e.g. the\n * controller name). This grants \"ownership\" of actions and events under this namespace to the\n * restricted messenger returned.\n * @param options.allowedActions - The list of actions that this restricted messenger should be\n * allowed to call.\n * @param options.allowedEvents - The list of events that this restricted messenger should be\n * allowed to subscribe to.\n */\n constructor({\n messenger,\n name,\n allowedActions,\n allowedEvents,\n }: {\n messenger?: Messenger<ActionConstraint, EventConstraint>;\n name: Namespace;\n allowedActions: NotNamespacedBy<Namespace, AllowedAction>[];\n allowedEvents: NotNamespacedBy<Namespace, AllowedEvent>[];\n }) {\n if (!messenger) {\n throw new Error('Messenger not provided');\n }\n // The above condition guarantees that one of these options is defined.\n this.#messenger = messenger;\n this.#namespace = name;\n this.#allowedActions = allowedActions;\n this.#allowedEvents = allowedEvents;\n }\n\n /**\n * Register an action handler.\n *\n * This will make the registered function available to call via the `call` method.\n *\n * The action type this handler is registered under *must* be in the current namespace.\n *\n * @param action - The action type. This is a unique identifier for this action.\n * @param handler - The action handler. This function gets called when the `call` method is\n * invoked with the given action type.\n * @throws Will throw if an action handler that is not in the current namespace is being registered.\n * @template ActionType - A type union of Action type strings that are namespaced by Namespace.\n */\n registerActionHandler<\n ActionType extends Action['type'] & NamespacedName<Namespace>,\n >(action: ActionType, handler: ActionHandler<Action, ActionType>) {\n /* istanbul ignore if */ // Branch unreachable with valid types\n if (!this.#isInCurrentNamespace(action)) {\n throw new Error(\n `Only allowed registering action handlers prefixed by '${\n this.#namespace\n }:'`,\n );\n }\n this.#messenger.registerActionHandler(action, handler);\n }\n\n /**\n * Registers action handlers for a list of methods on a messenger client\n *\n * @param messengerClient - The object that is expected to make use of the messenger.\n * @param methodNames - The names of the methods on the messenger client to register as action\n * handlers.\n * @template MessengerClient - The type expected to make use of the messenger.\n * @template MethodNames - The type union of method names to register as action handlers.\n */\n registerMethodActionHandlers<\n MessengerClient extends { name: string },\n MethodNames extends keyof MessengerClient & string,\n >(messengerClient: MessengerClient, methodNames: readonly MethodNames[]) {\n this.#messenger.registerMethodActionHandlers(messengerClient, methodNames);\n }\n\n /**\n * Unregister an action handler.\n *\n * This will prevent this action from being called.\n *\n * The action type being unregistered *must* be in the current namespace.\n *\n * @param action - The action type. This is a unique identifier for this action.\n * @throws Will throw if an action handler that is not in the current namespace is being unregistered.\n * @template ActionType - A type union of Action type strings that are namespaced by Namespace.\n */\n unregisterActionHandler<\n ActionType extends Action['type'] & NamespacedName<Namespace>,\n >(action: ActionType) {\n /* istanbul ignore if */ // Branch unreachable with valid types\n if (!this.#isInCurrentNamespace(action)) {\n throw new Error(\n `Only allowed unregistering action handlers prefixed by '${\n this.#namespace\n }:'`,\n );\n }\n this.#messenger.unregisterActionHandler(action);\n }\n\n /**\n * Call an action.\n *\n * This function will call the action handler corresponding to the given action type, passing\n * along any parameters given.\n *\n * The action type being called must be on the action allowlist.\n *\n * @param actionType - The action type. This is a unique identifier for this action.\n * @param params - The action parameters. These must match the type of the parameters of the\n * registered action handler.\n * @throws Will throw when no handler has been registered for the given type.\n * @template ActionType - A type union of allowed Action type strings.\n * @returns The action return value.\n */\n call<\n ActionType extends\n | AllowedAction\n | (Action['type'] & NamespacedName<Namespace>),\n >(\n actionType: ActionType,\n ...params: ExtractActionParameters<Action, ActionType>\n ): ExtractActionResponse<Action, ActionType> {\n if (!this.#isAllowedAction(actionType)) {\n throw new Error(`Action missing from allow list: ${actionType}`);\n }\n const response = this.#messenger.call<ActionType>(actionType, ...params);\n\n return response;\n }\n\n /**\n * Register a function for getting the initial payload for an event.\n *\n * This is used for events that represent a state change, where the payload is the state.\n * Registering a function for getting the payload allows event selectors to have a point of\n * comparison the first time state changes.\n *\n * The event type *must* be in the current namespace\n *\n * @param args - The arguments to this function\n * @param args.eventType - The event type to register a payload for.\n * @param args.getPayload - A function for retrieving the event payload.\n * @template EventType - A type union of Event type strings.\n */\n registerInitialEventPayload<\n EventType extends Event['type'] & NamespacedName<Namespace>,\n >({\n eventType,\n getPayload,\n }: {\n eventType: EventType;\n getPayload: () => ExtractEventPayload<Event, EventType>;\n }) {\n /* istanbul ignore if */ // Branch unreachable with valid types\n if (!this.#isInCurrentNamespace(eventType)) {\n throw new Error(\n `Only allowed publishing events prefixed by '${this.#namespace}:'`,\n );\n }\n this.#messenger.registerInitialEventPayload({\n eventType,\n getPayload,\n });\n }\n\n /**\n * Publish an event.\n *\n * Publishes the given payload to all subscribers of the given event type.\n *\n * The event type being published *must* be in the current namespace.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @throws Will throw if an event that is not in the current namespace is being published.\n * @template EventType - A type union of Event type strings that are namespaced by Namespace.\n */\n publish<EventType extends Event['type'] & NamespacedName<Namespace>>(\n event: EventType,\n ...payload: ExtractEventPayload<Event, EventType>\n ) {\n /* istanbul ignore if */ // Branch unreachable with valid types\n if (!this.#isInCurrentNamespace(event)) {\n throw new Error(\n `Only allowed publishing events prefixed by '${this.#namespace}:'`,\n );\n }\n this.#messenger.publish(event, ...payload);\n }\n\n /**\n * Subscribe to an event.\n *\n * Registers the given function as an event handler for the given event type.\n *\n * The event type being subscribed to must be on the event allowlist.\n *\n * @param eventType - The event type. This is a unique identifier for this event.\n * @param handler - The event handler. The type of the parameters for this event handler must\n * match the type of the payload for this event type.\n * @throws Will throw if the given event is not an allowed event for this messenger.\n * @template EventType - A type union of Event type strings.\n */\n subscribe<\n EventType extends\n | AllowedEvent\n | (Event['type'] & NamespacedName<Namespace>),\n >(eventType: EventType, handler: ExtractEventHandler<Event, EventType>): void;\n\n /**\n * Subscribe to an event, with a selector.\n *\n * Registers the given handler function as an event handler for the given\n * event type. When an event is published, its payload is first passed to the\n * selector. The event handler is only called if the selector's return value\n * differs from its last known return value.\n *\n * The event type being subscribed to must be on the event allowlist.\n *\n * @param eventType - The event type. This is a unique identifier for this event.\n * @param handler - The event handler. The type of the parameters for this event\n * handler must match the return type of the selector.\n * @param selector - The selector function used to select relevant data from\n * the event payload. The type of the parameters for this selector must match\n * the type of the payload for this event type.\n * @throws Will throw if the given event is not an allowed event for this messenger.\n * @template EventType - A type union of Event type strings.\n * @template SelectorReturnValue - The selector return value.\n */\n subscribe<\n EventType extends\n | AllowedEvent\n | (Event['type'] & NamespacedName<Namespace>),\n SelectorReturnValue,\n >(\n eventType: EventType,\n handler: SelectorEventHandler<SelectorReturnValue>,\n selector: SelectorFunction<Event, EventType, SelectorReturnValue>,\n ): void;\n\n subscribe<\n EventType extends\n | AllowedEvent\n | (Event['type'] & NamespacedName<Namespace>),\n SelectorReturnValue,\n >(\n event: EventType,\n handler:\n | ExtractEventHandler<Event, EventType>\n | SelectorEventHandler<SelectorReturnValue>,\n selector?: SelectorFunction<Event, EventType, SelectorReturnValue>,\n ) {\n if (!this.#isAllowedEvent(event)) {\n throw new Error(`Event missing from allow list: ${event}`);\n }\n\n if (selector) {\n return this.#messenger.subscribe(event, handler, selector);\n }\n return this.#messenger.subscribe(\n event,\n handler as ExtractEventHandler<Event, EventType>,\n );\n }\n\n /**\n * Unsubscribe from an event.\n *\n * Unregisters the given function as an event handler for the given event.\n *\n * The event type being unsubscribed to must be on the event allowlist.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param handler - The event handler to unregister.\n * @throws Will throw if the given event is not an allowed event for this messenger.\n * @template EventType - A type union of allowed Event type strings.\n * @template SelectorReturnValue - The selector return value.\n */\n unsubscribe<\n EventType extends\n | AllowedEvent\n | (Event['type'] & NamespacedName<Namespace>),\n SelectorReturnValue = unknown,\n >(\n event: EventType,\n handler:\n | ExtractEventHandler<Event, EventType>\n | SelectorEventHandler<SelectorReturnValue>,\n ) {\n if (!this.#isAllowedEvent(event)) {\n throw new Error(`Event missing from allow list: ${event}`);\n }\n this.#messenger.unsubscribe(event, handler);\n }\n\n /**\n * Clear subscriptions for a specific event.\n *\n * This will remove all subscribed handlers for this event.\n *\n * The event type being cleared *must* be in the current namespace.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @throws Will throw if a subscription for an event that is not in the current namespace is being cleared.\n * @template EventType - A type union of Event type strings that are namespaced by Namespace.\n */\n clearEventSubscriptions<\n EventType extends Event['type'] & NamespacedName<Namespace>,\n >(event: EventType) {\n if (!this.#isInCurrentNamespace(event)) {\n throw new Error(\n `Only allowed clearing events prefixed by '${this.#namespace}:'`,\n );\n }\n this.#messenger.clearEventSubscriptions(event);\n }\n\n /**\n * Determine whether the given event type is allowed. Event types are\n * allowed if they are in the current namespace or on the list of\n * allowed events.\n *\n * @param eventType - The event type to check.\n * @returns Whether the event type is allowed.\n */\n #isAllowedEvent(\n eventType: Event['type'],\n ): eventType is\n | NamespacedName<Namespace>\n | NotNamespacedBy<Namespace, AllowedEvent> {\n // Safely upcast to allow runtime check\n const allowedEvents: string[] | null = this.#allowedEvents;\n return (\n this.#isInCurrentNamespace(eventType) ||\n (allowedEvents !== null && allowedEvents.includes(eventType))\n );\n }\n\n /**\n * Determine whether the given action type is allowed. Action types\n * are allowed if they are in the current namespace or on the list of\n * allowed actions.\n *\n * @param actionType - The action type to check.\n * @returns Whether the action type is allowed.\n */\n #isAllowedAction(\n actionType: Action['type'],\n ): actionType is\n | NamespacedName<Namespace>\n | NotNamespacedBy<Namespace, AllowedAction> {\n // Safely upcast to allow runtime check\n const allowedActions: string[] | null = this.#allowedActions;\n return (\n this.#isInCurrentNamespace(actionType) ||\n (allowedActions !== null && allowedActions.includes(actionType))\n );\n }\n\n /**\n * Determine whether the given name is within the current namespace.\n *\n * @param name - The name to check\n * @returns Whether the name is within the current namespace\n */\n #isInCurrentNamespace(name: string): name is NamespacedName<Namespace> {\n return name.startsWith(`${this.#namespace}:`);\n }\n}\n"]}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
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");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
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");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _BaseController_internalState, _BaseController_messenger;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.deriveStateFromMetadata = exports.BaseController = void 0;
|
|
16
|
-
const immer_1 = require("immer");
|
|
17
|
-
(0, immer_1.enablePatches)();
|
|
18
|
-
/**
|
|
19
|
-
* Controller class that provides state management, subscriptions, and state metadata
|
|
20
|
-
*/
|
|
21
|
-
class BaseController {
|
|
22
|
-
/**
|
|
23
|
-
* Creates a BaseController instance.
|
|
24
|
-
*
|
|
25
|
-
* @param options - Controller options.
|
|
26
|
-
* @param options.messenger - The controller messenger.
|
|
27
|
-
* @param options.metadata - ControllerState metadata, describing how to "anonymize" the state, and which
|
|
28
|
-
* parts should be persisted.
|
|
29
|
-
* @param options.name - The name of the controller, used as a namespace for events and actions.
|
|
30
|
-
* @param options.state - Initial controller state.
|
|
31
|
-
*/
|
|
32
|
-
constructor({ messenger, metadata, name, state, }) {
|
|
33
|
-
/**
|
|
34
|
-
* The controller state.
|
|
35
|
-
*/
|
|
36
|
-
_BaseController_internalState.set(this, void 0);
|
|
37
|
-
/**
|
|
38
|
-
* The controller messenger.
|
|
39
|
-
*
|
|
40
|
-
* This is the same as the `messagingSystem` property, but has a type that only lets us use
|
|
41
|
-
* actions and events that are part of the `BaseController` class.
|
|
42
|
-
*/
|
|
43
|
-
_BaseController_messenger.set(this, void 0);
|
|
44
|
-
// The parameter type validates that the expected actions/events are present
|
|
45
|
-
// We don't have a way to validate the type property because the type is invariant
|
|
46
|
-
__classPrivateFieldSet(this, _BaseController_messenger, messenger, "f");
|
|
47
|
-
this.messenger = messenger;
|
|
48
|
-
this.name = name;
|
|
49
|
-
// Here we use `freeze` from Immer to enforce that the state is deeply
|
|
50
|
-
// immutable. Note that this is a runtime check, not a compile-time check.
|
|
51
|
-
// That is, unlike `Object.freeze`, this does not narrow the type
|
|
52
|
-
// recursively to `Readonly`. The equivalent in Immer is `Immutable`, but
|
|
53
|
-
// `Immutable` does not handle recursive types such as our `Json` type.
|
|
54
|
-
__classPrivateFieldSet(this, _BaseController_internalState, (0, immer_1.freeze)(state, true), "f");
|
|
55
|
-
this.metadata = metadata;
|
|
56
|
-
__classPrivateFieldGet(this, _BaseController_messenger, "f").registerActionHandler(`${name}:getState`, () => this.state);
|
|
57
|
-
__classPrivateFieldGet(this, _BaseController_messenger, "f").registerInitialEventPayload({
|
|
58
|
-
eventType: `${name}:stateChange`,
|
|
59
|
-
getPayload: () => [this.state, []],
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Retrieves current controller state.
|
|
64
|
-
*
|
|
65
|
-
* @returns The current state.
|
|
66
|
-
*/
|
|
67
|
-
get state() {
|
|
68
|
-
return __classPrivateFieldGet(this, _BaseController_internalState, "f");
|
|
69
|
-
}
|
|
70
|
-
set state(_) {
|
|
71
|
-
throw new Error(`Controller state cannot be directly mutated; use 'update' method instead.`);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Updates controller state. Accepts a callback that is passed a draft copy
|
|
75
|
-
* of the controller state. If a value is returned, it is set as the new
|
|
76
|
-
* state. Otherwise, any changes made within that callback to the draft are
|
|
77
|
-
* applied to the controller state.
|
|
78
|
-
*
|
|
79
|
-
* @param callback - Callback for updating state, passed a draft state
|
|
80
|
-
* object. Return a new state object or mutate the draft to update state.
|
|
81
|
-
* @returns An object that has the next state, patches applied in the update and inverse patches to
|
|
82
|
-
* rollback the update.
|
|
83
|
-
*/
|
|
84
|
-
update(callback) {
|
|
85
|
-
// We run into ts2589, "infinite type depth", if we don't cast
|
|
86
|
-
// produceWithPatches here.
|
|
87
|
-
const [nextState, patches, inversePatches] = immer_1.produceWithPatches(__classPrivateFieldGet(this, _BaseController_internalState, "f"), callback);
|
|
88
|
-
// Protect against unnecessary state updates when there is no state diff.
|
|
89
|
-
if (patches.length > 0) {
|
|
90
|
-
__classPrivateFieldSet(this, _BaseController_internalState, nextState, "f");
|
|
91
|
-
__classPrivateFieldGet(this, _BaseController_messenger, "f").publish(`${this.name}:stateChange`, nextState, patches);
|
|
92
|
-
}
|
|
93
|
-
return { nextState, patches, inversePatches };
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Applies immer patches to the current state. The patches come from the
|
|
97
|
-
* update function itself and can either be normal or inverse patches.
|
|
98
|
-
*
|
|
99
|
-
* @param patches - An array of immer patches that are to be applied to make
|
|
100
|
-
* or undo changes.
|
|
101
|
-
*/
|
|
102
|
-
applyPatches(patches) {
|
|
103
|
-
const nextState = (0, immer_1.applyPatches)(__classPrivateFieldGet(this, _BaseController_internalState, "f"), patches);
|
|
104
|
-
__classPrivateFieldSet(this, _BaseController_internalState, nextState, "f");
|
|
105
|
-
__classPrivateFieldGet(this, _BaseController_messenger, "f").publish(`${this.name}:stateChange`, nextState, patches);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Prepares the controller for garbage collection. This should be extended
|
|
109
|
-
* by any subclasses to clean up any additional connections or events.
|
|
110
|
-
*
|
|
111
|
-
* The only cleanup performed here is to remove listeners. While technically
|
|
112
|
-
* this is not required to ensure this instance is garbage collected, it at
|
|
113
|
-
* least ensures this instance won't be responsible for preventing the
|
|
114
|
-
* listeners from being garbage collected.
|
|
115
|
-
*/
|
|
116
|
-
destroy() {
|
|
117
|
-
this.messenger.clearEventSubscriptions(`${this.name}:stateChange`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.BaseController = BaseController;
|
|
121
|
-
_BaseController_internalState = new WeakMap(), _BaseController_messenger = new WeakMap();
|
|
122
|
-
/**
|
|
123
|
-
* Use the metadata to derive state according to the given metadata property.
|
|
124
|
-
*
|
|
125
|
-
* @param state - The full controller state.
|
|
126
|
-
* @param metadata - The controller metadata.
|
|
127
|
-
* @param metadataProperty - The metadata property to use to derive state.
|
|
128
|
-
* @param captureException - Reports an error to an error monitoring service.
|
|
129
|
-
* @returns The metadata-derived controller state.
|
|
130
|
-
*/
|
|
131
|
-
function deriveStateFromMetadata(state, metadata, metadataProperty, captureException) {
|
|
132
|
-
return Object.keys(state).reduce((derivedState, key) => {
|
|
133
|
-
try {
|
|
134
|
-
const stateMetadata = metadata[key];
|
|
135
|
-
if (!stateMetadata) {
|
|
136
|
-
throw new Error(`No metadata found for '${String(key)}'`);
|
|
137
|
-
}
|
|
138
|
-
const propertyMetadata = stateMetadata[metadataProperty];
|
|
139
|
-
const stateProperty = state[key];
|
|
140
|
-
if (typeof propertyMetadata === 'function') {
|
|
141
|
-
derivedState[key] = propertyMetadata(stateProperty);
|
|
142
|
-
}
|
|
143
|
-
else if (propertyMetadata) {
|
|
144
|
-
derivedState[key] = stateProperty;
|
|
145
|
-
}
|
|
146
|
-
return derivedState;
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
// Capture error without interrupting state-related operations
|
|
150
|
-
// See [ADR core#0016](https://github.com/MetaMask/decisions/blob/main/decisions/core/0016-core-classes-error-reporting.md)
|
|
151
|
-
if (captureException) {
|
|
152
|
-
try {
|
|
153
|
-
captureException(error instanceof Error ? error : new Error(String(error)));
|
|
154
|
-
}
|
|
155
|
-
catch (captureExceptionError) {
|
|
156
|
-
console.error(new Error(`Error thrown when calling 'captureException'`), captureExceptionError);
|
|
157
|
-
console.error(error);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
console.error(error);
|
|
162
|
-
}
|
|
163
|
-
return derivedState;
|
|
164
|
-
}
|
|
165
|
-
}, {});
|
|
166
|
-
}
|
|
167
|
-
exports.deriveStateFromMetadata = deriveStateFromMetadata;
|
|
168
|
-
//# sourceMappingURL=BaseController.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseController.cjs","sourceRoot":"","sources":["../../src/next/BaseController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,iCAAgF;AAGhF,IAAA,qBAAa,GAAE,CAAC;AAmKhB;;GAEG;AACH,MAAa,cAAc;IA4CzB;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,KAAK,GAgBN;QA7DD;;WAEG;QACH,gDAAgC;QAOhC;;;;;WAKG;QACM,4CAIP;QA0CA,4EAA4E;QAC5E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nC;YACD,OAAO,YAAY,CAAC;SACrB;QAAC,OAAO,KAAK,EAAE;YACd,8DAA8D;YAC9D,2HAA2H;YAC3H,IAAI,gBAAgB,EAAE;gBACpB,IAAI;oBACF,gBAAgB,CACd,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;iBACH;gBAAC,OAAO,qBAAqB,EAAE;oBAC9B,OAAO,CAAC,KAAK,CACX,IAAI,KAAK,CAAC,8CAA8C,CAAC,EACzD,qBAAqB,CACtB,CAAC;oBACF,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACtB;aACF;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aACtB;YACD,OAAO,YAAY,CAAC;SACrB;IACH,CAAC,EAAE,EAAW,CAAC,CAAC;AAClB,CAAC;AA7CD,0DA6CC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n Messenger,\n MessengerActions,\n MessengerEvents,\n} from '@metamask/messenger';\nimport type { Json, PublicInterface } from '@metamask/utils';\nimport { enablePatches, produceWithPatches, applyPatches, freeze } from 'immer';\nimport type { Draft, Patch } from 'immer';\n\nenablePatches();\n\n/**\n * A type that constrains the state of all controllers.\n *\n * In other words, the narrowest supertype encompassing all controller state.\n */\nexport type StateConstraint = Record<string, Json>;\n\n/**\n * A state change listener.\n *\n * This function will get called for each state change, and is given a copy of\n * the new state along with a set of patches describing the changes since the\n * last update.\n *\n * @param state - The new controller state.\n * @param patches - A list of patches describing any changes (see here for more\n * information: https://immerjs.github.io/immer/docs/patches)\n */\nexport type StateChangeListener<T> = (state: T, patches: Patch[]) => void;\n\n/**\n * An function to derive state.\n *\n * This function will accept one piece of the controller state (one property),\n * and will return some derivation of that state.\n *\n * @param value - A piece of controller state.\n * @returns Something derived from controller state.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type StateDeriver<T extends Json> = (value: T) => Json;\n\n/**\n * State metadata.\n *\n * This metadata describes which parts of state should be persisted, and how to\n * get an anonymized representation of the state.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type StateMetadata<T extends StateConstraint> = {\n [P in keyof T]-?: StatePropertyMetadata<T[P]>;\n};\n\n/**\n * Metadata for a single state property\n */\nexport type StatePropertyMetadata<ControllerState extends Json> = {\n /**\n * Indicates whether this property should be included in debug snapshots attached to Sentry\n * errors.\n *\n * Set this to false if the state may contain personally identifiable information, or if it's\n * too large to include in a debug snapshot.\n */\n includeInDebugSnapshot: boolean | StateDeriver<ControllerState>;\n /**\n * Indicates whether this property should be included in state logs.\n *\n * Set this to false if the data should be kept hidden from support agents (e.g. if it contains\n * secret keys, or personally-identifiable information that is not useful for debugging).\n *\n * We do allow state logs to contain some personally identifiable information to assist with\n * diagnosing errors (e.g. transaction hashes, addresses), but we still attempt to limit the\n * data we expose to what is most useful for helping users.\n */\n includeInStateLogs: boolean | StateDeriver<ControllerState>;\n /**\n * Indicates whether this property should be persisted.\n *\n * If true, the property will be persisted and saved between sessions.\n * If false, the property will not be saved between sessions, and it will always be missing from the `state` constructor parameter.\n */\n persist: boolean | StateDeriver<ControllerState>;\n /**\n * Indicates whether this property is used by the UI.\n *\n * If true, the property will be accessible from the UI.\n * If false, it will be inaccessible from the UI.\n *\n * Making a property accessible to the UI has a performance overhead, so it's better to set this\n * to `false` if it's not used in the UI, especially for properties that can be large in size.\n *\n * Note that we disallow the use of a state derivation function here to preserve type information\n * for the UI (the state deriver type always returns `Json`).\n */\n usedInUi: boolean;\n};\n\n/**\n * A universal supertype of `StateDeriver` types.\n * This type can be assigned to any `StateDeriver` type.\n */\nexport type StateDeriverConstraint = (value: never) => Json;\n\n/**\n * A universal supertype of `StatePropertyMetadata` types.\n * This type can be assigned to any `StatePropertyMetadata` type.\n */\nexport type StatePropertyMetadataConstraint = {\n includeInDebugSnapshot: boolean | StateDeriverConstraint;\n includeInStateLogs?: boolean | StateDeriverConstraint;\n persist: boolean | StateDeriverConstraint;\n usedInUi?: boolean;\n};\n\n/**\n * A universal supertype of `StateMetadata` types.\n * This type can be assigned to any `StateMetadata` type.\n */\nexport type StateMetadataConstraint = Record<\n string,\n StatePropertyMetadataConstraint\n>;\n\n/**\n * The widest subtype of all controller instances that inherit from `BaseController` (formerly `BaseControllerV2`).\n * Any `BaseController` subclass instance can be assigned to this type.\n */\nexport type BaseControllerInstance = Omit<\n PublicInterface<\n BaseController<\n string,\n StateConstraint,\n // Use `any` to allow any parent to be set.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Messenger<string, ActionConstraint, EventConstraint, any>\n >\n >,\n 'metadata'\n> & {\n metadata: StateMetadataConstraint;\n};\n\nexport type ControllerGetStateAction<\n ControllerName extends string,\n ControllerState extends StateConstraint,\n> = {\n type: `${ControllerName}:getState`;\n handler: () => ControllerState;\n};\n\nexport type ControllerStateChangeEvent<\n ControllerName extends string,\n ControllerState extends StateConstraint,\n> = {\n type: `${ControllerName}:stateChange`;\n payload: [ControllerState, Patch[]];\n};\n\nexport type ControllerActions<\n ControllerName extends string,\n ControllerState extends StateConstraint,\n> = ControllerGetStateAction<ControllerName, ControllerState>;\n\nexport type ControllerEvents<\n ControllerName extends string,\n ControllerState extends StateConstraint,\n> = ControllerStateChangeEvent<ControllerName, ControllerState>;\n\n/**\n * Controller class that provides state management, subscriptions, and state metadata\n */\nexport class BaseController<\n ControllerName extends string,\n ControllerState extends StateConstraint,\n ControllerMessenger extends Messenger<\n ControllerName,\n ActionConstraint,\n EventConstraint,\n // Use `any` to allow any parent to be set. `any` is harmless in a type constraint anyway,\n // it's the one totally safe place to use it.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n >,\n> {\n /**\n * The controller state.\n */\n #internalState: ControllerState;\n\n /**\n * The controller messenger. This is used to interact with other parts of the application.\n */\n protected messenger: ControllerMessenger;\n\n /**\n * The controller messenger.\n *\n * This is the same as the `messagingSystem` property, but has a type that only lets us use\n * actions and events that are part of the `BaseController` class.\n */\n readonly #messenger: Messenger<\n ControllerName,\n ControllerActions<ControllerName, ControllerState>,\n ControllerEvents<ControllerName, ControllerState>\n >;\n\n /**\n * The name of the controller.\n *\n * This is used by the ComposableController to construct a composed application state.\n */\n public readonly name: ControllerName;\n\n public readonly metadata: StateMetadata<ControllerState>;\n\n /**\n * Creates a BaseController instance.\n *\n * @param options - Controller options.\n * @param options.messenger - The controller messenger.\n * @param options.metadata - ControllerState metadata, describing how to \"anonymize\" the state, and which\n * parts should be persisted.\n * @param options.name - The name of the controller, used as a namespace for events and actions.\n * @param options.state - Initial controller state.\n */\n constructor({\n messenger,\n metadata,\n name,\n state,\n }: {\n messenger: ControllerActions<\n ControllerName,\n ControllerState\n >['type'] extends MessengerActions<ControllerMessenger>['type']\n ? ControllerEvents<\n ControllerName,\n ControllerState\n >['type'] extends MessengerEvents<ControllerMessenger>['type']\n ? ControllerMessenger\n : never\n : never;\n metadata: StateMetadata<ControllerState>;\n name: ControllerName;\n state: ControllerState;\n }) {\n // The parameter type validates that the expected actions/events are present\n // We don't have a way to validate the type property because the type is invariant\n this.#messenger = messenger as unknown as Messenger<\n ControllerName,\n ControllerActions<ControllerName, ControllerState>,\n ControllerEvents<ControllerName, ControllerState>\n >;\n this.messenger = messenger;\n this.name = name;\n // Here we use `freeze` from Immer to enforce that the state is deeply\n // immutable. Note that this is a runtime check, not a compile-time check.\n // That is, unlike `Object.freeze`, this does not narrow the type\n // recursively to `Readonly`. The equivalent in Immer is `Immutable`, but\n // `Immutable` does not handle recursive types such as our `Json` type.\n this.#internalState = freeze(state, true);\n this.metadata = metadata;\n\n this.#messenger.registerActionHandler(`${name}:getState`, () => this.state);\n\n this.#messenger.registerInitialEventPayload({\n eventType: `${name}:stateChange`,\n getPayload: () => [this.state, []],\n });\n }\n\n /**\n * Retrieves current controller state.\n *\n * @returns The current state.\n */\n get state() {\n return this.#internalState;\n }\n\n set state(_) {\n throw new Error(\n `Controller state cannot be directly mutated; use 'update' method instead.`,\n );\n }\n\n /**\n * Updates controller state. Accepts a callback that is passed a draft copy\n * of the controller state. If a value is returned, it is set as the new\n * state. Otherwise, any changes made within that callback to the draft are\n * applied to the controller state.\n *\n * @param callback - Callback for updating state, passed a draft state\n * object. Return a new state object or mutate the draft to update state.\n * @returns An object that has the next state, patches applied in the update and inverse patches to\n * rollback the update.\n */\n protected update(\n callback: (state: Draft<ControllerState>) => void | ControllerState,\n ): {\n nextState: ControllerState;\n patches: Patch[];\n inversePatches: Patch[];\n } {\n // We run into ts2589, \"infinite type depth\", if we don't cast\n // produceWithPatches here.\n const [nextState, patches, inversePatches] = (\n produceWithPatches as unknown as (\n state: ControllerState,\n cb: typeof callback,\n ) => [ControllerState, Patch[], Patch[]]\n )(this.#internalState, callback);\n\n // Protect against unnecessary state updates when there is no state diff.\n if (patches.length > 0) {\n this.#internalState = nextState;\n this.#messenger.publish(\n `${this.name}:stateChange` as const,\n nextState,\n patches,\n );\n }\n\n return { nextState, patches, inversePatches };\n }\n\n /**\n * Applies immer patches to the current state. The patches come from the\n * update function itself and can either be normal or inverse patches.\n *\n * @param patches - An array of immer patches that are to be applied to make\n * or undo changes.\n */\n protected applyPatches(patches: Patch[]) {\n const nextState = applyPatches(this.#internalState, patches);\n this.#internalState = nextState;\n this.#messenger.publish(\n `${this.name}:stateChange` as const,\n nextState,\n patches,\n );\n }\n\n /**\n * Prepares the controller for garbage collection. This should be extended\n * by any subclasses to clean up any additional connections or events.\n *\n * The only cleanup performed here is to remove listeners. While technically\n * this is not required to ensure this instance is garbage collected, it at\n * least ensures this instance won't be responsible for preventing the\n * listeners from being garbage collected.\n */\n protected destroy() {\n this.messenger.clearEventSubscriptions(`${this.name}:stateChange`);\n }\n}\n\n/**\n * Use the metadata to derive state according to the given metadata property.\n *\n * @param state - The full controller state.\n * @param metadata - The controller metadata.\n * @param metadataProperty - The metadata property to use to derive state.\n * @param captureException - Reports an error to an error monitoring service.\n * @returns The metadata-derived controller state.\n */\nexport function deriveStateFromMetadata<\n ControllerState extends StateConstraint,\n>(\n state: ControllerState,\n metadata: StateMetadata<ControllerState>,\n metadataProperty: keyof StatePropertyMetadata<Json>,\n captureException?: (error: Error) => void,\n): Record<keyof ControllerState, Json> {\n return (Object.keys(state) as (keyof ControllerState)[]).reduce<\n Record<keyof ControllerState, Json>\n >((derivedState, key) => {\n try {\n const stateMetadata = metadata[key];\n if (!stateMetadata) {\n throw new Error(`No metadata found for '${String(key)}'`);\n }\n const propertyMetadata = stateMetadata[metadataProperty];\n const stateProperty = state[key];\n if (typeof propertyMetadata === 'function') {\n derivedState[key] = propertyMetadata(stateProperty);\n } else if (propertyMetadata) {\n derivedState[key] = stateProperty;\n }\n return derivedState;\n } catch (error) {\n // Capture error without interrupting state-related operations\n // See [ADR core#0016](https://github.com/MetaMask/decisions/blob/main/decisions/core/0016-core-classes-error-reporting.md)\n if (captureException) {\n try {\n captureException(\n error instanceof Error ? error : new Error(String(error)),\n );\n } catch (captureExceptionError) {\n console.error(\n new Error(`Error thrown when calling 'captureException'`),\n captureExceptionError,\n );\n console.error(error);\n }\n } else {\n console.error(error);\n }\n return derivedState;\n }\n }, {} as never);\n}\n"]}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import type { ActionConstraint, EventConstraint, Messenger, MessengerActions, MessengerEvents } from "@metamask/messenger";
|
|
2
|
-
import type { Json, PublicInterface } from "@metamask/utils";
|
|
3
|
-
import type { Draft, Patch } from "immer";
|
|
4
|
-
/**
|
|
5
|
-
* A type that constrains the state of all controllers.
|
|
6
|
-
*
|
|
7
|
-
* In other words, the narrowest supertype encompassing all controller state.
|
|
8
|
-
*/
|
|
9
|
-
export type StateConstraint = Record<string, Json>;
|
|
10
|
-
/**
|
|
11
|
-
* A state change listener.
|
|
12
|
-
*
|
|
13
|
-
* This function will get called for each state change, and is given a copy of
|
|
14
|
-
* the new state along with a set of patches describing the changes since the
|
|
15
|
-
* last update.
|
|
16
|
-
*
|
|
17
|
-
* @param state - The new controller state.
|
|
18
|
-
* @param patches - A list of patches describing any changes (see here for more
|
|
19
|
-
* information: https://immerjs.github.io/immer/docs/patches)
|
|
20
|
-
*/
|
|
21
|
-
export type StateChangeListener<T> = (state: T, patches: Patch[]) => void;
|
|
22
|
-
/**
|
|
23
|
-
* An function to derive state.
|
|
24
|
-
*
|
|
25
|
-
* This function will accept one piece of the controller state (one property),
|
|
26
|
-
* and will return some derivation of that state.
|
|
27
|
-
*
|
|
28
|
-
* @param value - A piece of controller state.
|
|
29
|
-
* @returns Something derived from controller state.
|
|
30
|
-
*/
|
|
31
|
-
export type StateDeriver<T extends Json> = (value: T) => Json;
|
|
32
|
-
/**
|
|
33
|
-
* State metadata.
|
|
34
|
-
*
|
|
35
|
-
* This metadata describes which parts of state should be persisted, and how to
|
|
36
|
-
* get an anonymized representation of the state.
|
|
37
|
-
*/
|
|
38
|
-
export type StateMetadata<T extends StateConstraint> = {
|
|
39
|
-
[P in keyof T]-?: StatePropertyMetadata<T[P]>;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Metadata for a single state property
|
|
43
|
-
*/
|
|
44
|
-
export type StatePropertyMetadata<ControllerState extends Json> = {
|
|
45
|
-
/**
|
|
46
|
-
* Indicates whether this property should be included in debug snapshots attached to Sentry
|
|
47
|
-
* errors.
|
|
48
|
-
*
|
|
49
|
-
* Set this to false if the state may contain personally identifiable information, or if it's
|
|
50
|
-
* too large to include in a debug snapshot.
|
|
51
|
-
*/
|
|
52
|
-
includeInDebugSnapshot: boolean | StateDeriver<ControllerState>;
|
|
53
|
-
/**
|
|
54
|
-
* Indicates whether this property should be included in state logs.
|
|
55
|
-
*
|
|
56
|
-
* Set this to false if the data should be kept hidden from support agents (e.g. if it contains
|
|
57
|
-
* secret keys, or personally-identifiable information that is not useful for debugging).
|
|
58
|
-
*
|
|
59
|
-
* We do allow state logs to contain some personally identifiable information to assist with
|
|
60
|
-
* diagnosing errors (e.g. transaction hashes, addresses), but we still attempt to limit the
|
|
61
|
-
* data we expose to what is most useful for helping users.
|
|
62
|
-
*/
|
|
63
|
-
includeInStateLogs: boolean | StateDeriver<ControllerState>;
|
|
64
|
-
/**
|
|
65
|
-
* Indicates whether this property should be persisted.
|
|
66
|
-
*
|
|
67
|
-
* If true, the property will be persisted and saved between sessions.
|
|
68
|
-
* If false, the property will not be saved between sessions, and it will always be missing from the `state` constructor parameter.
|
|
69
|
-
*/
|
|
70
|
-
persist: boolean | StateDeriver<ControllerState>;
|
|
71
|
-
/**
|
|
72
|
-
* Indicates whether this property is used by the UI.
|
|
73
|
-
*
|
|
74
|
-
* If true, the property will be accessible from the UI.
|
|
75
|
-
* If false, it will be inaccessible from the UI.
|
|
76
|
-
*
|
|
77
|
-
* Making a property accessible to the UI has a performance overhead, so it's better to set this
|
|
78
|
-
* to `false` if it's not used in the UI, especially for properties that can be large in size.
|
|
79
|
-
*
|
|
80
|
-
* Note that we disallow the use of a state derivation function here to preserve type information
|
|
81
|
-
* for the UI (the state deriver type always returns `Json`).
|
|
82
|
-
*/
|
|
83
|
-
usedInUi: boolean;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* A universal supertype of `StateDeriver` types.
|
|
87
|
-
* This type can be assigned to any `StateDeriver` type.
|
|
88
|
-
*/
|
|
89
|
-
export type StateDeriverConstraint = (value: never) => Json;
|
|
90
|
-
/**
|
|
91
|
-
* A universal supertype of `StatePropertyMetadata` types.
|
|
92
|
-
* This type can be assigned to any `StatePropertyMetadata` type.
|
|
93
|
-
*/
|
|
94
|
-
export type StatePropertyMetadataConstraint = {
|
|
95
|
-
includeInDebugSnapshot: boolean | StateDeriverConstraint;
|
|
96
|
-
includeInStateLogs?: boolean | StateDeriverConstraint;
|
|
97
|
-
persist: boolean | StateDeriverConstraint;
|
|
98
|
-
usedInUi?: boolean;
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* A universal supertype of `StateMetadata` types.
|
|
102
|
-
* This type can be assigned to any `StateMetadata` type.
|
|
103
|
-
*/
|
|
104
|
-
export type StateMetadataConstraint = Record<string, StatePropertyMetadataConstraint>;
|
|
105
|
-
/**
|
|
106
|
-
* The widest subtype of all controller instances that inherit from `BaseController` (formerly `BaseControllerV2`).
|
|
107
|
-
* Any `BaseController` subclass instance can be assigned to this type.
|
|
108
|
-
*/
|
|
109
|
-
export type BaseControllerInstance = Omit<PublicInterface<BaseController<string, StateConstraint, Messenger<string, ActionConstraint, EventConstraint, any>>>, 'metadata'> & {
|
|
110
|
-
metadata: StateMetadataConstraint;
|
|
111
|
-
};
|
|
112
|
-
export type ControllerGetStateAction<ControllerName extends string, ControllerState extends StateConstraint> = {
|
|
113
|
-
type: `${ControllerName}:getState`;
|
|
114
|
-
handler: () => ControllerState;
|
|
115
|
-
};
|
|
116
|
-
export type ControllerStateChangeEvent<ControllerName extends string, ControllerState extends StateConstraint> = {
|
|
117
|
-
type: `${ControllerName}:stateChange`;
|
|
118
|
-
payload: [ControllerState, Patch[]];
|
|
119
|
-
};
|
|
120
|
-
export type ControllerActions<ControllerName extends string, ControllerState extends StateConstraint> = ControllerGetStateAction<ControllerName, ControllerState>;
|
|
121
|
-
export type ControllerEvents<ControllerName extends string, ControllerState extends StateConstraint> = ControllerStateChangeEvent<ControllerName, ControllerState>;
|
|
122
|
-
/**
|
|
123
|
-
* Controller class that provides state management, subscriptions, and state metadata
|
|
124
|
-
*/
|
|
125
|
-
export declare class BaseController<ControllerName extends string, ControllerState extends StateConstraint, ControllerMessenger extends Messenger<ControllerName, ActionConstraint, EventConstraint, any>> {
|
|
126
|
-
#private;
|
|
127
|
-
/**
|
|
128
|
-
* The controller messenger. This is used to interact with other parts of the application.
|
|
129
|
-
*/
|
|
130
|
-
protected messenger: ControllerMessenger;
|
|
131
|
-
/**
|
|
132
|
-
* The name of the controller.
|
|
133
|
-
*
|
|
134
|
-
* This is used by the ComposableController to construct a composed application state.
|
|
135
|
-
*/
|
|
136
|
-
readonly name: ControllerName;
|
|
137
|
-
readonly metadata: StateMetadata<ControllerState>;
|
|
138
|
-
/**
|
|
139
|
-
* Creates a BaseController instance.
|
|
140
|
-
*
|
|
141
|
-
* @param options - Controller options.
|
|
142
|
-
* @param options.messenger - The controller messenger.
|
|
143
|
-
* @param options.metadata - ControllerState metadata, describing how to "anonymize" the state, and which
|
|
144
|
-
* parts should be persisted.
|
|
145
|
-
* @param options.name - The name of the controller, used as a namespace for events and actions.
|
|
146
|
-
* @param options.state - Initial controller state.
|
|
147
|
-
*/
|
|
148
|
-
constructor({ messenger, metadata, name, state, }: {
|
|
149
|
-
messenger: ControllerActions<ControllerName, ControllerState>['type'] extends MessengerActions<ControllerMessenger>['type'] ? ControllerEvents<ControllerName, ControllerState>['type'] extends MessengerEvents<ControllerMessenger>['type'] ? ControllerMessenger : never : never;
|
|
150
|
-
metadata: StateMetadata<ControllerState>;
|
|
151
|
-
name: ControllerName;
|
|
152
|
-
state: ControllerState;
|
|
153
|
-
});
|
|
154
|
-
/**
|
|
155
|
-
* Retrieves current controller state.
|
|
156
|
-
*
|
|
157
|
-
* @returns The current state.
|
|
158
|
-
*/
|
|
159
|
-
get state(): ControllerState;
|
|
160
|
-
set state(_: ControllerState);
|
|
161
|
-
/**
|
|
162
|
-
* Updates controller state. Accepts a callback that is passed a draft copy
|
|
163
|
-
* of the controller state. If a value is returned, it is set as the new
|
|
164
|
-
* state. Otherwise, any changes made within that callback to the draft are
|
|
165
|
-
* applied to the controller state.
|
|
166
|
-
*
|
|
167
|
-
* @param callback - Callback for updating state, passed a draft state
|
|
168
|
-
* object. Return a new state object or mutate the draft to update state.
|
|
169
|
-
* @returns An object that has the next state, patches applied in the update and inverse patches to
|
|
170
|
-
* rollback the update.
|
|
171
|
-
*/
|
|
172
|
-
protected update(callback: (state: Draft<ControllerState>) => void | ControllerState): {
|
|
173
|
-
nextState: ControllerState;
|
|
174
|
-
patches: Patch[];
|
|
175
|
-
inversePatches: Patch[];
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Applies immer patches to the current state. The patches come from the
|
|
179
|
-
* update function itself and can either be normal or inverse patches.
|
|
180
|
-
*
|
|
181
|
-
* @param patches - An array of immer patches that are to be applied to make
|
|
182
|
-
* or undo changes.
|
|
183
|
-
*/
|
|
184
|
-
protected applyPatches(patches: Patch[]): void;
|
|
185
|
-
/**
|
|
186
|
-
* Prepares the controller for garbage collection. This should be extended
|
|
187
|
-
* by any subclasses to clean up any additional connections or events.
|
|
188
|
-
*
|
|
189
|
-
* The only cleanup performed here is to remove listeners. While technically
|
|
190
|
-
* this is not required to ensure this instance is garbage collected, it at
|
|
191
|
-
* least ensures this instance won't be responsible for preventing the
|
|
192
|
-
* listeners from being garbage collected.
|
|
193
|
-
*/
|
|
194
|
-
protected destroy(): void;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Use the metadata to derive state according to the given metadata property.
|
|
198
|
-
*
|
|
199
|
-
* @param state - The full controller state.
|
|
200
|
-
* @param metadata - The controller metadata.
|
|
201
|
-
* @param metadataProperty - The metadata property to use to derive state.
|
|
202
|
-
* @param captureException - Reports an error to an error monitoring service.
|
|
203
|
-
* @returns The metadata-derived controller state.
|
|
204
|
-
*/
|
|
205
|
-
export declare function deriveStateFromMetadata<ControllerState extends StateConstraint>(state: ControllerState, metadata: StateMetadata<ControllerState>, metadataProperty: keyof StatePropertyMetadata<Json>, captureException?: (error: Error) => void): Record<keyof ControllerState, Json>;
|
|
206
|
-
//# sourceMappingURL=BaseController.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseController.d.cts","sourceRoot":"","sources":["../../src/next/BaseController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,eAAe,EAChB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,wB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