@nestjs/throttler 1.1.3 → 2.0.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.
- package/README.md +6 -1
- package/dist/index.js +46 -23
- package/dist/throttler-module-options.interface.js +3 -3
- package/dist/throttler-storage.interface.js +3 -3
- package/dist/throttler.constants.js +8 -4
- package/dist/throttler.decorator.js +29 -25
- package/dist/throttler.exception.js +7 -7
- package/dist/throttler.guard.d.ts +1 -0
- package/dist/throttler.guard.js +107 -79
- package/dist/throttler.guard.js.map +1 -1
- package/dist/throttler.module.js +77 -58
- package/dist/throttler.providers.js +22 -18
- package/dist/throttler.service.js +47 -36
- package/dist/tsconfig.build.tsbuildinfo +1 -4833
- package/package.json +48 -47
- package/CHANGELOG.md +0 -94
|
@@ -1,42 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
var __decorate =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
var __decorate =
|
|
3
|
+
(this && this.__decorate) ||
|
|
4
|
+
function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length,
|
|
6
|
+
r =
|
|
7
|
+
c < 3
|
|
8
|
+
? target
|
|
9
|
+
: desc === null
|
|
10
|
+
? (desc = Object.getOwnPropertyDescriptor(target, key))
|
|
11
|
+
: desc,
|
|
12
|
+
d;
|
|
13
|
+
if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
|
|
14
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
15
|
+
else
|
|
16
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
17
|
+
if ((d = decorators[i]))
|
|
18
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
19
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports,
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
22
|
exports.ThrottlerStorageService = void 0;
|
|
10
|
-
const common_1 = require(
|
|
23
|
+
const common_1 = require('@nestjs/common');
|
|
11
24
|
let ThrottlerStorageService = class ThrottlerStorageService {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
this.storage[key].push(Date.now() + ttlMilliseconds);
|
|
28
|
-
const timeoutId = setTimeout(() => {
|
|
29
|
-
this.storage[key].shift();
|
|
30
|
-
clearTimeout(timeoutId);
|
|
31
|
-
}, ttlMilliseconds);
|
|
32
|
-
this.timeoutIds.push(timeoutId);
|
|
33
|
-
}
|
|
34
|
-
onApplicationShutdown() {
|
|
35
|
-
this.timeoutIds.forEach(clearTimeout);
|
|
25
|
+
constructor() {
|
|
26
|
+
this._storage = {};
|
|
27
|
+
this.timeoutIds = [];
|
|
28
|
+
}
|
|
29
|
+
get storage() {
|
|
30
|
+
return this._storage;
|
|
31
|
+
}
|
|
32
|
+
async getRecord(key) {
|
|
33
|
+
return this.storage[key] || [];
|
|
34
|
+
}
|
|
35
|
+
async addRecord(key, ttl) {
|
|
36
|
+
const ttlMilliseconds = ttl * 1000;
|
|
37
|
+
if (!this.storage[key]) {
|
|
38
|
+
this.storage[key] = [];
|
|
36
39
|
}
|
|
40
|
+
this.storage[key].push(Date.now() + ttlMilliseconds);
|
|
41
|
+
const timeoutId = setTimeout(() => {
|
|
42
|
+
this.storage[key].shift();
|
|
43
|
+
clearTimeout(timeoutId);
|
|
44
|
+
}, ttlMilliseconds);
|
|
45
|
+
this.timeoutIds.push(timeoutId);
|
|
46
|
+
}
|
|
47
|
+
onApplicationShutdown() {
|
|
48
|
+
this.timeoutIds.forEach(clearTimeout);
|
|
49
|
+
}
|
|
37
50
|
};
|
|
38
|
-
ThrottlerStorageService = __decorate([
|
|
39
|
-
common_1.Injectable()
|
|
40
|
-
], ThrottlerStorageService);
|
|
51
|
+
ThrottlerStorageService = __decorate([common_1.Injectable()], ThrottlerStorageService);
|
|
41
52
|
exports.ThrottlerStorageService = ThrottlerStorageService;
|
|
42
|
-
//# sourceMappingURL=throttler.service.js.map
|
|
53
|
+
//# sourceMappingURL=throttler.service.js.map
|