@lyrolab/nest-shared 0.0.1

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.
Files changed (83) hide show
  1. package/.husky/commit-msg +1 -0
  2. package/.husky/pre-commit +1 -0
  3. package/.nvmrc +1 -0
  4. package/.prettierrc +5 -0
  5. package/README.md +98 -0
  6. package/dist/ai/ai.module.d.ts +2 -0
  7. package/dist/ai/ai.module.js +21 -0
  8. package/dist/ai/ai.module.js.map +1 -0
  9. package/dist/ai/services/ai.service.d.ts +10 -0
  10. package/dist/ai/services/ai.service.js +54 -0
  11. package/dist/ai/services/ai.service.js.map +1 -0
  12. package/dist/app.module.d.ts +2 -0
  13. package/dist/app.module.js +21 -0
  14. package/dist/app.module.js.map +1 -0
  15. package/dist/bull/shared-bull.module.d.ts +4 -0
  16. package/dist/bull/shared-bull.module.js +40 -0
  17. package/dist/bull/shared-bull.module.js.map +1 -0
  18. package/dist/cache/shared-cache.module.d.ts +4 -0
  19. package/dist/cache/shared-cache.module.js +40 -0
  20. package/dist/cache/shared-cache.module.js.map +1 -0
  21. package/dist/database/filters/typeorm-exception.filter.d.ts +7 -0
  22. package/dist/database/filters/typeorm-exception.filter.js +35 -0
  23. package/dist/database/filters/typeorm-exception.filter.js.map +1 -0
  24. package/dist/database/shared-database.module.d.ts +18 -0
  25. package/dist/database/shared-database.module.js +119 -0
  26. package/dist/database/shared-database.module.js.map +1 -0
  27. package/dist/index.d.ts +12 -0
  28. package/dist/index.js +29 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/queue/controllers/queue.controller.d.ts +7 -0
  31. package/dist/queue/controllers/queue.controller.js +40 -0
  32. package/dist/queue/controllers/queue.controller.js.map +1 -0
  33. package/dist/queue/decorators/queue.decorator.d.ts +1 -0
  34. package/dist/queue/decorators/queue.decorator.js +6 -0
  35. package/dist/queue/decorators/queue.decorator.js.map +1 -0
  36. package/dist/queue/models/dto/queue-add.dto.d.ts +4 -0
  37. package/dist/queue/models/dto/queue-add.dto.js +28 -0
  38. package/dist/queue/models/dto/queue-add.dto.js.map +1 -0
  39. package/dist/queue/models/job-processor-interface.d.ts +4 -0
  40. package/dist/queue/models/job-processor-interface.js +3 -0
  41. package/dist/queue/models/job-processor-interface.js.map +1 -0
  42. package/dist/queue/processors/queue.processor.d.ts +11 -0
  43. package/dist/queue/processors/queue.processor.js +63 -0
  44. package/dist/queue/processors/queue.processor.js.map +1 -0
  45. package/dist/queue/queue.constants.d.ts +1 -0
  46. package/dist/queue/queue.constants.js +5 -0
  47. package/dist/queue/queue.constants.js.map +1 -0
  48. package/dist/queue/queue.module.d.ts +2 -0
  49. package/dist/queue/queue.module.js +28 -0
  50. package/dist/queue/queue.module.js.map +1 -0
  51. package/dist/queue/services/queue.service.d.ts +6 -0
  52. package/dist/queue/services/queue.service.js +35 -0
  53. package/dist/queue/services/queue.service.js.map +1 -0
  54. package/dist/redis/redis.config.d.ts +4 -0
  55. package/dist/redis/redis.config.js +11 -0
  56. package/dist/redis/redis.config.js.map +1 -0
  57. package/dist/redis/shared-redis.module.d.ts +9 -0
  58. package/dist/redis/shared-redis.module.js +68 -0
  59. package/dist/redis/shared-redis.module.js.map +1 -0
  60. package/dist/tsconfig.build.tsbuildinfo +1 -0
  61. package/eslint.config.mjs +35 -0
  62. package/nest-cli.json +9 -0
  63. package/package.json +126 -0
  64. package/src/ai/ai.module.ts +8 -0
  65. package/src/ai/services/ai.service.ts +51 -0
  66. package/src/app.module.ts +8 -0
  67. package/src/bull/shared-bull.module.ts +27 -0
  68. package/src/cache/shared-cache.module.ts +30 -0
  69. package/src/database/filters/typeorm-exception.filter.ts +35 -0
  70. package/src/database/shared-database.module.ts +136 -0
  71. package/src/index.ts +12 -0
  72. package/src/queue/controllers/queue.controller.ts +13 -0
  73. package/src/queue/decorators/queue.decorator.ts +3 -0
  74. package/src/queue/models/dto/queue-add.dto.ts +10 -0
  75. package/src/queue/models/job-processor-interface.ts +5 -0
  76. package/src/queue/processors/queue.processor.ts +53 -0
  77. package/src/queue/queue.constants.ts +1 -0
  78. package/src/queue/queue.module.ts +14 -0
  79. package/src/queue/services/queue.service.ts +17 -0
  80. package/src/redis/redis.config.ts +3 -0
  81. package/src/redis/shared-redis.module.ts +66 -0
  82. package/tsconfig.build.json +4 -0
  83. package/tsconfig.json +25 -0
@@ -0,0 +1,40 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.QueueController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const queue_service_1 = require("../services/queue.service");
18
+ const queue_add_dto_1 = require("../models/dto/queue-add.dto");
19
+ let QueueController = class QueueController {
20
+ queueService;
21
+ constructor(queueService) {
22
+ this.queueService = queueService;
23
+ }
24
+ async add(body) {
25
+ return this.queueService.add(body.name, body.data);
26
+ }
27
+ };
28
+ exports.QueueController = QueueController;
29
+ __decorate([
30
+ (0, common_1.Post)("add"),
31
+ __param(0, (0, common_1.Body)()),
32
+ __metadata("design:type", Function),
33
+ __metadata("design:paramtypes", [queue_add_dto_1.QueueAddDto]),
34
+ __metadata("design:returntype", Promise)
35
+ ], QueueController.prototype, "add", null);
36
+ exports.QueueController = QueueController = __decorate([
37
+ (0, common_1.Controller)("queue"),
38
+ __metadata("design:paramtypes", [queue_service_1.QueueService])
39
+ ], QueueController);
40
+ //# sourceMappingURL=queue.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.controller.js","sourceRoot":"","sources":["../../../src/queue/controllers/queue.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAuD;AACvD,6DAAwD;AACxD,+DAAyD;AAGlD,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAGrD,AAAN,KAAK,CAAC,GAAG,CAAS,IAAiB;QACjC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;CACF,CAAA;AAPY,0CAAe;AAIpB;IADL,IAAA,aAAI,EAAC,KAAK,CAAC;IACD,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAO,2BAAW;;0CAElC;0BANU,eAAe;IAD3B,IAAA,mBAAU,EAAC,OAAO,CAAC;qCAEyB,4BAAY;GAD5C,eAAe,CAO3B"}
@@ -0,0 +1 @@
1
+ export declare const JobProcessor: import("@nestjs/core").DiscoverableDecorator<unknown>;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JobProcessor = void 0;
4
+ const core_1 = require("@nestjs/core");
5
+ exports.JobProcessor = core_1.DiscoveryService.createDecorator();
6
+ //# sourceMappingURL=queue.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.decorator.js","sourceRoot":"","sources":["../../../src/queue/decorators/queue.decorator.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAElC,QAAA,YAAY,GAAG,uBAAgB,CAAC,eAAe,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ export declare class QueueAddDto {
2
+ name: string;
3
+ data?: Record<string, any>;
4
+ }
@@ -0,0 +1,28 @@
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
+ exports.QueueAddDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ class QueueAddDto {
15
+ name;
16
+ data;
17
+ }
18
+ exports.QueueAddDto = QueueAddDto;
19
+ __decorate([
20
+ (0, class_validator_1.IsString)(),
21
+ __metadata("design:type", String)
22
+ ], QueueAddDto.prototype, "name", void 0);
23
+ __decorate([
24
+ (0, class_validator_1.IsObject)(),
25
+ (0, class_validator_1.IsOptional)(),
26
+ __metadata("design:type", Object)
27
+ ], QueueAddDto.prototype, "data", void 0);
28
+ //# sourceMappingURL=queue-add.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue-add.dto.js","sourceRoot":"","sources":["../../../../src/queue/models/dto/queue-add.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAgE;AAEhE,MAAa,WAAW;IAEtB,IAAI,CAAQ;IAIZ,IAAI,CAAsB;CAC3B;AAPD,kCAOC;AALC;IADC,IAAA,0BAAQ,GAAE;;yCACC;AAIZ;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;yCACa"}
@@ -0,0 +1,4 @@
1
+ import { Job } from "bullmq";
2
+ export type JobProcessorInterface = {
3
+ process: (job: Job) => Promise<void>;
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=job-processor-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-processor-interface.js","sourceRoot":"","sources":["../../../src/queue/models/job-processor-interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { WorkerHost } from "@nestjs/bullmq";
2
+ import { DiscoveryService } from "@nestjs/core";
3
+ import { Job, Queue } from "bullmq";
4
+ export declare class QueueProcessor extends WorkerHost {
5
+ private readonly discoveryService;
6
+ private readonly queue;
7
+ constructor(discoveryService: DiscoveryService, queue: Queue);
8
+ process(job: Job): Promise<void>;
9
+ private jobProcessorFor;
10
+ private shouldProcessJob;
11
+ }
@@ -0,0 +1,63 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.QueueProcessor = void 0;
16
+ const bullmq_1 = require("@nestjs/bullmq");
17
+ const core_1 = require("@nestjs/core");
18
+ const bullmq_2 = require("bullmq");
19
+ const queue_decorator_1 = require("../decorators/queue.decorator");
20
+ const queue_constants_1 = require("../queue.constants");
21
+ let QueueProcessor = class QueueProcessor extends bullmq_1.WorkerHost {
22
+ discoveryService;
23
+ queue;
24
+ constructor(discoveryService, queue) {
25
+ super();
26
+ this.discoveryService = discoveryService;
27
+ this.queue = queue;
28
+ }
29
+ async process(job) {
30
+ const jobProcessor = this.jobProcessorFor(job.name);
31
+ if (!jobProcessor)
32
+ return;
33
+ const shouldProcess = await this.shouldProcessJob(job);
34
+ if (!shouldProcess)
35
+ return;
36
+ try {
37
+ await jobProcessor.process(job);
38
+ }
39
+ catch (error) {
40
+ console.error(error);
41
+ }
42
+ }
43
+ jobProcessorFor(jobName) {
44
+ return this.discoveryService
45
+ .getProviders({ metadataKey: queue_decorator_1.JobProcessor.KEY })
46
+ .find((provider) => this.discoveryService.getMetadataByDecorator(queue_decorator_1.JobProcessor, provider) === jobName)?.instance;
47
+ }
48
+ async shouldProcessJob(job) {
49
+ if (!job.repeatJobKey)
50
+ return true;
51
+ const activeJobs = await this.queue.getActive();
52
+ const activeJobsOfSameCronjob = activeJobs.filter(({ name, id }) => name === job.name && id !== job.id);
53
+ return activeJobsOfSameCronjob.length === 0;
54
+ }
55
+ };
56
+ exports.QueueProcessor = QueueProcessor;
57
+ exports.QueueProcessor = QueueProcessor = __decorate([
58
+ (0, bullmq_1.Processor)(queue_constants_1.DEFAULT_QUEUE, { concurrency: 100 }),
59
+ __param(1, (0, bullmq_1.InjectQueue)(queue_constants_1.DEFAULT_QUEUE)),
60
+ __metadata("design:paramtypes", [core_1.DiscoveryService,
61
+ bullmq_2.Queue])
62
+ ], QueueProcessor);
63
+ //# sourceMappingURL=queue.processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.processor.js","sourceRoot":"","sources":["../../../src/queue/processors/queue.processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,uCAA+C;AAC/C,mCAAmC;AACnC,mEAA4D;AAE5D,wDAAkD;AAG3C,I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,IAAI,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,CACrD,CAAA;QAED,OAAO,uBAAuB,CAAC,MAAM,KAAK,CAAC,CAAA;IAC7C,CAAC;CACF,CAAA;AA5CY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,kBAAS,EAAC,+BAAa,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC;IAI1C,WAAA,IAAA,oBAAW,EAAC,+BAAa,CAAC,CAAA;qCADQ,uBAAgB;QACC,cAAK;GAHhD,cAAc,CA4C1B"}
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_QUEUE = "default";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_QUEUE = void 0;
4
+ exports.DEFAULT_QUEUE = "default";
5
+ //# sourceMappingURL=queue.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.constants.js","sourceRoot":"","sources":["../../src/queue/queue.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare class QueueModule {
2
+ }
@@ -0,0 +1,28 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.QueueModule = void 0;
10
+ const bullmq_1 = require("@nestjs/bullmq");
11
+ const common_1 = require("@nestjs/common");
12
+ const core_1 = require("@nestjs/core");
13
+ const queue_processor_1 = require("./processors/queue.processor");
14
+ const queue_constants_1 = require("./queue.constants");
15
+ const queue_service_1 = require("./services/queue.service");
16
+ const queue_controller_1 = require("./controllers/queue.controller");
17
+ let QueueModule = class QueueModule {
18
+ };
19
+ exports.QueueModule = QueueModule;
20
+ exports.QueueModule = QueueModule = __decorate([
21
+ (0, common_1.Module)({
22
+ imports: [bullmq_1.BullModule.registerQueue({ name: queue_constants_1.DEFAULT_QUEUE }), core_1.DiscoveryModule],
23
+ providers: [queue_service_1.QueueService, queue_processor_1.QueueProcessor],
24
+ exports: [queue_service_1.QueueService],
25
+ controllers: [queue_controller_1.QueueController],
26
+ })
27
+ ], QueueModule);
28
+ //# sourceMappingURL=queue.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.module.js","sourceRoot":"","sources":["../../src/queue/queue.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2C;AAC3C,2CAAuC;AACvC,uCAA8C;AAC9C,kEAA6D;AAC7D,uDAAiD;AACjD,4DAAuD;AACvD,qEAAgE;AAOzD,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IANvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,mBAAU,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,+BAAa,EAAE,CAAC,EAAE,sBAAe,CAAC;QAC7E,SAAS,EAAE,CAAC,4BAAY,EAAE,gCAAc,CAAC;QACzC,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,WAAW,EAAE,CAAC,kCAAe,CAAC;KAC/B,CAAC;GACW,WAAW,CAAG"}
@@ -0,0 +1,6 @@
1
+ import { Job, JobsOptions, Queue } from "bullmq";
2
+ export declare class QueueService {
3
+ private readonly queue;
4
+ constructor(queue: Queue);
5
+ add(name: string, data: any, opts?: JobsOptions): Promise<Job<any, any, string>>;
6
+ }
@@ -0,0 +1,35 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.QueueService = void 0;
16
+ const bullmq_1 = require("@nestjs/bullmq");
17
+ const common_1 = require("@nestjs/common");
18
+ const bullmq_2 = require("bullmq");
19
+ const queue_constants_1 = require("../queue.constants");
20
+ let QueueService = class QueueService {
21
+ queue;
22
+ constructor(queue) {
23
+ this.queue = queue;
24
+ }
25
+ add(name, data, opts) {
26
+ return this.queue.add(name, data, opts);
27
+ }
28
+ };
29
+ exports.QueueService = QueueService;
30
+ exports.QueueService = QueueService = __decorate([
31
+ (0, common_1.Injectable)(),
32
+ __param(0, (0, bullmq_1.InjectQueue)(queue_constants_1.DEFAULT_QUEUE)),
33
+ __metadata("design:paramtypes", [bullmq_2.Queue])
34
+ ], QueueService);
35
+ //# sourceMappingURL=queue.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.service.js","sourceRoot":"","sources":["../../../src/queue/services/queue.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA2C;AAC3C,mCAAgD;AAChD,wDAAkD;AAG3C,IAAM,YAAY,GAAlB,MAAM,YAAY;IACkC;IAAzD,YAAyD,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;IAAG,CAAC;IAEzE,GAAG,CACD,IAAY,EACZ,IAAS,EACT,IAAkB;QAElB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACzC,CAAC;CACF,CAAA;AAVY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,oBAAW,EAAC,+BAAa,CAAC,CAAA;qCAAyB,cAAK;GAD1D,YAAY,CAUxB"}
@@ -0,0 +1,4 @@
1
+ export declare class RedisConfig {
2
+ readonly url: string;
3
+ constructor(url: string);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisConfig = void 0;
4
+ class RedisConfig {
5
+ url;
6
+ constructor(url) {
7
+ this.url = url;
8
+ }
9
+ }
10
+ exports.RedisConfig = RedisConfig;
11
+ //# sourceMappingURL=redis.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis.config.js","sourceRoot":"","sources":["../../src/redis/redis.config.ts"],"names":[],"mappings":";;;AAAA,MAAa,WAAW;IACM;IAA5B,YAA4B,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;CAC5C;AAFD,kCAEC"}
@@ -0,0 +1,9 @@
1
+ import { DynamicModule, OnModuleDestroy } from "@nestjs/common";
2
+ export declare class SharedRedisModule implements OnModuleDestroy {
3
+ private static testContainer;
4
+ static forRoot(): DynamicModule;
5
+ private static createTestConfiguration;
6
+ private static createProductionConfiguration;
7
+ static closeTestConnection(): Promise<void>;
8
+ onModuleDestroy(): Promise<void>;
9
+ }
@@ -0,0 +1,68 @@
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 SharedRedisModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SharedRedisModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const config_1 = require("@nestjs/config");
13
+ const testcontainers_1 = require("testcontainers");
14
+ const redis_config_1 = require("./redis.config");
15
+ let SharedRedisModule = class SharedRedisModule {
16
+ static { SharedRedisModule_1 = this; }
17
+ static testContainer = null;
18
+ static forRoot() {
19
+ return {
20
+ module: SharedRedisModule_1,
21
+ providers: [
22
+ {
23
+ provide: redis_config_1.RedisConfig,
24
+ useFactory: async (configService) => {
25
+ const isTestEnvironment = process.env.NODE_ENV === "test";
26
+ if (isTestEnvironment) {
27
+ return new redis_config_1.RedisConfig(await this.createTestConfiguration());
28
+ }
29
+ return new redis_config_1.RedisConfig(this.createProductionConfiguration(configService));
30
+ },
31
+ inject: [config_1.ConfigService],
32
+ },
33
+ ],
34
+ exports: [redis_config_1.RedisConfig],
35
+ imports: [config_1.ConfigModule],
36
+ global: true,
37
+ };
38
+ }
39
+ static async createTestConfiguration() {
40
+ if (!this.testContainer) {
41
+ this.testContainer = await new testcontainers_1.GenericContainer("redis")
42
+ .withExposedPorts(6379)
43
+ .withWaitStrategy(testcontainers_1.Wait.forAll([
44
+ testcontainers_1.Wait.forListeningPorts(),
45
+ testcontainers_1.Wait.forLogMessage("Ready to accept connections tcp"),
46
+ ]))
47
+ .start();
48
+ }
49
+ return `redis://${this.testContainer.getHost()}:${this.testContainer.getMappedPort(6379)}`;
50
+ }
51
+ static createProductionConfiguration(configService) {
52
+ return configService.get("REDIS_URL");
53
+ }
54
+ static async closeTestConnection() {
55
+ if (this.testContainer) {
56
+ await this.testContainer.stop();
57
+ this.testContainer = null;
58
+ }
59
+ }
60
+ async onModuleDestroy() {
61
+ await SharedRedisModule_1.closeTestConnection();
62
+ }
63
+ };
64
+ exports.SharedRedisModule = SharedRedisModule;
65
+ exports.SharedRedisModule = SharedRedisModule = SharedRedisModule_1 = __decorate([
66
+ (0, common_1.Module)({})
67
+ ], SharedRedisModule);
68
+ //# sourceMappingURL=shared-redis.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-redis.module.js","sourceRoot":"","sources":["../../src/redis/shared-redis.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuE;AACvE,2CAA4D;AAC5D,mDAA6E;AAC7E,iDAA4C;AAGrC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;;IACpB,MAAM,CAAC,aAAa,GAAgC,IAAI,CAAA;IAEhE,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,MAAM,EAAE,mBAAiB;YACzB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,0BAAW;oBACpB,UAAU,EAAE,KAAK,EAAE,aAA4B,EAAE,EAAE;wBACjD,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAA;wBAEzD,IAAI,iBAAiB,EAAE,CAAC;4BACtB,OAAO,IAAI,0BAAW,CAAC,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC,CAAA;wBAC9D,CAAC;wBAED,OAAO,IAAI,0BAAW,CACpB,IAAI,CAAC,6BAA6B,CAAC,aAAa,CAAC,CAClD,CAAA;oBACH,CAAC;oBACD,MAAM,EAAE,CAAC,sBAAa,CAAC;iBACxB;aACF;YACD,OAAO,EAAE,CAAC,0BAAW,CAAC;YACtB,OAAO,EAAE,CAAC,qBAAY,CAAC;YACvB,MAAM,EAAE,IAAI;SACb,CAAA;IACH,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,uBAAuB;QAC1C,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,IAAI,CAAC,aAAa,GAAG,MAAM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