@chromahq/core 1.0.52 → 1.0.53
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-B33Lf5tn.js → boot-CscXvoFf.js} +149 -3
- package/dist/boot-CscXvoFf.js.map +1 -0
- package/dist/{boot-DmW_OC5R.js → boot-DrOND1Zi.js} +148 -4
- package/dist/boot-DrOND1Zi.js.map +1 -0
- package/dist/boot.cjs.js +1 -1
- package/dist/boot.es.js +1 -1
- package/dist/index.cjs.js +18 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +162 -8
- package/dist/index.es.js +16 -4
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/dist/boot-B33Lf5tn.js.map +0 -1
- package/dist/boot-DmW_OC5R.js.map +0 -1
package/dist/index.cjs.js.map
CHANGED
|
@@ -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\nexport function Every(cron: string) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('job:options'
|
|
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,E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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
|
@@ -9,13 +9,14 @@ declare abstract class IMessage {
|
|
|
9
9
|
}
|
|
10
10
|
declare function Message(name: string): (constructor: any) => any;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Configuration options for scheduled jobs.
|
|
14
|
+
*/
|
|
12
15
|
interface JobOptions {
|
|
16
|
+
/** Unique identifier for the job */
|
|
13
17
|
id?: string;
|
|
18
|
+
/** Delay in milliseconds before first execution (for delay-based jobs) */
|
|
14
19
|
delay?: number;
|
|
15
|
-
cron?: string;
|
|
16
|
-
persistent?: boolean;
|
|
17
|
-
recurring?: boolean;
|
|
18
|
-
startPaused?: boolean;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
interface IJob<T = unknown> {
|
|
@@ -80,7 +81,42 @@ declare abstract class Job<T = unknown> implements IJob<T> {
|
|
|
80
81
|
|
|
81
82
|
declare const Delay: (ms: number) => (constructor: any) => any;
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Options for the Every decorator.
|
|
86
|
+
*/
|
|
87
|
+
interface EveryOptions {
|
|
88
|
+
/**
|
|
89
|
+
* If true, the job will only execute when the popup (or extension view) is visible.
|
|
90
|
+
* This reduces unnecessary background activity when the user isn't looking at the extension.
|
|
91
|
+
*/
|
|
92
|
+
requiresPopup?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Explicit job name (survives minification). Recommended for production builds.
|
|
95
|
+
*/
|
|
96
|
+
name?: string;
|
|
97
|
+
/**
|
|
98
|
+
* If true, job starts paused and must be resumed manually via Scheduler.resume()
|
|
99
|
+
*/
|
|
100
|
+
startPaused?: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Decorator for scheduling jobs using cron expressions.
|
|
104
|
+
*
|
|
105
|
+
* @param cron - Cron expression (e.g., '0 *\/5 * * * *' for every 5 minutes)
|
|
106
|
+
* @param options - Optional configuration for the job
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* // Basic usage - runs every 5 minutes
|
|
111
|
+
* @Every('0 *\/5 * * * *')
|
|
112
|
+
* export class MyJob { ... }
|
|
113
|
+
*
|
|
114
|
+
* // With options - only runs when popup is visible
|
|
115
|
+
* @Every('0 *\/5 * * * *', { requiresPopup: true, name: 'MyJob' })
|
|
116
|
+
* export class MyJob { ... }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function Every(cron: string, options?: EveryOptions): (constructor: any) => any;
|
|
84
120
|
|
|
85
121
|
/**
|
|
86
122
|
* Options for the EverySeconds decorator.
|
|
@@ -90,6 +126,11 @@ interface EverySecondsOptions {
|
|
|
90
126
|
startPaused?: boolean;
|
|
91
127
|
/** Explicit job name (survives minification). Required for production builds. */
|
|
92
128
|
name?: string;
|
|
129
|
+
/**
|
|
130
|
+
* If true, the job will only execute when the popup (or extension view) is visible.
|
|
131
|
+
* This reduces unnecessary background activity when the user isn't looking at the extension.
|
|
132
|
+
*/
|
|
133
|
+
requiresPopup?: boolean;
|
|
93
134
|
}
|
|
94
135
|
/**
|
|
95
136
|
* Decorator for jobs that run at a specific interval in seconds.
|
|
@@ -97,7 +138,7 @@ interface EverySecondsOptions {
|
|
|
97
138
|
* this decorator allows for second-level precision.
|
|
98
139
|
*
|
|
99
140
|
* @param seconds - The interval in seconds between job executions
|
|
100
|
-
* @param options - Optional configuration (startPaused, name, etc.)
|
|
141
|
+
* @param options - Optional configuration (startPaused, name, requiresPopup, etc.)
|
|
101
142
|
*
|
|
102
143
|
* @example
|
|
103
144
|
* ```typescript
|
|
@@ -109,6 +150,14 @@ interface EverySecondsOptions {
|
|
|
109
150
|
* }
|
|
110
151
|
* }
|
|
111
152
|
*
|
|
153
|
+
* // Job that only runs when popup is visible
|
|
154
|
+
* @EverySeconds(10, { name: 'UiUpdateJob', requiresPopup: true })
|
|
155
|
+
* export class UiUpdateJob implements IJob {
|
|
156
|
+
* async handle(context: JobContext) {
|
|
157
|
+
* console.log('Only runs when user is viewing extension');
|
|
158
|
+
* }
|
|
159
|
+
* }
|
|
160
|
+
*
|
|
112
161
|
* // Paused job that must be manually resumed
|
|
113
162
|
* @EverySeconds(2, { startPaused: true, name: 'OnDemandJob' })
|
|
114
163
|
* export class OnDemandJob implements IJob {
|
|
@@ -293,6 +342,111 @@ declare class NonceService {
|
|
|
293
342
|
}
|
|
294
343
|
declare function getNonceService(): NonceService;
|
|
295
344
|
|
|
345
|
+
/**
|
|
346
|
+
* @fileoverview Popup Visibility Service for Chrome Extensions.
|
|
347
|
+
*
|
|
348
|
+
* Tracks whether the extension popup (or any extension view) is currently visible
|
|
349
|
+
* by monitoring connected ports. This allows jobs to conditionally run only when
|
|
350
|
+
* a user is actively viewing the extension, reducing unnecessary background activity.
|
|
351
|
+
*
|
|
352
|
+
* @module services/PopupVisibilityService
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* import { PopupVisibilityService } from '@chromahq/core';
|
|
357
|
+
*
|
|
358
|
+
* // Check if popup is visible
|
|
359
|
+
* if (PopupVisibilityService.instance.isPopupVisible()) {
|
|
360
|
+
* // Run UI-related tasks
|
|
361
|
+
* }
|
|
362
|
+
*
|
|
363
|
+
* // Listen for visibility changes
|
|
364
|
+
* PopupVisibilityService.instance.onVisibilityChange((isVisible) => {
|
|
365
|
+
* console.log('Popup visibility changed:', isVisible);
|
|
366
|
+
* });
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
/** Callback type for visibility change events */
|
|
370
|
+
type VisibilityChangeCallback = (isVisible: boolean) => void;
|
|
371
|
+
/**
|
|
372
|
+
* Service that tracks popup/extension view visibility.
|
|
373
|
+
*
|
|
374
|
+
* Uses a singleton pattern to ensure consistent state across the application.
|
|
375
|
+
* The service is updated by the BridgeRuntime when ports connect/disconnect.
|
|
376
|
+
*/
|
|
377
|
+
declare class PopupVisibilityService {
|
|
378
|
+
private static _instance;
|
|
379
|
+
/** Number of currently connected ports (popup views) */
|
|
380
|
+
private connectedPortCount;
|
|
381
|
+
/** Listeners for visibility changes */
|
|
382
|
+
private listeners;
|
|
383
|
+
/** Timestamp of last visibility change */
|
|
384
|
+
private lastVisibilityChangeAt;
|
|
385
|
+
/**
|
|
386
|
+
* Private constructor - use PopupVisibilityService.instance instead.
|
|
387
|
+
*/
|
|
388
|
+
private constructor();
|
|
389
|
+
/**
|
|
390
|
+
* Get the singleton instance of the service.
|
|
391
|
+
*/
|
|
392
|
+
static get instance(): PopupVisibilityService;
|
|
393
|
+
/**
|
|
394
|
+
* Reset the singleton instance (primarily for testing).
|
|
395
|
+
* @internal
|
|
396
|
+
*/
|
|
397
|
+
static resetInstance(): void;
|
|
398
|
+
/**
|
|
399
|
+
* Check if the popup (or any extension view) is currently visible.
|
|
400
|
+
*
|
|
401
|
+
* @returns true if at least one port is connected (popup is open)
|
|
402
|
+
*/
|
|
403
|
+
isPopupVisible(): boolean;
|
|
404
|
+
/**
|
|
405
|
+
* Get the number of connected ports.
|
|
406
|
+
*
|
|
407
|
+
* @returns The current count of connected extension views
|
|
408
|
+
*/
|
|
409
|
+
getConnectedPortCount(): number;
|
|
410
|
+
/**
|
|
411
|
+
* Get the timestamp of the last visibility change.
|
|
412
|
+
*
|
|
413
|
+
* @returns Unix timestamp in milliseconds, or 0 if never changed
|
|
414
|
+
*/
|
|
415
|
+
getLastVisibilityChangeAt(): number;
|
|
416
|
+
/**
|
|
417
|
+
* Register a callback to be notified when visibility changes.
|
|
418
|
+
*
|
|
419
|
+
* @param callback - Function to call when visibility changes
|
|
420
|
+
* @returns Unsubscribe function to remove the listener
|
|
421
|
+
*/
|
|
422
|
+
onVisibilityChange(callback: VisibilityChangeCallback): () => void;
|
|
423
|
+
/**
|
|
424
|
+
* Called when a port connects (popup opens).
|
|
425
|
+
* @internal
|
|
426
|
+
*/
|
|
427
|
+
onPortConnected(): void;
|
|
428
|
+
/**
|
|
429
|
+
* Called when a port disconnects (popup closes).
|
|
430
|
+
* @internal
|
|
431
|
+
*/
|
|
432
|
+
onPortDisconnected(): void;
|
|
433
|
+
/**
|
|
434
|
+
* Sync the port count with the actual connected ports set.
|
|
435
|
+
* Called by BridgeRuntime to ensure consistency.
|
|
436
|
+
* @internal
|
|
437
|
+
*/
|
|
438
|
+
syncPortCount(count: number): void;
|
|
439
|
+
/**
|
|
440
|
+
* Notify all registered listeners of a visibility change.
|
|
441
|
+
*/
|
|
442
|
+
private notifyListeners;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get the PopupVisibilityService singleton instance.
|
|
446
|
+
* Convenience function for cleaner imports.
|
|
447
|
+
*/
|
|
448
|
+
declare function getPopupVisibilityService(): PopupVisibilityService;
|
|
449
|
+
|
|
296
450
|
/**
|
|
297
451
|
* @fileoverview Early Connection Listener for Chrome Extension Service Workers.
|
|
298
452
|
*
|
|
@@ -468,5 +622,5 @@ declare class JobRegistry {
|
|
|
468
622
|
private createJobContext;
|
|
469
623
|
}
|
|
470
624
|
|
|
471
|
-
export { Booteable, Delay, Every, EverySeconds, IMessage, Job, JobRegistry, JobState, Message, NonceService, Scheduler, Service, Store, Use, arePortsClaimed, bootstrap, claimEarlyPorts, container, create, getNonceService, isBooteable, isDestroyable, isEarlyListenerSetup, setupEarlyListener };
|
|
472
|
-
export type { CriticalPayload, EverySecondsOptions, IJob, JobContext, NonceCheckResult };
|
|
625
|
+
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 };
|
|
626
|
+
export type { CriticalPayload, EveryOptions, EverySecondsOptions, IJob, JobContext, NonceCheckResult };
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { inject, injectable } from '@inversifyjs/core';
|
|
2
|
-
export { J as JobRegistry,
|
|
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-DrOND1Zi.js';
|
|
3
3
|
import '@inversifyjs/container';
|
|
4
4
|
|
|
5
5
|
function Service() {
|
|
@@ -46,10 +46,21 @@ function JobConfig(options = {}) {
|
|
|
46
46
|
|
|
47
47
|
const Delay = (ms) => JobConfig({ delay: ms });
|
|
48
48
|
|
|
49
|
-
function Every(cron) {
|
|
49
|
+
function Every(cron, options) {
|
|
50
50
|
return function(constructor) {
|
|
51
51
|
injectable()(constructor);
|
|
52
|
-
|
|
52
|
+
if (options?.name) {
|
|
53
|
+
Reflect.defineMetadata("name", options.name, constructor);
|
|
54
|
+
}
|
|
55
|
+
Reflect.defineMetadata(
|
|
56
|
+
"job:options",
|
|
57
|
+
{
|
|
58
|
+
cron,
|
|
59
|
+
requiresPopup: options?.requiresPopup ?? false,
|
|
60
|
+
startPaused: options?.startPaused ?? false
|
|
61
|
+
},
|
|
62
|
+
constructor
|
|
63
|
+
);
|
|
53
64
|
return constructor;
|
|
54
65
|
};
|
|
55
66
|
}
|
|
@@ -65,7 +76,8 @@ function EverySeconds(seconds, options) {
|
|
|
65
76
|
{
|
|
66
77
|
delay: seconds * 1e3,
|
|
67
78
|
recurring: true,
|
|
68
|
-
startPaused: options?.startPaused ?? false
|
|
79
|
+
startPaused: options?.startPaused ?? false,
|
|
80
|
+
requiresPopup: options?.requiresPopup ?? false
|
|
69
81
|
},
|
|
70
82
|
constructor
|
|
71
83
|
);
|
package/dist/index.es.js.map
CHANGED
|
@@ -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\nexport function Every(cron: string) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata('job:options'
|
|
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,EAAA,KAA0C,MAAA,CAAO,EAAE;AAChE,MAAM,QAAQ,MAAM,GAAA,CAAI,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,IAAA,UAAA,GAAa,WAAW,CAAA;AACxB,IAAA,OAAA,CAAQ,cAAA,CAAe,MAAA,EAAQ,IAAA,EAAM,WAAW,CAAA;AAChD,IAAA,OAAO,WAAA;AAAA,GACT;A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