@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.
Files changed (45) hide show
  1. package/common/boilerplate.polyfill.d.ts +11 -0
  2. package/common/boilerplate.polyfill.js +57 -0
  3. package/common/dto/page-options.dto.d.ts +1 -1
  4. package/common/index.d.ts +0 -1
  5. package/common/index.js +0 -1
  6. package/decorators/controller.decorator.d.ts +1 -1
  7. package/decorators/property.decorators.js +1 -1
  8. package/decorators/timestamp-column.decorator.d.ts +1 -1
  9. package/decorators/user_auth.decorator.d.ts +1 -1
  10. package/health-checker/health-checker.controller.d.ts +2 -4
  11. package/health-checker/health-checker.controller.js +2 -5
  12. package/health-checker/health-checker.module.js +2 -3
  13. package/health-checker/index.d.ts +2 -0
  14. package/health-checker/index.js +18 -0
  15. package/helpers/date.helper.js +10 -10
  16. package/index.d.ts +4 -0
  17. package/index.js +4 -0
  18. package/package.json +142 -46
  19. package/setup/bootstrap.setup.js +37 -87
  20. package/setup/index.d.ts +5 -0
  21. package/setup/index.js +5 -0
  22. package/setup/mode.setup.d.ts +12 -0
  23. package/setup/mode.setup.js +60 -0
  24. package/setup/redis-lock.decorator.d.ts +5 -0
  25. package/setup/redis-lock.decorator.js +78 -0
  26. package/setup/redis-lock.service.d.ts +59 -0
  27. package/setup/redis-lock.service.js +362 -0
  28. package/setup/schedule.decorator.d.ts +23 -0
  29. package/setup/schedule.decorator.examples.d.ts +18 -0
  30. package/setup/schedule.decorator.examples.js +255 -0
  31. package/setup/schedule.decorator.js +233 -0
  32. package/setup/worker.decorator.d.ts +14 -0
  33. package/setup/worker.decorator.js +130 -0
  34. package/shared/serviceRegistryModule.js +17 -19
  35. package/shared/services/api-config.service.d.ts +9 -8
  36. package/shared/services/api-config.service.js +55 -46
  37. package/validator-json/default.js +9 -1
  38. package/validators/is-exists.validator.js +0 -2
  39. package/validators/is-unique.validator.js +0 -2
  40. package/validators/skip-empty.validator.d.ts +1 -1
  41. package/common/abstract-client.service.d.ts +0 -16
  42. package/common/abstract-client.service.js +0 -35
  43. package/health-checker/health-indicators/service.indicator.d.ts +0 -8
  44. package/health-checker/health-indicators/service.indicator.js +0 -66
  45. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,233 @@
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.WorkerCron = WorkerCron;
13
+ exports.WorkerInterval = WorkerInterval;
14
+ exports.WorkerTimeout = WorkerTimeout;
15
+ exports.WorkerCronWithLock = WorkerCronWithLock;
16
+ exports.WorkerIntervalWithLock = WorkerIntervalWithLock;
17
+ exports.WorkerTimeoutWithLock = WorkerTimeoutWithLock;
18
+ exports.WorkerCronSmart = WorkerCronSmart;
19
+ exports.WorkerIntervalSmart = WorkerIntervalSmart;
20
+ exports.WorkerCronAdvanced = WorkerCronAdvanced;
21
+ const common_1 = require("@nestjs/common");
22
+ const schedule_1 = require("@nestjs/schedule");
23
+ const mode_setup_1 = require("./mode.setup");
24
+ const redis_lock_service_1 = require("./redis-lock.service");
25
+ function generateLockKey(className, methodName) {
26
+ return `${className}.${methodName}`;
27
+ }
28
+ function executeWithRetry(fn, options) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const { retryCount = 0, retryDelay = 1000, useExponentialBackoff = false, maxRetryDelay = 60000, logger, taskName, } = options;
31
+ let lastError;
32
+ let attempt = 0;
33
+ while (attempt <= retryCount) {
34
+ try {
35
+ return yield fn();
36
+ }
37
+ catch (error) {
38
+ lastError = error;
39
+ attempt++;
40
+ if (attempt <= retryCount) {
41
+ let delay = retryDelay;
42
+ if (useExponentialBackoff) {
43
+ delay = Math.min(retryDelay * Math.pow(2, attempt - 1), maxRetryDelay);
44
+ }
45
+ logger.warn(`Task "${taskName}" failed (attempt ${attempt}/${retryCount + 1}), ` +
46
+ `retrying in ${delay}ms... Error: ${error.message}`);
47
+ yield new Promise((resolve) => setTimeout(resolve, delay));
48
+ }
49
+ }
50
+ }
51
+ throw lastError;
52
+ });
53
+ }
54
+ function createWorkerDecorator(baseDecorator, decoratorName) {
55
+ return function (target, propertyKey, descriptor) {
56
+ const originalMethod = descriptor.value;
57
+ descriptor.value = function (...args) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (!(0, mode_setup_1.shouldProcessQueues)()) {
60
+ return;
61
+ }
62
+ return originalMethod.apply(this, args);
63
+ });
64
+ };
65
+ baseDecorator(target, propertyKey, descriptor);
66
+ return descriptor;
67
+ };
68
+ }
69
+ function createWorkerDecoratorWithLock(baseDecorator, decoratorName, lockKey, options = {}) {
70
+ return function (target, propertyKey, descriptor) {
71
+ const originalMethod = descriptor.value;
72
+ const className = target.constructor.name;
73
+ const methodName = String(propertyKey);
74
+ const logger = new common_1.Logger(`${className}.${methodName}`);
75
+ const resolvedLockKey = typeof lockKey === 'function' ? lockKey() : lockKey;
76
+ descriptor.value = function (...args) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ if (!(0, mode_setup_1.shouldProcessQueues)()) {
79
+ return;
80
+ }
81
+ const lockService = redis_lock_service_1.RedisLockService.getOrCreateGlobalInstance();
82
+ const { lockTtl = 3600000, retryCount = 0, retryDelay = 1000, useExponentialBackoff = false, maxRetryDelay = 60000, logExecution = true, lockKeyPrefix = 'schedule', autoExtendLock = 0, onSuccess, onError, skipIfLocked = true, } = options;
83
+ const fullLockKey = `${lockKeyPrefix}:${resolvedLockKey}`;
84
+ const startTime = Date.now();
85
+ if (logExecution) {
86
+ logger.log(`Task starting...`);
87
+ }
88
+ try {
89
+ const lockResult = yield lockService.acquireLock(resolvedLockKey, {
90
+ ttl: lockTtl,
91
+ keyPrefix: lockKeyPrefix,
92
+ autoExtend: autoExtendLock,
93
+ });
94
+ if (!lockResult.acquired) {
95
+ if (skipIfLocked) {
96
+ logger.debug(`Lock "${fullLockKey}" is held by another instance, skipping execution`);
97
+ return null;
98
+ }
99
+ else {
100
+ throw new Error(`Failed to acquire lock "${fullLockKey}"`);
101
+ }
102
+ }
103
+ try {
104
+ const result = yield executeWithRetry(() => originalMethod.apply(this, args), {
105
+ retryCount,
106
+ retryDelay,
107
+ useExponentialBackoff,
108
+ maxRetryDelay,
109
+ logger,
110
+ taskName: `${className}.${methodName}`,
111
+ });
112
+ const duration = Date.now() - startTime;
113
+ if (logExecution) {
114
+ logger.log(`Task completed successfully in ${duration}ms`);
115
+ }
116
+ if (onSuccess) {
117
+ yield onSuccess(duration);
118
+ }
119
+ return result;
120
+ }
121
+ finally {
122
+ if (lockResult.autoExtendTimer) {
123
+ clearInterval(lockResult.autoExtendTimer);
124
+ }
125
+ yield lockService.releaseLock(resolvedLockKey, lockResult.lockValue, lockKeyPrefix);
126
+ if (logExecution) {
127
+ logger.debug(`Lock "${fullLockKey}" released`);
128
+ }
129
+ }
130
+ }
131
+ catch (error) {
132
+ const duration = Date.now() - startTime;
133
+ if (logExecution) {
134
+ logger.error(`Task failed after ${duration}ms: ${error.message}`, error.stack);
135
+ }
136
+ if (onError) {
137
+ yield onError(error);
138
+ }
139
+ throw error;
140
+ }
141
+ });
142
+ };
143
+ baseDecorator(target, propertyKey, descriptor);
144
+ return descriptor;
145
+ };
146
+ }
147
+ function WorkerCron(cronTime, options) {
148
+ return createWorkerDecorator((0, schedule_1.Cron)(cronTime, options), 'WorkerCron');
149
+ }
150
+ function WorkerInterval(timeout, name) {
151
+ if (name) {
152
+ return createWorkerDecorator((0, schedule_1.Interval)(name, timeout), 'WorkerInterval');
153
+ }
154
+ return createWorkerDecorator((0, schedule_1.Interval)(timeout), 'WorkerInterval');
155
+ }
156
+ function WorkerTimeout(timeout, name) {
157
+ if (name) {
158
+ return createWorkerDecorator((0, schedule_1.Timeout)(name, timeout), 'WorkerTimeout');
159
+ }
160
+ return createWorkerDecorator((0, schedule_1.Timeout)(timeout), 'WorkerTimeout');
161
+ }
162
+ function WorkerCronWithLock(cronTime, lockKeyOrOptions, lockTtl, cronOptions) {
163
+ return function (target, propertyKey, descriptor) {
164
+ let lockKey;
165
+ let options;
166
+ if (typeof lockKeyOrOptions === 'string') {
167
+ lockKey = lockKeyOrOptions;
168
+ options = { lockTtl: lockTtl || 3600000 };
169
+ }
170
+ else {
171
+ lockKey = generateLockKey(target.constructor.name, String(propertyKey));
172
+ options = lockKeyOrOptions;
173
+ }
174
+ return createWorkerDecoratorWithLock((0, schedule_1.Cron)(cronTime, cronOptions), 'WorkerCronWithLock', lockKey, options)(target, propertyKey, descriptor);
175
+ };
176
+ }
177
+ function WorkerIntervalWithLock(timeout, lockKeyOrOptions, lockTtl) {
178
+ return function (target, propertyKey, descriptor) {
179
+ let lockKey;
180
+ let options;
181
+ if (typeof lockKeyOrOptions === 'string') {
182
+ lockKey = lockKeyOrOptions;
183
+ options = { lockTtl: lockTtl || Math.floor(timeout * 0.8) };
184
+ }
185
+ else {
186
+ lockKey = generateLockKey(target.constructor.name, String(propertyKey));
187
+ options = Object.assign({ lockTtl: Math.floor(timeout * 0.8) }, lockKeyOrOptions);
188
+ }
189
+ return createWorkerDecoratorWithLock((0, schedule_1.Interval)(timeout), 'WorkerIntervalWithLock', lockKey, options)(target, propertyKey, descriptor);
190
+ };
191
+ }
192
+ function WorkerTimeoutWithLock(timeout, lockKeyOrOptions, lockTtl) {
193
+ return function (target, propertyKey, descriptor) {
194
+ let lockKey;
195
+ let options;
196
+ if (typeof lockKeyOrOptions === 'string') {
197
+ lockKey = lockKeyOrOptions;
198
+ options = { lockTtl: lockTtl || 300000 };
199
+ }
200
+ else {
201
+ lockKey = generateLockKey(target.constructor.name, String(propertyKey));
202
+ options = lockKeyOrOptions;
203
+ }
204
+ return createWorkerDecoratorWithLock((0, schedule_1.Timeout)(timeout), 'WorkerTimeoutWithLock', lockKey, options)(target, propertyKey, descriptor);
205
+ };
206
+ }
207
+ function WorkerCronSmart(cronTime, options = {}, cronOptions) {
208
+ return function (target, propertyKey, descriptor) {
209
+ const lockKey = generateLockKey(target.constructor.name, String(propertyKey));
210
+ return createWorkerDecoratorWithLock((0, schedule_1.Cron)(cronTime, cronOptions), 'WorkerCronSmart', lockKey, Object.assign({ lockTtl: 3600000, logExecution: true }, options))(target, propertyKey, descriptor);
211
+ };
212
+ }
213
+ function WorkerIntervalSmart(timeout, options = {}) {
214
+ return function (target, propertyKey, descriptor) {
215
+ const lockKey = generateLockKey(target.constructor.name, String(propertyKey));
216
+ return createWorkerDecoratorWithLock((0, schedule_1.Interval)(timeout), 'WorkerIntervalSmart', lockKey, Object.assign({ lockTtl: Math.floor(timeout * 0.8), logExecution: true }, options))(target, propertyKey, descriptor);
217
+ };
218
+ }
219
+ function WorkerCronAdvanced(cronTime, lockKeyOrOptions, options, cronOptions) {
220
+ return function (target, propertyKey, descriptor) {
221
+ let lockKey;
222
+ let finalOptions;
223
+ if (typeof lockKeyOrOptions === 'string') {
224
+ lockKey = lockKeyOrOptions;
225
+ finalOptions = Object.assign({ lockTtl: 3600000, logExecution: true }, options);
226
+ }
227
+ else {
228
+ lockKey = generateLockKey(target.constructor.name, String(propertyKey));
229
+ finalOptions = Object.assign({ lockTtl: 3600000, logExecution: true }, lockKeyOrOptions);
230
+ }
231
+ return createWorkerDecoratorWithLock((0, schedule_1.Cron)(cronTime, cronOptions), 'WorkerCronAdvanced', lockKey, finalOptions)(target, propertyKey, descriptor);
232
+ };
233
+ }
@@ -0,0 +1,14 @@
1
+ export declare function WorkerProcessor(queueName?: string): ClassDecorator;
2
+ export declare function WorkerProcess(name?: string): MethodDecorator;
3
+ export declare function WorkerOnQueueActive(): MethodDecorator;
4
+ export declare function WorkerOnQueueCompleted(): MethodDecorator;
5
+ export declare function WorkerOnQueueProgress(): MethodDecorator;
6
+ export declare function WorkerOnQueueFailed(): MethodDecorator;
7
+ export declare function WorkerOnQueueError(): MethodDecorator;
8
+ export declare function WorkerOnQueueWaiting(): MethodDecorator;
9
+ export declare function WorkerOnQueueStalled(): MethodDecorator;
10
+ export declare function WorkerOnQueueRemoved(): MethodDecorator;
11
+ export declare function WorkerOnQueueCleaned(): MethodDecorator;
12
+ export declare function WorkerOnQueueDrained(): MethodDecorator;
13
+ export declare function WorkerOnQueuePaused(): MethodDecorator;
14
+ export declare function WorkerOnQueueResumed(): MethodDecorator;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkerProcessor = WorkerProcessor;
4
+ exports.WorkerProcess = WorkerProcess;
5
+ exports.WorkerOnQueueActive = WorkerOnQueueActive;
6
+ exports.WorkerOnQueueCompleted = WorkerOnQueueCompleted;
7
+ exports.WorkerOnQueueProgress = WorkerOnQueueProgress;
8
+ exports.WorkerOnQueueFailed = WorkerOnQueueFailed;
9
+ exports.WorkerOnQueueError = WorkerOnQueueError;
10
+ exports.WorkerOnQueueWaiting = WorkerOnQueueWaiting;
11
+ exports.WorkerOnQueueStalled = WorkerOnQueueStalled;
12
+ exports.WorkerOnQueueRemoved = WorkerOnQueueRemoved;
13
+ exports.WorkerOnQueueCleaned = WorkerOnQueueCleaned;
14
+ exports.WorkerOnQueueDrained = WorkerOnQueueDrained;
15
+ exports.WorkerOnQueuePaused = WorkerOnQueuePaused;
16
+ exports.WorkerOnQueueResumed = WorkerOnQueueResumed;
17
+ const bull_1 = require("@nestjs/bull");
18
+ const mode_setup_1 = require("./mode.setup");
19
+ function WorkerProcessor(queueName) {
20
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
21
+ return (0, bull_1.Processor)(queueName);
22
+ }
23
+ return function (constructor) {
24
+ return constructor;
25
+ };
26
+ }
27
+ function WorkerProcess(name) {
28
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
29
+ return (0, bull_1.Process)(name);
30
+ }
31
+ return function (target, propertyKey, descriptor) {
32
+ return descriptor;
33
+ };
34
+ }
35
+ function WorkerOnQueueActive() {
36
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
37
+ return (0, bull_1.OnQueueActive)();
38
+ }
39
+ return function (target, propertyKey, descriptor) {
40
+ return descriptor;
41
+ };
42
+ }
43
+ function WorkerOnQueueCompleted() {
44
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
45
+ return (0, bull_1.OnQueueCompleted)();
46
+ }
47
+ return function (target, propertyKey, descriptor) {
48
+ return descriptor;
49
+ };
50
+ }
51
+ function WorkerOnQueueProgress() {
52
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
53
+ return (0, bull_1.OnQueueProgress)();
54
+ }
55
+ return function (target, propertyKey, descriptor) {
56
+ return descriptor;
57
+ };
58
+ }
59
+ function WorkerOnQueueFailed() {
60
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
61
+ return (0, bull_1.OnQueueFailed)();
62
+ }
63
+ return function (target, propertyKey, descriptor) {
64
+ return descriptor;
65
+ };
66
+ }
67
+ function WorkerOnQueueError() {
68
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
69
+ return (0, bull_1.OnQueueError)();
70
+ }
71
+ return function (target, propertyKey, descriptor) {
72
+ return descriptor;
73
+ };
74
+ }
75
+ function WorkerOnQueueWaiting() {
76
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
77
+ return (0, bull_1.OnQueueWaiting)();
78
+ }
79
+ return function (target, propertyKey, descriptor) {
80
+ return descriptor;
81
+ };
82
+ }
83
+ function WorkerOnQueueStalled() {
84
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
85
+ return (0, bull_1.OnQueueStalled)();
86
+ }
87
+ return function (target, propertyKey, descriptor) {
88
+ return descriptor;
89
+ };
90
+ }
91
+ function WorkerOnQueueRemoved() {
92
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
93
+ return (0, bull_1.OnQueueRemoved)();
94
+ }
95
+ return function (target, propertyKey, descriptor) {
96
+ return descriptor;
97
+ };
98
+ }
99
+ function WorkerOnQueueCleaned() {
100
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
101
+ return (0, bull_1.OnQueueCleaned)();
102
+ }
103
+ return function (target, propertyKey, descriptor) {
104
+ return descriptor;
105
+ };
106
+ }
107
+ function WorkerOnQueueDrained() {
108
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
109
+ return (0, bull_1.OnQueueDrained)();
110
+ }
111
+ return function (target, propertyKey, descriptor) {
112
+ return descriptor;
113
+ };
114
+ }
115
+ function WorkerOnQueuePaused() {
116
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
117
+ return (0, bull_1.OnQueuePaused)();
118
+ }
119
+ return function (target, propertyKey, descriptor) {
120
+ return descriptor;
121
+ };
122
+ }
123
+ function WorkerOnQueueResumed() {
124
+ if ((0, mode_setup_1.shouldProcessQueues)()) {
125
+ return (0, bull_1.OnQueueResumed)();
126
+ }
127
+ return function (target, propertyKey, descriptor) {
128
+ return descriptor;
129
+ };
130
+ }
@@ -5,34 +5,26 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
8
  var _a;
18
9
  Object.defineProperty(exports, "__esModule", { value: true });
19
10
  exports.ServiceRegistryModule = void 0;
20
11
  const path = require("path");
21
12
  const process = require("process");
22
- const typeorm_1 = require("typeorm");
23
13
  const bull_1 = require("@nestjs/bull");
24
14
  const nestjs_pino_1 = require("nestjs-pino");
25
15
  const config_1 = require("@nestjs/config");
26
16
  const common_1 = require("@nestjs/common");
27
- const typeorm_2 = require("@nestjs/typeorm");
17
+ const typeorm_1 = require("@nestjs/typeorm");
28
18
  const schedule_1 = require("@nestjs/schedule");
29
19
  const setup_1 = require("@sentry/nestjs/setup");
30
20
  const cache_manager_1 = require("@nestjs/cache-manager");
31
- const typeorm_transactional_1 = require("typeorm-transactional");
21
+ const transactional_1 = require("@nestjs-cls/transactional");
22
+ const transactional_adapter_typeorm_1 = require("@nestjs-cls/transactional-adapter-typeorm");
32
23
  const nestjs_i18n_1 = require("nestjs-i18n");
33
- const health_checker_module_1 = require("../health-checker/health-checker.module");
24
+ const health_checker_1 = require("../health-checker");
34
25
  const services_1 = require("./services");
35
26
  const nestjs_cls_1 = require("nestjs-cls");
27
+ const typeorm_2 = require("typeorm");
36
28
  const providers = [
37
29
  services_1.ApiConfigService,
38
30
  services_1.ValidatorService,
@@ -40,7 +32,7 @@ const providers = [
40
32
  services_1.TranslationService,
41
33
  ];
42
34
  if (!((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.ENV_FILE_PATH)) {
43
- require('../setup/bootstrap.setup');
35
+ Promise.resolve().then(() => require('../setup/bootstrap.setup'));
44
36
  }
45
37
  services_1.ApiConfigService.rootPath = process.env.ROOT_PATH;
46
38
  const modules = [
@@ -54,6 +46,15 @@ const modules = [
54
46
  nestjs_cls_1.ClsModule.forRoot({
55
47
  global: true,
56
48
  middleware: { mount: true },
49
+ plugins: [
50
+ new transactional_1.ClsPluginTransactional({
51
+ imports: [typeorm_1.TypeOrmModule],
52
+ adapter: new transactional_adapter_typeorm_1.TransactionalAdapterTypeOrm({
53
+ dataSourceToken: typeorm_2.DataSource,
54
+ }),
55
+ enableTransactionProxy: true,
56
+ }),
57
+ ],
57
58
  }),
58
59
  nestjs_pino_1.LoggerModule.forRootAsync({
59
60
  inject: [services_1.ApiConfigService],
@@ -71,15 +72,12 @@ const modules = [
71
72
  }),
72
73
  resolvers: [new nestjs_i18n_1.QueryResolver(['lang']), nestjs_i18n_1.AcceptLanguageResolver],
73
74
  }),
74
- health_checker_module_1.HealthCheckerModule,
75
+ health_checker_1.HealthCheckerModule,
75
76
  ];
76
77
  if (services_1.ApiConfigService.toBoolean(process.env.DB_ENABLED, true)) {
77
- modules.push(typeorm_2.TypeOrmModule.forRootAsync({
78
+ modules.push(typeorm_1.TypeOrmModule.forRootAsync({
78
79
  inject: [services_1.ApiConfigService],
79
80
  useFactory: (config) => config.typeormConfig,
80
- dataSourceFactory: (options) => __awaiter(void 0, void 0, void 0, function* () {
81
- return (0, typeorm_transactional_1.addTransactionalDataSource)(new typeorm_1.DataSource(options));
82
- }),
83
81
  }));
84
82
  }
85
83
  if (services_1.ApiConfigService.toBoolean(process.env.BULL_ENABLED)) {
@@ -5,21 +5,17 @@ import { Params } from 'nestjs-pino';
5
5
  import { BullRootModuleOptions } from '@nestjs/bull/dist/interfaces/bull-module-options.interface';
6
6
  import { AxiosProxyConfig } from 'axios';
7
7
  import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
8
+ import Keyv from 'keyv';
8
9
  export declare class ApiConfigService {
9
10
  private configService;
10
11
  static rootPath: string;
11
12
  constructor(configService: ConfigService);
12
- static getRootPath(): string;
13
13
  get isDev(): boolean;
14
14
  get apiVersion(): string;
15
15
  get isProd(): boolean;
16
16
  get isSit(): boolean;
17
17
  get isUat(): boolean;
18
18
  get isTest(): boolean;
19
- getNumber(key: string, defaultValue?: number): number;
20
- getBoolean(key: string, defaultValue?: boolean): boolean;
21
- static toBoolean(value: string, defaultValue?: any): boolean;
22
- getString(key: string): string;
23
19
  get nodeEnv(): string;
24
20
  get fallbackLanguage(): string;
25
21
  get typeormConfig(): TypeOrmModuleOptions;
@@ -48,11 +44,16 @@ export declare class ApiConfigService {
48
44
  };
49
45
  get isRedisEnabled(): boolean;
50
46
  get bullConfig(): BullRootModuleOptions;
47
+ get pinoConfig(): Params;
48
+ get axiosProxyConfig(): AxiosProxyConfig | false;
49
+ static getRootPath(): string;
50
+ static toBoolean(value: string, defaultValue?: any): boolean;
51
+ getNumber(key: string, defaultValue?: number): number;
52
+ getBoolean(key: string, defaultValue?: boolean): boolean;
53
+ getString(key: string, defaultValue?: string): string;
51
54
  cacheConfig(): Promise<{
52
55
  isGlobal: boolean;
53
- store: import("cache-manager-ioredis-yet").RedisStore;
56
+ store: Keyv<any>;
54
57
  }>;
55
- get pinoConfig(): Params;
56
- get axiosProxyConfig(): AxiosProxyConfig | false;
57
58
  private get;
58
59
  }
@@ -23,20 +23,15 @@ exports.ApiConfigService = void 0;
23
23
  const common_1 = require("@nestjs/common");
24
24
  const config_1 = require("@nestjs/config");
25
25
  const lodash_1 = require("lodash");
26
- const cache_manager_ioredis_yet_1 = require("cache-manager-ioredis-yet");
27
26
  const connect_redis_1 = require("connect-redis");
28
27
  const ioredis_1 = require("ioredis");
29
28
  const common_2 = require("../../common");
29
+ const keyv_1 = require("keyv");
30
+ const redis_1 = require("@keyv/redis");
30
31
  let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
31
32
  constructor(configService) {
32
33
  this.configService = configService;
33
34
  }
34
- static getRootPath() {
35
- if (!ApiConfigService_1.rootPath) {
36
- throw new Error(`rootPath is not set`);
37
- }
38
- return ApiConfigService_1.rootPath;
39
- }
40
35
  get isDev() {
41
36
  return this.nodeEnv === 'dev';
42
37
  }
@@ -55,34 +50,6 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
55
50
  get isTest() {
56
51
  return this.nodeEnv === 'test';
57
52
  }
58
- getNumber(key, defaultValue) {
59
- const value = this.get(key, defaultValue);
60
- try {
61
- return Number(value);
62
- }
63
- catch (_a) {
64
- throw new Error(`key:${key}, value:${value} - is not a number`);
65
- }
66
- }
67
- getBoolean(key, defaultValue) {
68
- const value = this.get(key, defaultValue);
69
- return ApiConfigService_1.toBoolean(value);
70
- }
71
- static toBoolean(value, defaultValue = null) {
72
- try {
73
- return Boolean(JSON.parse(value));
74
- }
75
- catch (_a) {
76
- if (!(0, lodash_1.isNil)(defaultValue)) {
77
- return defaultValue;
78
- }
79
- throw new Error(`value:${value} - is not a boolean`);
80
- }
81
- }
82
- getString(key) {
83
- const value = this.get(key);
84
- return value.replace(/\\n/g, '\n');
85
- }
86
53
  get nodeEnv() {
87
54
  return this.getString('NODE_ENV');
88
55
  }
@@ -92,11 +59,11 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
92
59
  get typeormConfig() {
93
60
  return {
94
61
  autoLoadEntities: true,
95
- keepConnectionAlive: !this.isDev,
96
62
  type: 'mysql',
97
63
  host: this.getString('DB_HOST'),
98
64
  port: this.getNumber('DB_PORT'),
99
65
  username: this.getString('DB_USERNAME'),
66
+ entityPrefix: this.getString('DB_PREFIX', '').toLowerCase(),
100
67
  password: this.getString('DB_PASSWORD'),
101
68
  database: this.getString('DB_DATABASE'),
102
69
  subscribers: [],
@@ -131,6 +98,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
131
98
  return this.getBoolean('CORS_ENABLED');
132
99
  }
133
100
  catch (error) {
101
+ console.log(error);
134
102
  return false;
135
103
  }
136
104
  }
@@ -170,8 +138,9 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
170
138
  saveUninitialized: false,
171
139
  };
172
140
  if (this.getBoolean('SESSION_REDIS_ENABLED')) {
173
- config.store = new connect_redis_1.default({
174
- client: new ioredis_1.default(this.ioRedisConfig),
141
+ const redisClient = new ioredis_1.default(this.ioRedisConfig);
142
+ config.store = new connect_redis_1.RedisStore({
143
+ client: redisClient,
175
144
  prefix: this.getString('SESSION_REDIS_PREFIX'),
176
145
  });
177
146
  }
@@ -232,14 +201,6 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
232
201
  },
233
202
  };
234
203
  }
235
- cacheConfig() {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- return {
238
- isGlobal: true,
239
- store: yield (0, cache_manager_ioredis_yet_1.redisStore)(Object.assign(Object.assign({}, this.ioRedisConfig), { ttl: this.getNumber('CACHE_TTL') })),
240
- };
241
- });
242
- }
243
204
  get pinoConfig() {
244
205
  const transport = this.isDev
245
206
  ? {
@@ -284,6 +245,54 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
284
245
  port: this.getNumber('DIRECT_PROXY_PORT'),
285
246
  };
286
247
  }
248
+ static getRootPath() {
249
+ if (!ApiConfigService_1.rootPath) {
250
+ throw new Error(`rootPath is not set`);
251
+ }
252
+ return ApiConfigService_1.rootPath;
253
+ }
254
+ static toBoolean(value, defaultValue = null) {
255
+ try {
256
+ return Boolean(JSON.parse(value));
257
+ }
258
+ catch (_a) {
259
+ if (!(0, lodash_1.isNil)(defaultValue)) {
260
+ return defaultValue;
261
+ }
262
+ throw new Error(`value:${value} - is not a boolean`);
263
+ }
264
+ }
265
+ getNumber(key, defaultValue) {
266
+ const value = this.get(key, defaultValue);
267
+ try {
268
+ return Number(value);
269
+ }
270
+ catch (_a) {
271
+ throw new Error(`key:${key}, value:${value} - is not a number`);
272
+ }
273
+ }
274
+ getBoolean(key, defaultValue) {
275
+ const value = this.get(key, defaultValue);
276
+ return ApiConfigService_1.toBoolean(value);
277
+ }
278
+ getString(key, defaultValue) {
279
+ const value = this.get(key, defaultValue);
280
+ return value.replace(/\\n/g, '\n');
281
+ }
282
+ cacheConfig() {
283
+ return __awaiter(this, void 0, void 0, function* () {
284
+ const uri = `redis://${this.getString('REDIS_USERNAME') ? this.getString('REDIS_USERNAME') + ':' : ''}${this.getString('REDIS_PASSWORD') ? this.getString('REDIS_PASSWORD') + '@' : ''}${this.getString('REDIS_HOST')}:${this.getNumber('REDIS_PORT')}/${this.getNumber('REDIS_DB')}`;
285
+ const keyvRedis = new redis_1.default(uri);
286
+ const store = new keyv_1.default({
287
+ store: keyvRedis,
288
+ ttl: this.getNumber('CACHE_TTL'),
289
+ });
290
+ return {
291
+ isGlobal: true,
292
+ store,
293
+ };
294
+ });
295
+ }
287
296
  get(key, defaultValue) {
288
297
  const value = this.configService.get(key);
289
298
  if ((0, lodash_1.isNil)(value)) {
@@ -83,7 +83,15 @@ function applyConverters(propertyMetadatas, options, i18n) {
83
83
  const converterResult = typeof converter === 'function' ? converter(meta, options) : converter;
84
84
  const items = {};
85
85
  let message = '';
86
- const originMessage = typeof meta.message === 'function' ? meta.message(meta) : meta.message;
86
+ const originMessage = typeof meta.message === 'function'
87
+ ? meta.message({
88
+ value: undefined,
89
+ constraints: meta.constraints,
90
+ targetName: meta.target.name || '',
91
+ object: {},
92
+ property: meta.propertyName,
93
+ })
94
+ : meta.message;
87
95
  if ((0, lodash_1.isString)(originMessage)) {
88
96
  const [translationKey, argsString] = originMessage.split('|');
89
97
  const args = !!argsString ? JSON.parse(argsString) : {};