@mondart/nestjs-common-module 1.1.47 → 1.1.48

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.
@@ -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 forRoot(options: CachingModuleOptions): DynamicModule;
5
- static forRootAsync(options: CachingModuleAsyncOptions): DynamicModule;
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,21 @@ 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 forRoot(options) {
17
+ static register(options) {
18
+ const cacheModuleOptions = {
19
+ isGlobal: true,
20
+ store: redisStore,
21
+ ttl: options.ttl,
22
+ host: options.host,
23
+ port: options.port,
24
+ password: options.password,
25
+ max: 10000,
26
+ };
19
27
  return {
20
28
  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
- ],
29
+ imports: [cache_manager_1.CacheModule.register(cacheModuleOptions)],
36
30
  providers: [
37
31
  {
38
32
  provide: caching_interface_1.CACHING_MODULE_OPTIONS,
@@ -43,7 +37,7 @@ let CachingModule = CachingModule_1 = class CachingModule {
43
37
  exports: [caching_service_1.CachingService],
44
38
  };
45
39
  }
46
- static forRootAsync(options) {
40
+ static registerAsync(options) {
47
41
  return {
48
42
  module: CachingModule_1,
49
43
  imports: [...options.imports],
@@ -52,39 +46,34 @@ let CachingModule = CachingModule_1 = class CachingModule {
52
46
  };
53
47
  }
54
48
  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
49
  if (options.useFactory) {
71
- return {
72
- provide: caching_interface_1.CACHING_MODULE_OPTIONS,
73
- useFactory: options.useFactory,
74
- inject: options.inject || [],
75
- };
50
+ return [
51
+ {
52
+ provide: caching_interface_1.CACHING_MODULE_OPTIONS,
53
+ useFactory: options.useFactory,
54
+ inject: options.inject || [],
55
+ },
56
+ ];
76
57
  }
77
- return {
78
- provide: caching_interface_1.CACHING_MODULE_OPTIONS,
79
- useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
80
- inject: [options.useExisting || options.useClass],
81
- };
82
- }
83
- static createOptionsProvider(options) {
84
- return {
85
- provide: kafka_interface_1.KAFKA_MODULE_OPTIONS,
86
- useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
87
- };
58
+ const useClass = options.useClass || options.useExisting;
59
+ if (useClass) {
60
+ return [
61
+ {
62
+ provide: caching_interface_1.CACHING_MODULE_OPTIONS,
63
+ useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
64
+ inject: [options.useExisting || options.useClass],
65
+ },
66
+ ...(options.useClass
67
+ ? [
68
+ {
69
+ provide: options.useClass,
70
+ useClass: options.useClass,
71
+ },
72
+ ]
73
+ : []),
74
+ ];
75
+ }
76
+ throw new Error('Invalid CachingModuleAsyncOptions');
88
77
  }
89
78
  };
90
79
  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 result;
30
+ return undefined;
31
31
  }
32
32
  async set(key, value, ttlSeconds) {
33
- return await this.cacheManager.set(key, JSON.stringify(value), ttlSeconds * 1000);
33
+ await this.cacheManager.set(key, JSON.stringify(value), ttlSeconds);
34
34
  }
35
35
  async del(key) {
36
- return await this.cacheManager.del(key);
36
+ await this.cacheManager.del(key);
37
37
  }
38
38
  };
39
39
  exports.CachingService = CachingService;