@nestjs/common 9.1.1 → 9.1.3

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.
@@ -13,11 +13,27 @@ const default_options_1 = require("./default-options");
13
13
  function createCacheManager() {
14
14
  return {
15
15
  provide: cache_constants_1.CACHE_MANAGER,
16
- useFactory: (options) => {
16
+ useFactory: async (options) => {
17
17
  const cacheManager = (0, load_package_util_1.loadPackage)('cache-manager', 'CacheModule', () => require('cache-manager'));
18
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
19
+ const cacheManagerVersion = require('cache-manager/package.json').version;
20
+ const cacheManagerMajor = cacheManagerVersion.split('.')[0];
21
+ const cachingFactory = async (store, options) => {
22
+ if (cacheManagerMajor < 5) {
23
+ return cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), Object.assign(Object.assign({}, options), { store })));
24
+ }
25
+ let cache = 'memory';
26
+ if (typeof store === 'object' && 'create' in store) {
27
+ cache = store.create;
28
+ }
29
+ else if (typeof store === 'function') {
30
+ cache = store;
31
+ }
32
+ return cacheManager.caching(cache, Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), options));
33
+ };
18
34
  return Array.isArray(options)
19
- ? cacheManager.multiCaching(options.map(store => cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), (store || {})))))
20
- : cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), (options || {})));
35
+ ? cacheManager.multiCaching(await Promise.all(options.map(option => cachingFactory(option.store, option))))
36
+ : cachingFactory(options.store, options);
21
37
  },
22
38
  inject: [cache_module_definition_1.MODULE_OPTIONS_TOKEN],
23
39
  };
@@ -57,7 +57,7 @@ export declare class ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey ex
57
57
  * )
58
58
  * ```
59
59
  */
60
- setExtras<ExtraModuleDefinitionOptions>(extras: ExtraModuleDefinitionOptions, transformDefinition: (definition: DynamicModule, extras: ExtraModuleDefinitionOptions) => DynamicModule): ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
60
+ setExtras<ExtraModuleDefinitionOptions>(extras: ExtraModuleDefinitionOptions, transformDefinition?: (definition: DynamicModule, extras: ExtraModuleDefinitionOptions) => DynamicModule): ConfigurableModuleBuilder<ModuleOptions, StaticMethodKey, FactoryClassMethodKey, ExtraModuleDefinitionOptions>;
61
61
  /**
62
62
  * Dynamic modules must expose public static methods that let you pass in
63
63
  * configuration parameters (control the module's behavior from the outside).
@@ -38,7 +38,7 @@ class ConfigurableModuleBuilder {
38
38
  * )
39
39
  * ```
40
40
  */
41
- setExtras(extras, transformDefinition) {
41
+ setExtras(extras, transformDefinition = def => def) {
42
42
  const builder = new ConfigurableModuleBuilder(this.options, this);
43
43
  builder.extras = extras;
44
44
  builder.transformModuleDefinition = transformDefinition;
@@ -125,7 +125,7 @@ class ConfigurableModuleBuilder {
125
125
  return self.transformModuleDefinition({
126
126
  module: this,
127
127
  providers,
128
- }, options);
128
+ }, Object.assign(Object.assign({}, self.extras), options));
129
129
  }
130
130
  static [asyncMethodKey](options) {
131
131
  const providers = this.createAsyncProviders(options);
@@ -139,7 +139,7 @@ class ConfigurableModuleBuilder {
139
139
  module: this,
140
140
  imports: options.imports || [],
141
141
  providers,
142
- }, options);
142
+ }, Object.assign(Object.assign({}, self.extras), options));
143
143
  }
144
144
  static omitExtras(input, extras) {
145
145
  if (!extras) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "9.1.1",
3
+ "version": "9.1.3",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -22,7 +22,7 @@
22
22
  "uuid": "9.0.0"
23
23
  },
24
24
  "peerDependencies": {
25
- "cache-manager": "*",
25
+ "cache-manager": "<=5",
26
26
  "class-transformer": "*",
27
27
  "class-validator": "*",
28
28
  "reflect-metadata": "^0.1.12",