@mondart/nestjs-common-module 1.1.47 → 1.1.49
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/lib/caching/caching.module.d.ts +2 -5
- package/dist/lib/caching/caching.module.js +54 -52
- package/dist/lib/caching/caching.service.d.ts +1 -1
- package/dist/lib/caching/caching.service.js +3 -3
- package/dist/lib/caching/index.d.ts +1 -0
- package/dist/lib/caching/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
2
|
import { CachingModuleAsyncOptions, CachingModuleOptions } from './caching.interface';
|
|
3
3
|
export declare class CachingModule {
|
|
4
|
-
static
|
|
5
|
-
static
|
|
4
|
+
static register(options: CachingModuleOptions): DynamicModule;
|
|
5
|
+
static registerAsync(options: CachingModuleAsyncOptions): DynamicModule;
|
|
6
6
|
private static createAsyncProviders;
|
|
7
|
-
private static createProviders;
|
|
8
|
-
private static createAsyncOptionsProvider;
|
|
9
|
-
private static createOptionsProvider;
|
|
10
7
|
}
|
|
@@ -12,27 +12,20 @@ const common_1 = require("@nestjs/common");
|
|
|
12
12
|
const caching_service_1 = require("./caching.service");
|
|
13
13
|
const cache_manager_1 = require("@nestjs/cache-manager");
|
|
14
14
|
const caching_interface_1 = require("./caching.interface");
|
|
15
|
-
const kafka_interface_1 = require("../kafka/kafka.interface");
|
|
16
15
|
const redisStore = require("cache-manager-redis-store");
|
|
17
16
|
let CachingModule = CachingModule_1 = class CachingModule {
|
|
18
|
-
static
|
|
17
|
+
static register(options) {
|
|
18
|
+
const cacheModuleOptions = {
|
|
19
|
+
store: redisStore,
|
|
20
|
+
ttl: Number(options.ttl),
|
|
21
|
+
host: options.host,
|
|
22
|
+
port: Number(options.port),
|
|
23
|
+
password: options.password,
|
|
24
|
+
max: 10000,
|
|
25
|
+
};
|
|
19
26
|
return {
|
|
20
27
|
module: CachingModule_1,
|
|
21
|
-
imports: [
|
|
22
|
-
cache_manager_1.CacheModule.register({
|
|
23
|
-
isGlobal: true,
|
|
24
|
-
useFactory: async (options) => ({
|
|
25
|
-
store: redisStore,
|
|
26
|
-
ttl: options.ttl,
|
|
27
|
-
host: options.host,
|
|
28
|
-
port: options.port,
|
|
29
|
-
password: options.password,
|
|
30
|
-
max: 10000,
|
|
31
|
-
isGlobal: true,
|
|
32
|
-
}),
|
|
33
|
-
inject: [caching_interface_1.CACHING_MODULE_OPTIONS],
|
|
34
|
-
}),
|
|
35
|
-
],
|
|
28
|
+
imports: [cache_manager_1.CacheModule.register(cacheModuleOptions)],
|
|
36
29
|
providers: [
|
|
37
30
|
{
|
|
38
31
|
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
@@ -40,51 +33,60 @@ let CachingModule = CachingModule_1 = class CachingModule {
|
|
|
40
33
|
},
|
|
41
34
|
caching_service_1.CachingService,
|
|
42
35
|
],
|
|
43
|
-
exports: [caching_service_1.CachingService],
|
|
36
|
+
exports: [caching_service_1.CachingService, cache_manager_1.CacheModule],
|
|
44
37
|
};
|
|
45
38
|
}
|
|
46
|
-
static
|
|
39
|
+
static registerAsync(options) {
|
|
47
40
|
return {
|
|
48
41
|
module: CachingModule_1,
|
|
49
|
-
imports: [
|
|
42
|
+
imports: [
|
|
43
|
+
...(options.imports || []),
|
|
44
|
+
cache_manager_1.CacheModule.registerAsync({
|
|
45
|
+
imports: options.imports || [],
|
|
46
|
+
useFactory: async (cachingOptions) => ({
|
|
47
|
+
store: redisStore,
|
|
48
|
+
ttl: Number(cachingOptions.ttl),
|
|
49
|
+
host: cachingOptions.host,
|
|
50
|
+
port: Number(cachingOptions.port),
|
|
51
|
+
password: cachingOptions.password,
|
|
52
|
+
max: 10000,
|
|
53
|
+
}),
|
|
54
|
+
inject: [caching_interface_1.CACHING_MODULE_OPTIONS],
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
50
57
|
providers: [...this.createAsyncProviders(options), caching_service_1.CachingService],
|
|
51
|
-
exports: [
|
|
58
|
+
exports: [caching_service_1.CachingService, cache_manager_1.CacheModule],
|
|
52
59
|
};
|
|
53
60
|
}
|
|
54
61
|
static createAsyncProviders(options) {
|
|
55
|
-
if (options.useExisting || options.useFactory) {
|
|
56
|
-
return [this.createAsyncOptionsProvider(options)];
|
|
57
|
-
}
|
|
58
|
-
return [
|
|
59
|
-
this.createAsyncOptionsProvider(options),
|
|
60
|
-
{
|
|
61
|
-
provide: options.useClass,
|
|
62
|
-
useClass: options.useClass,
|
|
63
|
-
},
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
static createProviders(options) {
|
|
67
|
-
return [this.createOptionsProvider(options)];
|
|
68
|
-
}
|
|
69
|
-
static createAsyncOptionsProvider(options) {
|
|
70
62
|
if (options.useFactory) {
|
|
71
|
-
return
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
66
|
+
useFactory: options.useFactory,
|
|
67
|
+
inject: options.inject || [],
|
|
68
|
+
},
|
|
69
|
+
];
|
|
76
70
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
const useClass = options.useClass || options.useExisting;
|
|
72
|
+
if (useClass) {
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
76
|
+
useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
|
|
77
|
+
inject: [options.useExisting || options.useClass],
|
|
78
|
+
},
|
|
79
|
+
...(options.useClass
|
|
80
|
+
? [
|
|
81
|
+
{
|
|
82
|
+
provide: options.useClass,
|
|
83
|
+
useClass: options.useClass,
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
: []),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
throw new Error('Invalid CachingModuleAsyncOptions');
|
|
88
90
|
}
|
|
89
91
|
};
|
|
90
92
|
exports.CachingModule = CachingModule;
|
|
@@ -3,7 +3,7 @@ export declare class CachingService {
|
|
|
3
3
|
private cacheManager;
|
|
4
4
|
constructor(cacheManager: Cache);
|
|
5
5
|
getRedisClient(): import("cache-manager").Store;
|
|
6
|
-
get<T>(key: string): Promise<T>;
|
|
6
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
7
7
|
set<T>(key: string, value: T, ttlSeconds: number): Promise<void>;
|
|
8
8
|
del(key: string): Promise<void>;
|
|
9
9
|
}
|
|
@@ -27,13 +27,13 @@ let CachingService = class CachingService {
|
|
|
27
27
|
if (result) {
|
|
28
28
|
return JSON.parse(result);
|
|
29
29
|
}
|
|
30
|
-
return
|
|
30
|
+
return undefined;
|
|
31
31
|
}
|
|
32
32
|
async set(key, value, ttlSeconds) {
|
|
33
|
-
|
|
33
|
+
await this.cacheManager.set(key, JSON.stringify(value), ttlSeconds);
|
|
34
34
|
}
|
|
35
35
|
async del(key) {
|
|
36
|
-
|
|
36
|
+
await this.cacheManager.del(key);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
exports.CachingService = CachingService;
|
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./caching.module"), exports);
|
|
18
18
|
__exportStar(require("./caching.service"), exports);
|
|
19
|
+
__exportStar(require("./caching.interface"), exports);
|