@nest-omni/core 2.0.1-9 → 3.1.1-11
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/common/boilerplate.polyfill.d.ts +11 -0
- package/common/boilerplate.polyfill.js +57 -0
- package/common/dto/page-options.dto.d.ts +1 -1
- package/common/index.d.ts +0 -1
- package/common/index.js +0 -1
- package/decorators/controller.decorator.d.ts +1 -1
- package/decorators/property.decorators.js +1 -1
- package/decorators/timestamp-column.decorator.d.ts +1 -1
- package/decorators/user_auth.decorator.d.ts +1 -1
- package/health-checker/health-checker.controller.d.ts +2 -4
- package/health-checker/health-checker.controller.js +2 -5
- package/health-checker/health-checker.module.js +2 -3
- package/health-checker/index.d.ts +2 -0
- package/health-checker/index.js +18 -0
- package/helpers/date.helper.js +10 -10
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/package.json +142 -46
- package/setup/bootstrap.setup.js +37 -87
- package/setup/index.d.ts +5 -0
- package/setup/index.js +5 -0
- package/setup/mode.setup.d.ts +12 -0
- package/setup/mode.setup.js +60 -0
- package/setup/redis-lock.decorator.d.ts +5 -0
- package/setup/redis-lock.decorator.js +78 -0
- package/setup/redis-lock.service.d.ts +59 -0
- package/setup/redis-lock.service.js +362 -0
- package/setup/schedule.decorator.d.ts +23 -0
- package/setup/schedule.decorator.examples.d.ts +18 -0
- package/setup/schedule.decorator.examples.js +255 -0
- package/setup/schedule.decorator.js +233 -0
- package/setup/worker.decorator.d.ts +14 -0
- package/setup/worker.decorator.js +130 -0
- package/shared/serviceRegistryModule.js +17 -19
- package/shared/services/api-config.service.d.ts +9 -8
- package/shared/services/api-config.service.js +55 -46
- package/validator-json/default.js +9 -1
- package/validators/is-exists.validator.js +0 -2
- package/validators/is-unique.validator.js +0 -2
- package/validators/skip-empty.validator.d.ts +1 -1
- package/common/abstract-client.service.d.ts +0 -16
- package/common/abstract-client.service.js +0 -35
- package/health-checker/health-indicators/service.indicator.d.ts +0 -8
- package/health-checker/health-indicators/service.indicator.js +0 -66
- package/tsconfig.tsbuildinfo +0 -1
package/setup/bootstrap.setup.js
CHANGED
|
@@ -16,6 +16,7 @@ const dotenv = require("dotenv");
|
|
|
16
16
|
const fs_1 = require("fs");
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const process = require("process");
|
|
19
|
+
const mode_setup_1 = require("./mode.setup");
|
|
19
20
|
function findValidRootPath() {
|
|
20
21
|
const getAppRootPath = () => {
|
|
21
22
|
if (require.main && require.main.filename) {
|
|
@@ -69,24 +70,24 @@ Sentry.init({
|
|
|
69
70
|
dsn: process.env.SENTRY_DSN || '',
|
|
70
71
|
release: process.env.API_VERSION || '',
|
|
71
72
|
environment: process.env.NODE_ENV || 'unkown',
|
|
72
|
-
debug:
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
debug: false,
|
|
74
|
+
sampleRate: 1.0,
|
|
75
|
+
tracesSampleRate: 0.01,
|
|
76
|
+
profileSessionSampleRate: 0.01,
|
|
75
77
|
profileLifecycle: 'trace',
|
|
76
78
|
sendDefaultPii: true,
|
|
77
79
|
integrations: [profiling_node_1.nodeProfilingIntegration],
|
|
78
80
|
});
|
|
79
81
|
const crud_1 = require("@dataui/crud");
|
|
80
82
|
const core_1 = require("@nestjs/core");
|
|
81
|
-
const typeorm_transactional_1 = require("typeorm-transactional");
|
|
82
83
|
const nestjs_pino_1 = require("nestjs-pino");
|
|
83
84
|
const session = require("express-session");
|
|
84
85
|
const bodyParse = require("body-parser");
|
|
86
|
+
const compression = require("compression");
|
|
85
87
|
const __1 = require("../");
|
|
86
88
|
const common_1 = require("@nestjs/common");
|
|
87
89
|
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
88
90
|
const nestjs_cls_1 = require("nestjs-cls");
|
|
89
|
-
const compression = require("compression");
|
|
90
91
|
const class_validator_1 = require("class-validator");
|
|
91
92
|
const setup_1 = require("@sentry/nestjs/setup");
|
|
92
93
|
crud_1.CrudConfigService.load({
|
|
@@ -116,79 +117,21 @@ crud_1.CrudConfigService.load({
|
|
|
116
117
|
},
|
|
117
118
|
},
|
|
118
119
|
});
|
|
119
|
-
const setupProcessHandlers = (app) => {
|
|
120
|
-
const logger = app.get(nestjs_pino_1.Logger);
|
|
121
|
-
process.on('uncaughtException', (error) => {
|
|
122
|
-
logger.fatal({ error, stack: error.stack, pid: process.pid }, 'Uncaught Exception');
|
|
123
|
-
process.exit(1);
|
|
124
|
-
});
|
|
125
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
126
|
-
logger.error({
|
|
127
|
-
reason: {
|
|
128
|
-
message: reason.message,
|
|
129
|
-
stack: reason.stack,
|
|
130
|
-
name: reason.name,
|
|
131
|
-
},
|
|
132
|
-
promise,
|
|
133
|
-
pid: process.pid,
|
|
134
|
-
}, 'Unhandled Rejection');
|
|
135
|
-
});
|
|
136
|
-
process.on('exit', (code) => {
|
|
137
|
-
logger.warn(`Process exiting with code ${code}`, {
|
|
138
|
-
uptime: process.uptime(),
|
|
139
|
-
memoryUsage: process.memoryUsage(),
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
const setupGracefulShutdown = (app) => {
|
|
144
|
-
const logger = app.get(nestjs_pino_1.Logger);
|
|
145
|
-
const shutdown = (signal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
-
var _a;
|
|
147
|
-
try {
|
|
148
|
-
logger.warn(`Received ${signal}, starting graceful shutdown...`, {
|
|
149
|
-
uptime: process.uptime(),
|
|
150
|
-
connections: (_a = app.getHttpServer()) === null || _a === void 0 ? void 0 : _a.address(),
|
|
151
|
-
});
|
|
152
|
-
yield Promise.race([
|
|
153
|
-
app.close(),
|
|
154
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error('Shutdown timeout exceeded')), 15000)),
|
|
155
|
-
]);
|
|
156
|
-
logger.log('Application successfully closed', {
|
|
157
|
-
resourcesReleased: true,
|
|
158
|
-
pid: process.pid,
|
|
159
|
-
});
|
|
160
|
-
process.exit(0);
|
|
161
|
-
}
|
|
162
|
-
catch (err) {
|
|
163
|
-
logger.error('Graceful shutdown failed', {
|
|
164
|
-
error: {
|
|
165
|
-
message: err.message,
|
|
166
|
-
stack: err.stack,
|
|
167
|
-
name: err.name,
|
|
168
|
-
},
|
|
169
|
-
critical: true,
|
|
170
|
-
pid: process.pid,
|
|
171
|
-
});
|
|
172
|
-
process.exit(1);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
process.on('SIGQUIT', () => shutdown('SIGQUIT'));
|
|
176
|
-
process.on('SIGHUP', () => shutdown('SIGHUP'));
|
|
177
|
-
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
178
|
-
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
179
|
-
};
|
|
180
120
|
function bootstrapSetup(AppModule, SetupSwagger) {
|
|
181
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
(0,
|
|
122
|
+
const shouldStartHttp = (0, mode_setup_1.shouldStartHttpServer)();
|
|
183
123
|
const app = yield core_1.NestFactory.create(AppModule, {
|
|
184
124
|
bufferLogs: true,
|
|
125
|
+
autoFlushLogs: true,
|
|
185
126
|
});
|
|
186
127
|
(0, class_validator_1.useContainer)(app.select(AppModule), { fallbackOnErrors: true });
|
|
187
128
|
const configService = app.select(__1.ServiceRegistryModule).get(__1.ApiConfigService);
|
|
188
129
|
const logger = app.get(nestjs_pino_1.Logger);
|
|
189
|
-
|
|
130
|
+
app.useLogger(logger);
|
|
131
|
+
app.flushLogs();
|
|
132
|
+
logger.log(`Application Mode: ${(0, mode_setup_1.getModeDescription)()}`);
|
|
133
|
+
logger.log(`Environment: ${process.env.NODE_ENV || 'unknown'}`);
|
|
190
134
|
app.enableShutdownHooks();
|
|
191
|
-
setupGracefulShutdown(app);
|
|
192
135
|
app.enableVersioning();
|
|
193
136
|
app.enable('trust proxy');
|
|
194
137
|
app.use(bodyParse.json({ limit: '50mb' }), new nestjs_cls_1.ClsMiddleware({}).use, (0, __1.RequestIdMiddleware)(), (0, __1.PowerByMiddleware)(), (0, __1.OmniAuthMiddleware)(), compression());
|
|
@@ -202,26 +145,33 @@ function bootstrapSetup(AppModule, SetupSwagger) {
|
|
|
202
145
|
stopAtFirstError: true,
|
|
203
146
|
validationError: { target: false, value: false },
|
|
204
147
|
}));
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
148
|
+
if (shouldStartHttp) {
|
|
149
|
+
if (configService.documentationEnabled && SetupSwagger) {
|
|
150
|
+
SetupSwagger(app, configService.documentationPath);
|
|
151
|
+
logger.log(`Swagger docs available at ${configService.documentationPath}`);
|
|
152
|
+
}
|
|
153
|
+
if (configService.viewsEnabled) {
|
|
154
|
+
app.setBaseViewsDir((0, path_1.join)(__1.ApiConfigService.rootPath, 'views'));
|
|
155
|
+
app.setViewEngine('ejs');
|
|
156
|
+
logger.log('View engine initialized');
|
|
157
|
+
}
|
|
158
|
+
if (configService.sessionEnabled) {
|
|
159
|
+
app.use(session(configService.sessionConfig));
|
|
160
|
+
logger.log('Session middleware enabled');
|
|
161
|
+
}
|
|
162
|
+
if (configService.corsEnabled) {
|
|
163
|
+
app.enableCors(configService.corsConfig);
|
|
164
|
+
logger.log('CORS configuration applied');
|
|
165
|
+
}
|
|
166
|
+
const port = configService.appConfig.port;
|
|
167
|
+
yield app.listen(port);
|
|
168
|
+
logger.log(`HTTP Server running on ${yield app.getUrl()}`);
|
|
217
169
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
logger.log('
|
|
170
|
+
else {
|
|
171
|
+
logger.log('Running in Worker-only mode - HTTP server not started');
|
|
172
|
+
logger.log('Application is ready to process background tasks');
|
|
173
|
+
yield app.init();
|
|
221
174
|
}
|
|
222
|
-
const port = configService.appConfig.port;
|
|
223
|
-
yield app.listen(port);
|
|
224
|
-
logger.log(`Server running on ${yield app.getUrl()}`);
|
|
225
175
|
return app;
|
|
226
176
|
});
|
|
227
177
|
}
|
package/setup/index.d.ts
CHANGED
package/setup/index.js
CHANGED
|
@@ -15,3 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./bootstrap.setup"), exports);
|
|
18
|
+
__exportStar(require("./mode.setup"), exports);
|
|
19
|
+
__exportStar(require("./worker.decorator"), exports);
|
|
20
|
+
__exportStar(require("./schedule.decorator"), exports);
|
|
21
|
+
__exportStar(require("./redis-lock.service"), exports);
|
|
22
|
+
__exportStar(require("./redis-lock.decorator"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum ApplicationMode {
|
|
2
|
+
HTTP = "http",
|
|
3
|
+
WORKER = "worker",
|
|
4
|
+
HYBRID = "hybrid"
|
|
5
|
+
}
|
|
6
|
+
export declare function getApplicationMode(): ApplicationMode;
|
|
7
|
+
export declare function shouldProcessQueues(): boolean;
|
|
8
|
+
export declare function shouldStartHttpServer(): boolean;
|
|
9
|
+
export declare function isHttpMode(): boolean;
|
|
10
|
+
export declare function isWorkerMode(): boolean;
|
|
11
|
+
export declare function isHybridMode(): boolean;
|
|
12
|
+
export declare function getModeDescription(): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationMode = void 0;
|
|
4
|
+
exports.getApplicationMode = getApplicationMode;
|
|
5
|
+
exports.shouldProcessQueues = shouldProcessQueues;
|
|
6
|
+
exports.shouldStartHttpServer = shouldStartHttpServer;
|
|
7
|
+
exports.isHttpMode = isHttpMode;
|
|
8
|
+
exports.isWorkerMode = isWorkerMode;
|
|
9
|
+
exports.isHybridMode = isHybridMode;
|
|
10
|
+
exports.getModeDescription = getModeDescription;
|
|
11
|
+
var ApplicationMode;
|
|
12
|
+
(function (ApplicationMode) {
|
|
13
|
+
ApplicationMode["HTTP"] = "http";
|
|
14
|
+
ApplicationMode["WORKER"] = "worker";
|
|
15
|
+
ApplicationMode["HYBRID"] = "hybrid";
|
|
16
|
+
})(ApplicationMode || (exports.ApplicationMode = ApplicationMode = {}));
|
|
17
|
+
function getApplicationMode() {
|
|
18
|
+
const mode = (process.env.APP_MODE || process.env.MODE || 'hybrid')
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.trim();
|
|
21
|
+
switch (mode) {
|
|
22
|
+
case 'http':
|
|
23
|
+
return ApplicationMode.HTTP;
|
|
24
|
+
case 'worker':
|
|
25
|
+
return ApplicationMode.WORKER;
|
|
26
|
+
case 'hybrid':
|
|
27
|
+
default:
|
|
28
|
+
return ApplicationMode.HYBRID;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function shouldProcessQueues() {
|
|
32
|
+
const mode = getApplicationMode();
|
|
33
|
+
return mode === ApplicationMode.WORKER || mode === ApplicationMode.HYBRID;
|
|
34
|
+
}
|
|
35
|
+
function shouldStartHttpServer() {
|
|
36
|
+
const mode = getApplicationMode();
|
|
37
|
+
return mode === ApplicationMode.HTTP || mode === ApplicationMode.HYBRID;
|
|
38
|
+
}
|
|
39
|
+
function isHttpMode() {
|
|
40
|
+
return getApplicationMode() === ApplicationMode.HTTP;
|
|
41
|
+
}
|
|
42
|
+
function isWorkerMode() {
|
|
43
|
+
return getApplicationMode() === ApplicationMode.WORKER;
|
|
44
|
+
}
|
|
45
|
+
function isHybridMode() {
|
|
46
|
+
return getApplicationMode() === ApplicationMode.HYBRID;
|
|
47
|
+
}
|
|
48
|
+
function getModeDescription() {
|
|
49
|
+
const mode = getApplicationMode();
|
|
50
|
+
switch (mode) {
|
|
51
|
+
case ApplicationMode.HTTP:
|
|
52
|
+
return 'HTTP-only mode (no background workers)';
|
|
53
|
+
case ApplicationMode.WORKER:
|
|
54
|
+
return 'Worker-only mode (no HTTP server)';
|
|
55
|
+
case ApplicationMode.HYBRID:
|
|
56
|
+
return 'Hybrid mode (HTTP server + background workers)';
|
|
57
|
+
default:
|
|
58
|
+
return 'Unknown mode';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LockOptions } from './redis-lock.service';
|
|
2
|
+
export declare function UseRedisLock(lockKey: string, options?: LockOptions & {
|
|
3
|
+
skipReturnValue?: any;
|
|
4
|
+
}): MethodDecorator;
|
|
5
|
+
export declare function UseRedisLockOrSkip(lockKey: string, ttl?: number): MethodDecorator;
|
|
@@ -0,0 +1,78 @@
|
|
|
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.UseRedisLock = UseRedisLock;
|
|
13
|
+
exports.UseRedisLockOrSkip = UseRedisLockOrSkip;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
function UseRedisLock(lockKey, options = {}) {
|
|
16
|
+
return function (target, propertyKey, descriptor) {
|
|
17
|
+
const originalMethod = descriptor.value;
|
|
18
|
+
const logger = new common_1.Logger(`RedisLock:${String(propertyKey)}`);
|
|
19
|
+
descriptor.value = function (...args) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a;
|
|
22
|
+
const { RedisLockService } = yield Promise.resolve().then(() => require('./redis-lock.service'));
|
|
23
|
+
let lockService = RedisLockService.getGlobalInstance();
|
|
24
|
+
if (!lockService) {
|
|
25
|
+
try {
|
|
26
|
+
lockService = RedisLockService.getOrCreateGlobalInstance();
|
|
27
|
+
logger.debug('RedisLockService auto-initialized for decorator');
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
logger.error(`Failed to auto-initialize RedisLockService: ${error.message}. ` +
|
|
31
|
+
`Please ensure Redis is accessible or call configureRedisLock() in your application setup.`);
|
|
32
|
+
throw new Error(`RedisLockService initialization failed. Please check Redis connection or call configureRedisLock() in your application setup.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const skipReturnValue = (_a = options.skipReturnValue) !== null && _a !== void 0 ? _a : null;
|
|
36
|
+
try {
|
|
37
|
+
const lockResult = yield lockService.acquireLock(lockKey, options);
|
|
38
|
+
if (!lockResult.acquired) {
|
|
39
|
+
logger.log(`Lock '${lockKey}' is already held, skipping execution of ${String(propertyKey)}`);
|
|
40
|
+
return skipReturnValue;
|
|
41
|
+
}
|
|
42
|
+
logger.debug(`Lock '${lockKey}' acquired, executing ${String(propertyKey)}`);
|
|
43
|
+
try {
|
|
44
|
+
return yield originalMethod.apply(this, args);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
logger.error(`Error executing ${String(propertyKey)} with lock '${lockKey}':`, error);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
if (lockResult.autoExtendTimer) {
|
|
52
|
+
clearInterval(lockResult.autoExtendTimer);
|
|
53
|
+
}
|
|
54
|
+
yield lockService.releaseLock(lockKey, lockResult.lockValue, options.keyPrefix);
|
|
55
|
+
logger.debug(`Lock '${lockKey}' released`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error.message.includes('ECONNREFUSED') ||
|
|
60
|
+
error.message.includes('Redis connection') ||
|
|
61
|
+
error.message.includes('RedisLockService initialization failed')) {
|
|
62
|
+
logger.error(`Redis connection error in ${String(propertyKey)}: ${error.message}. ` +
|
|
63
|
+
`Skipping execution to prevent issues.`);
|
|
64
|
+
return skipReturnValue;
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return descriptor;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function UseRedisLockOrSkip(lockKey, ttl = 300000) {
|
|
74
|
+
return UseRedisLock(lockKey, {
|
|
75
|
+
ttl,
|
|
76
|
+
skipReturnValue: false,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
export interface LockOptions {
|
|
3
|
+
ttl?: number;
|
|
4
|
+
retryCount?: number;
|
|
5
|
+
retryDelay?: number;
|
|
6
|
+
keyPrefix?: string;
|
|
7
|
+
throwOnFailure?: boolean;
|
|
8
|
+
autoExtend?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface LockResult {
|
|
11
|
+
acquired: boolean;
|
|
12
|
+
lockValue?: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
autoExtendTimer?: NodeJS.Timeout;
|
|
15
|
+
}
|
|
16
|
+
export interface RedisOptions {
|
|
17
|
+
host?: string;
|
|
18
|
+
port?: number;
|
|
19
|
+
password?: string;
|
|
20
|
+
db?: number;
|
|
21
|
+
retryDelay?: number;
|
|
22
|
+
maxRetries?: number;
|
|
23
|
+
reconnectOnError?: (err: Error) => boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare class RedisLockService implements OnModuleInit, OnModuleDestroy {
|
|
26
|
+
private static globalInstance;
|
|
27
|
+
private static globalConfig;
|
|
28
|
+
private readonly logger;
|
|
29
|
+
private redis;
|
|
30
|
+
private redisOptions;
|
|
31
|
+
private isConnected;
|
|
32
|
+
private isConnecting;
|
|
33
|
+
private connectionPromise;
|
|
34
|
+
private readonly defaultOptions;
|
|
35
|
+
private readonly defaultRedisOptions;
|
|
36
|
+
constructor(redisOptions?: RedisOptions);
|
|
37
|
+
static initializeGlobalInstance(config?: RedisOptions): RedisLockService;
|
|
38
|
+
static getGlobalInstance(): RedisLockService | null;
|
|
39
|
+
static getOrCreateGlobalInstance(): RedisLockService;
|
|
40
|
+
static setGlobalInstance(instance: RedisLockService): void;
|
|
41
|
+
onModuleInit(): Promise<void>;
|
|
42
|
+
onModuleDestroy(): Promise<void>;
|
|
43
|
+
acquireLock(key: string, options?: LockOptions): Promise<LockResult>;
|
|
44
|
+
releaseLock(key: string, lockValue: string, keyPrefix?: string): Promise<boolean>;
|
|
45
|
+
extendLock(key: string, lockValue: string, ttl: number, keyPrefix?: string): Promise<boolean>;
|
|
46
|
+
isLocked(key: string, keyPrefix?: string): Promise<boolean>;
|
|
47
|
+
withLock<T>(key: string, fn: () => Promise<T>, options?: LockOptions): Promise<T | null>;
|
|
48
|
+
getLockInfo(key: string, keyPrefix?: string): Promise<{
|
|
49
|
+
value: string | null;
|
|
50
|
+
ttl: number | null;
|
|
51
|
+
}>;
|
|
52
|
+
forceRelease(key: string, keyPrefix?: string): Promise<boolean>;
|
|
53
|
+
getRedisOptions(): RedisOptions;
|
|
54
|
+
private getRedis;
|
|
55
|
+
private createRedisConnection;
|
|
56
|
+
private generateLockValue;
|
|
57
|
+
private buildLockKey;
|
|
58
|
+
private sleep;
|
|
59
|
+
}
|