@nest-boot/schedule 7.0.2 → 7.1.0

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.
File without changes
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ describe("public API", () => {
36
+ it("should export schedule module APIs", async () => {
37
+ const api = await Promise.resolve().then(() => __importStar(require(".")));
38
+ expect(api.ScheduleModule).toBeDefined();
39
+ expect(api.ScheduleRegistry).toBeDefined();
40
+ expect(api.Schedule).toBeDefined();
41
+ expect(api.Cron).toBeDefined();
42
+ expect(api.Interval).toBeDefined();
43
+ });
44
+ });
45
+ //# sourceMappingURL=index.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,GAAG,GAAG,wDAAa,GAAG,GAAC,CAAC;QAE9B,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,WAAW,EAAE,CAAC;QACzC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,5 +1,17 @@
1
1
  import { type RegisterQueueOptions } from "@nest-boot/bullmq";
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
+ */
2
10
  export interface ScheduleModuleOptions extends RegisterQueueOptions {
11
+ /** Whether to automatically start processing scheduled jobs on module init. */
3
12
  autorun?: boolean;
13
+ /** Maximum number of concurrent scheduled jobs to process. */
4
14
  concurrency?: number;
15
+ /** Optional Redis connection options for the schedule queue. */
16
+ connection?: ConnectionOptions;
5
17
  }
@@ -1,6 +1,10 @@
1
1
  import { JobSchedulerTemplateOptions } from "bullmq";
2
+ /** Options for configuring a scheduled job. */
2
3
  export interface ScheduleOptions extends JobSchedulerTemplateOptions {
4
+ /** Type of schedule: `"cron"` for cron expressions or `"interval"` for millisecond intervals. */
3
5
  type: "cron" | "interval";
6
+ /** Cron expression (for `"cron"` type) or millisecond interval (for `"interval"` type). */
4
7
  value: number | string;
8
+ /** Timezone for cron expressions (defaults to `"UTC"`). */
5
9
  timezone?: string;
6
10
  }
@@ -1,4 +1,21 @@
1
1
  import { type ScheduleOptions } from "./schedule-options.interface";
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
+ */
2
7
  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
+ */
3
14
  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
+ */
4
21
  export declare const Interval: (value: number | string, options?: Omit<ScheduleOptions, "type" | "value">) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
@@ -3,16 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Interval = exports.Cron = exports.Schedule = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const schedule_module_definition_1 = require("./schedule.module-definition");
6
+ /**
7
+ * Decorator that registers a method as a scheduled job.
8
+ * @param options - Schedule configuration (type, value, timezone, etc.)
9
+ * @returns Method decorator
10
+ */
6
11
  const Schedule = (options) => (target, propertyKey, descriptor) => {
7
12
  (0, common_1.SetMetadata)(schedule_module_definition_1.SCHEDULE_METADATA_KEY, options)(target, propertyKey, descriptor);
8
13
  };
9
14
  exports.Schedule = Schedule;
15
+ /**
16
+ * Decorator that registers a method as a cron-scheduled job.
17
+ * @param value - Cron expression (e.g. `"0 * * * *"`)
18
+ * @param options - Additional schedule options (timezone, etc.)
19
+ * @returns Method decorator
20
+ */
10
21
  const Cron = (value, options) => (0, exports.Schedule)({
11
22
  type: "cron",
12
23
  value,
13
24
  ...(options ?? {}),
14
25
  });
15
26
  exports.Cron = Cron;
27
+ /**
28
+ * Decorator that registers a method as an interval-scheduled job.
29
+ * @param value - Interval in milliseconds
30
+ * @param options - Additional schedule options
31
+ * @returns Method decorator
32
+ */
16
33
  const Interval = (value, options) => (0, exports.Schedule)({
17
34
  type: "interval",
18
35
  value,
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.decorator.js","sourceRoot":"","sources":["../src/schedule.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6EAAqE;AAG9D,MAAM,QAAQ,GACnB,CAAC,OAAwB,EAAE,EAAE,CAC7B,CACE,MAAc,EACd,WAAmB,EACnB,UAAsC,EACtC,EAAE;IACF,IAAA,oBAAW,EAA0B,kDAAqB,EAAE,OAAO,CAAC,CAClE,MAAM,EACN,WAAW,EACX,UAAU,CACX,CAAC;AACJ,CAAC,CAAC;AAZS,QAAA,QAAQ,YAYjB;AAEG,MAAM,IAAI,GAAG,CAClB,KAAa,EACb,OAAiD,EACjD,EAAE,CACF,IAAA,gBAAQ,EAAC;IACP,IAAI,EAAE,MAAM;IACZ,KAAK;IACL,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;CACnB,CAAC,CAAC;AARQ,QAAA,IAAI,QAQZ;AAEE,MAAM,QAAQ,GAAG,CACtB,KAAsB,EACtB,OAAiD,EACjD,EAAE,CACF,IAAA,gBAAQ,EAAC;IACP,IAAI,EAAE,UAAU;IAChB,KAAK;IACL,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;CACnB,CAAC,CAAC;AARQ,QAAA,QAAQ,YAQhB"}
1
+ {"version":3,"file":"schedule.decorator.js","sourceRoot":"","sources":["../src/schedule.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6EAAqE;AAGrE;;;;GAIG;AACI,MAAM,QAAQ,GACnB,CAAC,OAAwB,EAAE,EAAE,CAC7B,CACE,MAAc,EACd,WAAmB,EACnB,UAAsC,EACtC,EAAE;IACF,IAAA,oBAAW,EAA0B,kDAAqB,EAAE,OAAO,CAAC,CAClE,MAAM,EACN,WAAW,EACX,UAAU,CACX,CAAC;AACJ,CAAC,CAAC;AAZS,QAAA,QAAQ,YAYjB;AAEJ;;;;;GAKG;AACI,MAAM,IAAI,GAAG,CAClB,KAAa,EACb,OAAiD,EACjD,EAAE,CACF,IAAA,gBAAQ,EAAC;IACP,IAAI,EAAE,MAAM;IACZ,KAAK;IACL,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;CACnB,CAAC,CAAC;AARQ,QAAA,IAAI,QAQZ;AAEL;;;;;GAKG;AACI,MAAM,QAAQ,GAAG,CACtB,KAAsB,EACtB,OAAiD,EACjD,EAAE,CACF,IAAA,gBAAQ,EAAC;IACP,IAAI,EAAE,UAAU;IAChB,KAAK;IACL,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;CACnB,CAAC,CAAC;AARQ,QAAA,QAAQ,YAQhB"}
@@ -0,0 +1 @@
1
+ import "reflect-metadata";
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ require("reflect-metadata");
13
+ const schedule_decorator_1 = require("./schedule.decorator");
14
+ const schedule_module_definition_1 = require("./schedule.module-definition");
15
+ function getMethod(prototype, name) {
16
+ return Object.getOwnPropertyDescriptor(prototype, name)?.value;
17
+ }
18
+ describe("schedule decorators", () => {
19
+ class ExampleSchedules {
20
+ explicit() {
21
+ return undefined;
22
+ }
23
+ cron() {
24
+ return undefined;
25
+ }
26
+ interval() {
27
+ return undefined;
28
+ }
29
+ }
30
+ __decorate([
31
+ (0, schedule_decorator_1.Schedule)({
32
+ type: "cron",
33
+ value: "0 1 * * *",
34
+ timezone: "Asia/Shanghai",
35
+ }),
36
+ __metadata("design:type", Function),
37
+ __metadata("design:paramtypes", []),
38
+ __metadata("design:returntype", void 0)
39
+ ], ExampleSchedules.prototype, "explicit", null);
40
+ __decorate([
41
+ (0, schedule_decorator_1.Cron)("* * * * *", {
42
+ attempts: 2,
43
+ timezone: "UTC",
44
+ }),
45
+ __metadata("design:type", Function),
46
+ __metadata("design:paramtypes", []),
47
+ __metadata("design:returntype", void 0)
48
+ ], ExampleSchedules.prototype, "cron", null);
49
+ __decorate([
50
+ (0, schedule_decorator_1.Interval)("5000", {
51
+ removeOnComplete: true,
52
+ }),
53
+ __metadata("design:type", Function),
54
+ __metadata("design:paramtypes", []),
55
+ __metadata("design:returntype", void 0)
56
+ ], ExampleSchedules.prototype, "interval", null);
57
+ it("should attach explicit schedule metadata", () => {
58
+ expect(Reflect.getMetadata(schedule_module_definition_1.SCHEDULE_METADATA_KEY, getMethod(ExampleSchedules.prototype, "explicit"))).toEqual({
59
+ type: "cron",
60
+ value: "0 1 * * *",
61
+ timezone: "Asia/Shanghai",
62
+ });
63
+ });
64
+ it("should build cron and interval metadata with optional job options", () => {
65
+ expect(Reflect.getMetadata(schedule_module_definition_1.SCHEDULE_METADATA_KEY, getMethod(ExampleSchedules.prototype, "cron"))).toEqual({
66
+ attempts: 2,
67
+ timezone: "UTC",
68
+ type: "cron",
69
+ value: "* * * * *",
70
+ });
71
+ expect(Reflect.getMetadata(schedule_module_definition_1.SCHEDULE_METADATA_KEY, getMethod(ExampleSchedules.prototype, "interval"))).toEqual({
72
+ removeOnComplete: true,
73
+ type: "interval",
74
+ value: "5000",
75
+ });
76
+ });
77
+ it("should default omitted decorator options to an empty object", () => {
78
+ class Defaults {
79
+ cron() {
80
+ return undefined;
81
+ }
82
+ interval() {
83
+ return undefined;
84
+ }
85
+ }
86
+ __decorate([
87
+ (0, schedule_decorator_1.Cron)("0 * * * *"),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", []),
90
+ __metadata("design:returntype", void 0)
91
+ ], Defaults.prototype, "cron", null);
92
+ __decorate([
93
+ (0, schedule_decorator_1.Interval)(1000),
94
+ __metadata("design:type", Function),
95
+ __metadata("design:paramtypes", []),
96
+ __metadata("design:returntype", void 0)
97
+ ], Defaults.prototype, "interval", null);
98
+ expect(Reflect.getMetadata(schedule_module_definition_1.SCHEDULE_METADATA_KEY, getMethod(Defaults.prototype, "cron"))).toEqual({
99
+ type: "cron",
100
+ value: "0 * * * *",
101
+ });
102
+ expect(Reflect.getMetadata(schedule_module_definition_1.SCHEDULE_METADATA_KEY, getMethod(Defaults.prototype, "interval"))).toEqual({
103
+ type: "interval",
104
+ value: 1000,
105
+ });
106
+ });
107
+ });
108
+ //# sourceMappingURL=schedule.decorator.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.decorator.spec.js","sourceRoot":"","sources":["../src/schedule.decorator.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAA0B;AAE1B,6DAAgE;AAChE,6EAAqE;AAErE,SAAS,SAAS,CAAC,SAAiB,EAAE,IAAY;IAChD,OAAO,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC;AACjE,CAAC;AAED,QAAQ,CAAC,qBAAqB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F,CAAC,OAAO,CAAC;YACR,gBAAgB,EAAE,IAAI;YACtB,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,QAAQ;YAEZ,IAAI;gBACF,OAAO,SAAS,CAAC;YACnB,CAAC;YAGD,QAAQ;gBACN,OAAO,SAAS,CAAC;YACnB,CAAC;SACF;QARC;YADC,IAAA,yBAAI,EAAC,WAAW,CAAC;;;;4CAGjB;QAGD;YADC,IAAA,6BAAQ,EAAC,IAAI,CAAC;;;;gDAGd;QAGH,MAAM,CACJ,OAAO,CAAC,WAAW,CACjB,kDAAqB,EACrB,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,CACtC,CACF,CAAC,OAAO,CAAC;YACR,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,WAAW;SACnB,CAAC,CAAC;QACH,MAAM,CACJ,OAAO,CAAC,WAAW,CACjB,kDAAqB,EACrB,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAC1C,CACF,CAAC,OAAO,CAAC;YACR,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -2,4 +2,4 @@ import { type ScheduleModuleOptions } from "./schedule-module-options.interface"
2
2
  export declare const SCHEDULE_QUEUE_NAME = "schedule";
3
3
  export declare const SCHEDULE_METADATA_KEY: `${string}-${string}-${string}-${string}-${string}`;
4
4
  export declare const MODULE_OPTIONS_TOKEN: unique symbol;
5
- export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ScheduleModuleOptions, "forRoot", "create", {}>, BASE_MODULE_OPTIONS_TOKEN: string | symbol;
5
+ export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ScheduleModuleOptions, "forRoot", "create", {}>, BASE_MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: ScheduleModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<ScheduleModuleOptions, "create"> & Partial<{}>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BASE_MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.MODULE_OPTIONS_TOKEN = exports.SCHEDULE_METADATA_KEY = exports.SCHEDULE_QUEUE_NAME = void 0;
4
+ exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.BASE_MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.MODULE_OPTIONS_TOKEN = exports.SCHEDULE_METADATA_KEY = exports.SCHEDULE_QUEUE_NAME = void 0;
5
5
  const common_1 = require("@nestjs/common");
6
6
  const crypto_1 = require("crypto");
7
7
  exports.SCHEDULE_QUEUE_NAME = "schedule";
@@ -9,5 +9,5 @@ exports.SCHEDULE_METADATA_KEY = (0, crypto_1.randomUUID)();
9
9
  exports.MODULE_OPTIONS_TOKEN = Symbol("ScheduleModuleOptions");
10
10
  _a = new common_1.ConfigurableModuleBuilder()
11
11
  .setClassMethodName("forRoot")
12
- .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.BASE_MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
12
+ .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.BASE_MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
13
13
  //# sourceMappingURL=schedule.module-definition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.module-definition.js","sourceRoot":"","sources":["../src/schedule.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAC3D,mCAAoC;AAIvB,QAAA,mBAAmB,GAAG,UAAU,CAAC;AAEjC,QAAA,qBAAqB,GAAG,IAAA,mBAAU,GAAE,CAAC;AAErC,QAAA,oBAAoB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAEvD,KAGT,IAAI,kCAAyB,EAAyB;KACvD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EAJR,+BAAuB,+BACD,iCAAyB,2BAGtC"}
1
+ {"version":3,"file":"schedule.module-definition.js","sourceRoot":"","sources":["../src/schedule.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAC3D,mCAAoC;AAIvB,QAAA,mBAAmB,GAAG,UAAU,CAAC;AAEjC,QAAA,qBAAqB,GAAG,IAAA,mBAAU,GAAE,CAAC;AAErC,QAAA,oBAAoB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAEvD,KAKT,IAAI,kCAAyB,EAAyB;KACvD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EANR,+BAAuB,+BACD,iCAAyB,4BAC/C,oBAAY,oBACZ,0BAAkB,yBAGT"}
@@ -1,3 +1,23 @@
1
- import { ConfigurableModuleClass } from "./schedule.module-definition";
1
+ import { type DynamicModule } from "@nestjs/common";
2
+ import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./schedule.module-definition";
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
+ */
2
10
  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
+ 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
+ static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
3
23
  }
@@ -13,7 +13,30 @@ const core_1 = require("@nestjs/core");
13
13
  const schedule_module_definition_1 = require("./schedule.module-definition");
14
14
  const schedule_processor_1 = require("./schedule.processor");
15
15
  const schedule_registry_1 = require("./schedule.registry");
16
+ /**
17
+ * Job scheduling module powered by BullMQ.
18
+ *
19
+ * @remarks
20
+ * Provides cron-like job scheduling using BullMQ queues.
21
+ * Supports decorator-based schedule registration and configurable concurrency.
22
+ */
16
23
  let ScheduleModule = class ScheduleModule extends schedule_module_definition_1.ConfigurableModuleClass {
24
+ /**
25
+ * Registers the ScheduleModule with the given options.
26
+ * @param options - Configuration options including connection and concurrency
27
+ * @returns Dynamic module configuration
28
+ */
29
+ static forRoot(options) {
30
+ return super.forRoot(options);
31
+ }
32
+ /**
33
+ * Registers the ScheduleModule asynchronously with factory functions.
34
+ * @param options - Async configuration options
35
+ * @returns Dynamic module configuration
36
+ */
37
+ static forRootAsync(options) {
38
+ return super.forRootAsync(options);
39
+ }
17
40
  };
18
41
  exports.ScheduleModule = ScheduleModule;
19
42
  exports.ScheduleModule = ScheduleModule = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.module.js","sourceRoot":"","sources":["../src/schedule.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA+C;AAC/C,2CAAwD;AACxD,uCAA+C;AAE/C,6EAIsC;AACtC,6DAAyD;AACzD,2DAAuD;AAyBhD,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,oDAAuB;CAAG,CAAA;AAAjD,wCAAc;yBAAd,cAAc;IAtB1B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,sBAAe;YACf,mBAAU,CAAC,kBAAkB,CAAC;gBAC5B,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,CAAC,iDAAoB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B;YACjB;gBACE,OAAO,EAAE,iDAAoB;gBAC7B,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,sDAAyB,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,iDAAoB,CAAC;KAChC,CAAC;GACW,cAAc,CAoB1B"}
@@ -1 +1 @@
1
- import "dotenv/config";
1
+ export {};
@@ -1,39 +1,91 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- require("dotenv/config");
4
- const bullmq_1 = require("@nest-boot/bullmq");
5
- const testing_1 = require("@nestjs/testing");
6
- const _1 = require(".");
7
- describe("BullModule", () => {
8
- let app;
9
- it(`ScheduleModule`, async () => {
10
- const moduleRef = await testing_1.Test.createTestingModule({
11
- imports: [bullmq_1.BullModule, _1.ScheduleModule],
12
- }).compile();
13
- app = moduleRef.createNestApplication();
14
- await app.init();
15
- await app.close();
3
+ const common_1 = require("@nestjs/common");
4
+ const constants_1 = require("@nestjs/common/constants");
5
+ const core_1 = require("@nestjs/core");
6
+ let mockRegisterQueueAsyncOptions;
7
+ const mockQueueModule = {
8
+ module: class QueueModule {
9
+ },
10
+ };
11
+ const mockRegisterQueueAsync = jest.fn((options) => {
12
+ mockRegisterQueueAsyncOptions = options;
13
+ return mockQueueModule;
14
+ });
15
+ const mockProcessorDecorator = jest.fn();
16
+ const mockProcessor = jest.fn(() => mockProcessorDecorator);
17
+ jest.mock("@nest-boot/bullmq", () => ({
18
+ BullModule: {
19
+ registerQueueAsync: mockRegisterQueueAsync,
20
+ },
21
+ InjectQueue: jest.fn(() => jest.fn()),
22
+ Processor: mockProcessor,
23
+ WorkerHost: class WorkerHost {
24
+ constructor() {
25
+ this.worker = {
26
+ concurrency: 1,
27
+ run: jest.fn().mockResolvedValue(undefined),
28
+ };
29
+ }
30
+ },
31
+ }));
32
+ const schedule_module_1 = require("./schedule.module");
33
+ const schedule_module_definition_1 = require("./schedule.module-definition");
34
+ const schedule_processor_1 = require("./schedule.processor");
35
+ const schedule_registry_1 = require("./schedule.registry");
36
+ describe("ScheduleModule", () => {
37
+ beforeEach(() => {
38
+ jest.clearAllMocks();
39
+ });
40
+ it("should expose configurable root registrations", () => {
41
+ const options = {
42
+ concurrency: 3,
43
+ };
44
+ const useFactory = () => options;
45
+ const dynamicModule = schedule_module_1.ScheduleModule.forRoot(options);
46
+ const asyncModule = schedule_module_1.ScheduleModule.forRootAsync({
47
+ useFactory,
48
+ });
49
+ expect(dynamicModule.module).toBe(schedule_module_1.ScheduleModule);
50
+ expect(dynamicModule.providers).toEqual(expect.arrayContaining([
51
+ {
52
+ provide: schedule_module_definition_1.BASE_MODULE_OPTIONS_TOKEN,
53
+ useValue: options,
54
+ },
55
+ ]));
56
+ expect(asyncModule.providers).toEqual(expect.arrayContaining([
57
+ {
58
+ inject: [],
59
+ provide: schedule_module_definition_1.BASE_MODULE_OPTIONS_TOKEN,
60
+ useFactory,
61
+ },
62
+ ]));
16
63
  });
17
- it(`ScheduleModule.forRoot`, async () => {
18
- const moduleRef = await testing_1.Test.createTestingModule({
19
- imports: [bullmq_1.BullModule, _1.ScheduleModule.forRoot({})],
20
- }).compile();
21
- app = moduleRef.createNestApplication();
22
- await app.init();
23
- await app.close();
64
+ it("should provide options, queue registration, and schedule services", () => {
65
+ const imports = Reflect.getMetadata(constants_1.MODULE_METADATA.IMPORTS, schedule_module_1.ScheduleModule);
66
+ const providers = Reflect.getMetadata(constants_1.MODULE_METADATA.PROVIDERS, schedule_module_1.ScheduleModule);
67
+ const exports = Reflect.getMetadata(constants_1.MODULE_METADATA.EXPORTS, schedule_module_1.ScheduleModule);
68
+ const optionsProvider = providers.find((provider) => provider.provide === schedule_module_definition_1.MODULE_OPTIONS_TOKEN);
69
+ expect(imports).toEqual([core_1.DiscoveryModule, mockQueueModule]);
70
+ expect(providers).toEqual(expect.arrayContaining([common_1.Logger, schedule_registry_1.ScheduleRegistry, schedule_processor_1.ScheduleProcessor]));
71
+ expect(exports).toEqual([schedule_module_definition_1.MODULE_OPTIONS_TOKEN]);
72
+ expect(optionsProvider.useFactory(undefined)).toEqual({});
73
+ expect(optionsProvider.useFactory({
74
+ autorun: false,
75
+ })).toEqual({
76
+ autorun: false,
77
+ });
24
78
  });
25
- it(`ScheduleModule.forRootAsync`, async () => {
26
- const moduleRef = await testing_1.Test.createTestingModule({
27
- imports: [
28
- bullmq_1.BullModule,
29
- _1.ScheduleModule.forRootAsync({
30
- useFactory: () => ({}),
31
- }),
32
- ],
33
- }).compile();
34
- app = moduleRef.createNestApplication();
35
- await app.init();
36
- await app.close();
79
+ it("should register the schedule queue from module options", () => {
80
+ expect(mockRegisterQueueAsyncOptions).toEqual(expect.objectContaining({
81
+ inject: [schedule_module_definition_1.MODULE_OPTIONS_TOKEN],
82
+ name: "schedule",
83
+ }));
84
+ expect(mockRegisterQueueAsyncOptions.useFactory({
85
+ concurrency: 2,
86
+ })).toEqual({
87
+ concurrency: 2,
88
+ });
37
89
  });
38
90
  });
39
91
  //# sourceMappingURL=schedule.module.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.module.spec.js","sourceRoot":"","sources":["../src/schedule.module.spec.ts"],"names":[],"mappings":";;AAAA,yBAAuB;AAEvB,8CAA+C;AAE/C,6CAAuC;AAEvC,wBAAmC;AAEnC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,IAAI,GAAqB,CAAC;IAE1B,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;QAC9B,MAAM,SAAS,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC/C,OAAO,EAAE,CAAC,mBAAU,EAAE,iBAAc,CAAC;SACtC,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,GAAG,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC,IAAI,EAAE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