@chromahq/core 1.0.48 → 1.0.50

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.
@@ -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', { cron }, constructor);\n return constructor;\n };\n}\n","import { injectable } from '@inversifyjs/core';\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 *\n * @example\n * ```typescript\n * @EverySeconds(5)\n * export class MyJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs every 5 seconds');\n * }\n * }\n * ```\n */\nexport function EverySeconds(seconds: number) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata(\n 'job:options',\n {\n delay: seconds * 1000,\n recurring: true,\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,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,IAAAD,eAAA,GAAa,WAAW,CAAA;AACxB,IAAA,OAAA,CAAQ,cAAA,CAAe,MAAA,EAAQ,IAAA,EAAM,WAAW,CAAA;AAChD,I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AA,CAAQ,cAAA;AAAA,MACN,aAAA;AAAA,MACA;AAAA,QACE,OAAO,OAAA,GAAU,GAAA;AAAA,QACjB,SAAA,EAAW;AAAA,OACb;AAAA,MACA;AAAA,KACF;AACA,IAAA,OAAO,WAAA;AAAA,GACT;AACF;;AChCO,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'));\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', { cron }, constructor);\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\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, etc.)\n *\n * @example\n * ```typescript\n * // Auto-starting job (default)\n * @EverySeconds(5)\n * export class MyJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs every 5 seconds');\n * }\n * }\n *\n * // Paused job that must be manually resumed\n * @EverySeconds(2, { startPaused: true })\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 Reflect.defineMetadata(\n 'job:options',\n {\n delay: seconds * 1000,\n recurring: true,\n startPaused: options?.startPaused ?? 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,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,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,SA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{
15
15
  cron?: string;
16
16
  persistent?: boolean;
17
17
  recurring?: boolean;
18
+ startPaused?: boolean;
18
19
  }
19
20
 
20
21
  interface IJob<T = unknown> {
@@ -81,24 +82,41 @@ declare const Delay: (ms: number) => (constructor: any) => any;
81
82
 
82
83
  declare function Every(cron: string): (constructor: any) => any;
83
84
 
85
+ /**
86
+ * Options for the EverySeconds decorator.
87
+ */
88
+ interface EverySecondsOptions {
89
+ /** If true, job starts paused and must be resumed manually via Scheduler.resume() */
90
+ startPaused?: boolean;
91
+ }
84
92
  /**
85
93
  * Decorator for jobs that run at a specific interval in seconds.
86
94
  * Unlike cron expressions which have minute-level granularity,
87
95
  * this decorator allows for second-level precision.
88
96
  *
89
97
  * @param seconds - The interval in seconds between job executions
98
+ * @param options - Optional configuration (startPaused, etc.)
90
99
  *
91
100
  * @example
92
101
  * ```typescript
102
+ * // Auto-starting job (default)
93
103
  * @EverySeconds(5)
94
104
  * export class MyJob implements IJob {
95
105
  * async handle(context: JobContext) {
96
106
  * console.log('Runs every 5 seconds');
97
107
  * }
98
108
  * }
109
+ *
110
+ * // Paused job that must be manually resumed
111
+ * @EverySeconds(2, { startPaused: true })
112
+ * export class OnDemandJob implements IJob {
113
+ * async handle(context: JobContext) {
114
+ * console.log('Runs when resumed');
115
+ * }
116
+ * }
99
117
  * ```
100
118
  */
101
- declare function EverySeconds(seconds: number): (constructor: any) => any;
119
+ declare function EverySeconds(seconds: number, options?: EverySecondsOptions): (constructor: any) => any;
102
120
 
103
121
  declare abstract class Booteable {
104
122
  /**
@@ -362,5 +380,91 @@ declare class BootstrapBuilder {
362
380
  }): Promise<void>;
363
381
  }
364
382
 
365
- export { Booteable, Delay, Every, EverySeconds, IMessage, Job, JobState, Message, NonceService, Service, Store, Use, arePortsClaimed, bootstrap, claimEarlyPorts, container, create, getNonceService, isBooteable, isDestroyable, isEarlyListenerSetup, setupEarlyListener };
366
- export type { CriticalPayload, IJob, JobContext, NonceCheckResult };
383
+ /**
384
+ * Shared logger interface for consistent logging across the application
385
+ */
386
+ interface Logger {
387
+ info(message: string, context?: Record<string, any>): void;
388
+ success(message: string): void;
389
+ warn(message: string): void;
390
+ error(message: string, error?: Error): void;
391
+ debug(message: string, context?: Record<string, any>): void;
392
+ divider?(): void;
393
+ }
394
+
395
+ declare class Scheduler {
396
+ private readonly registry;
397
+ private readonly alarm;
398
+ private readonly timeout;
399
+ private readonly logger;
400
+ constructor(logger?: Logger);
401
+ schedule(id: string, options: JobOptions): void;
402
+ pause(id: string): void;
403
+ resume(id: string): void;
404
+ stop(id: string): void;
405
+ private execute;
406
+ private getScheduleTime;
407
+ getJobState(id: string): JobState | undefined;
408
+ listJobs(): Array<{
409
+ id: string;
410
+ state: JobState;
411
+ options: JobOptions;
412
+ }>;
413
+ /**
414
+ * Gracefully shutdown the scheduler, clearing all timers
415
+ */
416
+ shutdown(): void;
417
+ /**
418
+ * Get scheduler stats for monitoring
419
+ */
420
+ getStats(): {
421
+ jobs: number;
422
+ timeouts: number;
423
+ alarms: number;
424
+ };
425
+ }
426
+
427
+ declare class JobRegistry {
428
+ private static _instance;
429
+ private jobs;
430
+ static get instance(): JobRegistry;
431
+ /**
432
+ * Remove a job from the registry (for cleanup after permanent stop)
433
+ */
434
+ remove(id: string): boolean;
435
+ /**
436
+ * Get the number of registered jobs
437
+ */
438
+ size(): number;
439
+ /**
440
+ * Clear all jobs (useful for testing or shutdown)
441
+ */
442
+ clear(): void;
443
+ register(id: string, job: IJob, options: JobOptions): void;
444
+ resolve(id: string): IJob | undefined;
445
+ meta(id: string): JobOptions | undefined;
446
+ getContext(id: string): JobContext | undefined;
447
+ updateState(id: string, state: JobState): void;
448
+ setTimeoutId(id: string, timeoutId: NodeJS.Timeout): void;
449
+ setIntervalId(id: string, intervalId: NodeJS.Timeout): void;
450
+ clearTimers(id: string): void;
451
+ pause(id: string): void;
452
+ resume(id: string): void;
453
+ stop(id: string): void;
454
+ listAll(): Array<{
455
+ id: string;
456
+ state: JobState;
457
+ options: JobOptions;
458
+ }>;
459
+ /**
460
+ * Find job IDs that match a class name pattern (case-insensitive).
461
+ *
462
+ * @param classNamePattern - Partial or full class name to search for
463
+ * @returns Array of matching job IDs
464
+ */
465
+ findByClassName(classNamePattern: string): string[];
466
+ private createJobContext;
467
+ }
468
+
469
+ 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 };
470
+ export type { CriticalPayload, 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 JobState, N as NonceService, a as arePortsClaimed, e as bootstrap, c as claimEarlyPorts, b as container, d as create, g as getNonceService, i as isEarlyListenerSetup, s as setupEarlyListener } from './boot-uR3rw2A8.js';
2
+ export { J as JobRegistry, f as JobState, N as NonceService, S as Scheduler, a as arePortsClaimed, e as bootstrap, c as claimEarlyPorts, b as container, d as create, g as getNonceService, i as isEarlyListenerSetup, s as setupEarlyListener } from './boot-CskDM5Yw.js';
3
3
  import '@inversifyjs/container';
4
4
 
5
5
  function Service() {
@@ -54,14 +54,15 @@ function Every(cron) {
54
54
  };
55
55
  }
56
56
 
57
- function EverySeconds(seconds) {
57
+ function EverySeconds(seconds, options) {
58
58
  return function(constructor) {
59
59
  injectable()(constructor);
60
60
  Reflect.defineMetadata(
61
61
  "job:options",
62
62
  {
63
63
  delay: seconds * 1e3,
64
- recurring: true
64
+ recurring: true,
65
+ startPaused: options?.startPaused ?? false
65
66
  },
66
67
  constructor
67
68
  );
@@ -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', { cron }, constructor);\n return constructor;\n };\n}\n","import { injectable } from '@inversifyjs/core';\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 *\n * @example\n * ```typescript\n * @EverySeconds(5)\n * export class MyJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs every 5 seconds');\n * }\n * }\n * ```\n */\nexport function EverySeconds(seconds: number) {\n return function (constructor: any) {\n injectable()(constructor);\n Reflect.defineMetadata(\n 'job:options',\n {\n delay: seconds * 1000,\n recurring: true,\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;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,MA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,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.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', { cron }, constructor);\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\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, etc.)\n *\n * @example\n * ```typescript\n * // Auto-starting job (default)\n * @EverySeconds(5)\n * export class MyJob implements IJob {\n * async handle(context: JobContext) {\n * console.log('Runs every 5 seconds');\n * }\n * }\n *\n * // Paused job that must be manually resumed\n * @EverySeconds(2, { startPaused: true })\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 Reflect.defineMetadata(\n 'job:options',\n {\n delay: seconds * 1000,\n recurring: true,\n startPaused: options?.startPaused ?? 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,CA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OAAO,SAAU,WAAA,EAAkB;AACjC,IAAA,UAAA,GAAa,WAAW,CAAA;AACxB,IAAA,OAAA,CAAQ,cAAA,CAAe,aAAA,EAAe,EAAE,IAAA,IAAQ,WAAW,CAAA;AAC3D,IAAA,OAAO,WAAA;AAAA,GACT;AACF;;AC6BO,SAAS,YAAA,CAAa,SAAiB,OAAA,EAA+B;AAC3E,EAAA,OAAO,SAAU,WAAA,EAAkB;AACjC,IAAA,UAAA,GAAa,WAAW,CAAA;AACxB,IAAA,OAAA,CAAQ,cAAA;AAAA,MACN,aAAA;AAAA,MACA;AAAA,QACE,OAAO,OAAA,GAAU,GAAA;AAAA,QACjB,SAAA,EAAW,IAAA;AAAA,QACX,WAAA,EAAa,SAAS,WAAA,IAAe;AAAA,OACvC;AAAA,MACA;AAAA,KACF;AACA,IAAA,OAAO,WAAA;AAAA,GACT;AACF;;ACnDO,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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromahq/core",
3
- "version": "1.0.48",
3
+ "version": "1.0.50",
4
4
  "description": "Core library for building Chrome extensions with Chroma framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",