@nest-boot/schedule 8.0.0-beta.0 → 8.0.0-beta.2

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,17 +1,7 @@
1
1
  import { type RegisterQueueOptions } from "@nest-boot/bullmq";
2
2
  import { type ConnectionOptions } from "bullmq";
3
- /**
4
- * Configuration options for the schedule module.
5
- *
6
- * @remarks
7
- * Extends BullMQ queue options with schedule-specific settings
8
- * for controlling job processing behavior.
9
- */
10
3
  export interface ScheduleModuleOptions extends RegisterQueueOptions {
11
- /** Whether to automatically start processing scheduled jobs on module init. */
12
4
  autorun?: boolean;
13
- /** Maximum number of concurrent scheduled jobs to process. */
14
5
  concurrency?: number;
15
- /** Optional Redis connection options for the schedule queue. */
16
6
  connection?: ConnectionOptions;
17
7
  }
@@ -1,10 +1,6 @@
1
1
  import { JobSchedulerTemplateOptions } from "bullmq";
2
- /** Options for configuring a scheduled job. */
3
2
  export interface ScheduleOptions extends JobSchedulerTemplateOptions {
4
- /** Type of schedule: `"cron"` for cron expressions or `"interval"` for millisecond intervals. */
5
3
  type: "cron" | "interval";
6
- /** Cron expression (for `"cron"` type) or millisecond interval (for `"interval"` type). */
7
4
  value: number | string;
8
- /** Timezone for cron expressions (defaults to `"UTC"`). */
9
5
  timezone?: string;
10
6
  }
@@ -1,21 +1,4 @@
1
1
  import { type ScheduleOptions } from "./schedule-options.interface.js";
2
- /**
3
- * Decorator that registers a method as a scheduled job.
4
- * @param options - Schedule configuration (type, value, timezone, etc.)
5
- * @returns Method decorator
6
- */
7
2
  export declare const Schedule: (options: ScheduleOptions) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
8
- /**
9
- * Decorator that registers a method as a cron-scheduled job.
10
- * @param value - Cron expression (e.g. `"0 * * * *"`)
11
- * @param options - Additional schedule options (timezone, etc.)
12
- * @returns Method decorator
13
- */
14
3
  export declare const Cron: (value: string, options?: Omit<ScheduleOptions, "type" | "value">) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
15
- /**
16
- * Decorator that registers a method as an interval-scheduled job.
17
- * @param value - Interval in milliseconds
18
- * @param options - Additional schedule options
19
- * @returns Method decorator
20
- */
21
4
  export declare const Interval: (value: number | string, options?: Omit<ScheduleOptions, "type" | "value">) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
@@ -1,30 +1,13 @@
1
1
  import { SetMetadata } from "@nestjs/common";
2
2
  import { SCHEDULE_METADATA_KEY } from "./schedule.module-definition.js";
3
- /**
4
- * Decorator that registers a method as a scheduled job.
5
- * @param options - Schedule configuration (type, value, timezone, etc.)
6
- * @returns Method decorator
7
- */
8
3
  export const Schedule = (options) => (target, propertyKey, descriptor) => {
9
4
  SetMetadata(SCHEDULE_METADATA_KEY, options)(target, propertyKey, descriptor);
10
5
  };
11
- /**
12
- * Decorator that registers a method as a cron-scheduled job.
13
- * @param value - Cron expression (e.g. `"0 * * * *"`)
14
- * @param options - Additional schedule options (timezone, etc.)
15
- * @returns Method decorator
16
- */
17
6
  export const Cron = (value, options) => Schedule({
18
7
  type: "cron",
19
8
  value,
20
9
  ...(options ?? {}),
21
10
  });
22
- /**
23
- * Decorator that registers a method as an interval-scheduled job.
24
- * @param value - Interval in milliseconds
25
- * @param options - Additional schedule options
26
- * @returns Method decorator
27
- */
28
11
  export const Interval = (value, options) => Schedule({
29
12
  type: "interval",
30
13
  value,
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.decorator.js","sourceRoot":"","sources":["../src/schedule.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAGxE;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GACnB,CAAC,OAAwB,EAAE,EAAE,CAC7B,CACE,MAAc,EACd,WAAmB,EACnB,UAAsC,EACtC,EAAE;IAC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IACL,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;CACnB,CAAC,CAAC"}
@@ -1,23 +1,6 @@
1
1
  import { type DynamicModule } from "@nestjs/common";
2
2
  import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./schedule.module-definition.js";
3
- /**
4
- * Job scheduling module powered by BullMQ.
5
- *
6
- * @remarks
7
- * Provides cron-like job scheduling using BullMQ queues.
8
- * Supports decorator-based schedule registration and configurable concurrency.
9
- */
10
3
  export declare class ScheduleModule extends ConfigurableModuleClass {
11
- /**
12
- * Registers the ScheduleModule with the given options.
13
- * @param options - Configuration options including connection and concurrency
14
- * @returns Dynamic module configuration
15
- */
16
4
  static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
17
- /**
18
- * Registers the ScheduleModule asynchronously with factory functions.
19
- * @param options - Async configuration options
20
- * @returns Dynamic module configuration
21
- */
22
5
  static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
23
6
  }
@@ -10,27 +10,10 @@ import { DiscoveryModule } from "@nestjs/core";
10
10
  import { BASE_MODULE_OPTIONS_TOKEN, ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, } from "./schedule.module-definition.js";
11
11
  import { ScheduleProcessor } from "./schedule.processor.js";
12
12
  import { ScheduleRegistry } from "./schedule.registry.js";
13
- /**
14
- * Job scheduling module powered by BullMQ.
15
- *
16
- * @remarks
17
- * Provides cron-like job scheduling using BullMQ queues.
18
- * Supports decorator-based schedule registration and configurable concurrency.
19
- */
20
13
  let ScheduleModule = class ScheduleModule extends ConfigurableModuleClass {
21
- /**
22
- * Registers the ScheduleModule with the given options.
23
- * @param options - Configuration options including connection and concurrency
24
- * @returns Dynamic module configuration
25
- */
26
14
  static forRoot(options) {
27
15
  return super.forRoot(options);
28
16
  }
29
- /**
30
- * Registers the ScheduleModule asynchronously with factory functions.
31
- * @param options - Async configuration options
32
- * @returns Dynamic module configuration
33
- */
34
17
  static forRootAsync(options) {
35
18
  return super.forRootAsync(options);
36
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.module.js","sourceRoot":"","sources":["../src/schedule.module.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAsB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAEL,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,GAErB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D;;;;;;GAMG;AAuBI,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,uBAAuB;IACzD;;;;OAIG;IACH,MAAM,CAAU,OAAO,CAAC,OAA4B;QAClD,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAU,YAAY,CAC1B,OAAkC;QAElC,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AApBY,cAAc;IAtB1B,MAAM,EAAE;IACR,MAAM,CAAC;QACN,OAAO,EAAE;YACP,eAAe;YACf,UAAU,CAAC,kBAAkB,CAAC;gBAC5B,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,CAAC,oBAAoB,CAAC;gBAC9B,UAAU,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,OAAO;aACxD,CAAC;SACH;QACD,SAAS,EAAE;YACT,MAAM;YACN,gBAAgB;YAChB,iBAAiB;YACjB;gBACE,OAAO,EAAE,oBAAoB;gBAC7B,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,yBAAyB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gBA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AAE,KAAK,EAAE,yBAAyB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gBAC9D,UAAU,EAAE,CAAC,OAA+B,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE;aAC/D;SACF;QACD,OAAO,EAAE,CAAC,oBAAoB,CAAC;KAChC,CAAC;GACW,cAAc,CAoB1B"}
@@ -6,6 +6,7 @@ import { type ScheduleModuleOptions } from "./schedule-module-options.interface.
6
6
  export declare class ScheduleProcessor extends WorkerHost implements OnApplicationBootstrap {
7
7
  private readonly scheduleRegistry;
8
8
  private readonly options?;
9
+ private readonly logger;
9
10
  constructor(scheduleRegistry: ScheduleRegistry, options?: ScheduleModuleOptions | undefined);
10
11
  process(job: Job): Promise<void>;
11
12
  onApplicationBootstrap(): void;
@@ -10,13 +10,15 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  var __param = (this && this.__param) || function (paramIndex, decorator) {
11
11
  return function (target, key) { decorator(target, key, paramIndex); }
12
12
  };
13
+ var ScheduleProcessor_1;
13
14
  import { Processor, WorkerHost } from "@nest-boot/bullmq";
14
- import { Inject, Optional } from "@nestjs/common";
15
+ import { Inject, Logger, Optional, } from "@nestjs/common";
15
16
  import { MODULE_OPTIONS_TOKEN } from "./schedule.module-definition.js";
16
17
  import { ScheduleRegistry } from "./schedule.registry.js";
17
- let ScheduleProcessor = class ScheduleProcessor extends WorkerHost {
18
+ let ScheduleProcessor = ScheduleProcessor_1 = class ScheduleProcessor extends WorkerHost {
18
19
  scheduleRegistry;
19
20
  options;
21
+ logger = new Logger(ScheduleProcessor_1.name);
20
22
  constructor(scheduleRegistry, options) {
21
23
  super();
22
24
  this.scheduleRegistry = scheduleRegistry;
@@ -30,13 +32,14 @@ let ScheduleProcessor = class ScheduleProcessor extends WorkerHost {
30
32
  this.worker.concurrency = this.options.concurrency;
31
33
  }
32
34
  if (this.options?.autorun !== false) {
33
- this.worker.run().catch(() => {
34
- //
35
+ void this.worker.run().catch((error) => {
36
+ const message = error instanceof Error ? error.message : String(error);
37
+ this.logger.error(`Schedule worker stopped unexpectedly: ${message}`, error instanceof Error ? error.stack : undefined);
35
38
  });
36
39
  }
37
40
  }
38
41
  };
39
- ScheduleProcessor = __decorate([
42
+ ScheduleProcessor = ScheduleProcessor_1 = __decorate([
40
43
  Processor("schedule", { autorun: false }),
41
44
  __param(1, Optional()),
42
45
  __param(1, Inject(MODULE_OPTIONS_TOKEN)),
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.processor.js","sourceRoot":"","sources":["../src/schedule.processor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAA0B,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAInD,IAAM,iBAAiB,GAAvB,MAAM,iBACX,SAAQ,UAAU;IAIC;IAGA;IAJnB,YACmB,gBAAkC,EAGlC,OAA+B;QAEhD,KAAK,EAAE,CAAC;QALS,qBAAgB,GAAhB,gBAAgB,CAAkB;QAGlC,YAAO,GAAP,OAAO,CAAwB;IAGlD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAQ;QACpB,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACvD,CAAC;IAED,sBAAsB;QACpB,IAAI,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;QACrD,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,KAAK,KAAK,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,C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AAE,OAAO,KAAK,KAAK,EAAE,CAAC;YACpC,KAAK,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAC9C,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAEvE,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,yCAAyC,OAAO,EAAE,EAClD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CACjD,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAA;AApCY,iBAAiB;IAD7B,SAAS,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAUrC,WAAA,QAAQ,EAAE,CAAA;IACV,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;qCAFM,gBAAgB;GAR1C,iBAAiB,CAoC7B"}
@@ -2,49 +2,20 @@ import { OnApplicationBootstrap } from "@nestjs/common";
2
2
  import { DiscoveryService, MetadataScanner, Reflector } from "@nestjs/core";
3
3
  import { Queue } from "bullmq";
4
4
  import { type ScheduleOptions } from "./schedule-options.interface.js";
5
- /**
6
- * Registry that discovers and manages scheduled jobs at application startup.
7
- *
8
- * @remarks
9
- * Scans all controllers and providers for methods decorated with
10
- * {@link Schedule}, {@link Cron}, or {@link Interval}, then registers
11
- * them as BullMQ job schedulers. Removes stale schedulers that are no
12
- * longer defined in the codebase.
13
- */
14
5
  export declare class ScheduleRegistry implements OnApplicationBootstrap {
15
6
  private readonly queue;
16
7
  private readonly reflector;
17
8
  private readonly discoveryService;
18
9
  private readonly metadataScanner;
19
- /** Logger instance for the schedule registry. @internal */
20
10
  private readonly logger;
21
- /** Map of schedule names to their handlers and options. @internal */
22
11
  private readonly schedules;
23
- /**
24
- * Creates a new ScheduleRegistry instance.
25
- * @param queue - BullMQ queue for managing scheduled jobs
26
- * @param reflector - NestJS reflector for reading decorator metadata
27
- * @param discoveryService - NestJS discovery service for scanning providers
28
- * @param metadataScanner - Scanner for extracting method metadata
29
- */
30
12
  constructor(queue: Queue, reflector: Reflector, discoveryService: DiscoveryService, metadataScanner: MetadataScanner);
31
- /**
32
- * Retrieves a registered schedule entry by name.
33
- * @param name - The schedule identifier (className.methodName)
34
- * @returns The schedule handler and options, or undefined
35
- */
36
13
  get(name: string): {
37
- /** Handler function bound to the original instance. */
38
14
  handler: () => Promise<void>;
39
- /** Schedule options from the decorator. */
40
15
  options: ScheduleOptions;
41
16
  } | undefined;
42
- /** Scans controllers and providers for schedule-decorated methods. @internal */
43
17
  private discoverySchedules;
44
- /** Removes job schedulers that are no longer defined. @internal */
45
18
  private cleanUnregisteredSchedules;
46
- /** Registers all discovered schedules as BullMQ job schedulers. @internal */
47
19
  private registerSchedules;
48
- /** Discovers all scheduled methods and registers them as BullMQ job schedulers. */
49
20
  onApplicationBootstrap(): Promise<void>;
50
21
  }
@@ -16,46 +16,22 @@ import { Logger } from "@nestjs/common";
16
16
  import { DiscoveryService, MetadataScanner, Reflector } from "@nestjs/core";
17
17
  import { Queue } from "bullmq";
18
18
  import { SCHEDULE_METADATA_KEY, SCHEDULE_QUEUE_NAME, } from "./schedule.module-definition.js";
19
- /**
20
- * Registry that discovers and manages scheduled jobs at application startup.
21
- *
22
- * @remarks
23
- * Scans all controllers and providers for methods decorated with
24
- * {@link Schedule}, {@link Cron}, or {@link Interval}, then registers
25
- * them as BullMQ job schedulers. Removes stale schedulers that are no
26
- * longer defined in the codebase.
27
- */
28
19
  let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
29
20
  queue;
30
21
  reflector;
31
22
  discoveryService;
32
23
  metadataScanner;
33
- /** Logger instance for the schedule registry. @internal */
34
24
  logger = new Logger(ScheduleRegistry_1.name);
35
- /** Map of schedule names to their handlers and options. @internal */
36
25
  schedules = new Map();
37
- /**
38
- * Creates a new ScheduleRegistry instance.
39
- * @param queue - BullMQ queue for managing scheduled jobs
40
- * @param reflector - NestJS reflector for reading decorator metadata
41
- * @param discoveryService - NestJS discovery service for scanning providers
42
- * @param metadataScanner - Scanner for extracting method metadata
43
- */
44
26
  constructor(queue, reflector, discoveryService, metadataScanner) {
45
27
  this.queue = queue;
46
28
  this.reflector = reflector;
47
29
  this.discoveryService = discoveryService;
48
30
  this.metadataScanner = metadataScanner;
49
31
  }
50
- /**
51
- * Retrieves a registered schedule entry by name.
52
- * @param name - The schedule identifier (className.methodName)
53
- * @returns The schedule handler and options, or undefined
54
- */
55
32
  get(name) {
56
33
  return this.schedules.get(name);
57
34
  }
58
- /** Scans controllers and providers for schedule-decorated methods. @internal */
59
35
  discoverySchedules() {
60
36
  [
61
37
  ...this.discoveryService.getControllers(),
@@ -80,7 +56,6 @@ let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
80
56
  }
81
57
  });
82
58
  }
83
- /** Removes job schedulers that are no longer defined. @internal */
84
59
  async cleanUnregisteredSchedules() {
85
60
  const jobSchedulers = await this.queue.getJobSchedulers();
86
61
  for (const jobScheduler of jobSchedulers) {
@@ -90,7 +65,6 @@ let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
90
65
  }
91
66
  }
92
67
  }
93
- /** Registers all discovered schedules as BullMQ job schedulers. @internal */
94
68
  async registerSchedules() {
95
69
  for (const [name, { options: { type, value, timezone, ...jobOptions }, },] of this.schedules.entries()) {
96
70
  await this.queue.upsertJobScheduler(name, {
@@ -109,7 +83,6 @@ let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
109
83
  this.logger.log(`Registered {${name}, ${type}, ${String(value)}}`);
110
84
  }
111
85
  }
112
- /** Discovers all scheduled methods and registers them as BullMQ job schedulers. */
113
86
  async onApplicationBootstrap() {
114
87
  this.discoverySchedules();
115
88
  await this.cleanUnregisteredSchedules();
@@ -1 +1 @@
1
- {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I,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAClD,EACF,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,KAAK,CAAC,kBAAkB,CACjC,IAAI,EACJ;gBACE,EAAE,EAAE,QAAQ,IAAI,KAAK;gBACrB,GAAG,CAAC,IAAI,KAAK,MAAM;oBACjB,CAAC,CAAC;wBACE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE;qBAC1B;oBACH,CAAC,CAAC;wBACE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;qBACrB,CAAC;aACP,EACD;gBACE,IAAI;gBACJ,IAAI,EAAE,UAAU;aACjB,CACF,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,IAAI,KAAK,IAAI,KAAK,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAGD,KAAK,CAAC,sBAAsB;QAC1B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC1B,MAAM,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACxC,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;IACjC,CAAC;CACF,CAAA;AA1HY,gBAAgB;IAuBxB,WAAA,WAAW,CAAC,mBAAmB,CAAC,CAAA;qCACT,KAAK;QACD,SAAS;QACF,gBAAgB;QACjB,eAAe;GA3BxC,gBAAgB,CA0H5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-boot/schedule",
3
- "version": "8.0.0-beta.0",
3
+ "version": "8.0.0-beta.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nest-boot/nest-boot.git",
@@ -14,8 +14,8 @@
14
14
  },
15
15
  "homepage": "",
16
16
  "license": "MIT",
17
- "main": "dist/index.js",
18
- "types": "dist/index.d.ts",
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
19
  "directories": {
20
20
  "lib": "dist"
21
21
  },
@@ -24,33 +24,34 @@
24
24
  "templates"
25
25
  ],
26
26
  "devDependencies": {
27
- "@nestjs/bullmq": "^11.0.4",
28
- "@nestjs/common": "next",
29
- "@nestjs/core": "next",
30
- "@nestjs/testing": "next",
27
+ "@nestjs/bullmq": "^12.0.0",
28
+ "@nestjs/common": "^12.0.1",
29
+ "@nestjs/core": "^12.0.1",
30
+ "@nestjs/testing": "^12.0.1",
31
31
  "@types/ms": "^0.7.31",
32
32
  "@types/node": "^26.0.0",
33
- "@vitest/coverage-v8": "^4.1.2",
33
+ "@vitest/coverage-v8": "^4.1.11",
34
34
  "bullmq": "^5.61.0",
35
35
  "dotenv": "^17.2.3",
36
36
  "eslint": "^9.39.3",
37
37
  "reflect-metadata": "^0.2.2",
38
38
  "rxjs": "^7.8.2",
39
39
  "typescript": "^6.0.3",
40
- "vitest": "^4.1.2",
41
- "@nest-boot/bullmq": "^8.0.0-beta.0",
42
- "@nest-boot/eslint-config": "^8.0.0-beta.0",
43
- "@nest-boot/eslint-plugin": "^8.0.0-beta.0",
44
- "@nest-boot/tsconfig": "^8.0.0-beta.0"
40
+ "vite-tsconfig-paths": "^5.1.4",
41
+ "vitest": "^4.1.11",
42
+ "@nest-boot/bullmq": "^8.0.0-beta.2",
43
+ "@nest-boot/eslint-config": "^8.0.0-beta.2",
44
+ "@nest-boot/eslint-plugin": "^8.0.0-beta.2",
45
+ "@nest-boot/tsconfig": "^8.0.0-beta.2"
45
46
  },
46
47
  "peerDependencies": {
47
- "@nestjs/bullmq": "^11.0.0",
48
- "@nestjs/common": "^12.0.0-alpha.5",
49
- "@nestjs/core": "^12.0.0-alpha.5",
48
+ "@nestjs/bullmq": "^12.0.0",
49
+ "@nestjs/common": "^12.0.0",
50
+ "@nestjs/core": "^12.0.0",
50
51
  "bullmq": "^5.0.0",
51
52
  "reflect-metadata": "^0.2.2",
52
53
  "rxjs": "^7.0.0",
53
- "@nest-boot/bullmq": "^8.0.0-beta.0"
54
+ "@nest-boot/bullmq": "^8.0.0-beta.2"
54
55
  },
55
56
  "publishConfig": {
56
57
  "access": "public"
@@ -62,6 +63,16 @@
62
63
  ]
63
64
  },
64
65
  "type": "module",
66
+ "engines": {
67
+ "node": ">=26.0.0"
68
+ },
69
+ "exports": {
70
+ ".": {
71
+ "types": "./dist/index.d.ts",
72
+ "import": "./dist/index.js"
73
+ },
74
+ "./package.json": "./package.json"
75
+ },
65
76
  "scripts": {
66
77
  "build": "tsc -p tsconfig.build.json",
67
78
  "clean": "rm -rf .nx && rm -rf node_modules && rm -rf dist",