@metamask-previews/base-controller 7.0.2-preview-9e831370 → 7.1.0-preview-03f094b7

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/BaseControllerV2.cjs.map +1 -1
  3. package/dist/BaseControllerV2.d.cts +2 -2
  4. package/dist/BaseControllerV2.d.cts.map +1 -1
  5. package/dist/BaseControllerV2.d.mts +2 -2
  6. package/dist/BaseControllerV2.d.mts.map +1 -1
  7. package/dist/BaseControllerV2.mjs.map +1 -1
  8. package/dist/{ControllerMessenger.mjs → Messenger.cjs} +47 -42
  9. package/dist/Messenger.cjs.map +1 -0
  10. package/dist/{ControllerMessenger.d.mts → Messenger.d.cts} +19 -19
  11. package/dist/Messenger.d.cts.map +1 -0
  12. package/dist/{ControllerMessenger.d.cts → Messenger.d.mts} +19 -19
  13. package/dist/Messenger.d.mts.map +1 -0
  14. package/dist/{ControllerMessenger.cjs → Messenger.mjs} +43 -46
  15. package/dist/Messenger.mjs.map +1 -0
  16. package/dist/{RestrictedControllerMessenger.mjs → RestrictedMessenger.cjs} +68 -54
  17. package/dist/RestrictedMessenger.cjs.map +1 -0
  18. package/dist/{RestrictedControllerMessenger.d.cts → RestrictedMessenger.d.cts} +35 -23
  19. package/dist/RestrictedMessenger.d.cts.map +1 -0
  20. package/dist/{RestrictedControllerMessenger.d.mts → RestrictedMessenger.d.mts} +35 -23
  21. package/dist/RestrictedMessenger.d.mts.map +1 -0
  22. package/dist/{RestrictedControllerMessenger.cjs → RestrictedMessenger.mjs} +64 -58
  23. package/dist/RestrictedMessenger.mjs.map +1 -0
  24. package/dist/index.cjs +7 -5
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +4 -4
  27. package/dist/index.d.cts.map +1 -1
  28. package/dist/index.d.mts +4 -4
  29. package/dist/index.d.mts.map +1 -1
  30. package/dist/index.mjs +2 -2
  31. package/dist/index.mjs.map +1 -1
  32. package/package.json +3 -3
  33. package/dist/ControllerMessenger.cjs.map +0 -1
  34. package/dist/ControllerMessenger.d.cts.map +0 -1
  35. package/dist/ControllerMessenger.d.mts.map +0 -1
  36. package/dist/ControllerMessenger.mjs.map +0 -1
  37. package/dist/RestrictedControllerMessenger.cjs.map +0 -1
  38. package/dist/RestrictedControllerMessenger.d.cts.map +0 -1
  39. package/dist/RestrictedControllerMessenger.d.mts.map +0 -1
  40. package/dist/RestrictedControllerMessenger.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestrictedMessenger.cjs","sourceRoot":"","sources":["../src/RestrictedMessenger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AA2CA;;;;;;;;;;;;;;;GAeG;AACH,MAAa,mBAAmB;IAe9B;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,EACV,mBAAmB,EACnB,SAAS,EACT,IAAI,EACJ,cAAc,EACd,aAAa,GAOd;;QAvCQ,iDAAyD;QAEzD,iDAAsB;QAEtB,sDAA6D;QAE7D,qDAA2D;QAkClE,IAAI,SAAS,IAAI,mBAAmB,EAAE;YACpC,MAAM,IAAI,KAAK,CACb,wHAAwH,CACzH,CAAC;SACH;aAAM,IAAI,CAAC,SAAS,IAAI,CAAC,mBAAmB,EAAE;YAC7C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;SAC3C;QACD,uEAAuE;QACvE,oEAAoE;QACpE,uBAAA,IAAI,kCAAc,CAAC,SAAS,IAAI,mBAAmB,CAAE,MAAA,CAAC;QACtD,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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AAA,IAAI,sCAAW,IAAI,CACjE,CAAC;SACH;QACD,uBAAA,IAAI,sCAAW,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;CAqDF;AAnXD,kDAmXC;AAE+B,4DAA6B;4UA5CzD,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 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 * @deprecated This has been renamed to `RestrictedMessengerConstraint`.\n */\nexport type RestrictedControllerMessengerConstraint<\n Namespace extends string = string,\n> = RestrictedMessengerConstraint<Namespace>;\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.controllerMessenger - The messenger instance that is being wrapped. (deprecated)\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 controllerMessenger,\n messenger,\n name,\n allowedActions,\n allowedEvents,\n }: {\n controllerMessenger?: Messenger<ActionConstraint, EventConstraint>;\n messenger?: Messenger<ActionConstraint, EventConstraint>;\n name: Namespace;\n allowedActions: NotNamespacedBy<Namespace, AllowedAction>[];\n allowedEvents: NotNamespacedBy<Namespace, AllowedEvent>[];\n }) {\n if (messenger && controllerMessenger) {\n throw new Error(\n `Both messenger properties provided. Provide message using only 'messenger' option, 'controllerMessenger' is deprecated`,\n );\n } else if (!messenger && !controllerMessenger) {\n throw new Error('Messenger not provided');\n }\n // The above condition guarantees that one of these options is defined.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#messenger = (messenger ?? controllerMessenger)!;\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 unqiue 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 * 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 unqiue 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 */\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: ExtractEventHandler<Event, EventType>,\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(event, handler);\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 */\n unsubscribe<\n EventType extends\n | AllowedEvent\n | (Event['type'] & NamespacedName<Namespace>),\n >(event: EventType, handler: ExtractEventHandler<Event, EventType>) {\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\nexport { RestrictedMessenger as RestrictedControllerMessenger };\n"]}
@@ -1,16 +1,25 @@
1
- import type { ActionConstraint, ActionHandler, ControllerMessenger, EventConstraint, ExtractActionParameters, ExtractActionResponse, ExtractEventHandler, ExtractEventPayload, NamespacedName, NotNamespacedBy, SelectorEventHandler, SelectorFunction } from "./ControllerMessenger.cjs";
1
+ import type { ActionConstraint, ActionHandler, Messenger, EventConstraint, ExtractActionParameters, ExtractActionResponse, ExtractEventHandler, ExtractEventPayload, NamespacedName, NotNamespacedBy, SelectorEventHandler, SelectorFunction } from "./Messenger.cjs";
2
2
  /**
3
- * A universal supertype of all `RestrictedControllerMessenger` instances.
4
- * This type can be assigned to any `RestrictedControllerMessenger` type.
3
+ * A universal supertype of all `RestrictedMessenger` instances. This type can be assigned to any
4
+ * `RestrictedMessenger` type.
5
5
  *
6
- * @template ControllerName - Name of the controller. Optionally can be used to
7
- * narrow this type to a constraint for the messenger of a specific controller.
6
+ * @template Namespace - Name of the module this messenger is for. Optionally can be used to
7
+ * narrow this type to a constraint for the messenger of a specific module.
8
8
  */
9
- export type RestrictedControllerMessengerConstraint<ControllerName extends string = string> = RestrictedControllerMessenger<ControllerName, ActionConstraint, EventConstraint, string, string>;
9
+ export type RestrictedMessengerConstraint<Namespace extends string = string> = RestrictedMessenger<Namespace, ActionConstraint, EventConstraint, string, string>;
10
10
  /**
11
- * A restricted controller messenger.
11
+ * A universal supertype of all `RestrictedMessenger` instances. This type can be assigned to any
12
+ * `RestrictedMessenger` type.
12
13
  *
13
- * This acts as a wrapper around the controller messenger instance that restricts access to actions
14
+ * @template Namespace - Name of the module this messenger is for. Optionally can be used to
15
+ * narrow this type to a constraint for the messenger of a specific module.
16
+ * @deprecated This has been renamed to `RestrictedMessengerConstraint`.
17
+ */
18
+ export type RestrictedControllerMessengerConstraint<Namespace extends string = string> = RestrictedMessengerConstraint<Namespace>;
19
+ /**
20
+ * A restricted messenger.
21
+ *
22
+ * This acts as a wrapper around the messenger instance that restricts access to actions
14
23
  * and events.
15
24
  *
16
25
  * @template Namespace - The namespace for this messenger. Typically this is the name of the controller or
@@ -23,28 +32,30 @@ export type RestrictedControllerMessengerConstraint<ControllerName extends strin
23
32
  * @template AllowedEvent - A type union of the 'type' string for any allowed events.
24
33
  * This must not include internal events that are in the messenger's namespace.
25
34
  */
26
- export declare class RestrictedControllerMessenger<Namespace extends string, Action extends ActionConstraint, Event extends EventConstraint, AllowedAction extends string, AllowedEvent extends string> {
35
+ export declare class RestrictedMessenger<Namespace extends string, Action extends ActionConstraint, Event extends EventConstraint, AllowedAction extends string, AllowedEvent extends string> {
27
36
  #private;
28
37
  /**
29
- * Constructs a restricted controller messenger
38
+ * Constructs a restricted messenger
30
39
  *
31
40
  * The provided allowlists grant the ability to call the listed actions and subscribe to the
32
41
  * listed events. The "name" provided grants ownership of any actions and events under that
33
42
  * namespace. Ownership allows registering actions and publishing events, as well as
34
43
  * unregistering actions and clearing event subscriptions.
35
44
  *
36
- * @param options - The controller options.
37
- * @param options.controllerMessenger - The controller messenger instance that is being wrapped.
45
+ * @param options - Options.
46
+ * @param options.controllerMessenger - The messenger instance that is being wrapped. (deprecated)
47
+ * @param options.messenger - The messenger instance that is being wrapped.
38
48
  * @param options.name - The name of the thing this messenger will be handed to (e.g. the
39
49
  * controller name). This grants "ownership" of actions and events under this namespace to the
40
- * restricted controller messenger returned.
41
- * @param options.allowedActions - The list of actions that this restricted controller messenger
42
- * should be alowed to call.
43
- * @param options.allowedEvents - The list of events that this restricted controller messenger
44
- * should be allowed to subscribe to.
50
+ * restricted messenger returned.
51
+ * @param options.allowedActions - The list of actions that this restricted messenger should be
52
+ * allowed to call.
53
+ * @param options.allowedEvents - The list of events that this restricted messenger should be
54
+ * allowed to subscribe to.
45
55
  */
46
- constructor({ controllerMessenger, name, allowedActions, allowedEvents, }: {
47
- controllerMessenger: ControllerMessenger<ActionConstraint, EventConstraint>;
56
+ constructor({ controllerMessenger, messenger, name, allowedActions, allowedEvents, }: {
57
+ controllerMessenger?: Messenger<ActionConstraint, EventConstraint>;
58
+ messenger?: Messenger<ActionConstraint, EventConstraint>;
48
59
  name: Namespace;
49
60
  allowedActions: NotNamespacedBy<Namespace, AllowedAction>[];
50
61
  allowedEvents: NotNamespacedBy<Namespace, AllowedEvent>[];
@@ -132,7 +143,7 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Act
132
143
  * @param eventType - The event type. This is a unique identifier for this event.
133
144
  * @param handler - The event handler. The type of the parameters for this event handler must
134
145
  * match the type of the payload for this event type.
135
- * @throws Will throw if the given event is not an allowed event for this controller messenger.
146
+ * @throws Will throw if the given event is not an allowed event for this messenger.
136
147
  * @template EventType - A type union of Event type strings.
137
148
  */
138
149
  subscribe<EventType extends AllowedEvent | (Event['type'] & NamespacedName<Namespace>)>(eventType: EventType, handler: ExtractEventHandler<Event, EventType>): void;
@@ -152,7 +163,7 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Act
152
163
  * @param selector - The selector function used to select relevant data from
153
164
  * the event payload. The type of the parameters for this selector must match
154
165
  * the type of the payload for this event type.
155
- * @throws Will throw if the given event is not an allowed event for this controller messenger.
166
+ * @throws Will throw if the given event is not an allowed event for this messenger.
156
167
  * @template EventType - A type union of Event type strings.
157
168
  * @template SelectorReturnValue - The selector return value.
158
169
  */
@@ -166,7 +177,7 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Act
166
177
  *
167
178
  * @param event - The event type. This is a unique identifier for this event.
168
179
  * @param handler - The event handler to unregister.
169
- * @throws Will throw if the given event is not an allowed event for this controller messenger.
180
+ * @throws Will throw if the given event is not an allowed event for this messenger.
170
181
  * @template EventType - A type union of allowed Event type strings.
171
182
  */
172
183
  unsubscribe<EventType extends AllowedEvent | (Event['type'] & NamespacedName<Namespace>)>(event: EventType, handler: ExtractEventHandler<Event, EventType>): void;
@@ -183,4 +194,5 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Act
183
194
  */
184
195
  clearEventSubscriptions<EventType extends Event['type'] & NamespacedName<Namespace>>(event: EventType): void;
185
196
  }
186
- //# sourceMappingURL=RestrictedControllerMessenger.d.cts.map
197
+ export { RestrictedMessenger as RestrictedControllerMessenger };
198
+ //# sourceMappingURL=RestrictedMessenger.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestrictedMessenger.d.cts","sourceRoot":"","sources":["../src/RestrictedMessenger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EACjB,wBAAoB;AAErB;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM,IACzE,mBAAmB,CACjB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,MAAM,CACP,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,MAAM,uCAAuC,CACjD,SAAS,SAAS,MAAM,GAAG,MAAM,IAC/B,6BAA6B,CAAC,SAAS,CAAC,CA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M,CAAC,GAAG,cAAc,CAAC,SAAS,CAAC,EAC3D,KAAK,EAAE,SAAS;CA4DnB;AAED,OAAO,EAAE,mBAAmB,IAAI,6BAA6B,EAAE,CAAC"}
@@ -1,16 +1,25 @@
1
- import type { ActionConstraint, ActionHandler, ControllerMessenger, EventConstraint, ExtractActionParameters, ExtractActionResponse, ExtractEventHandler, ExtractEventPayload, NamespacedName, NotNamespacedBy, SelectorEventHandler, SelectorFunction } from "./ControllerMessenger.mjs";
1
+ import type { ActionConstraint, ActionHandler, Messenger, EventConstraint, ExtractActionParameters, ExtractActionResponse, ExtractEventHandler, ExtractEventPayload, NamespacedName, NotNamespacedBy, SelectorEventHandler, SelectorFunction } from "./Messenger.mjs";
2
2
  /**
3
- * A universal supertype of all `RestrictedControllerMessenger` instances.
4
- * This type can be assigned to any `RestrictedControllerMessenger` type.
3
+ * A universal supertype of all `RestrictedMessenger` instances. This type can be assigned to any
4
+ * `RestrictedMessenger` type.
5
5
  *
6
- * @template ControllerName - Name of the controller. Optionally can be used to
7
- * narrow this type to a constraint for the messenger of a specific controller.
6
+ * @template Namespace - Name of the module this messenger is for. Optionally can be used to
7
+ * narrow this type to a constraint for the messenger of a specific module.
8
8
  */
9
- export type RestrictedControllerMessengerConstraint<ControllerName extends string = string> = RestrictedControllerMessenger<ControllerName, ActionConstraint, EventConstraint, string, string>;
9
+ export type RestrictedMessengerConstraint<Namespace extends string = string> = RestrictedMessenger<Namespace, ActionConstraint, EventConstraint, string, string>;
10
10
  /**
11
- * A restricted controller messenger.
11
+ * A universal supertype of all `RestrictedMessenger` instances. This type can be assigned to any
12
+ * `RestrictedMessenger` type.
12
13
  *
13
- * This acts as a wrapper around the controller messenger instance that restricts access to actions
14
+ * @template Namespace - Name of the module this messenger is for. Optionally can be used to
15
+ * narrow this type to a constraint for the messenger of a specific module.
16
+ * @deprecated This has been renamed to `RestrictedMessengerConstraint`.
17
+ */
18
+ export type RestrictedControllerMessengerConstraint<Namespace extends string = string> = RestrictedMessengerConstraint<Namespace>;
19
+ /**
20
+ * A restricted messenger.
21
+ *
22
+ * This acts as a wrapper around the messenger instance that restricts access to actions
14
23
  * and events.
15
24
  *
16
25
  * @template Namespace - The namespace for this messenger. Typically this is the name of the controller or
@@ -23,28 +32,30 @@ export type RestrictedControllerMessengerConstraint<ControllerName extends strin
23
32
  * @template AllowedEvent - A type union of the 'type' string for any allowed events.
24
33
  * This must not include internal events that are in the messenger's namespace.
25
34
  */
26
- export declare class RestrictedControllerMessenger<Namespace extends string, Action extends ActionConstraint, Event extends EventConstraint, AllowedAction extends string, AllowedEvent extends string> {
35
+ export declare class RestrictedMessenger<Namespace extends string, Action extends ActionConstraint, Event extends EventConstraint, AllowedAction extends string, AllowedEvent extends string> {
27
36
  #private;
28
37
  /**
29
- * Constructs a restricted controller messenger
38
+ * Constructs a restricted messenger
30
39
  *
31
40
  * The provided allowlists grant the ability to call the listed actions and subscribe to the
32
41
  * listed events. The "name" provided grants ownership of any actions and events under that
33
42
  * namespace. Ownership allows registering actions and publishing events, as well as
34
43
  * unregistering actions and clearing event subscriptions.
35
44
  *
36
- * @param options - The controller options.
37
- * @param options.controllerMessenger - The controller messenger instance that is being wrapped.
45
+ * @param options - Options.
46
+ * @param options.controllerMessenger - The messenger instance that is being wrapped. (deprecated)
47
+ * @param options.messenger - The messenger instance that is being wrapped.
38
48
  * @param options.name - The name of the thing this messenger will be handed to (e.g. the
39
49
  * controller name). This grants "ownership" of actions and events under this namespace to the
40
- * restricted controller messenger returned.
41
- * @param options.allowedActions - The list of actions that this restricted controller messenger
42
- * should be alowed to call.
43
- * @param options.allowedEvents - The list of events that this restricted controller messenger
44
- * should be allowed to subscribe to.
50
+ * restricted messenger returned.
51
+ * @param options.allowedActions - The list of actions that this restricted messenger should be
52
+ * allowed to call.
53
+ * @param options.allowedEvents - The list of events that this restricted messenger should be
54
+ * allowed to subscribe to.
45
55
  */
46
- constructor({ controllerMessenger, name, allowedActions, allowedEvents, }: {
47
- controllerMessenger: ControllerMessenger<ActionConstraint, EventConstraint>;
56
+ constructor({ controllerMessenger, messenger, name, allowedActions, allowedEvents, }: {
57
+ controllerMessenger?: Messenger<ActionConstraint, EventConstraint>;
58
+ messenger?: Messenger<ActionConstraint, EventConstraint>;
48
59
  name: Namespace;
49
60
  allowedActions: NotNamespacedBy<Namespace, AllowedAction>[];
50
61
  allowedEvents: NotNamespacedBy<Namespace, AllowedEvent>[];
@@ -132,7 +143,7 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Act
132
143
  * @param eventType - The event type. This is a unique identifier for this event.
133
144
  * @param handler - The event handler. The type of the parameters for this event handler must
134
145
  * match the type of the payload for this event type.
135
- * @throws Will throw if the given event is not an allowed event for this controller messenger.
146
+ * @throws Will throw if the given event is not an allowed event for this messenger.
136
147
  * @template EventType - A type union of Event type strings.
137
148
  */
138
149
  subscribe<EventType extends AllowedEvent | (Event['type'] & NamespacedName<Namespace>)>(eventType: EventType, handler: ExtractEventHandler<Event, EventType>): void;
@@ -152,7 +163,7 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Act
152
163
  * @param selector - The selector function used to select relevant data from
153
164
  * the event payload. The type of the parameters for this selector must match
154
165
  * the type of the payload for this event type.
155
- * @throws Will throw if the given event is not an allowed event for this controller messenger.
166
+ * @throws Will throw if the given event is not an allowed event for this messenger.
156
167
  * @template EventType - A type union of Event type strings.
157
168
  * @template SelectorReturnValue - The selector return value.
158
169
  */
@@ -166,7 +177,7 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Act
166
177
  *
167
178
  * @param event - The event type. This is a unique identifier for this event.
168
179
  * @param handler - The event handler to unregister.
169
- * @throws Will throw if the given event is not an allowed event for this controller messenger.
180
+ * @throws Will throw if the given event is not an allowed event for this messenger.
170
181
  * @template EventType - A type union of allowed Event type strings.
171
182
  */
172
183
  unsubscribe<EventType extends AllowedEvent | (Event['type'] & NamespacedName<Namespace>)>(event: EventType, handler: ExtractEventHandler<Event, EventType>): void;
@@ -183,4 +194,5 @@ export declare class RestrictedControllerMessenger<Namespace extends string, Act
183
194
  */
184
195
  clearEventSubscriptions<EventType extends Event['type'] & NamespacedName<Namespace>>(event: EventType): void;
185
196
  }
186
- //# sourceMappingURL=RestrictedControllerMessenger.d.mts.map
197
+ export { RestrictedMessenger as RestrictedControllerMessenger };
198
+ //# sourceMappingURL=RestrictedMessenger.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestrictedMessenger.d.mts","sourceRoot":"","sources":["../src/RestrictedMessenger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EACjB,wBAAoB;AAErB;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM,IACzE,mBAAmB,CACjB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,MAAM,CACP,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,MAAM,uCAAuC,CACjD,SAAS,SAAS,MAAM,GAAG,MAAM,IAC/B,6BAA6B,CAAC,SAAS,CAAC,CAAC;AAE7C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,mBAAmB,CAC9B,SAAS,SAAS,MAAM,EACxB,MAAM,SAAS,gBAAgB,EAC/B,KAAK,SAAS,eAAe,EAC7B,aAAa,SAAS,MAAM,EAC5B,YAAY,SAAS,MAAM;;IAU3B;;;;;;;;;;;;;;;;;;OAkBG;gBACS,EACV,mBAAmB,EACnB,SAAS,EACT,IAAI,EACJ,cAAc,EACd,aAAa,GACd,EAAE;QACD,mBAAmB,CAAC,EAAE,SAAS,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;QACnE,SAAS,CAAC,EAAE,SAAS,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;QACzD,IA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H,SAAS,CACP,SAAS,SACL,YAAY,GACZ,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,EAC/C,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,IAAI;IAE7E;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAAS,CACP,SAAS,SACL,YAAY,GACZ,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,EAC/C,mBAAmB,EAEnB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,oBAAoB,CAAC,mBAAmB,CAAC,EAClD,QAAQ,EAAE,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,mBAAmB,CAAC,GAChE,IAAI;IAsBP;;;;;;;;;;;OAWG;IACH,WAAW,CACT,SAAS,SACL,YAAY,GACZ,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,EAC/C,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC;IAOlE;;;;;;;;;;OAUG;IACH,uBAAuB,CACrB,SAAS,SAAS,KAAK,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,SAAS,CAAC,EAC3D,KAAK,EAAE,SAAS;CA4DnB;AAED,OAAO,EAAE,mBAAmB,IAAI,6BAA6B,EAAE,CAAC"}
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
2
  if (kind === "m") throw new TypeError("Private method is not writable");
4
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -10,13 +9,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
9
  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
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
11
  };
13
- var _RestrictedControllerMessenger_instances, _RestrictedControllerMessenger_controllerMessenger, _RestrictedControllerMessenger_controllerName, _RestrictedControllerMessenger_allowedActions, _RestrictedControllerMessenger_allowedEvents, _RestrictedControllerMessenger_isAllowedEvent, _RestrictedControllerMessenger_isAllowedAction, _RestrictedControllerMessenger_isInCurrentNamespace;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.RestrictedControllerMessenger = void 0;
12
+ var _RestrictedMessenger_instances, _RestrictedMessenger_messenger, _RestrictedMessenger_namespace, _RestrictedMessenger_allowedActions, _RestrictedMessenger_allowedEvents, _RestrictedMessenger_isAllowedEvent, _RestrictedMessenger_isAllowedAction, _RestrictedMessenger_isInCurrentNamespace;
16
13
  /**
17
- * A restricted controller messenger.
14
+ * A restricted messenger.
18
15
  *
19
- * This acts as a wrapper around the controller messenger instance that restricts access to actions
16
+ * This acts as a wrapper around the messenger instance that restricts access to actions
20
17
  * and events.
21
18
  *
22
19
  * @template Namespace - The namespace for this messenger. Typically this is the name of the controller or
@@ -29,35 +26,44 @@ exports.RestrictedControllerMessenger = void 0;
29
26
  * @template AllowedEvent - A type union of the 'type' string for any allowed events.
30
27
  * This must not include internal events that are in the messenger's namespace.
31
28
  */
32
- class RestrictedControllerMessenger {
29
+ export class RestrictedMessenger {
33
30
  /**
34
- * Constructs a restricted controller messenger
31
+ * Constructs a restricted messenger
35
32
  *
36
33
  * The provided allowlists grant the ability to call the listed actions and subscribe to the
37
34
  * listed events. The "name" provided grants ownership of any actions and events under that
38
35
  * namespace. Ownership allows registering actions and publishing events, as well as
39
36
  * unregistering actions and clearing event subscriptions.
40
37
  *
41
- * @param options - The controller options.
42
- * @param options.controllerMessenger - The controller messenger instance that is being wrapped.
38
+ * @param options - Options.
39
+ * @param options.controllerMessenger - The messenger instance that is being wrapped. (deprecated)
40
+ * @param options.messenger - The messenger instance that is being wrapped.
43
41
  * @param options.name - The name of the thing this messenger will be handed to (e.g. the
44
42
  * controller name). This grants "ownership" of actions and events under this namespace to the
45
- * restricted controller messenger returned.
46
- * @param options.allowedActions - The list of actions that this restricted controller messenger
47
- * should be alowed to call.
48
- * @param options.allowedEvents - The list of events that this restricted controller messenger
49
- * should be allowed to subscribe to.
43
+ * restricted messenger returned.
44
+ * @param options.allowedActions - The list of actions that this restricted messenger should be
45
+ * allowed to call.
46
+ * @param options.allowedEvents - The list of events that this restricted messenger should be
47
+ * allowed to subscribe to.
50
48
  */
51
- constructor({ controllerMessenger, name, allowedActions, allowedEvents, }) {
52
- _RestrictedControllerMessenger_instances.add(this);
53
- _RestrictedControllerMessenger_controllerMessenger.set(this, void 0);
54
- _RestrictedControllerMessenger_controllerName.set(this, void 0);
55
- _RestrictedControllerMessenger_allowedActions.set(this, void 0);
56
- _RestrictedControllerMessenger_allowedEvents.set(this, void 0);
57
- __classPrivateFieldSet(this, _RestrictedControllerMessenger_controllerMessenger, controllerMessenger, "f");
58
- __classPrivateFieldSet(this, _RestrictedControllerMessenger_controllerName, name, "f");
59
- __classPrivateFieldSet(this, _RestrictedControllerMessenger_allowedActions, allowedActions, "f");
60
- __classPrivateFieldSet(this, _RestrictedControllerMessenger_allowedEvents, allowedEvents, "f");
49
+ constructor({ controllerMessenger, messenger, name, allowedActions, allowedEvents, }) {
50
+ _RestrictedMessenger_instances.add(this);
51
+ _RestrictedMessenger_messenger.set(this, void 0);
52
+ _RestrictedMessenger_namespace.set(this, void 0);
53
+ _RestrictedMessenger_allowedActions.set(this, void 0);
54
+ _RestrictedMessenger_allowedEvents.set(this, void 0);
55
+ if (messenger && controllerMessenger) {
56
+ throw new Error(`Both messenger properties provided. Provide message using only 'messenger' option, 'controllerMessenger' is deprecated`);
57
+ }
58
+ else if (!messenger && !controllerMessenger) {
59
+ throw new Error('Messenger not provided');
60
+ }
61
+ // The above condition guarantees that one of these options is defined.
62
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63
+ __classPrivateFieldSet(this, _RestrictedMessenger_messenger, (messenger ?? controllerMessenger), "f");
64
+ __classPrivateFieldSet(this, _RestrictedMessenger_namespace, name, "f");
65
+ __classPrivateFieldSet(this, _RestrictedMessenger_allowedActions, allowedActions, "f");
66
+ __classPrivateFieldSet(this, _RestrictedMessenger_allowedEvents, allowedEvents, "f");
61
67
  }
62
68
  /**
63
69
  * Register an action handler.
@@ -74,10 +80,10 @@ class RestrictedControllerMessenger {
74
80
  */
75
81
  registerActionHandler(action, handler) {
76
82
  /* istanbul ignore if */ // Branch unreachable with valid types
77
- if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, action)) {
78
- throw new Error(`Only allowed registering action handlers prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`);
83
+ if (!__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isInCurrentNamespace).call(this, action)) {
84
+ throw new Error(`Only allowed registering action handlers prefixed by '${__classPrivateFieldGet(this, _RestrictedMessenger_namespace, "f")}:'`);
79
85
  }
80
- __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").registerActionHandler(action, handler);
86
+ __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").registerActionHandler(action, handler);
81
87
  }
82
88
  /**
83
89
  * Unregister an action handler.
@@ -92,10 +98,10 @@ class RestrictedControllerMessenger {
92
98
  */
93
99
  unregisterActionHandler(action) {
94
100
  /* istanbul ignore if */ // Branch unreachable with valid types
95
- if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, action)) {
96
- throw new Error(`Only allowed unregistering action handlers prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`);
101
+ if (!__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isInCurrentNamespace).call(this, action)) {
102
+ throw new Error(`Only allowed unregistering action handlers prefixed by '${__classPrivateFieldGet(this, _RestrictedMessenger_namespace, "f")}:'`);
97
103
  }
98
- __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").unregisterActionHandler(action);
104
+ __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").unregisterActionHandler(action);
99
105
  }
100
106
  /**
101
107
  * Call an action.
@@ -113,10 +119,10 @@ class RestrictedControllerMessenger {
113
119
  * @returns The action return value.
114
120
  */
115
121
  call(actionType, ...params) {
116
- if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isAllowedAction).call(this, actionType)) {
122
+ if (!__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isAllowedAction).call(this, actionType)) {
117
123
  throw new Error(`Action missing from allow list: ${actionType}`);
118
124
  }
119
- const response = __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").call(actionType, ...params);
125
+ const response = __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").call(actionType, ...params);
120
126
  return response;
121
127
  }
122
128
  /**
@@ -134,10 +140,10 @@ class RestrictedControllerMessenger {
134
140
  */
135
141
  registerInitialEventPayload({ eventType, getPayload, }) {
136
142
  /* istanbul ignore if */ // Branch unreachable with valid types
137
- if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, eventType)) {
138
- throw new Error(`Only allowed publishing events prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`);
143
+ if (!__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isInCurrentNamespace).call(this, eventType)) {
144
+ throw new Error(`Only allowed publishing events prefixed by '${__classPrivateFieldGet(this, _RestrictedMessenger_namespace, "f")}:'`);
139
145
  }
140
- __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").registerInitialEventPayload({
146
+ __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").registerInitialEventPayload({
141
147
  eventType,
142
148
  getPayload,
143
149
  });
@@ -157,19 +163,19 @@ class RestrictedControllerMessenger {
157
163
  */
158
164
  publish(event, ...payload) {
159
165
  /* istanbul ignore if */ // Branch unreachable with valid types
160
- if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, event)) {
161
- throw new Error(`Only allowed publishing events prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`);
166
+ if (!__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isInCurrentNamespace).call(this, event)) {
167
+ throw new Error(`Only allowed publishing events prefixed by '${__classPrivateFieldGet(this, _RestrictedMessenger_namespace, "f")}:'`);
162
168
  }
163
- __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").publish(event, ...payload);
169
+ __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").publish(event, ...payload);
164
170
  }
165
171
  subscribe(event, handler, selector) {
166
- if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isAllowedEvent).call(this, event)) {
172
+ if (!__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isAllowedEvent).call(this, event)) {
167
173
  throw new Error(`Event missing from allow list: ${event}`);
168
174
  }
169
175
  if (selector) {
170
- return __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").subscribe(event, handler, selector);
176
+ return __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").subscribe(event, handler, selector);
171
177
  }
172
- return __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").subscribe(event, handler);
178
+ return __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").subscribe(event, handler);
173
179
  }
174
180
  /**
175
181
  * Unsubscribe from an event.
@@ -180,14 +186,14 @@ class RestrictedControllerMessenger {
180
186
  *
181
187
  * @param event - The event type. This is a unique identifier for this event.
182
188
  * @param handler - The event handler to unregister.
183
- * @throws Will throw if the given event is not an allowed event for this controller messenger.
189
+ * @throws Will throw if the given event is not an allowed event for this messenger.
184
190
  * @template EventType - A type union of allowed Event type strings.
185
191
  */
186
192
  unsubscribe(event, handler) {
187
- if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isAllowedEvent).call(this, event)) {
193
+ if (!__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isAllowedEvent).call(this, event)) {
188
194
  throw new Error(`Event missing from allow list: ${event}`);
189
195
  }
190
- __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").unsubscribe(event, handler);
196
+ __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").unsubscribe(event, handler);
191
197
  }
192
198
  /**
193
199
  * Clear subscriptions for a specific event.
@@ -201,24 +207,24 @@ class RestrictedControllerMessenger {
201
207
  * @template EventType - A type union of Event type strings that are namespaced by Namespace.
202
208
  */
203
209
  clearEventSubscriptions(event) {
204
- if (!__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, event)) {
205
- throw new Error(`Only allowed clearing events prefixed by '${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:'`);
210
+ if (!__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isInCurrentNamespace).call(this, event)) {
211
+ throw new Error(`Only allowed clearing events prefixed by '${__classPrivateFieldGet(this, _RestrictedMessenger_namespace, "f")}:'`);
206
212
  }
207
- __classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerMessenger, "f").clearEventSubscriptions(event);
213
+ __classPrivateFieldGet(this, _RestrictedMessenger_messenger, "f").clearEventSubscriptions(event);
208
214
  }
209
215
  }
210
- exports.RestrictedControllerMessenger = RestrictedControllerMessenger;
211
- _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) {
216
+ _RestrictedMessenger_messenger = new WeakMap(), _RestrictedMessenger_namespace = new WeakMap(), _RestrictedMessenger_allowedActions = new WeakMap(), _RestrictedMessenger_allowedEvents = new WeakMap(), _RestrictedMessenger_instances = new WeakSet(), _RestrictedMessenger_isAllowedEvent = function _RestrictedMessenger_isAllowedEvent(eventType) {
212
217
  // Safely upcast to allow runtime check
213
- const allowedEvents = __classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedEvents, "f");
214
- return (__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, eventType) ||
218
+ const allowedEvents = __classPrivateFieldGet(this, _RestrictedMessenger_allowedEvents, "f");
219
+ return (__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isInCurrentNamespace).call(this, eventType) ||
215
220
  (allowedEvents !== null && allowedEvents.includes(eventType)));
216
- }, _RestrictedControllerMessenger_isAllowedAction = function _RestrictedControllerMessenger_isAllowedAction(actionType) {
221
+ }, _RestrictedMessenger_isAllowedAction = function _RestrictedMessenger_isAllowedAction(actionType) {
217
222
  // Safely upcast to allow runtime check
218
- const allowedActions = __classPrivateFieldGet(this, _RestrictedControllerMessenger_allowedActions, "f");
219
- return (__classPrivateFieldGet(this, _RestrictedControllerMessenger_instances, "m", _RestrictedControllerMessenger_isInCurrentNamespace).call(this, actionType) ||
223
+ const allowedActions = __classPrivateFieldGet(this, _RestrictedMessenger_allowedActions, "f");
224
+ return (__classPrivateFieldGet(this, _RestrictedMessenger_instances, "m", _RestrictedMessenger_isInCurrentNamespace).call(this, actionType) ||
220
225
  (allowedActions !== null && allowedActions.includes(actionType)));
221
- }, _RestrictedControllerMessenger_isInCurrentNamespace = function _RestrictedControllerMessenger_isInCurrentNamespace(name) {
222
- return name.startsWith(`${__classPrivateFieldGet(this, _RestrictedControllerMessenger_controllerName, "f")}:`);
226
+ }, _RestrictedMessenger_isInCurrentNamespace = function _RestrictedMessenger_isInCurrentNamespace(name) {
227
+ return name.startsWith(`${__classPrivateFieldGet(this, _RestrictedMessenger_namespace, "f")}:`);
223
228
  };
224
- //# sourceMappingURL=RestrictedControllerMessenger.cjs.map
229
+ export { RestrictedMessenger as RestrictedControllerMessenger };
230
+ //# sourceMappingURL=RestrictedMessenger.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestrictedMessenger.mjs","sourceRoot":"","sources":["../src/RestrictedMessenger.ts"],"names":[],"mappings":";;;;;;;;;;;;AA2CA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,mBAAmB;IAe9B;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,EACV,mBAAmB,EACnB,SAAS,EACT,IAAI,EACJ,cAAc,EACd,aAAa,GAOd;;QAvCQ,iDAAyD;QAEzD,iDAAsB;QAEtB,sDAA6D;QAE7D,qDAA2D;QAkClE,IAAI,SAAS,IAAI,mBAAmB,EAAE;YACpC,MAAM,IAAI,KAAK,CACb,wHAAwH,CACzH,CAAC;SACH;aAAM,IAAI,CAAC,SAAS,IAAI,CAAC,mBAAmB,EAAE;YAC7C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;SAC3C;QACD,uEAAuE;QACvE,oEAAoE;QACpE,uBAAA,IAAI,kCAAc,CAAC,SAAS,IAAI,mBAAmB,CAAE,MAAA,CAAC;QACtD,uBAAA,IAAI,kCAAc,IAAI,MAAA,CAAC;QACvB,uBAAA,IAAI,uCAAmB,cAAc,MAAA,CAAC;QACtC,uBAAA,IAAI,sCAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;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,IAAI,CAAC,uBAAA,IAAI,iFAAsB,MAA1B,IAAI,EAAuB,KAAK,CAAC,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,6CAA6C,uBAAA,IAAI,sCAAW,IAAI,CACjE,CAAC;SACH;QACD,uBAAA,IAAI,sCAAW,CAAC,uBAAuB,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;AAGH,OAAO,EAAE,mBAAmB,IAAI,6BAA6B,EAAE,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 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 * @deprecated This has been renamed to `RestrictedMessengerConstraint`.\n */\nexport type RestrictedControllerMessengerConstraint<\n Namespace extends string = string,\n> = RestrictedMessengerConstraint<Namespace>;\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.controllerMessenger - The messenger instance that is being wrapped. (deprecated)\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 controllerMessenger,\n messenger,\n name,\n allowedActions,\n allowedEvents,\n }: {\n controllerMessenger?: Messenger<ActionConstraint, EventConstraint>;\n messenger?: Messenger<ActionConstraint, EventConstraint>;\n name: Namespace;\n allowedActions: NotNamespacedBy<Namespace, AllowedAction>[];\n allowedEvents: NotNamespacedBy<Namespace, AllowedEvent>[];\n }) {\n if (messenger && controllerMessenger) {\n throw new Error(\n `Both messenger properties provided. Provide message using only 'messenger' option, 'controllerMessenger' is deprecated`,\n );\n } else if (!messenger && !controllerMessenger) {\n throw new Error('Messenger not provided');\n }\n // The above condition guarantees that one of these options is defined.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#messenger = (messenger ?? controllerMessenger)!;\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 unqiue 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 * 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 unqiue 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 */\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: ExtractEventHandler<Event, EventType>,\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(event, handler);\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 */\n unsubscribe<\n EventType extends\n | AllowedEvent\n | (Event['type'] & NamespacedName<Namespace>),\n >(event: EventType, handler: ExtractEventHandler<Event, EventType>) {\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\nexport { RestrictedMessenger as RestrictedControllerMessenger };\n"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RestrictedControllerMessenger = exports.ControllerMessenger = exports.isBaseController = exports.getPersistentState = exports.getAnonymizedState = exports.BaseController = exports.isBaseControllerV1 = exports.BaseControllerV1 = void 0;
3
+ exports.RestrictedMessenger = exports.RestrictedControllerMessenger = exports.Messenger = exports.ControllerMessenger = exports.isBaseController = exports.getPersistentState = exports.getAnonymizedState = exports.BaseController = exports.isBaseControllerV1 = exports.BaseControllerV1 = void 0;
4
4
  var BaseControllerV1_1 = require("./BaseControllerV1.cjs");
5
5
  Object.defineProperty(exports, "BaseControllerV1", { enumerable: true, get: function () { return BaseControllerV1_1.BaseControllerV1; } });
6
6
  Object.defineProperty(exports, "isBaseControllerV1", { enumerable: true, get: function () { return BaseControllerV1_1.isBaseControllerV1; } });
@@ -9,8 +9,10 @@ Object.defineProperty(exports, "BaseController", { enumerable: true, get: functi
9
9
  Object.defineProperty(exports, "getAnonymizedState", { enumerable: true, get: function () { return BaseControllerV2_1.getAnonymizedState; } });
10
10
  Object.defineProperty(exports, "getPersistentState", { enumerable: true, get: function () { return BaseControllerV2_1.getPersistentState; } });
11
11
  Object.defineProperty(exports, "isBaseController", { enumerable: true, get: function () { return BaseControllerV2_1.isBaseController; } });
12
- var ControllerMessenger_1 = require("./ControllerMessenger.cjs");
13
- Object.defineProperty(exports, "ControllerMessenger", { enumerable: true, get: function () { return ControllerMessenger_1.ControllerMessenger; } });
14
- var RestrictedControllerMessenger_1 = require("./RestrictedControllerMessenger.cjs");
15
- Object.defineProperty(exports, "RestrictedControllerMessenger", { enumerable: true, get: function () { return RestrictedControllerMessenger_1.RestrictedControllerMessenger; } });
12
+ var Messenger_1 = require("./Messenger.cjs");
13
+ Object.defineProperty(exports, "ControllerMessenger", { enumerable: true, get: function () { return Messenger_1.ControllerMessenger; } });
14
+ Object.defineProperty(exports, "Messenger", { enumerable: true, get: function () { return Messenger_1.Messenger; } });
15
+ var RestrictedMessenger_1 = require("./RestrictedMessenger.cjs");
16
+ Object.defineProperty(exports, "RestrictedControllerMessenger", { enumerable: true, get: function () { return RestrictedMessenger_1.RestrictedControllerMessenger; } });
17
+ Object.defineProperty(exports, "RestrictedMessenger", { enumerable: true, get: function () { return RestrictedMessenger_1.RestrictedMessenger; } });
16
18
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,2DAA0E;AAAjE,oHAAA,gBAAgB,OAAA;AAAE,sHAAA,kBAAkB,OAAA;AAgB7C,2DAK4B;AAJ1B,kHAAA,cAAc,OAAA;AACd,sHAAA,kBAAkB,OAAA;AAClB,sHAAA,kBAAkB,OAAA;AAClB,oHAAA,gBAAgB,OAAA;AAgBlB,iEAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAE5B,qFAAgF;AAAvE,8IAAA,6BAA6B,OAAA","sourcesContent":["export type {\n BaseConfig,\n BaseControllerV1Instance,\n BaseState,\n ConfigConstraint as ConfigConstraintV1,\n Listener,\n StateConstraint as StateConstraintV1,\n} from './BaseControllerV1';\nexport { BaseControllerV1, isBaseControllerV1 } from './BaseControllerV1';\nexport type {\n BaseControllerInstance,\n ControllerInstance,\n Listener as ListenerV2,\n StateConstraint,\n LegacyControllerStateConstraint,\n StateDeriver,\n StateDeriverConstraint,\n StateMetadata,\n StateMetadataConstraint,\n StatePropertyMetadata,\n StatePropertyMetadataConstraint,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from './BaseControllerV2';\nexport {\n BaseController,\n getAnonymizedState,\n getPersistentState,\n isBaseController,\n} from './BaseControllerV2';\nexport type {\n ActionHandler,\n ExtractActionParameters,\n ExtractActionResponse,\n ExtractEventHandler,\n ExtractEventPayload,\n GenericEventHandler,\n SelectorFunction,\n ActionConstraint,\n EventConstraint,\n NamespacedBy,\n NotNamespacedBy,\n NamespacedName,\n} from './ControllerMessenger';\nexport { ControllerMessenger } from './ControllerMessenger';\nexport type { RestrictedControllerMessengerConstraint } from './RestrictedControllerMessenger';\nexport { RestrictedControllerMessenger } from './RestrictedControllerMessenger';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,2DAA0E;AAAjE,oHAAA,gBAAgB,OAAA;AAAE,sHAAA,kBAAkB,OAAA;AAgB7C,2DAK4B;AAJ1B,kHAAA,cAAc,OAAA;AACd,sHAAA,kBAAkB,OAAA;AAClB,sHAAA,kBAAkB,OAAA;AAClB,oHAAA,gBAAgB,OAAA;AAgBlB,6CAA6D;AAApD,gHAAA,mBAAmB,OAAA;AAAE,sGAAA,SAAS,OAAA;AAKvC,iEAG+B;AAF7B,oIAAA,6BAA6B,OAAA;AAC7B,0HAAA,mBAAmB,OAAA","sourcesContent":["export type {\n BaseConfig,\n BaseControllerV1Instance,\n BaseState,\n ConfigConstraint as ConfigConstraintV1,\n Listener,\n StateConstraint as StateConstraintV1,\n} from './BaseControllerV1';\nexport { BaseControllerV1, isBaseControllerV1 } from './BaseControllerV1';\nexport type {\n BaseControllerInstance,\n ControllerInstance,\n Listener as ListenerV2,\n StateConstraint,\n LegacyControllerStateConstraint,\n StateDeriver,\n StateDeriverConstraint,\n StateMetadata,\n StateMetadataConstraint,\n StatePropertyMetadata,\n StatePropertyMetadataConstraint,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from './BaseControllerV2';\nexport {\n BaseController,\n getAnonymizedState,\n getPersistentState,\n isBaseController,\n} from './BaseControllerV2';\nexport type {\n ActionHandler,\n ExtractActionParameters,\n ExtractActionResponse,\n ExtractEventHandler,\n ExtractEventPayload,\n GenericEventHandler,\n SelectorFunction,\n ActionConstraint,\n EventConstraint,\n NamespacedBy,\n NotNamespacedBy,\n NamespacedName,\n} from './Messenger';\nexport { ControllerMessenger, Messenger } from './Messenger';\nexport type {\n RestrictedControllerMessengerConstraint,\n RestrictedMessengerConstraint,\n} from './RestrictedMessenger';\nexport {\n RestrictedControllerMessenger,\n RestrictedMessenger,\n} from './RestrictedMessenger';\n"]}