@chromahq/core 1.0.56 → 1.0.58

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/dist/boot.es.js CHANGED
@@ -1,3 +1,4 @@
1
- export { f as bootstrap, c as claimEarlyPorts, i as isEarlyListenerSetup, s as setupEarlyListener } from './boot-c2gJZWBc.js';
1
+ export { j as bootstrap, d as claimEarlyPorts, i as isEarlyListenerSetup, s as setupEarlyListener } from './boot-DPtu_qKj.js';
2
2
  import '@inversifyjs/container';
3
+ import '@inversifyjs/core';
3
4
  //# sourceMappingURL=boot.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"boot.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"boot.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
package/dist/index.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@inversifyjs/core');
4
- var boot = require('./boot-CUFlC4bu.js');
4
+ var boot = require('./boot--zb14Gg3.js');
5
5
  require('@inversifyjs/container');
6
6
 
7
7
  function Service() {
@@ -9,6 +9,7 @@ function Service() {
9
9
  }
10
10
  const Use = (id) => core.inject(id);
11
11
  const Store = () => Use(/* @__PURE__ */ Symbol.for("Store"));
12
+ const EventBus = () => Use(/* @__PURE__ */ Symbol.for("EventBus"));
12
13
 
13
14
  class IMessage {
14
15
  handle(...args) {
@@ -102,11 +103,18 @@ function isDestroyable(obj) {
102
103
  return typeof obj.destroy === "function";
103
104
  }
104
105
 
106
+ Object.defineProperty(exports, "AppEventBus", {
107
+ enumerable: true,
108
+ get: function () { return boot.AppEventBus; }
109
+ });
110
+ exports.EventBusToken = boot.EventBusToken;
105
111
  exports.JobRegistry = boot.JobRegistry;
106
112
  exports.JobState = boot.JobState;
107
113
  exports.NonceService = boot.NonceService;
108
114
  exports.PopupVisibilityService = boot.PopupVisibilityService;
115
+ exports.SUBSCRIBE_METADATA_KEY = boot.SUBSCRIBE_METADATA_KEY;
109
116
  exports.Scheduler = boot.Scheduler;
117
+ exports.Subscribe = boot.Subscribe;
110
118
  exports.arePortsClaimed = boot.arePortsClaimed;
111
119
  exports.bootstrap = boot.bootstrap;
112
120
  exports.claimEarlyPorts = boot.claimEarlyPorts;
@@ -114,10 +122,12 @@ exports.container = boot.container;
114
122
  exports.create = boot.create;
115
123
  exports.getNonceService = boot.getNonceService;
116
124
  exports.getPopupVisibilityService = boot.getPopupVisibilityService;
125
+ exports.getSubscribeMetadata = boot.getSubscribeMetadata;
117
126
  exports.isEarlyListenerSetup = boot.isEarlyListenerSetup;
118
127
  exports.setupEarlyListener = boot.setupEarlyListener;
119
128
  exports.Booteable = Booteable;
120
129
  exports.Delay = Delay;
130
+ exports.EventBus = EventBus;
121
131
  exports.Every = Every;
122
132
  exports.EverySeconds = EverySeconds;
123
133
  exports.IMessage = IMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/decorators/Service.ts","../src/decorators/Message.ts","../src/scheduler/core/Job.ts","../src/scheduler/decorators/Job.ts","../src/scheduler/decorators/Delay.ts","../src/scheduler/decorators/Every.ts","../src/scheduler/decorators/EverySeconds.ts","../src/services/booteable.ts"],"sourcesContent":["import { inject, injectable } from '@inversifyjs/core';\n\nexport function Service() {\n return injectable();\n}\n\nexport const Use = (id: symbol | string | NewableFunction) => inject(id);\nexport const Store = () => Use(Symbol.for('Store'));\n","import { injectable } from '@inversifyjs/core';\n\nexport abstract class IMessage {\n handle(...args: any[]): Promise<void> | void {\n throw new Error('Method not implemented.');\n }\n}\n\nexport function Message(name: string) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('name', name, constructor);\n return constructor;\n };\n}\n","import { IJob, JobContext } from './IJob';\n\nexport abstract class Job<T = unknown> implements IJob<T> {\n constructor(public readonly data?: T) {}\n\n abstract handle(context?: JobContext): Promise<void> | void;\n\n pause?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} paused`);\n }\n\n resume?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} resumed`);\n }\n\n stop?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} stopped`);\n }\n}\n","import { injectable } from '@inversifyjs/core';\nimport { JobOptions } from '../core/JobOptions';\n\nexport function JobConfig<T extends new (...args: any[]) => any>(options: JobOptions = {}) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('job:options', options, constructor);\n return constructor;\n };\n}\n","import { JobConfig } from './Job';\n\nexport const Delay = (ms: number) => JobConfig({ delay: ms });\n","import { injectable } from '@inversifyjs/core';\n\n/**\n * Options for the Every decorator.\n */\nexport interface EveryOptions {\n /**\n * If true, the job will only execute when the popup (or extension view) is visible.\n * This reduces unnecessary background activity when the user isn't looking at the extension.\n */\n requiresPopup?: boolean;\n\n /**\n * Explicit job name (survives minification). Recommended for production builds.\n */\n name?: string;\n\n /**\n * If true, job starts paused and must be resumed manually via Scheduler.resume()\n */\n startPaused?: boolean;\n}\n\n/**\n * Decorator for scheduling jobs using cron expressions.\n *\n * @param cron - Cron expression (e.g., '0 *\\/5 * * * *' for every 5 minutes)\n * @param options - Optional configuration for the job\n *\n * @example\n * ```typescript\n * // Basic usage - runs every 5 minutes\n * @Every('0 *\\/5 * * * *')\n * export class MyJob { ... }\n *\n * // With options - only runs when popup is visible\n * @Every('0 *\\/5 * * * *', { requiresPopup: true, name: 'MyJob' })\n * export class MyJob { ... }\n * ```\n */\nexport function Every(cron: string, options?: EveryOptions) {\n return function (constructor: any) {\n injectable()(constructor);\n\n // Set explicit name metadata to survive minification\n if (options?.name) {\n Reflect.defineMetadata('name', options.name, constructor);\n }\n\n Reflect.defineMetadata(\n 'job:options',\n {\n cron,\n requiresPopup: options?.requiresPopup ?? false,\n startPaused: options?.startPaused ?? false,\n },\n constructor,\n );\n return constructor;\n };\n}\n","import { injectable } from '@inversifyjs/core';\n\n/**\n * Options for the EverySeconds decorator.\n */\nexport interface EverySecondsOptions {\n /** If true, job starts paused and must be resumed manually via Scheduler.resume() */\n startPaused?: boolean;\n\n /** Explicit job name (survives minification). Required for production builds. */\n name?: string;\n\n /**\n * If true, the job will only execute when the popup (or extension view) is visible.\n * This reduces unnecessary background activity when the user isn't looking at the extension.\n */\n requiresPopup?: boolean;\n}\n\n/**\n * Decorator for jobs that run at a specific interval in seconds.\n * Unlike cron expressions which have minute-level granularity,\n * this decorator allows for second-level precision.\n *\n * @param seconds - The interval in seconds between job executions\n * @param options - Optional configuration (startPaused, name, requiresPopup, etc.)\n *\n * @example\n * ```typescript\n * // Auto-starting job (default)\n * @EverySeconds(5, { name: 'MyJob' })\n * export class MyJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs every 5 seconds');\n * }\n * }\n *\n * // Job that only runs when popup is visible\n * @EverySeconds(10, { name: 'UiUpdateJob', requiresPopup: true })\n * export class UiUpdateJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Only runs when user is viewing extension');\n * }\n * }\n *\n * // Paused job that must be manually resumed\n * @EverySeconds(2, { startPaused: true, name: 'OnDemandJob' })\n * export class OnDemandJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs when resumed');\n * }\n * }\n * ```\n */\nexport function EverySeconds(seconds: number, options?: EverySecondsOptions) {\n return function (constructor: any) {\n injectable()(constructor);\n // Set explicit name metadata to survive minification\n if (options?.name) {\n Reflect.defineMetadata('name', options.name, constructor);\n }\n\n Reflect.defineMetadata(\n 'job:options',\n {\n delay: seconds * 1000,\n recurring: true,\n startPaused: options?.startPaused ?? false,\n requiresPopup: options?.requiresPopup ?? false,\n },\n constructor,\n );\n return constructor;\n };\n}\n","export abstract class Booteable {\n /**\n * Boot method to be called when the service is initialized.\n * This method can be used to perform any setup or initialization logic.\n */\n abstract boot(): void;\n /**\n * Optional destroy method to be called when the service is being destroyed.\n * This can be used to clean up resources or perform any necessary teardown logic.\n */\n destroy?(): void {\n // Default implementation does nothing\n }\n}\n\nexport function isBooteable(obj: any): obj is Booteable {\n return typeof obj.boot === 'function';\n}\n\nexport function isDestroyable(obj: any): obj is Booteable {\n return typeof obj.destroy === 'function';\n}\n"],"names":["injectable","inject"],"mappings":";;;;;;AAEO,SAAS,OAAA,GAAU;AACxB,EAAA,OAAOA,eAAA,EAAW;AACpB;AAEO,MAAM,GAAA,GAAM,CAAC,EAAA,KAA0CC,WAAA,CAAO,EAAE;AAChE,MAAM,QAAQ,MAAM,GAAA,iBAAI,MAAA,CAAO,GAAA,CAAI,OAAO,CAAC;;ACL3C,MAAe,QAAA,CAAS;AAAA,EAC7B,UAAU,IAAA,EAAmC;AAC3C,IAAA,MAAM,IAAI,MAAM,yBAAyB,CAAA;AAAA;AAE7C;AAEO,SAAS,QAAQ,IAAA,EAAc;AACpC,EAAA,OAAO,SAAU,WAAA,EAAkB;AACjC,IAAAD,eAAA,GAAa,WAAW,CAAA;AACxB,IAAA,OAAA,CAAQ,cAAA,CAAe,MAAA,EAAQ,IAAA,EAAM,WAAW,CAAA;AAChD,IAAA,OAAO,WAAA;AAAA,GACT;AACF;;ACZO,MAAe,GAAA,CAAoC;AAAA,EACxD,YAA4B,IAAA,EAAU;AAAV,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA;AAAW,EAIvC,KAAA,GAA+B;AAC7B,IAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,IAAA,EAAO,IAAA,CAAK,WAAA,CAAY,IAAI,CAAA,OAAA,CAAS,CAAA;AAAA;AACnD,EAEA,MAAA,GAAgC;AAC9B,IAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,IAAA,EAAO,IAAA,CAAK,WAAA,CAAY,IAAI,CAAA,QAAA,CAAU,CAAA;AAAA;AACpD,EAEA,IAAA,GAA8B;AAC5B,IAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,IAAA,EAAO,IAAA,CAAK,WAAA,CAAY,IAAI,CAAA,QAAA,CAAU,CAAA;AAAA;AAEtD;;ACfO,SAAS,SAAA,CAAiD,OAAA,GAAsB,EAAC,EA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C;AAAA,MACA;AAAA,KACF;AACA,IAAA,OAAO,WAAA;AAAA,GACT;AACF;;AC1EO,MAAe,SAAA,CAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAU9B,OAAA,GAAiB;AAAA;AAGnB;AAEO,SAAS,YAAY,GAAA,EAA4B;AACtD,EAAA,OAAO,OAAO,IAAI,IAAA,KAAS,UAAA;AAC7B;AAEO,SAAS,cAAc,GAAA,EAA4B;AACxD,EAAA,OAAO,OAAO,IAAI,OAAA,KAAY,UAAA;AAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/decorators/Service.ts","../src/decorators/Message.ts","../src/scheduler/core/Job.ts","../src/scheduler/decorators/Job.ts","../src/scheduler/decorators/Delay.ts","../src/scheduler/decorators/Every.ts","../src/scheduler/decorators/EverySeconds.ts","../src/services/booteable.ts"],"sourcesContent":["import { inject, injectable } from '@inversifyjs/core';\n\nexport function Service() {\n return injectable();\n}\n\nexport const Use = (id: symbol | string | NewableFunction) => inject(id);\nexport const Store = () => Use(Symbol.for('Store'));\nexport const EventBus = () => Use(Symbol.for('EventBus'));\n","import { injectable } from '@inversifyjs/core';\n\nexport abstract class IMessage {\n handle(...args: any[]): Promise<void> | void {\n throw new Error('Method not implemented.');\n }\n}\n\nexport function Message(name: string) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('name', name, constructor);\n return constructor;\n };\n}\n","import { IJob, JobContext } from './IJob';\n\nexport abstract class Job<T = unknown> implements IJob<T> {\n constructor(public readonly data?: T) {}\n\n abstract handle(context?: JobContext): Promise<void> | void;\n\n pause?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} paused`);\n }\n\n resume?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} resumed`);\n }\n\n stop?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} stopped`);\n }\n}\n","import { injectable } from '@inversifyjs/core';\nimport { JobOptions } from '../core/JobOptions';\n\nexport function JobConfig<T extends new (...args: any[]) => any>(options: JobOptions = {}) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('job:options', options, constructor);\n return constructor;\n };\n}\n","import { JobConfig } from './Job';\n\nexport const Delay = (ms: number) => JobConfig({ delay: ms });\n","import { injectable } from '@inversifyjs/core';\n\n/**\n * Options for the Every decorator.\n */\nexport interface EveryOptions {\n /**\n * If true, the job will only execute when the popup (or extension view) is visible.\n * This reduces unnecessary background activity when the user isn't looking at the extension.\n */\n requiresPopup?: boolean;\n\n /**\n * Explicit job name (survives minification). Recommended for production builds.\n */\n name?: string;\n\n /**\n * If true, job starts paused and must be resumed manually via Scheduler.resume()\n */\n startPaused?: boolean;\n}\n\n/**\n * Decorator for scheduling jobs using cron expressions.\n *\n * @param cron - Cron expression (e.g., '0 *\\/5 * * * *' for every 5 minutes)\n * @param options - Optional configuration for the job\n *\n * @example\n * ```typescript\n * // Basic usage - runs every 5 minutes\n * @Every('0 *\\/5 * * * *')\n * export class MyJob { ... }\n *\n * // With options - only runs when popup is visible\n * @Every('0 *\\/5 * * * *', { requiresPopup: true, name: 'MyJob' })\n * export class MyJob { ... }\n * ```\n */\nexport function Every(cron: string, options?: EveryOptions) {\n return function (constructor: any) {\n injectable()(constructor);\n\n // Set explicit name metadata to survive minification\n if (options?.name) {\n Reflect.defineMetadata('name', options.name, constructor);\n }\n\n Reflect.defineMetadata(\n 'job:options',\n {\n cron,\n requiresPopup: options?.requiresPopup ?? false,\n startPaused: options?.startPaused ?? false,\n },\n constructor,\n );\n return constructor;\n };\n}\n","import { injectable } from '@inversifyjs/core';\n\n/**\n * Options for the EverySeconds decorator.\n */\nexport interface EverySecondsOptions {\n /** If true, job starts paused and must be resumed manually via Scheduler.resume() */\n startPaused?: boolean;\n\n /** Explicit job name (survives minification). Required for production builds. */\n name?: string;\n\n /**\n * If true, the job will only execute when the popup (or extension view) is visible.\n * This reduces unnecessary background activity when the user isn't looking at the extension.\n */\n requiresPopup?: boolean;\n}\n\n/**\n * Decorator for jobs that run at a specific interval in seconds.\n * Unlike cron expressions which have minute-level granularity,\n * this decorator allows for second-level precision.\n *\n * @param seconds - The interval in seconds between job executions\n * @param options - Optional configuration (startPaused, name, requiresPopup, etc.)\n *\n * @example\n * ```typescript\n * // Auto-starting job (default)\n * @EverySeconds(5, { name: 'MyJob' })\n * export class MyJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs every 5 seconds');\n * }\n * }\n *\n * // Job that only runs when popup is visible\n * @EverySeconds(10, { name: 'UiUpdateJob', requiresPopup: true })\n * export class UiUpdateJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Only runs when user is viewing extension');\n * }\n * }\n *\n * // Paused job that must be manually resumed\n * @EverySeconds(2, { startPaused: true, name: 'OnDemandJob' })\n * export class OnDemandJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs when resumed');\n * }\n * }\n * ```\n */\nexport function EverySeconds(seconds: number, options?: EverySecondsOptions) {\n return function (constructor: any) {\n injectable()(constructor);\n // Set explicit name metadata to survive minification\n if (options?.name) {\n Reflect.defineMetadata('name', options.name, constructor);\n }\n\n Reflect.defineMetadata(\n 'job:options',\n {\n delay: seconds * 1000,\n recurring: true,\n startPaused: options?.startPaused ?? false,\n requiresPopup: options?.requiresPopup ?? false,\n },\n constructor,\n );\n return constructor;\n };\n}\n","export abstract class Booteable {\n /**\n * Boot method to be called when the service is initialized.\n * This method can be used to perform any setup or initialization logic.\n */\n abstract boot(): void;\n /**\n * Optional destroy method to be called when the service is being destroyed.\n * This can be used to clean up resources or perform any necessary teardown logic.\n */\n destroy?(): void {\n // Default implementation does nothing\n }\n}\n\nexport function isBooteable(obj: any): obj is Booteable {\n return typeof obj.boot === 'function';\n}\n\nexport function isDestroyable(obj: any): obj is Booteable {\n return typeof obj.destroy === 'function';\n}\n"],"names":["injectable","inject"],"mappings":";;;;;;AAEO,SAAS,OAAA,GAAU;AACxB,EAAA,OAAOA,eAAA,EAAW;AACpB;AAEO,MAAM,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;AAAA;AAAA,EAU9B,OAAA,GAAiB;AAAA;AAGnB;AAEO,SAAS,YAAY,GAAA,EAA4B;AACtD,EAAA,OAAO,OAAO,IAAI,IAAA,KAAS,UAAA;AAC7B;AAEO,SAAS,cAAc,GAAA,EAA4B;AACxD,EAAA,OAAO,OAAO,IAAI,OAAA,KAAY,UAAA;AAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -3,12 +3,162 @@ import { Container } from '@inversifyjs/container';
3
3
  declare function Service(): ClassDecorator;
4
4
  declare const Use: (id: symbol | string | NewableFunction) => MethodDecorator & ParameterDecorator & PropertyDecorator;
5
5
  declare const Store: () => MethodDecorator & ParameterDecorator & PropertyDecorator;
6
+ declare const EventBus: () => MethodDecorator & ParameterDecorator & PropertyDecorator;
6
7
 
7
8
  declare abstract class IMessage {
8
9
  handle(...args: any[]): Promise<void> | void;
9
10
  }
10
11
  declare function Message(name: string): (constructor: any) => any;
11
12
 
13
+ /**
14
+ * @fileoverview Method decorator for subscribing to application events.
15
+ *
16
+ * The `@Subscribe` decorator marks a method as an event handler. During
17
+ * bootstrap, the framework scans all registered services and jobs for
18
+ * methods decorated with `@Subscribe` and wires them to the {@link AppEventBus}.
19
+ *
20
+ * @module events/Subscribe
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { Service, Subscribe } from '@chromahq/core';
25
+ *
26
+ * @Service()
27
+ * class MyService {
28
+ * @Subscribe('auth:login')
29
+ * async onLogin(payload: { walletId: string }) {
30
+ * console.log('User logged in:', payload.walletId);
31
+ * }
32
+ *
33
+ * @Subscribe('wallet:selected')
34
+ * onWalletSelected(payload: { walletId: string }) {
35
+ * // handle wallet selection change
36
+ * }
37
+ * }
38
+ * ```
39
+ */
40
+ /** Reflect metadata key used to store subscription info on a class */
41
+ declare const SUBSCRIBE_METADATA_KEY = "chroma:subscribe";
42
+ /**
43
+ * Metadata entry stored by the @Subscribe decorator.
44
+ *
45
+ * @interface
46
+ */
47
+ interface SubscribeMetadata {
48
+ /** The event name to subscribe to (e.g. 'auth:login') */
49
+ eventName: string;
50
+ /** The method name on the class prototype */
51
+ methodName: string;
52
+ }
53
+ /**
54
+ * Method decorator that subscribes the decorated method to a named event.
55
+ *
56
+ * The method will be called with the event payload whenever the event is
57
+ * emitted through the {@link AppEventBus}. Multiple methods on the same
58
+ * class can subscribe to different (or the same) events.
59
+ *
60
+ * @param eventName - the event identifier to subscribe to (e.g. 'auth:login')
61
+ * @returns MethodDecorator
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * @Subscribe('auth:login')
66
+ * async onLogin(payload: { walletId: string }) {
67
+ * await this.refreshData(payload.walletId);
68
+ * }
69
+ * ```
70
+ */
71
+ declare function Subscribe(eventName: string): (target: object, propertyKey: string, _descriptor: PropertyDescriptor) => void;
72
+ /**
73
+ * Read all @Subscribe metadata entries from a class constructor.
74
+ *
75
+ * @param constructor - the class constructor to inspect
76
+ * @returns array of subscription metadata (empty if none)
77
+ */
78
+ declare function getSubscribeMetadata(constructor: Function): SubscribeMetadata[];
79
+
80
+ /**
81
+ * @fileoverview Generic application-wide event bus.
82
+ *
83
+ * Provides a centralised pub/sub mechanism for decoupled communication
84
+ * between services, jobs, and handlers. The bus is created once during
85
+ * bootstrap, bound to the DI container, and can be injected into any
86
+ * `@Service()` or job via `@Use(AppEventBus)`.
87
+ *
88
+ * The framework automatically wires methods decorated with `@Subscribe`
89
+ * during the bootstrap phase, but manual subscriptions via {@link on}
90
+ * are also supported.
91
+ *
92
+ * @module events/AppEventBus
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { Service, EventBus } from '@chromahq/core';
97
+ * import type { AppEventBus } from '@chromahq/core';
98
+ *
99
+ * @Service()
100
+ * class AuthService {
101
+ * constructor(@EventBus() private bus: AppEventBus) {}
102
+ *
103
+ * async login(walletId: string) {
104
+ * // ... perform login ...
105
+ * await this.bus.emit('auth:login', { walletId });
106
+ * }
107
+ * }
108
+ * ```
109
+ */
110
+ /** Handler function signature for event subscriptions */
111
+ type EventHandler<T = unknown> = (payload: T) => void | Promise<void>;
112
+ /** DI container token for resolving the AppEventBus singleton */
113
+ declare const EventBusToken: unique symbol;
114
+ /**
115
+ * Generic application event bus.
116
+ *
117
+ * Implements a simple pub/sub pattern. Handlers are invoked in parallel
118
+ * via `Promise.allSettled` — a failure in one handler never prevents
119
+ * other handlers from executing.
120
+ */
121
+ declare class AppEventBus {
122
+ /** Registry of all active subscriptions */
123
+ private subscriptions;
124
+ /** Auto-incrementing ID counter */
125
+ private nextId;
126
+ /**
127
+ * Subscribe to a named event.
128
+ *
129
+ * @param eventName - the event to listen for
130
+ * @param handler - callback invoked with the event payload
131
+ * @param handlerName - human-readable name for logging
132
+ * @returns an unsubscribe function
133
+ */
134
+ on<T = unknown>(eventName: string, handler: EventHandler<T>, handlerName: string): () => void;
135
+ /**
136
+ * Emit a named event to all matching subscribers.
137
+ *
138
+ * Handlers execute in parallel. Individual handler failures are caught
139
+ * and logged — they do not propagate or block other handlers.
140
+ *
141
+ * @param eventName - the event to emit
142
+ * @param payload - optional data passed to every handler
143
+ */
144
+ emit<T = unknown>(eventName: string, payload?: T): Promise<void>;
145
+ /**
146
+ * Get the total number of active subscriptions.
147
+ * Useful for debugging and testing.
148
+ */
149
+ getSubscriptionCount(): number;
150
+ /**
151
+ * Get the number of subscriptions for a specific event.
152
+ *
153
+ * @param eventName - the event to count subscriptions for
154
+ */
155
+ getSubscriptionCountForEvent(eventName: string): number;
156
+ /**
157
+ * Remove all subscriptions. Primarily for testing.
158
+ */
159
+ clearAllSubscriptions(): void;
160
+ }
161
+
12
162
  /**
13
163
  * Configuration options for scheduled jobs.
14
164
  */
@@ -601,6 +751,7 @@ declare class Scheduler {
601
751
  */
602
752
  private resumePopupDependentJobs;
603
753
  schedule(id: string, options: JobOptions): void;
754
+ private scheduleInternal;
604
755
  pause(id: string): void;
605
756
  resume(id: string): void;
606
757
  stop(id: string): void;
@@ -668,5 +819,5 @@ declare class JobRegistry {
668
819
  private createJobContext;
669
820
  }
670
821
 
671
- export { Booteable, Delay, Every, EverySeconds, IMessage, Job, JobRegistry, JobState, Message, NonceService, PopupVisibilityService, Scheduler, Service, Store, Use, arePortsClaimed, bootstrap, claimEarlyPorts, container, create, getNonceService, getPopupVisibilityService, isBooteable, isDestroyable, isEarlyListenerSetup, setupEarlyListener };
672
- export type { CriticalPayload, EveryOptions, EverySecondsOptions, IJob, JobContext, NonceCheckResult };
822
+ export { AppEventBus, Booteable, Delay, EventBus, EventBusToken, Every, EverySeconds, IMessage, Job, JobRegistry, JobState, Message, NonceService, PopupVisibilityService, SUBSCRIBE_METADATA_KEY, Scheduler, Service, Store, Subscribe, Use, arePortsClaimed, bootstrap, claimEarlyPorts, container, create, getNonceService, getPopupVisibilityService, getSubscribeMetadata, isBooteable, isDestroyable, isEarlyListenerSetup, setupEarlyListener };
823
+ export type { CriticalPayload, EventHandler, EveryOptions, EverySecondsOptions, IJob, JobContext, NonceCheckResult, SubscribeMetadata };
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { inject, injectable } from '@inversifyjs/core';
2
- export { J as JobRegistry, h as JobState, N as NonceService, P as PopupVisibilityService, S as Scheduler, b as arePortsClaimed, f as bootstrap, c as claimEarlyPorts, d as container, e as create, g as getNonceService, a as getPopupVisibilityService, i as isEarlyListenerSetup, s as setupEarlyListener } from './boot-c2gJZWBc.js';
2
+ export { A as AppEventBus, E as EventBusToken, J as JobRegistry, l as JobState, N as NonceService, P as PopupVisibilityService, a as SUBSCRIBE_METADATA_KEY, k as Scheduler, S as Subscribe, e as arePortsClaimed, j as bootstrap, d as claimEarlyPorts, f as container, h as create, b as getNonceService, c as getPopupVisibilityService, g as getSubscribeMetadata, i as isEarlyListenerSetup, s as setupEarlyListener } from './boot-DPtu_qKj.js';
3
3
  import '@inversifyjs/container';
4
4
 
5
5
  function Service() {
@@ -7,6 +7,7 @@ function Service() {
7
7
  }
8
8
  const Use = (id) => inject(id);
9
9
  const Store = () => Use(/* @__PURE__ */ Symbol.for("Store"));
10
+ const EventBus = () => Use(/* @__PURE__ */ Symbol.for("EventBus"));
10
11
 
11
12
  class IMessage {
12
13
  handle(...args) {
@@ -100,5 +101,5 @@ function isDestroyable(obj) {
100
101
  return typeof obj.destroy === "function";
101
102
  }
102
103
 
103
- export { Booteable, Delay, Every, EverySeconds, IMessage, Job, Message, Service, Store, Use, isBooteable, isDestroyable };
104
+ export { Booteable, Delay, EventBus, Every, EverySeconds, IMessage, Job, Message, Service, Store, Use, isBooteable, isDestroyable };
104
105
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/decorators/Service.ts","../src/decorators/Message.ts","../src/scheduler/core/Job.ts","../src/scheduler/decorators/Job.ts","../src/scheduler/decorators/Delay.ts","../src/scheduler/decorators/Every.ts","../src/scheduler/decorators/EverySeconds.ts","../src/services/booteable.ts"],"sourcesContent":["import { inject, injectable } from '@inversifyjs/core';\n\nexport function Service() {\n return injectable();\n}\n\nexport const Use = (id: symbol | string | NewableFunction) => inject(id);\nexport const Store = () => Use(Symbol.for('Store'));\n","import { injectable } from '@inversifyjs/core';\n\nexport abstract class IMessage {\n handle(...args: any[]): Promise<void> | void {\n throw new Error('Method not implemented.');\n }\n}\n\nexport function Message(name: string) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('name', name, constructor);\n return constructor;\n };\n}\n","import { IJob, JobContext } from './IJob';\n\nexport abstract class Job<T = unknown> implements IJob<T> {\n constructor(public readonly data?: T) {}\n\n abstract handle(context?: JobContext): Promise<void> | void;\n\n pause?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} paused`);\n }\n\n resume?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} resumed`);\n }\n\n stop?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} stopped`);\n }\n}\n","import { injectable } from '@inversifyjs/core';\nimport { JobOptions } from '../core/JobOptions';\n\nexport function JobConfig<T extends new (...args: any[]) => any>(options: JobOptions = {}) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('job:options', options, constructor);\n return constructor;\n };\n}\n","import { JobConfig } from './Job';\n\nexport const Delay = (ms: number) => JobConfig({ delay: ms });\n","import { injectable } from '@inversifyjs/core';\n\n/**\n * Options for the Every decorator.\n */\nexport interface EveryOptions {\n /**\n * If true, the job will only execute when the popup (or extension view) is visible.\n * This reduces unnecessary background activity when the user isn't looking at the extension.\n */\n requiresPopup?: boolean;\n\n /**\n * Explicit job name (survives minification). Recommended for production builds.\n */\n name?: string;\n\n /**\n * If true, job starts paused and must be resumed manually via Scheduler.resume()\n */\n startPaused?: boolean;\n}\n\n/**\n * Decorator for scheduling jobs using cron expressions.\n *\n * @param cron - Cron expression (e.g., '0 *\\/5 * * * *' for every 5 minutes)\n * @param options - Optional configuration for the job\n *\n * @example\n * ```typescript\n * // Basic usage - runs every 5 minutes\n * @Every('0 *\\/5 * * * *')\n * export class MyJob { ... }\n *\n * // With options - only runs when popup is visible\n * @Every('0 *\\/5 * * * *', { requiresPopup: true, name: 'MyJob' })\n * export class MyJob { ... }\n * ```\n */\nexport function Every(cron: string, options?: EveryOptions) {\n return function (constructor: any) {\n injectable()(constructor);\n\n // Set explicit name metadata to survive minification\n if (options?.name) {\n Reflect.defineMetadata('name', options.name, constructor);\n }\n\n Reflect.defineMetadata(\n 'job:options',\n {\n cron,\n requiresPopup: options?.requiresPopup ?? false,\n startPaused: options?.startPaused ?? false,\n },\n constructor,\n );\n return constructor;\n };\n}\n","import { injectable } from '@inversifyjs/core';\n\n/**\n * Options for the EverySeconds decorator.\n */\nexport interface EverySecondsOptions {\n /** If true, job starts paused and must be resumed manually via Scheduler.resume() */\n startPaused?: boolean;\n\n /** Explicit job name (survives minification). Required for production builds. */\n name?: string;\n\n /**\n * If true, the job will only execute when the popup (or extension view) is visible.\n * This reduces unnecessary background activity when the user isn't looking at the extension.\n */\n requiresPopup?: boolean;\n}\n\n/**\n * Decorator for jobs that run at a specific interval in seconds.\n * Unlike cron expressions which have minute-level granularity,\n * this decorator allows for second-level precision.\n *\n * @param seconds - The interval in seconds between job executions\n * @param options - Optional configuration (startPaused, name, requiresPopup, etc.)\n *\n * @example\n * ```typescript\n * // Auto-starting job (default)\n * @EverySeconds(5, { name: 'MyJob' })\n * export class MyJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs every 5 seconds');\n * }\n * }\n *\n * // Job that only runs when popup is visible\n * @EverySeconds(10, { name: 'UiUpdateJob', requiresPopup: true })\n * export class UiUpdateJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Only runs when user is viewing extension');\n * }\n * }\n *\n * // Paused job that must be manually resumed\n * @EverySeconds(2, { startPaused: true, name: 'OnDemandJob' })\n * export class OnDemandJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs when resumed');\n * }\n * }\n * ```\n */\nexport function EverySeconds(seconds: number, options?: EverySecondsOptions) {\n return function (constructor: any) {\n injectable()(constructor);\n // Set explicit name metadata to survive minification\n if (options?.name) {\n Reflect.defineMetadata('name', options.name, constructor);\n }\n\n Reflect.defineMetadata(\n 'job:options',\n {\n delay: seconds * 1000,\n recurring: true,\n startPaused: options?.startPaused ?? false,\n requiresPopup: options?.requiresPopup ?? false,\n },\n constructor,\n );\n return constructor;\n };\n}\n","export abstract class Booteable {\n /**\n * Boot method to be called when the service is initialized.\n * This method can be used to perform any setup or initialization logic.\n */\n abstract boot(): void;\n /**\n * Optional destroy method to be called when the service is being destroyed.\n * This can be used to clean up resources or perform any necessary teardown logic.\n */\n destroy?(): void {\n // Default implementation does nothing\n }\n}\n\nexport function isBooteable(obj: any): obj is Booteable {\n return typeof obj.boot === 'function';\n}\n\nexport function isDestroyable(obj: any): obj is Booteable {\n return typeof obj.destroy === 'function';\n}\n"],"names":[],"mappings":";;;;AAEO,SAAS,OAAA,GAAU;AACxB,EAAA,OAAO,UAAA,EAAW;AACpB;AAEO,MAAM,GAAA,GAAM,CAAC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AAO,IAAI,IAAA,KAAS,UAAA;AAC7B;AAEO,SAAS,cAAc,GAAA,EAA4B;AACxD,EAAA,OAAO,OAAO,IAAI,OAAA,KAAY,UAAA;AAChC;;;;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/decorators/Service.ts","../src/decorators/Message.ts","../src/scheduler/core/Job.ts","../src/scheduler/decorators/Job.ts","../src/scheduler/decorators/Delay.ts","../src/scheduler/decorators/Every.ts","../src/scheduler/decorators/EverySeconds.ts","../src/services/booteable.ts"],"sourcesContent":["import { inject, injectable } from '@inversifyjs/core';\n\nexport function Service() {\n return injectable();\n}\n\nexport const Use = (id: symbol | string | NewableFunction) => inject(id);\nexport const Store = () => Use(Symbol.for('Store'));\nexport const EventBus = () => Use(Symbol.for('EventBus'));\n","import { injectable } from '@inversifyjs/core';\n\nexport abstract class IMessage {\n handle(...args: any[]): Promise<void> | void {\n throw new Error('Method not implemented.');\n }\n}\n\nexport function Message(name: string) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('name', name, constructor);\n return constructor;\n };\n}\n","import { IJob, JobContext } from './IJob';\n\nexport abstract class Job<T = unknown> implements IJob<T> {\n constructor(public readonly data?: T) {}\n\n abstract handle(context?: JobContext): Promise<void> | void;\n\n pause?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} paused`);\n }\n\n resume?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} resumed`);\n }\n\n stop?(): Promise<void> | void {\n console.log(`Job ${this.constructor.name} stopped`);\n }\n}\n","import { injectable } from '@inversifyjs/core';\nimport { JobOptions } from '../core/JobOptions';\n\nexport function JobConfig<T extends new (...args: any[]) => any>(options: JobOptions = {}) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('job:options', options, constructor);\n return constructor;\n };\n}\n","import { JobConfig } from './Job';\n\nexport const Delay = (ms: number) => JobConfig({ delay: ms });\n","import { injectable } from '@inversifyjs/core';\n\n/**\n * Options for the Every decorator.\n */\nexport interface EveryOptions {\n /**\n * If true, the job will only execute when the popup (or extension view) is visible.\n * This reduces unnecessary background activity when the user isn't looking at the extension.\n */\n requiresPopup?: boolean;\n\n /**\n * Explicit job name (survives minification). Recommended for production builds.\n */\n name?: string;\n\n /**\n * If true, job starts paused and must be resumed manually via Scheduler.resume()\n */\n startPaused?: boolean;\n}\n\n/**\n * Decorator for scheduling jobs using cron expressions.\n *\n * @param cron - Cron expression (e.g., '0 *\\/5 * * * *' for every 5 minutes)\n * @param options - Optional configuration for the job\n *\n * @example\n * ```typescript\n * // Basic usage - runs every 5 minutes\n * @Every('0 *\\/5 * * * *')\n * export class MyJob { ... }\n *\n * // With options - only runs when popup is visible\n * @Every('0 *\\/5 * * * *', { requiresPopup: true, name: 'MyJob' })\n * export class MyJob { ... }\n * ```\n */\nexport function Every(cron: string, options?: EveryOptions) {\n return function (constructor: any) {\n injectable()(constructor);\n\n // Set explicit name metadata to survive minification\n if (options?.name) {\n Reflect.defineMetadata('name', options.name, constructor);\n }\n\n Reflect.defineMetadata(\n 'job:options',\n {\n cron,\n requiresPopup: options?.requiresPopup ?? false,\n startPaused: options?.startPaused ?? false,\n },\n constructor,\n );\n return constructor;\n };\n}\n","import { injectable } from '@inversifyjs/core';\n\n/**\n * Options for the EverySeconds decorator.\n */\nexport interface EverySecondsOptions {\n /** If true, job starts paused and must be resumed manually via Scheduler.resume() */\n startPaused?: boolean;\n\n /** Explicit job name (survives minification). Required for production builds. */\n name?: string;\n\n /**\n * If true, the job will only execute when the popup (or extension view) is visible.\n * This reduces unnecessary background activity when the user isn't looking at the extension.\n */\n requiresPopup?: boolean;\n}\n\n/**\n * Decorator for jobs that run at a specific interval in seconds.\n * Unlike cron expressions which have minute-level granularity,\n * this decorator allows for second-level precision.\n *\n * @param seconds - The interval in seconds between job executions\n * @param options - Optional configuration (startPaused, name, requiresPopup, etc.)\n *\n * @example\n * ```typescript\n * // Auto-starting job (default)\n * @EverySeconds(5, { name: 'MyJob' })\n * export class MyJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs every 5 seconds');\n * }\n * }\n *\n * // Job that only runs when popup is visible\n * @EverySeconds(10, { name: 'UiUpdateJob', requiresPopup: true })\n * export class UiUpdateJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Only runs when user is viewing extension');\n * }\n * }\n *\n * // Paused job that must be manually resumed\n * @EverySeconds(2, { startPaused: true, name: 'OnDemandJob' })\n * export class OnDemandJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs when resumed');\n * }\n * }\n * ```\n */\nexport function EverySeconds(seconds: number, options?: EverySecondsOptions) {\n return function (constructor: any) {\n injectable()(constructor);\n // Set explicit name metadata to survive minification\n if (options?.name) {\n Reflect.defineMetadata('name', options.name, constructor);\n }\n\n Reflect.defineMetadata(\n 'job:options',\n {\n delay: seconds * 1000,\n recurring: true,\n startPaused: options?.startPaused ?? false,\n requiresPopup: options?.requiresPopup ?? false,\n },\n constructor,\n );\n return constructor;\n };\n}\n","export abstract class Booteable {\n /**\n * Boot method to be called when the service is initialized.\n * This method can be used to perform any setup or initialization logic.\n */\n abstract boot(): void;\n /**\n * Optional destroy method to be called when the service is being destroyed.\n * This can be used to clean up resources or perform any necessary teardown logic.\n */\n destroy?(): void {\n // Default implementation does nothing\n }\n}\n\nexport function isBooteable(obj: any): obj is Booteable {\n return typeof obj.boot === 'function';\n}\n\nexport function isDestroyable(obj: any): obj is Booteable {\n return typeof obj.destroy === 'function';\n}\n"],"names":[],"mappings":";;;;AAEO,SAAS,OAAA,GAAU;AACxB,EAAA,OAAO,UAAA,EAAW;AACpB;AAEO,MAAM,GAAA,GAAM,CAAC,EAAA,KAA0C,MAAA,CAAO,EAAE;AAChE,MAAM,QAAQ,MAAM,GAAA,iBAAI,MAAA,CAAO,GAAA,CAAI,OAAO,CAAC;AAC3C,MAAM,WAAW,MAAM,GAAA,iBAAI,MAAA,CAAO,GAAA,CAAI,UAAU,CAAC;;ACNjD,MAAe,QAAA,CAAS;AAAA,EAC7B,UAAU,IAA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 @@
1
1
  {
2
2
  "name": "@chromahq/core",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "description": "Core library for building Chrome extensions with Chroma framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",