@mondart/nestjs-common-module 2.3.5 → 2.4.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.
- package/dist/decorators/swagger-api-response.decorator.d.ts +1 -0
- package/dist/decorators/swagger-api-response.decorator.js +5 -0
- package/dist/dto/response/index.d.ts +1 -0
- package/dist/dto/response/index.js +1 -0
- package/dist/dto/response/paginate-metadata-response.dto.d.ts +12 -0
- package/dist/dto/response/paginate-metadata-response.dto.js +43 -0
- package/dist/dto/response/success-response.dto.d.ts +5 -5
- package/dist/lib/bottleneck/bottleneck.module.d.ts +8 -0
- package/dist/lib/bottleneck/bottleneck.module.js +109 -0
- package/dist/lib/bottleneck/constants/bottleneck.const.d.ts +3 -0
- package/dist/lib/bottleneck/constants/bottleneck.const.js +6 -0
- package/dist/lib/bottleneck/cqrs-wrapper/queued-command-bus.d.ts +8 -0
- package/dist/lib/bottleneck/cqrs-wrapper/queued-command-bus.js +31 -0
- package/dist/lib/bottleneck/cqrs-wrapper/queued-query-bus.d.ts +8 -0
- package/dist/lib/bottleneck/cqrs-wrapper/queued-query-bus.js +31 -0
- package/dist/lib/bottleneck/decorators/config-bottleneck.decorator.d.ts +2 -0
- package/dist/lib/bottleneck/decorators/config-bottleneck.decorator.js +7 -0
- package/dist/lib/bottleneck/decorators/skip-bottleneck.decorator.d.ts +1 -0
- package/dist/lib/bottleneck/decorators/skip-bottleneck.decorator.js +7 -0
- package/dist/lib/bottleneck/decorators/use-bottleneck.decorator.d.ts +1 -0
- package/dist/lib/bottleneck/decorators/use-bottleneck.decorator.js +7 -0
- package/dist/lib/bottleneck/index.d.ts +10 -0
- package/dist/lib/bottleneck/index.js +26 -0
- package/dist/lib/bottleneck/interceptors/bottleneck.interceptor.d.ts +12 -0
- package/dist/lib/bottleneck/interceptors/bottleneck.interceptor.js +82 -0
- package/dist/lib/bottleneck/interfaces/bottleneck-options.interface.d.ts +39 -0
- package/dist/lib/bottleneck/interfaces/bottleneck-options.interface.js +4 -0
- package/dist/lib/bottleneck/services/bottleneck.service.d.ts +14 -0
- package/dist/lib/bottleneck/services/bottleneck.service.js +93 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/validators/is-date-range.validator.d.ts +1 -1
- package/dist/validators/is-date-range.validator.js +19 -12
- package/package.json +3 -1
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
var BottleneckService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.BottleneckService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const bottleneck_1 = require("bottleneck");
|
|
19
|
+
const bottleneck_options_interface_1 = require("../interfaces/bottleneck-options.interface");
|
|
20
|
+
const ioredis_1 = require("ioredis");
|
|
21
|
+
let BottleneckService = BottleneckService_1 = class BottleneckService {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.logger = new common_1.Logger(BottleneckService_1.name, {
|
|
25
|
+
timestamp: true,
|
|
26
|
+
});
|
|
27
|
+
this.cache = new Map();
|
|
28
|
+
const { useRedis, redis, appName, ...rest } = this.options;
|
|
29
|
+
const redisOptions = useRedis && redis
|
|
30
|
+
? {
|
|
31
|
+
datastore: 'ioredis',
|
|
32
|
+
Redis: ioredis_1.default,
|
|
33
|
+
clientOptions: {
|
|
34
|
+
host: redis.host,
|
|
35
|
+
port: redis.port,
|
|
36
|
+
username: redis.username,
|
|
37
|
+
password: redis.password,
|
|
38
|
+
db: redis.database,
|
|
39
|
+
tls: redis.tls ? {} : undefined,
|
|
40
|
+
},
|
|
41
|
+
timeout: redis.ttl,
|
|
42
|
+
}
|
|
43
|
+
: undefined;
|
|
44
|
+
this.group = new bottleneck_1.default.Group({
|
|
45
|
+
id: `bottleneck-${appName ?? 'app'}`,
|
|
46
|
+
maxConcurrent: 1,
|
|
47
|
+
minTime: 0,
|
|
48
|
+
clearDatastore: true,
|
|
49
|
+
...redisOptions,
|
|
50
|
+
...rest,
|
|
51
|
+
});
|
|
52
|
+
this.group.on('idle', (key) => {
|
|
53
|
+
setTimeout(() => this.group.deleteKey(key).catch(() => { }), 30_000);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
getLimiter(key, opts) {
|
|
57
|
+
const limiter = this.group.key(key);
|
|
58
|
+
if (opts)
|
|
59
|
+
limiter.updateSettings(opts);
|
|
60
|
+
return limiter;
|
|
61
|
+
}
|
|
62
|
+
scheduleForKey(key, task, opts) {
|
|
63
|
+
const limiter = this.getLimiter(key, opts);
|
|
64
|
+
this.logger.debug(`Scheduling task for key ${key}`);
|
|
65
|
+
return limiter.schedule(task);
|
|
66
|
+
}
|
|
67
|
+
async runQueuedTask(key, fn) {
|
|
68
|
+
if (this.cache.has(key)) {
|
|
69
|
+
this.logger.debug(`Cache hit for key ${key}`);
|
|
70
|
+
return this.cache.get(key);
|
|
71
|
+
}
|
|
72
|
+
const limiter = this.getLimiter(key);
|
|
73
|
+
const taskPromise = limiter.schedule(async () => {
|
|
74
|
+
try {
|
|
75
|
+
return await fn();
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
this.cache.delete(key);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.cache.set(key, taskPromise);
|
|
82
|
+
return taskPromise;
|
|
83
|
+
}
|
|
84
|
+
async onModuleDestroy() {
|
|
85
|
+
await this.group.disconnect();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
exports.BottleneckService = BottleneckService;
|
|
89
|
+
exports.BottleneckService = BottleneckService = BottleneckService_1 = __decorate([
|
|
90
|
+
(0, common_1.Injectable)(),
|
|
91
|
+
__param(0, (0, common_1.Inject)(bottleneck_options_interface_1.BOTTLENECK_MODULE_OPTIONS)),
|
|
92
|
+
__metadata("design:paramtypes", [Object])
|
|
93
|
+
], BottleneckService);
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.js
CHANGED