murlock 1.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/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +6 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +18 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/lock.decorator.d.ts +1 -0
- package/dist/decorators/lock.decorator.js +11 -0
- package/dist/decorators/lock.decorator.js.map +1 -0
- package/dist/decorators/murlock.decorator.d.ts +2 -0
- package/dist/decorators/murlock.decorator.js +66 -0
- package/dist/decorators/murlock.decorator.js.map +1 -0
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/exceptions/index.js +18 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/murlock.exception.d.ts +3 -0
- package/dist/exceptions/murlock.exception.js +11 -0
- package/dist/exceptions/murlock.exception.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/index.d.ts +1 -0
- package/dist/interceptors/index.js +18 -0
- package/dist/interceptors/index.js.map +1 -0
- package/dist/interceptors/lock.interceptor.d.ts +12 -0
- package/dist/interceptors/lock.interceptor.js +66 -0
- package/dist/interceptors/lock.interceptor.js.map +1 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +19 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/lock-meta-data.interface.d.ts +4 -0
- package/dist/interfaces/lock-meta-data.interface.js +3 -0
- package/dist/interfaces/lock-meta-data.interface.js.map +1 -0
- package/dist/interfaces/lock-options.interface.d.ts +4 -0
- package/dist/interfaces/lock-options.interface.js +3 -0
- package/dist/interfaces/lock-options.interface.js.map +1 -0
- package/dist/interfaces/murlock-meta-data.interface.d.ts +4 -0
- package/dist/interfaces/murlock-meta-data.interface.js +3 -0
- package/dist/interfaces/murlock-meta-data.interface.js.map +1 -0
- package/dist/interfaces/murlock-options.interface.d.ts +12 -0
- package/dist/interfaces/murlock-options.interface.js +3 -0
- package/dist/interfaces/murlock-options.interface.js.map +1 -0
- package/dist/lock.module.d.ts +5 -0
- package/dist/lock.module.js +40 -0
- package/dist/lock.module.js.map +1 -0
- package/dist/lock.service.d.ts +9 -0
- package/dist/lock.service.js +58 -0
- package/dist/lock.service.js.map +1 -0
- package/dist/lock.spec.d.ts +1 -0
- package/dist/lock.spec.js +53 -0
- package/dist/lock.spec.js.map +1 -0
- package/dist/murlock.module.d.ts +8 -0
- package/dist/murlock.module.js +71 -0
- package/dist/murlock.module.js.map +1 -0
- package/dist/murlock.service.d.ts +13 -0
- package/dist/murlock.service.js +79 -0
- package/dist/murlock.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +42 -0
- package/tsconfig.json +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Alex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# NestJS MurLock
|
|
2
|
+
|
|
3
|
+
MurLock is a distributed lock solution designed for the NestJS framework. It provides a decorator `@MurLock()` that allows for critical sections of your application to be locked to prevent race conditions. MurLock uses Redis to ensure locks are respected across multiple instances of your application, making it perfect for microservices.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Redis-Based**: Implements a fast and effective lock mechanism using Redis.
|
|
8
|
+
- **Parameter-Based Locking**: Creates locks based on request parameters or bodies.
|
|
9
|
+
- **Highly Customizable**: Customize many parameters, such as lock duration.
|
|
10
|
+
- **Logging Support**: Detailed logging with internal nestjs-logger.
|
|
11
|
+
- **OOP and Generic Structure**: Easily integratable and expandable due to its OOP and generic design.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
MurLock has a peer dependency on `@nestjs/common` and `reflect-metadata`. These should already be installed in your NestJS project. In addition, you'll also need to install the `redis` package.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install --save murlock redis reflect-metadata
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Basic Usage
|
|
22
|
+
|
|
23
|
+
MurLock is primarily used through the `@MurLock()` decorator.
|
|
24
|
+
|
|
25
|
+
First, you need to import and register the `MurLockModule` in your module:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { MurLockModule } from 'murlock';
|
|
29
|
+
|
|
30
|
+
@Module({
|
|
31
|
+
imports: [
|
|
32
|
+
MurLockModule.registerSync({
|
|
33
|
+
redisOptions: { host: 'localhost', port: 6379 },
|
|
34
|
+
wait: 1000,
|
|
35
|
+
maxAttempts: 3,
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
})
|
|
39
|
+
export class AppModule {}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then, you can use `@MurLock()` in your services:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { MurLock } from 'murlock';
|
|
46
|
+
|
|
47
|
+
@Injectable()
|
|
48
|
+
export class AppService {
|
|
49
|
+
@MurLock(5000, 'user.id')
|
|
50
|
+
async someFunction(user: User): Promise<void> {
|
|
51
|
+
// Some critical section that only one request should be able to execute at a time
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
In the example above, the `@MurLock()` decorator will prevent `someFunction()` from being executed concurrently for the same user. If another request comes in for the same user before `someFunction()` has finished executing, it will wait up to 5000 milliseconds (5 seconds) for the lock to be released. If the lock is not released within this time, an `MurLockException` will be thrown.
|
|
57
|
+
|
|
58
|
+
The parameters to `@MurLock()` are a release time (in milliseconds), followed by any number of key parameters. The key parameters are used to create a unique key for each lock. They should be properties of the parameters of the method. In the example above, 'user.id' is used, which means the lock key will be different for each user ID.
|
|
59
|
+
|
|
60
|
+
## Advanced Usage
|
|
61
|
+
|
|
62
|
+
MurLock also supports async configuration. This can be useful if your Redis configuration is not known at compile time.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { MurLockModule } from 'murlock';
|
|
66
|
+
|
|
67
|
+
@Module({
|
|
68
|
+
imports: [
|
|
69
|
+
MurLockModule.registerAsync({
|
|
70
|
+
imports: [ConfigModule],
|
|
71
|
+
useFactory: async (configService: ConfigService) => ({
|
|
72
|
+
redisOptions: configService.get('REDIS_OPTIONS'),
|
|
73
|
+
wait: configService.get('MURLOCK_WAIT'),
|
|
74
|
+
maxAttempts: configService.get('MURLOCK_MAX_ATTEMPTS'),
|
|
75
|
+
}),
|
|
76
|
+
inject: [ConfigService],
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
})
|
|
80
|
+
export class AppModule {}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
In the example above, the `ConfigModule` and `ConfigService` are used to provide the configuration for MurLock asynchronously.
|
|
84
|
+
|
|
85
|
+
For more details on usage and configuration, please refer to the API documentation below.
|
|
86
|
+
|
|
87
|
+
## API Documentation
|
|
88
|
+
|
|
89
|
+
For more detailed API documentation, please see the source code, which is thoroughly commented and should provide enough information for most use cases. The key classes and interfaces to be aware of are:
|
|
90
|
+
|
|
91
|
+
- `MurLockService`: A service that provides methods for locking and unlocking. Normally you would not use this directly, but it is provided for more complex use cases.
|
|
92
|
+
|
|
93
|
+
- `MurLockModuleOptions`: An interface for the options that can be passed to `MurLockModule.registerSync()`.
|
|
94
|
+
|
|
95
|
+
- `MurLockModuleAsyncOptions`: An interface for the options that can be passed to `MurLockModule.registerAsync()`.
|
|
96
|
+
|
|
97
|
+
- `MurLock()`: A decorator that provides distributed locking functionality.
|
|
98
|
+
|
|
99
|
+
- `MurLockMetadata`: An interface for the metadata associated with a `@MurLock()` method.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
This project is licensed under the [MIT License](LICENSE_FILE_URL).
|
|
104
|
+
|
|
105
|
+
## Contact
|
|
106
|
+
|
|
107
|
+
If you have any questions or feedback, feel free to contact me at ozmen.eyupfurkan@gmail.com.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MURLOCK_SERVICE_METADATA_KEY = exports.MURLOCK_KEY_METADATA = void 0;
|
|
4
|
+
exports.MURLOCK_KEY_METADATA = Symbol('MURLOCK_KEY_METADATA');
|
|
5
|
+
exports.MURLOCK_SERVICE_METADATA_KEY = Symbol('MURLOCK_SERVICE_METADATA_KEY');
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAEtD,QAAA,4BAA4B,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './murlock.decorator';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./murlock.decorator"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Lock(releaseTime: number, ...params: string[]): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Lock = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const interceptors_1 = require("../interceptors");
|
|
7
|
+
function Lock(releaseTime, ...params) {
|
|
8
|
+
return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(constants_1.LOCK_KEY_METADATA, { releaseTime, params }), (0, common_1.UseInterceptors)(interceptors_1.LockInterceptor));
|
|
9
|
+
}
|
|
10
|
+
exports.Lock = Lock;
|
|
11
|
+
//# sourceMappingURL=lock.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.decorator.js","sourceRoot":"","sources":["../../lib/decorators/lock.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA+E;AAC/E,4CAAiD;AACjD,kDAAkD;AAElD,SAAgB,IAAI,CAAC,WAAmB,EAAE,GAAG,MAAgB;IAC3D,OAAO,IAAA,wBAAe,EACpB,IAAA,oBAAW,EAAC,6BAAiB,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,EACvD,IAAA,wBAAe,EAAC,8BAAe,CAAC,CACjC,CAAC;AACJ,CAAC;AALD,oBAKC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MurLock = void 0;
|
|
13
|
+
require("reflect-metadata");
|
|
14
|
+
const murlock_service_1 = require("../murlock.service");
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
|
+
const exceptions_1 = require("../exceptions");
|
|
17
|
+
function getParameterNames(func) {
|
|
18
|
+
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
|
19
|
+
const ARGUMENT_NAMES = /([^\s,]+)/g;
|
|
20
|
+
const fnStr = func.toString().replace(STRIP_COMMENTS, '');
|
|
21
|
+
const result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
|
|
22
|
+
return result || [];
|
|
23
|
+
}
|
|
24
|
+
function MurLock(releaseTime, ...keyParams) {
|
|
25
|
+
return (target, propertyKey, descriptor) => {
|
|
26
|
+
const originalMethod = descriptor.value;
|
|
27
|
+
const methodParameterNames = getParameterNames(originalMethod);
|
|
28
|
+
descriptor.value = function (...args) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const lockKeyElements = [
|
|
31
|
+
target.constructor.name,
|
|
32
|
+
propertyKey,
|
|
33
|
+
...keyParams.map((keyParam) => {
|
|
34
|
+
const [source, path] = keyParam.split('.');
|
|
35
|
+
const parameterIndex = methodParameterNames.indexOf(source);
|
|
36
|
+
if (parameterIndex >= 0) {
|
|
37
|
+
const parameterValue = args[parameterIndex];
|
|
38
|
+
if (path && typeof parameterValue === 'object' && parameterValue !== null && path in parameterValue) {
|
|
39
|
+
return parameterValue[path];
|
|
40
|
+
}
|
|
41
|
+
return parameterValue instanceof Object ? parameterValue.toString() : parameterValue;
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
];
|
|
45
|
+
const lockKey = lockKeyElements.join(':');
|
|
46
|
+
const murLockService = Reflect.getMetadata(constants_1.MURLOCK_SERVICE_METADATA_KEY, murlock_service_1.MurLockService);
|
|
47
|
+
const isLockSuccessful = yield murLockService.lock(lockKey, releaseTime);
|
|
48
|
+
if (!isLockSuccessful) {
|
|
49
|
+
throw new exceptions_1.MurLockException('Could not obtain lock');
|
|
50
|
+
}
|
|
51
|
+
let result;
|
|
52
|
+
try {
|
|
53
|
+
result = yield originalMethod.apply(this, args);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
yield murLockService.unlock(lockKey);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
Reflect.defineMetadata('MURLOCK_KEY_METADATA', { releaseTime, keyParams }, descriptor.value);
|
|
62
|
+
return descriptor;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
exports.MurLock = MurLock;
|
|
66
|
+
//# sourceMappingURL=murlock.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"murlock.decorator.js","sourceRoot":"","sources":["../../lib/decorators/murlock.decorator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4BAA0B;AAC1B,wDAAoD;AACpD,4CAA4D;AAC5D,8CAAiD;AAEjD,SAAS,iBAAiB,CAAC,IAAI;IAC7B,MAAM,cAAc,GAAG,kCAAkC,CAAC;IAC1D,MAAM,cAAc,GAAG,YAAY,CAAC;IAEpC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC7F,OAAO,MAAM,IAAI,EAAE,CAAC;AACtB,CAAC;AAED,SAAgB,OAAO,CAAC,WAAmB,EAAE,GAAG,SAAmB;IACjE,OAAO,CACL,MAAW,EACX,WAAmB,EACnB,UAA8B,EAC9B,EAAE;QACF,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QACxC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAC;QAG/D,UAAU,CAAC,KAAK,GAAG,UAAgB,GAAG,IAAW;;gBAC/C,MAAM,eAAe,GAAG;oBACtB,MAAM,CAAC,WAAW,CAAC,IAAI;oBACvB,WAAW;oBACX,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;wBAC5B,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;wBAC3C,MAAM,cAAc,GAAG,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;wBAC5D,IAAI,cAAc,IAAI,CAAC,EAAE;4BACvB,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;4BAC5C,IAAI,IAAI,IAAI,OAAO,cAAc,KAAK,QAAQ,IAAI,cAAc,KAAK,IAAI,IAAI,IAAI,IAAI,cAAc,EAAE;gCACnG,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;6BAC7B;4BACD,OAAO,cAAc,YAAY,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;yBACtF;oBACH,CAAC,CAAC;iBACH,CAAC;gBACF,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAE1C,MAAM,cAAc,GAAmB,OAAO,CAAC,WAAW,CAAC,wCAA4B,EAAE,gCAAc,CAAC,CAAC;gBAEzG,MAAM,gBAAgB,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;gBACzE,IAAI,CAAC,gBAAgB,EAAE;oBACrB,MAAM,IAAI,6BAAgB,CAAC,uBAAuB,CAAC,CAAC;iBACrD;gBAED,IAAI,MAAM,CAAC;gBACX,IAAI;oBACF,MAAM,GAAG,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;iBACjD;wBAAS;oBACR,MAAM,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;iBACtC;gBAED,OAAO,MAAM,CAAC;YAChB,CAAC;SAAA,CAAC;QAEF,OAAO,CAAC,cAAc,CACpB,sBAAsB,EACtB,EAAE,WAAW,EAAE,SAAS,EAAE,EAC1B,UAAU,CAAC,KAAK,CACjB,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AArDD,0BAqDC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './murlock.exception';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./murlock.exception"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MurLockException = void 0;
|
|
4
|
+
class MurLockException extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "MurLockException";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.MurLockException = MurLockException;
|
|
11
|
+
//# sourceMappingURL=murlock.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"murlock.exception.js","sourceRoot":"","sources":["../../lib/exceptions/murlock.exception.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AALD,4CAKC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./murlock.service"), exports);
|
|
18
|
+
__exportStar(require("./murlock.module"), exports);
|
|
19
|
+
__exportStar(require("./decorators"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,+CAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lock.interceptor';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./lock.interceptor"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/interceptors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { LockService } from '../lock.service';
|
|
4
|
+
import { PinoLogger } from 'nestjs-pino';
|
|
5
|
+
import { Observable } from 'rxjs';
|
|
6
|
+
export declare class LockInterceptor implements NestInterceptor {
|
|
7
|
+
private readonly lockService;
|
|
8
|
+
private readonly reflector;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
constructor(lockService: LockService, reflector: Reflector, logger: PinoLogger);
|
|
11
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var LockInterceptor_1;
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.LockInterceptor = void 0;
|
|
23
|
+
const common_1 = require("@nestjs/common");
|
|
24
|
+
const core_1 = require("@nestjs/core");
|
|
25
|
+
const constants_1 = require("../constants");
|
|
26
|
+
const lock_service_1 = require("../lock.service");
|
|
27
|
+
const nestjs_pino_1 = require("nestjs-pino");
|
|
28
|
+
const rxjs_1 = require("rxjs");
|
|
29
|
+
let LockInterceptor = exports.LockInterceptor = LockInterceptor_1 = class LockInterceptor {
|
|
30
|
+
constructor(lockService, reflector, logger) {
|
|
31
|
+
this.lockService = lockService;
|
|
32
|
+
this.reflector = reflector;
|
|
33
|
+
this.logger = logger;
|
|
34
|
+
this.logger.setContext(LockInterceptor_1.name);
|
|
35
|
+
}
|
|
36
|
+
intercept(context, next) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const lockMetadata = this.reflector.get(constants_1.LOCK_KEY_METADATA, context.getHandler());
|
|
39
|
+
if (!lockMetadata) {
|
|
40
|
+
return next.handle();
|
|
41
|
+
}
|
|
42
|
+
const { releaseTime, params } = lockMetadata;
|
|
43
|
+
const request = context.switchToHttp().getRequest();
|
|
44
|
+
const lockKey = params
|
|
45
|
+
.map((param) => request.params[param] || request.body[param])
|
|
46
|
+
.join(':');
|
|
47
|
+
const isLockSuccessful = yield this.lockService.lock(lockKey, releaseTime);
|
|
48
|
+
if (!isLockSuccessful) {
|
|
49
|
+
throw new common_1.InternalServerErrorException('Could not obtain lock');
|
|
50
|
+
}
|
|
51
|
+
return next.handle().pipe((0, rxjs_1.tap)(() => this.logger.info(`Processing complete, releasing lock for key ${lockKey}`)), (0, rxjs_1.catchError)((error) => {
|
|
52
|
+
this.logger.error(`Error processing request: ${error.message}`);
|
|
53
|
+
return (0, rxjs_1.throwError)(error);
|
|
54
|
+
}), (0, rxjs_1.finalize)(() => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
yield this.lockService.unlock(lockKey);
|
|
56
|
+
})));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.LockInterceptor = LockInterceptor = LockInterceptor_1 = __decorate([
|
|
61
|
+
(0, common_1.Injectable)(),
|
|
62
|
+
__metadata("design:paramtypes", [lock_service_1.LockService,
|
|
63
|
+
core_1.Reflector,
|
|
64
|
+
nestjs_pino_1.PinoLogger])
|
|
65
|
+
], LockInterceptor);
|
|
66
|
+
//# sourceMappingURL=lock.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.interceptor.js","sourceRoot":"","sources":["../../lib/interceptors/lock.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AACzC,4CAAiD;AAEjD,kDAA8C;AAC9C,6CAAyC;AACzC,+BAAyE;AAGlE,IAAM,eAAe,iDAArB,MAAM,eAAe;IAC1B,YACmB,WAAwB,EACxB,SAAoB,EACpB,MAAkB;QAFlB,gBAAW,GAAX,WAAW,CAAa;QACxB,cAAS,GAAT,SAAS,CAAW;QACpB,WAAM,GAAN,MAAM,CAAY;QAEnC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,iBAAe,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAEK,SAAS,CACb,OAAyB,EACzB,IAAiB;;YAEjB,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CACrC,6BAAiB,EACjB,OAAO,CAAC,UAAU,EAAE,CACrB,CAAC;YAEF,IAAI,CAAC,YAAY,EAAE;gBACjB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;aACtB;YAED,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;YAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YACpD,MAAM,OAAO,GAAG,MAAM;iBACnB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBAC5D,IAAI,CAAC,GAAG,CAAC,CAAC;YAEb,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YAE3E,IAAI,CAAC,gBAAgB,EAAE;gBACrB,MAAM,IAAI,qCAA4B,CAAC,uBAAuB,CAAC,CAAC;aACjE;YAED,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,IAAA,UAAG,EAAC,GAAG,EAAE,CACP,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,+CAA+C,OAAO,EAAE,CACzD,CACF,EACD,IAAA,iBAAU,EAAC,CAAC,KAAK,EAAE,EAAE;gBACnB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBAChE,OAAO,IAAA,iBAAU,EAAC,KAAK,CAAC,CAAC;YAC3B,CAAC,CAAC,EACF,IAAA,eAAQ,EAAC,GAAS,EAAE;gBAClB,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACzC,CAAC,CAAA,CAAC,CACH,CAAC;QACJ,CAAC;KAAA;CACF,CAAA;0BAjDY,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAGqB,0BAAW;QACb,gBAAS;QACZ,wBAAU;GAJ1B,eAAe,CAiD3B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./murlock-meta-data.interface"), exports);
|
|
18
|
+
__exportStar(require("./murlock-options.interface"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,8DAA4C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-meta-data.interface.js","sourceRoot":"","sources":["../../lib/interfaces/lock-meta-data.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-options.interface.js","sourceRoot":"","sources":["../../lib/interfaces/lock-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"murlock-meta-data.interface.js","sourceRoot":"","sources":["../../lib/interfaces/murlock-meta-data.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ClientOpts } from 'redis';
|
|
2
|
+
export interface MurLockModuleOptions {
|
|
3
|
+
redisOptions: ClientOpts;
|
|
4
|
+
ttl: number;
|
|
5
|
+
wait: number;
|
|
6
|
+
maxAttempts: number;
|
|
7
|
+
}
|
|
8
|
+
export interface MurLockModuleAsyncOptions {
|
|
9
|
+
imports?: any[];
|
|
10
|
+
inject?: any[];
|
|
11
|
+
useFactory: (...args: any[]) => Promise<MurLockModuleOptions> | MurLockModuleOptions;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"murlock-options.interface.js","sourceRoot":"","sources":["../../lib/interfaces/murlock-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -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 LockModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.LockModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const Redis = require("ioredis");
|
|
13
|
+
const lock_service_1 = require("./lock.service");
|
|
14
|
+
const interceptors_1 = require("./interceptors");
|
|
15
|
+
const nestjs_pino_1 = require("nestjs-pino");
|
|
16
|
+
let LockModule = exports.LockModule = LockModule_1 = class LockModule {
|
|
17
|
+
static register(options) {
|
|
18
|
+
const redisClientProvider = {
|
|
19
|
+
provide: 'REDIS_CLIENT',
|
|
20
|
+
useFactory: () => {
|
|
21
|
+
return new Redis.Redis(options.redisOptions);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
module: LockModule_1,
|
|
26
|
+
providers: [
|
|
27
|
+
lock_service_1.LockService,
|
|
28
|
+
interceptors_1.LockInterceptor,
|
|
29
|
+
redisClientProvider,
|
|
30
|
+
nestjs_pino_1.PinoLogger,
|
|
31
|
+
],
|
|
32
|
+
exports: [lock_service_1.LockService, interceptors_1.LockInterceptor],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.LockModule = LockModule = LockModule_1 = __decorate([
|
|
37
|
+
(0, common_1.Global)(),
|
|
38
|
+
(0, common_1.Module)({})
|
|
39
|
+
], LockModule);
|
|
40
|
+
//# sourceMappingURL=lock.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.module.js","sourceRoot":"","sources":["../lib/lock.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+D;AAC/D,iCAAiC;AACjC,iDAA6C;AAC7C,iDAAiD;AACjD,6CAAyC;AAOlC,IAAM,UAAU,uCAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,QAAQ,CAAC,OAA0B;QACxC,MAAM,mBAAmB,GAAG;YAC1B,OAAO,EAAE,cAAc;YACvB,UAAU,EAAE,GAAgB,EAAE;gBAC5B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC/C,CAAC;SACF,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,SAAS,EAAE;gBACT,0BAAW;gBACX,8BAAe;gBACf,mBAAmB;gBACnB,wBAAU;aACX;YACD,OAAO,EAAE,CAAC,0BAAW,EAAE,8BAAe,CAAC;SACxC,CAAC;IACJ,CAAC;CACF,CAAA;qBApBY,UAAU;IAFtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAoBtB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PinoLogger } from 'nestjs-pino';
|
|
2
|
+
import * as Redis from 'ioredis';
|
|
3
|
+
export declare class LockService {
|
|
4
|
+
private readonly redisClient;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(redisClient: Redis.Redis, logger: PinoLogger);
|
|
7
|
+
lock(lockKey: string, releaseTime: number): Promise<boolean>;
|
|
8
|
+
unlock(lockKey: string): Promise<void>;
|
|
9
|
+
}
|