@nestjs/common 11.1.12 → 11.1.14

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 (33) hide show
  1. package/Readme.md +1 -0
  2. package/interfaces/external/cors-options.interface.d.ts +1 -1
  3. package/package.json +2 -2
  4. package/pipes/validation.pipe.js +18 -4
  5. package/services/console-logger.service.js +3 -6
  6. package/cache/cache.constants.d.ts +0 -12
  7. package/cache/cache.constants.js +0 -16
  8. package/cache/cache.module-definition.d.ts +0 -2
  9. package/cache/cache.module-definition.js +0 -10
  10. package/cache/cache.module.d.ts +0 -29
  11. package/cache/cache.module.js +0 -48
  12. package/cache/cache.providers.d.ts +0 -7
  13. package/cache/cache.providers.js +0 -45
  14. package/cache/decorators/cache-key.decorator.d.ts +0 -15
  15. package/cache/decorators/cache-key.decorator.js +0 -21
  16. package/cache/decorators/cache-ttl.decorator.d.ts +0 -16
  17. package/cache/decorators/cache-ttl.decorator.js +0 -7
  18. package/cache/decorators/index.d.ts +0 -2
  19. package/cache/decorators/index.js +0 -5
  20. package/cache/default-options.d.ts +0 -5
  21. package/cache/default-options.js +0 -8
  22. package/cache/index.d.ts +0 -5
  23. package/cache/index.js +0 -8
  24. package/cache/interceptors/cache.interceptor.d.ts +0 -23
  25. package/cache/interceptors/cache.interceptor.js +0 -98
  26. package/cache/interceptors/index.d.ts +0 -1
  27. package/cache/interceptors/index.js +0 -4
  28. package/cache/interfaces/cache-manager.interface.d.ts +0 -76
  29. package/cache/interfaces/cache-manager.interface.js +0 -2
  30. package/cache/interfaces/cache-module.interface.d.ts +0 -56
  31. package/cache/interfaces/cache-module.interface.js +0 -2
  32. package/cache/interfaces/index.d.ts +0 -2
  33. package/cache/interfaces/index.js +0 -5
package/Readme.md CHANGED
@@ -63,6 +63,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
63
63
  <td><a href="https://microsoft.com/" target="_blank"><img src="https://nestjs.com/img/logos/microsoft-logo.png" width="180" valign="middle" /></a></td>
64
64
  <td><a href="https://mojam.co" target="_blank"><img src="https://nestjs.com/img/logos/mojam-logo.png" width="80" valign="middle" /></a></td>
65
65
  <td><a href="https://valor-software.com/" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/valor-software.png" width="170" valign="middle" /></a></td>
66
+ <td><a href="https://serpapi.com/" target="_blank"><img src="https://nestjs.com/img/logos/serpapi-logo.png" width="150" valign="middle" /></a></td>
66
67
  </tr>
67
68
  </table>
68
69
 
@@ -8,7 +8,7 @@ type StaticOrigin = boolean | string | RegExp | (string | RegExp)[];
8
8
  *
9
9
  * @publicApi
10
10
  */
11
- export type CustomOrigin = (requestOrigin: string, callback: (err: Error | null, origin?: StaticOrigin) => void) => void;
11
+ export type CustomOrigin = (requestOrigin: string | undefined, callback: (err: Error | null, origin?: StaticOrigin) => void) => void;
12
12
  /**
13
13
  * Interface describing CORS options that can be set.
14
14
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "11.1.12",
3
+ "version": "11.1.14",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -38,5 +38,5 @@
38
38
  "optional": true
39
39
  }
40
40
  },
41
- "gitHead": "96932ad073cc417e26f0bdea8f58d58145b1ca19"
41
+ "gitHead": "5d31df7eb62d89952d827eadc19123fb441f541e"
42
42
  }
@@ -12,6 +12,11 @@ const load_package_util_1 = require("../utils/load-package.util");
12
12
  const shared_utils_1 = require("../utils/shared.utils");
13
13
  let classValidator = {};
14
14
  let classTransformer = {};
15
+ /**
16
+ * Built-in JavaScript types that should be excluded from prototype stripping
17
+ * to avoid conflicts with test frameworks like Jest's useFakeTimers
18
+ */
19
+ const BUILT_IN_TYPES = [Date, RegExp, Error, Map, Set, WeakMap, WeakSet];
15
20
  /**
16
21
  * @see [Validation](https://docs.nestjs.com/techniques/validation)
17
22
  *
@@ -21,7 +26,7 @@ let ValidationPipe = class ValidationPipe {
21
26
  constructor(options) {
22
27
  options = options || {};
23
28
  const { transform, disableErrorMessages, errorHttpStatusCode, expectedType, transformOptions, validateCustomDecorators, ...validatorOptions } = options;
24
- // @see https://github.com/nestjs/nest/issues/10683#issuecomment-1413690508
29
+ // @see [https://github.com/nestjs/nest/issues/10683#issuecomment-1413690508](https://github.com/nestjs/nest/issues/10683#issuecomment-1413690508)
25
30
  this.validatorOptions = { forbidUnknownValues: false, ...validatorOptions };
26
31
  this.isTransformEnabled = !!transform;
27
32
  this.transformOptions = transformOptions;
@@ -76,7 +81,7 @@ let ValidationPipe = class ValidationPipe {
76
81
  if (originalValue === undefined && originalEntity === '') {
77
82
  // Since SWC requires empty string for validation (to avoid an error),
78
83
  // a fallback is needed to revert to the original value (when undefined).
79
- // @see https://github.com/nestjs/nest/issues/14430
84
+ // @see [https://github.com/nestjs/nest/issues/14430](https://github.com/nestjs/nest/issues/14430)
80
85
  return originalValue;
81
86
  }
82
87
  if (isPrimitive) {
@@ -159,7 +164,7 @@ let ValidationPipe = class ValidationPipe {
159
164
  // SWC requires empty string to be returned instead of an empty object
160
165
  // when the value is nil and the metatype is not a class instance, but a plain object (enum, for example).
161
166
  // Otherwise, the error will be thrown.
162
- // @see https://github.com/nestjs/nest/issues/12680
167
+ // @see [https://github.com/nestjs/nest/issues/12680](https://github.com/nestjs/nest/issues/12680)
163
168
  return '';
164
169
  }
165
170
  stripProtoKeys(value) {
@@ -168,15 +173,24 @@ let ValidationPipe = class ValidationPipe {
168
173
  util_1.types.isTypedArray(value)) {
169
174
  return;
170
175
  }
176
+ // Skip built-in JavaScript primitives to avoid Jest useFakeTimers conflicts
177
+ if (BUILT_IN_TYPES.some(type => value instanceof type)) {
178
+ return;
179
+ }
171
180
  if (Array.isArray(value)) {
172
181
  for (const v of value) {
173
182
  this.stripProtoKeys(v);
174
183
  }
175
184
  return;
176
185
  }
186
+ // Delete dangerous prototype pollution keys
177
187
  delete value.__proto__;
178
- delete value.constructor;
179
188
  delete value.prototype;
189
+ // Only delete constructor if it's NOT a built-in type
190
+ const constructorType = value?.constructor;
191
+ if (constructorType && !BUILT_IN_TYPES.includes(constructorType)) {
192
+ delete value.constructor;
193
+ }
180
194
  for (const key in value) {
181
195
  this.stripProtoKeys(value[key]);
182
196
  }
@@ -284,10 +284,10 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
284
284
  colors: this.options.colors,
285
285
  breakLength,
286
286
  };
287
- if (this.options.maxArrayLength) {
287
+ if (typeof this.options.maxArrayLength !== 'undefined') {
288
288
  inspectOptions.maxArrayLength = this.options.maxArrayLength;
289
289
  }
290
- if (this.options.maxStringLength) {
290
+ if (typeof this.options.maxStringLength !== 'undefined') {
291
291
  inspectOptions.maxStringLength = this.options.maxStringLength;
292
292
  }
293
293
  return inspectOptions;
@@ -329,10 +329,7 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
329
329
  stack: args[1],
330
330
  context: this.context,
331
331
  }
332
- : {
333
- messages: [args[0]],
334
- context: args[1],
335
- };
332
+ : { ...this.getContextAndMessagesToPrint(args) };
336
333
  }
337
334
  const { messages, context } = this.getContextAndMessagesToPrint(args);
338
335
  if (messages?.length <= 1) {
@@ -1,12 +0,0 @@
1
- /**
2
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
3
- * @publicApi
4
- */
5
- export declare const CACHE_MANAGER = "CACHE_MANAGER";
6
- export declare const CACHE_KEY_METADATA = "cache_module:cache_key";
7
- export declare const CACHE_TTL_METADATA = "cache_module:cache_ttl";
8
- /**
9
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
10
- * @publicApi
11
- */
12
- export declare const CACHE_MODULE_OPTIONS: string | symbol;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CACHE_MODULE_OPTIONS = exports.CACHE_TTL_METADATA = exports.CACHE_KEY_METADATA = exports.CACHE_MANAGER = void 0;
4
- const cache_module_definition_1 = require("./cache.module-definition");
5
- /**
6
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
7
- * @publicApi
8
- */
9
- exports.CACHE_MANAGER = 'CACHE_MANAGER';
10
- exports.CACHE_KEY_METADATA = 'cache_module:cache_key';
11
- exports.CACHE_TTL_METADATA = 'cache_module:cache_ttl';
12
- /**
13
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
14
- * @publicApi
15
- */
16
- exports.CACHE_MODULE_OPTIONS = cache_module_definition_1.MODULE_OPTIONS_TOKEN;
@@ -1,2 +0,0 @@
1
- import { CacheModuleOptions } from './interfaces/cache-module.interface';
2
- export declare const ConfigurableModuleClass: import("../module-utils").ConfigurableModuleCls<CacheModuleOptions, "register", "createCacheOptions", {}>, MODULE_OPTIONS_TOKEN: string | symbol;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
5
- const module_utils_1 = require("../module-utils");
6
- _a = new module_utils_1.ConfigurableModuleBuilder({
7
- moduleName: 'Cache',
8
- })
9
- .setFactoryMethodName('createCacheOptions')
10
- .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
@@ -1,29 +0,0 @@
1
- import { DynamicModule } from '../interfaces';
2
- import { ConfigurableModuleClass } from './cache.module-definition';
3
- import { CacheModuleAsyncOptions, CacheModuleOptions } from './interfaces/cache-module.interface';
4
- /**
5
- * Module that provides Nest cache-manager.
6
- *
7
- * @see [Caching](https://docs.nestjs.com/techniques/caching)
8
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
9
- * @publicApi
10
- */
11
- export declare class CacheModule extends ConfigurableModuleClass {
12
- /**
13
- * Configure the cache manager statically.
14
- *
15
- * @param options options to configure the cache manager
16
- *
17
- * @see [Customize caching](https://docs.nestjs.com/techniques/caching#customize-caching)
18
- */
19
- static register<StoreConfig extends Record<any, any> = Record<string, any>>(options?: CacheModuleOptions<StoreConfig>): DynamicModule;
20
- /**
21
- * Configure the cache manager dynamically.
22
- *
23
- * @param options method for dynamically supplying cache manager configuration
24
- * options
25
- *
26
- * @see [Async configuration](https://docs.nestjs.com/techniques/caching#async-configuration)
27
- */
28
- static registerAsync<StoreConfig extends Record<any, any> = Record<string, any>>(options: CacheModuleAsyncOptions<StoreConfig>): DynamicModule;
29
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CacheModule = void 0;
4
- const tslib_1 = require("tslib");
5
- const decorators_1 = require("../decorators");
6
- const cache_constants_1 = require("./cache.constants");
7
- const cache_module_definition_1 = require("./cache.module-definition");
8
- const cache_providers_1 = require("./cache.providers");
9
- /**
10
- * Module that provides Nest cache-manager.
11
- *
12
- * @see [Caching](https://docs.nestjs.com/techniques/caching)
13
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
14
- * @publicApi
15
- */
16
- let CacheModule = class CacheModule extends cache_module_definition_1.ConfigurableModuleClass {
17
- /**
18
- * Configure the cache manager statically.
19
- *
20
- * @param options options to configure the cache manager
21
- *
22
- * @see [Customize caching](https://docs.nestjs.com/techniques/caching#customize-caching)
23
- */
24
- static register(options = {}) {
25
- return Object.assign({ global: options.isGlobal }, super.register(options));
26
- }
27
- /**
28
- * Configure the cache manager dynamically.
29
- *
30
- * @param options method for dynamically supplying cache manager configuration
31
- * options
32
- *
33
- * @see [Async configuration](https://docs.nestjs.com/techniques/caching#async-configuration)
34
- */
35
- static registerAsync(options) {
36
- const moduleDefinition = super.registerAsync(options);
37
- return Object.assign(Object.assign({ global: options.isGlobal }, moduleDefinition), { providers: options.extraProviders
38
- ? moduleDefinition.providers.concat(options.extraProviders)
39
- : moduleDefinition.providers });
40
- }
41
- };
42
- CacheModule = tslib_1.__decorate([
43
- (0, decorators_1.Module)({
44
- providers: [(0, cache_providers_1.createCacheManager)()],
45
- exports: [cache_constants_1.CACHE_MANAGER],
46
- })
47
- ], CacheModule);
48
- exports.CacheModule = CacheModule;
@@ -1,7 +0,0 @@
1
- import { Provider } from '../interfaces';
2
- /**
3
- * Creates a CacheManager Provider.
4
- *
5
- * @publicApi
6
- */
7
- export declare function createCacheManager(): Provider;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCacheManager = void 0;
4
- const load_package_util_1 = require("../utils/load-package.util");
5
- const cache_constants_1 = require("./cache.constants");
6
- const cache_module_definition_1 = require("./cache.module-definition");
7
- const default_options_1 = require("./default-options");
8
- /**
9
- * Creates a CacheManager Provider.
10
- *
11
- * @publicApi
12
- */
13
- function createCacheManager() {
14
- return {
15
- provide: cache_constants_1.CACHE_MANAGER,
16
- useFactory: async (options) => {
17
- const cacheManager = (0, load_package_util_1.loadPackage)('cache-manager', 'CacheModule', () => require('cache-manager'));
18
- const cacheManagerIsv5OrGreater = 'memoryStore' in cacheManager;
19
- const cachingFactory = async (store, options) => {
20
- if (!cacheManagerIsv5OrGreater) {
21
- return cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), Object.assign(Object.assign({}, options), { store })));
22
- }
23
- let cache = 'memory';
24
- default_options_1.defaultCacheOptions.ttl *= 1000;
25
- if (typeof store === 'object') {
26
- if ('create' in store) {
27
- cache = store.create;
28
- }
29
- else {
30
- cache = store;
31
- }
32
- }
33
- else if (typeof store === 'function') {
34
- cache = store;
35
- }
36
- return cacheManager.caching(cache, Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), options));
37
- };
38
- return Array.isArray(options)
39
- ? cacheManager.multiCaching(await Promise.all(options.map(option => cachingFactory(option.store, option))))
40
- : cachingFactory(options.store, options);
41
- },
42
- inject: [cache_module_definition_1.MODULE_OPTIONS_TOKEN],
43
- };
44
- }
45
- exports.createCacheManager = createCacheManager;
@@ -1,15 +0,0 @@
1
- /**
2
- * Decorator that sets the caching key used to store/retrieve cached items for
3
- * Web sockets or Microservice based apps.
4
- *
5
- * For example:
6
- * `@CacheKey('events')`
7
- *
8
- * @param key string naming the field to be used as a cache key
9
- *
10
- * @see [Caching](https://docs.nestjs.com/techniques/caching)
11
- *
12
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
13
- * @publicApi
14
- */
15
- export declare const CacheKey: (key: string) => import("../../decorators").CustomDecorator<string>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CacheKey = void 0;
4
- const decorators_1 = require("../../decorators");
5
- const cache_constants_1 = require("../cache.constants");
6
- /**
7
- * Decorator that sets the caching key used to store/retrieve cached items for
8
- * Web sockets or Microservice based apps.
9
- *
10
- * For example:
11
- * `@CacheKey('events')`
12
- *
13
- * @param key string naming the field to be used as a cache key
14
- *
15
- * @see [Caching](https://docs.nestjs.com/techniques/caching)
16
- *
17
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
18
- * @publicApi
19
- */
20
- const CacheKey = (key) => (0, decorators_1.SetMetadata)(cache_constants_1.CACHE_KEY_METADATA, key);
21
- exports.CacheKey = CacheKey;
@@ -1,16 +0,0 @@
1
- import { ExecutionContext } from '../../interfaces/features/execution-context.interface';
2
- /**
3
- * Decorator that sets the cache ttl setting the duration for cache expiration.
4
- *
5
- * For example: `@CacheTTL(5)`
6
- *
7
- * @param ttl number set the cache expiration time
8
- *
9
- * @see [Caching](https://docs.nestjs.com/techniques/caching)
10
- *
11
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
12
- * @publicApi
13
- */
14
- type CacheTTLFactory = (ctx: ExecutionContext) => Promise<number> | number;
15
- export declare const CacheTTL: (ttl: number | CacheTTLFactory) => import("../../decorators").CustomDecorator<string>;
16
- export {};
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CacheTTL = void 0;
4
- const decorators_1 = require("../../decorators");
5
- const cache_constants_1 = require("../cache.constants");
6
- const CacheTTL = (ttl) => (0, decorators_1.SetMetadata)(cache_constants_1.CACHE_TTL_METADATA, ttl);
7
- exports.CacheTTL = CacheTTL;
@@ -1,2 +0,0 @@
1
- export * from './cache-key.decorator';
2
- export * from './cache-ttl.decorator';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./cache-key.decorator"), exports);
5
- tslib_1.__exportStar(require("./cache-ttl.decorator"), exports);
@@ -1,5 +0,0 @@
1
- export declare const defaultCacheOptions: {
2
- ttl: number;
3
- max: number;
4
- store: string;
5
- };
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultCacheOptions = void 0;
4
- exports.defaultCacheOptions = {
5
- ttl: 5,
6
- max: 100,
7
- store: 'memory',
8
- };
package/cache/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './cache.constants';
2
- export * from './cache.module';
3
- export * from './decorators';
4
- export * from './interceptors';
5
- export * from './interfaces';
package/cache/index.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./cache.constants"), exports);
5
- tslib_1.__exportStar(require("./cache.module"), exports);
6
- tslib_1.__exportStar(require("./decorators"), exports);
7
- tslib_1.__exportStar(require("./interceptors"), exports);
8
- tslib_1.__exportStar(require("./interfaces"), exports);
@@ -1,23 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { CallHandler, ExecutionContext, HttpServer, NestInterceptor } from '../../interfaces';
3
- /** @deprecated Import from the "@nestjs/core" instead. */
4
- export interface HttpAdapterHost<T extends HttpServer = any> {
5
- httpAdapter: T;
6
- }
7
- /**
8
- * @see [Caching](https://docs.nestjs.com/techniques/caching)
9
- *
10
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
11
- * @publicApi
12
- */
13
- export declare class CacheInterceptor implements NestInterceptor {
14
- protected readonly cacheManager: any;
15
- protected readonly reflector: any;
16
- protected readonly httpAdapterHost: HttpAdapterHost;
17
- protected allowedMethods: string[];
18
- private cacheManagerIsv5OrGreater;
19
- constructor(cacheManager: any, reflector: any);
20
- intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
21
- protected trackBy(context: ExecutionContext): string | undefined;
22
- protected isRequestCacheable(context: ExecutionContext): boolean;
23
- }
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CacheInterceptor = void 0;
4
- const tslib_1 = require("tslib");
5
- const rxjs_1 = require("rxjs");
6
- const operators_1 = require("rxjs/operators");
7
- const decorators_1 = require("../../decorators");
8
- const file_stream_1 = require("../../file-stream");
9
- const logger_service_1 = require("../../services/logger.service");
10
- const load_package_util_1 = require("../../utils/load-package.util");
11
- const shared_utils_1 = require("../../utils/shared.utils");
12
- const cache_constants_1 = require("../cache.constants");
13
- /** @deprecated */
14
- const HTTP_ADAPTER_HOST = 'HttpAdapterHost';
15
- /** @deprecated */
16
- const REFLECTOR = 'Reflector';
17
- /**
18
- * @see [Caching](https://docs.nestjs.com/techniques/caching)
19
- *
20
- * @deprecated `CacheModule` (from the `@nestjs/common` package) is deprecated and will be removed in the next major release. Please, use the `@nestjs/cache-manager` package instead
21
- * @publicApi
22
- */
23
- let CacheInterceptor = class CacheInterceptor {
24
- constructor(cacheManager, reflector) {
25
- this.cacheManager = cacheManager;
26
- this.reflector = reflector;
27
- this.allowedMethods = ['GET'];
28
- // We need to check if the cache-manager package is v5 or greater
29
- // because the set method signature changed in v5
30
- const cacheManagerPackage = (0, load_package_util_1.loadPackage)('cache-manager', 'CacheModule', () => require('cache-manager'));
31
- this.cacheManagerIsv5OrGreater = 'memoryStore' in cacheManagerPackage;
32
- logger_service_1.Logger.warn('DEPRECATED! "CacheModule" (from the "@nestjs/common" package) is deprecated and will be removed in the next major release. Please, use the "@nestjs/cache-manager" package instead.');
33
- }
34
- async intercept(context, next) {
35
- var _a;
36
- const key = this.trackBy(context);
37
- const ttlValueOrFactory = (_a = this.reflector.get(cache_constants_1.CACHE_TTL_METADATA, context.getHandler())) !== null && _a !== void 0 ? _a : null;
38
- if (!key) {
39
- return next.handle();
40
- }
41
- try {
42
- const value = await this.cacheManager.get(key);
43
- if (!(0, shared_utils_1.isNil)(value)) {
44
- return (0, rxjs_1.of)(value);
45
- }
46
- const ttl = (0, shared_utils_1.isFunction)(ttlValueOrFactory)
47
- ? await ttlValueOrFactory(context)
48
- : ttlValueOrFactory;
49
- return next.handle().pipe((0, operators_1.tap)(async (response) => {
50
- if (response instanceof file_stream_1.StreamableFile) {
51
- return;
52
- }
53
- const args = [key, response];
54
- if (!(0, shared_utils_1.isNil)(ttl)) {
55
- args.push(this.cacheManagerIsv5OrGreater ? ttl : { ttl });
56
- }
57
- try {
58
- await this.cacheManager.set(...args);
59
- }
60
- catch (err) {
61
- logger_service_1.Logger.error(`An error has occurred when inserting "key: ${key}", "value: ${response}"`, 'CacheInterceptor');
62
- }
63
- }));
64
- }
65
- catch (_b) {
66
- return next.handle();
67
- }
68
- }
69
- trackBy(context) {
70
- const httpAdapter = this.httpAdapterHost.httpAdapter;
71
- const isHttpApp = httpAdapter && !!httpAdapter.getRequestMethod;
72
- const cacheMetadata = this.reflector.get(cache_constants_1.CACHE_KEY_METADATA, context.getHandler());
73
- if (!isHttpApp || cacheMetadata) {
74
- return cacheMetadata;
75
- }
76
- const request = context.getArgByIndex(0);
77
- if (!this.isRequestCacheable(context)) {
78
- return undefined;
79
- }
80
- return httpAdapter.getRequestUrl(request);
81
- }
82
- isRequestCacheable(context) {
83
- const req = context.switchToHttp().getRequest();
84
- return this.allowedMethods.includes(req.method);
85
- }
86
- };
87
- tslib_1.__decorate([
88
- (0, decorators_1.Optional)(),
89
- (0, decorators_1.Inject)(HTTP_ADAPTER_HOST),
90
- tslib_1.__metadata("design:type", Object)
91
- ], CacheInterceptor.prototype, "httpAdapterHost", void 0);
92
- CacheInterceptor = tslib_1.__decorate([
93
- (0, decorators_1.Injectable)(),
94
- tslib_1.__param(0, (0, decorators_1.Inject)(cache_constants_1.CACHE_MANAGER)),
95
- tslib_1.__param(1, (0, decorators_1.Inject)(REFLECTOR)),
96
- tslib_1.__metadata("design:paramtypes", [Object, Object])
97
- ], CacheInterceptor);
98
- exports.CacheInterceptor = CacheInterceptor;
@@ -1 +0,0 @@
1
- export * from './cache.interceptor';
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./cache.interceptor"), exports);
@@ -1,76 +0,0 @@
1
- export interface LiteralObject {
2
- [key: string]: any;
3
- }
4
- /**
5
- * Interface defining a cache store. Implement this interface to create a custom
6
- * cache store.
7
- *
8
- * @publicApi
9
- */
10
- export interface CacheStore {
11
- /**
12
- * Create a key/value pair in the cache.
13
- *
14
- * @param key cache key
15
- * @param value cache value
16
- */
17
- set<T>(key: string, value: T, options?: CacheStoreSetOptions<T> | number): Promise<void> | void;
18
- /**
19
- * Retrieve a key/value pair from the cache.
20
- *
21
- * @param key cache key
22
- */
23
- get<T>(key: string): Promise<T | undefined> | T | undefined;
24
- /**
25
- * Destroy a key/value pair from the cache.
26
- *
27
- * @param key cache key
28
- */
29
- del?(key: string): void | Promise<void>;
30
- }
31
- export interface CacheStoreSetOptions<T> {
32
- /**
33
- * Time to live - amount of time in seconds that a response is cached before it
34
- * is deleted. Defaults based on your cache manager settings.
35
- */
36
- ttl?: ((value: T) => number) | number;
37
- }
38
- /**
39
- * Interface defining a factory to create a cache store.
40
- *
41
- * @publicApi
42
- */
43
- export type CacheStoreFactory = {
44
- /**
45
- * Return a configured cache store.
46
- *
47
- * @param args Cache manager options received from `CacheModule.register()`
48
- * or `CacheModule.registerAsync()`
49
- */
50
- create(args: LiteralObject): CacheStore;
51
- } | ((args: LiteralObject) => CacheStore | Promise<CacheStore>);
52
- /**
53
- * Interface defining Cache Manager configuration options.
54
- *
55
- * @publicApi
56
- */
57
- export interface CacheManagerOptions {
58
- /**
59
- * Cache storage manager. Default is `'memory'` (in-memory store). See
60
- * [Different stores](https://docs.nestjs.com/techniques/caching#different-stores)
61
- * for more info.
62
- */
63
- store?: string | CacheStoreFactory | CacheStore;
64
- /**
65
- * Time to live - amount of time that a response is cached before it
66
- * is deleted. Subsequent request will call through the route handler and refresh
67
- * the cache. Defaults to 5 seconds. In `cache-manager@^4` this value is in seconds.
68
- * In `cache-manager@^5` this value is in milliseconds.
69
- */
70
- ttl?: number;
71
- /**
72
- * Maximum number of responses to store in the cache. Defaults to 100.
73
- */
74
- max?: number;
75
- isCacheableValue?: (value: any) => boolean;
76
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,56 +0,0 @@
1
- import { Provider, Type } from '../../interfaces';
2
- import { ConfigurableModuleAsyncOptions } from '../../module-utils';
3
- import { CacheManagerOptions } from './cache-manager.interface';
4
- export type CacheModuleOptions<StoreConfig extends Record<any, any> = Record<string, any>> = CacheManagerOptions & StoreConfig & {
5
- /**
6
- * If "true', register `CacheModule` as a global module.
7
- */
8
- isGlobal?: boolean;
9
- };
10
- /**
11
- * Interface describing a `CacheOptionsFactory`. Providers supplying configuration
12
- * options for the Cache module must implement this interface.
13
- *
14
- * @see [Async configuration](https://docs.nestjs.com/techniques/caching#async-configuration)
15
- *
16
- * @publicApi
17
- */
18
- export interface CacheOptionsFactory<StoreConfig extends Record<any, any> = Record<string, any>> {
19
- createCacheOptions(): Promise<CacheModuleOptions<StoreConfig>> | CacheModuleOptions<StoreConfig>;
20
- }
21
- /**
22
- * Options for dynamically configuring the Cache module.
23
- *
24
- * @see [Async configuration](https://docs.nestjs.com/techniques/caching#async-configuration)
25
- *
26
- * @publicApi
27
- */
28
- export interface CacheModuleAsyncOptions<StoreConfig extends Record<any, any> = Record<string, any>> extends ConfigurableModuleAsyncOptions<CacheModuleOptions<StoreConfig>, keyof CacheOptionsFactory> {
29
- /**
30
- * Injection token resolving to an existing provider. The provider must implement
31
- * the `CacheOptionsFactory` interface.
32
- */
33
- useExisting?: Type<CacheOptionsFactory<StoreConfig>>;
34
- /**
35
- * Injection token resolving to a class that will be instantiated as a provider.
36
- * The class must implement the `CacheOptionsFactory` interface.
37
- */
38
- useClass?: Type<CacheOptionsFactory<StoreConfig>>;
39
- /**
40
- * Function returning options (or a Promise resolving to options) to configure the
41
- * cache module.
42
- */
43
- useFactory?: (...args: any[]) => Promise<CacheModuleOptions<StoreConfig>> | CacheModuleOptions<StoreConfig>;
44
- /**
45
- * Dependencies that a Factory may inject.
46
- */
47
- inject?: any[];
48
- /**
49
- * Extra providers to be registered within a scope of this module.
50
- */
51
- extraProviders?: Provider[];
52
- /**
53
- * If "true', register `CacheModule` as a global module.
54
- */
55
- isGlobal?: boolean;
56
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- export * from './cache-manager.interface';
2
- export * from './cache-module.interface';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./cache-manager.interface"), exports);
5
- tslib_1.__exportStar(require("./cache-module.interface"), exports);