@nestjs/common 8.2.0 → 8.2.4

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/Readme.md CHANGED
@@ -57,10 +57,13 @@ With official support, you can get expert help straight from Nest core team. We
57
57
  Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
58
58
 
59
59
  #### Principal Sponsors
60
- <table style="text-align:center;"><tr><td>
60
+ <table style="text-align:center;"><tr>
61
+ <td><a href="https://trilon.io" target="_blank"><img src="https://nestjs.com/img/trilon.svg" width="200" valign="middle" /></a></td>
62
+ <td><a href="https://www.redhat.com" target="_blank"><img src="https://nestjs.com/img/red-hat-logo.svg" width="200" valign="middle" /></a></td>
63
+ <td>
61
64
  <a href="https://github.com/Sanofi-IADC" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/sanofi.png" width="180" valign="middle" /></a></td>
62
65
  <td>
63
- <a href="https://trilon.io" target="_blank"><img src="https://nestjs.com/img/trilon.svg" width="200" valign="middle" /></a></td>
66
+ <a href="https://nx.dev" target="_blank"><img src="https://nestjs.com/img/nx-logo.png" height="45" valign="middle" /></a></td>
64
67
  </tr></table>
65
68
 
66
69
  #### Gold Sponsors
@@ -78,7 +81,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
78
81
  <table style="text-align:center;"><tr><td>
79
82
  <a href="https://neoteric.eu/" target="_blank"><img src="https://nestjs.com/img/neoteric-cut.png" width="120" valign="middle" /></a> </td><td>
80
83
  <a href="http://gojob.com" target="_blank"><img src="http://nestjs.com/img/gojob-logo.png" valign="middle" width="100" /></a> </td><td>
81
- <a href="http://www.leogistics.com" target="_blank"><img src="https://nestjs.com/img/leogistics-logo.jpeg" width="150" valign="middle" /></td><td>
84
+ <a href="https://www.myleodsc.com/" target="_blank"><img src="https://nestjs.com/img/myleo-logo.png" width="180" valign="middle" /></td><td>
82
85
  <a href="https://careers.meetdandy.com/?gh_src=063ba61e3us" target="_blank"><img src="https://nestjs.com/img/dandy-roles-logo.svg" width="150" valign="middle" /></td><td>
83
86
  <a href="https://www.castlecraft.in" target="_blank"><img src="https://nestjs.com/img/castlecraft-logo.png" width="150" valign="middle" /></td>
84
87
  <td><a href="https://www.tinystacks.com" target="_blank"><img src="https://nestjs.com/img/tinystacks-logo.png#1" width="140" valign="middle" /></td></tr></table>
@@ -113,6 +116,8 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
113
116
  <td align="center" valign="middle"><a href="https://studyclerk.com/pay-for-research-paper" target="_blank"><img src="https://nestjs.com/img/studyclerk-logo.png" width="125" valign="middle" /></a></td><td align="center" valign="middle"><a href="https://xyndata.com" target="_blank"><img src="https://nestjs.com/img/xyndata-logo.png" width="125" valign="middle" /></a></td></tr><tr>
114
117
  <td align="center" valign="middle"><a href="https://www.anonymistic.com/" target="_blank"><img src="https://nestjs.com/img/anonymistic-logo.png" width="125" valign="middle" /></a></td>
115
118
  <td align="center" valign="middle"><a href="https://www.naologic.com/" target="_blank"><img src="https://nestjs.com/img/naologic-logo.svg" width="125" valign="middle" /></a></td>
119
+ <td align="center" valign="middle"><a href="https://messaged.com/" target="_blank"><img src="https://nestjs.com/img/messaged-logo.png" width="50" valign="middle" /></a></td>
120
+ <td align="center" valign="middle"><a href="https://triplecore.io" target="_blank"><img src="https://nestjs.com/img/triplecore-logo.svg" width="50" valign="middle" /></a></td>
116
121
  </tr></table>
117
122
 
118
123
  ## Backers
@@ -15,7 +15,7 @@ export declare class CacheModule {
15
15
  *
16
16
  * @see [Customize caching](https://docs.nestjs.com/techniques/caching#customize-caching)
17
17
  */
18
- static register(options?: CacheModuleOptions): DynamicModule;
18
+ static register<StoreConfig extends Record<any, any> = Record<string, any>>(options?: CacheModuleOptions<StoreConfig>): DynamicModule;
19
19
  /**
20
20
  * Configure the cache manager dynamically.
21
21
  *
@@ -24,7 +24,7 @@ export declare class CacheModule {
24
24
  *
25
25
  * @see [Async configuration](https://docs.nestjs.com/techniques/caching#async-configuration)
26
26
  */
27
- static registerAsync(options: CacheModuleAsyncOptions): DynamicModule;
27
+ static registerAsync<StoreConfig extends Record<any, any> = Record<string, any>>(options: CacheModuleAsyncOptions<StoreConfig>): DynamicModule;
28
28
  private static createAsyncProviders;
29
29
  private static createAsyncOptionsProvider;
30
30
  }
@@ -1,12 +1,11 @@
1
1
  import { ModuleMetadata, Provider, Type } from '../../interfaces';
2
2
  import { CacheManagerOptions } from './cache-manager.interface';
3
- export interface CacheModuleOptions extends CacheManagerOptions {
3
+ export declare type CacheModuleOptions<StoreConfig extends Record<any, any> = Record<string, any>> = CacheManagerOptions & StoreConfig & {
4
4
  /**
5
5
  * If "true', register `CacheModule` as a global module.
6
6
  */
7
7
  isGlobal?: boolean;
8
- [key: string]: any;
9
- }
8
+ };
10
9
  /**
11
10
  * Interface describing a `CacheOptionsFactory`. Providers supplying configuration
12
11
  * options for the Cache module must implement this interface.
@@ -15,8 +14,8 @@ export interface CacheModuleOptions extends CacheManagerOptions {
15
14
  *
16
15
  * @publicApi
17
16
  */
18
- export interface CacheOptionsFactory {
19
- createCacheOptions(): Promise<CacheModuleOptions> | CacheModuleOptions;
17
+ export interface CacheOptionsFactory<StoreConfig extends Record<any, any> = Record<string, any>> {
18
+ createCacheOptions(): Promise<CacheModuleOptions<StoreConfig>> | CacheModuleOptions<StoreConfig>;
20
19
  }
21
20
  /**
22
21
  * Options for dynamically configuring the Cache module.
@@ -25,22 +24,22 @@ export interface CacheOptionsFactory {
25
24
  *
26
25
  * @publicApi
27
26
  */
28
- export interface CacheModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
27
+ export interface CacheModuleAsyncOptions<StoreConfig extends Record<any, any> = Record<string, any>> extends Pick<ModuleMetadata, 'imports'> {
29
28
  /**
30
29
  * Injection token resolving to an existing provider. The provider must implement
31
30
  * the `CacheOptionsFactory` interface.
32
31
  */
33
- useExisting?: Type<CacheOptionsFactory>;
32
+ useExisting?: Type<CacheOptionsFactory<StoreConfig>>;
34
33
  /**
35
34
  * Injection token resolving to a class that will be instantiated as a provider.
36
35
  * The class must implement the `CacheOptionsFactory` interface.
37
36
  */
38
- useClass?: Type<CacheOptionsFactory>;
37
+ useClass?: Type<CacheOptionsFactory<StoreConfig>>;
39
38
  /**
40
39
  * Function returning options (or a Promise resolving to options) to configure the
41
40
  * cache module.
42
41
  */
43
- useFactory?: (...args: any[]) => Promise<CacheModuleOptions> | CacheModuleOptions;
42
+ useFactory?: (...args: any[]) => Promise<CacheModuleOptions<StoreConfig>> | CacheModuleOptions<StoreConfig>;
44
43
  /**
45
44
  * Dependencies that a Factory may inject.
46
45
  */
package/constants.d.ts CHANGED
@@ -29,3 +29,6 @@ export declare const REDIRECT_METADATA = "__redirect__";
29
29
  export declare const RESPONSE_PASSTHROUGH_METADATA = "__responsePassthrough__";
30
30
  export declare const SSE_METADATA = "__sse__";
31
31
  export declare const VERSION_METADATA = "__version__";
32
+ export declare const INJECTABLE_WATERMARK = "__injectable__";
33
+ export declare const CONTROLLER_WATERMARK = "__controller__";
34
+ export declare const CATCH_WATERMARK = "__catch__";
package/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VERSION_METADATA = exports.SSE_METADATA = exports.RESPONSE_PASSTHROUGH_METADATA = exports.REDIRECT_METADATA = exports.HEADERS_METADATA = exports.MODULE_PATH = exports.HTTP_CODE_METADATA = exports.INTERCEPTORS_METADATA = exports.RENDER_METADATA = exports.GUARDS_METADATA = exports.PIPES_METADATA = exports.FILTER_CATCH_EXCEPTIONS = exports.EXCEPTION_FILTERS_METADATA = exports.CUSTOM_ROUTE_AGRS_METADATA = exports.ROUTE_ARGS_METADATA = exports.METHOD_METADATA = exports.SCOPE_OPTIONS_METADATA = exports.OPTIONAL_PROPERTY_DEPS_METADATA = exports.PROPERTY_DEPS_METADATA = exports.OPTIONAL_DEPS_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.PATH_METADATA = exports.HOST_METADATA = exports.GLOBAL_MODULE_METADATA = exports.MODULE_METADATA = void 0;
3
+ exports.CATCH_WATERMARK = exports.CONTROLLER_WATERMARK = exports.INJECTABLE_WATERMARK = exports.VERSION_METADATA = exports.SSE_METADATA = exports.RESPONSE_PASSTHROUGH_METADATA = exports.REDIRECT_METADATA = exports.HEADERS_METADATA = exports.MODULE_PATH = exports.HTTP_CODE_METADATA = exports.INTERCEPTORS_METADATA = exports.RENDER_METADATA = exports.GUARDS_METADATA = exports.PIPES_METADATA = exports.FILTER_CATCH_EXCEPTIONS = exports.EXCEPTION_FILTERS_METADATA = exports.CUSTOM_ROUTE_AGRS_METADATA = exports.ROUTE_ARGS_METADATA = exports.METHOD_METADATA = exports.SCOPE_OPTIONS_METADATA = exports.OPTIONAL_PROPERTY_DEPS_METADATA = exports.PROPERTY_DEPS_METADATA = exports.OPTIONAL_DEPS_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.PATH_METADATA = exports.HOST_METADATA = exports.GLOBAL_MODULE_METADATA = exports.MODULE_METADATA = void 0;
4
4
  exports.MODULE_METADATA = {
5
5
  IMPORTS: 'imports',
6
6
  PROVIDERS: 'providers',
@@ -32,3 +32,6 @@ exports.REDIRECT_METADATA = '__redirect__';
32
32
  exports.RESPONSE_PASSTHROUGH_METADATA = '__responsePassthrough__';
33
33
  exports.SSE_METADATA = '__sse__';
34
34
  exports.VERSION_METADATA = '__version__';
35
+ exports.INJECTABLE_WATERMARK = '__injectable__';
36
+ exports.CONTROLLER_WATERMARK = '__controller__';
37
+ exports.CATCH_WATERMARK = '__catch__';
@@ -21,6 +21,7 @@ const constants_1 = require("../../constants");
21
21
  */
22
22
  function Catch(...exceptions) {
23
23
  return (target) => {
24
+ Reflect.defineMetadata(constants_1.CATCH_WATERMARK, true, target);
24
25
  Reflect.defineMetadata(constants_1.FILTER_CATCH_EXCEPTIONS, exceptions, target);
25
26
  };
26
27
  }
@@ -47,9 +47,12 @@ function Controller(prefixOrOptions) {
47
47
  prefixOrOptions.path || defaultPath,
48
48
  prefixOrOptions.host,
49
49
  { scope: prefixOrOptions.scope },
50
- prefixOrOptions.version,
50
+ Array.isArray(prefixOrOptions.version)
51
+ ? Array.from(new Set(prefixOrOptions.version))
52
+ : prefixOrOptions.version,
51
53
  ];
52
54
  return (target) => {
55
+ Reflect.defineMetadata(constants_1.CONTROLLER_WATERMARK, true, target);
53
56
  Reflect.defineMetadata(constants_1.PATH_METADATA, path, target);
54
57
  Reflect.defineMetadata(constants_1.HOST_METADATA, host, target);
55
58
  Reflect.defineMetadata(constants_1.SCOPE_OPTIONS_METADATA, scopeOptions, target);
@@ -33,6 +33,7 @@ const constants_1 = require("../../constants");
33
33
  */
34
34
  function Injectable(options) {
35
35
  return (target) => {
36
+ Reflect.defineMetadata(constants_1.INJECTABLE_WATERMARK, true, target);
36
37
  Reflect.defineMetadata(constants_1.SCOPE_OPTIONS_METADATA, options, target);
37
38
  };
38
39
  }
@@ -8,6 +8,10 @@ const constants_1 = require("../../constants");
8
8
  * @publicApi
9
9
  */
10
10
  function Version(version) {
11
+ if (Array.isArray(version)) {
12
+ // Drop duplicated versions
13
+ version = Array.from(new Set(version));
14
+ }
11
15
  return (target, key, descriptor) => {
12
16
  Reflect.defineMetadata(constants_1.VERSION_METADATA, version, descriptor.value);
13
17
  return descriptor;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StreamableFile = void 0;
4
4
  const stream_1 = require("stream");
5
+ const shared_utils_1 = require("../utils/shared.utils");
5
6
  class StreamableFile {
6
7
  constructor(bufferOrReadStream, options = {}) {
7
8
  this.options = options;
@@ -10,8 +11,7 @@ class StreamableFile {
10
11
  this.stream.push(bufferOrReadStream);
11
12
  this.stream.push(null);
12
13
  }
13
- else if (bufferOrReadStream.pipe &&
14
- typeof bufferOrReadStream.pipe === 'function') {
14
+ else if (bufferOrReadStream.pipe && shared_utils_1.isFunction(bufferOrReadStream.pipe)) {
15
15
  this.stream = bufferOrReadStream;
16
16
  }
17
17
  }
@@ -1,6 +1,5 @@
1
1
  import { ShutdownSignal } from '../enums/shutdown-signal.enum';
2
2
  import { LoggerService, LogLevel } from '../services/logger.service';
3
- import { Abstract } from './abstract.interface';
4
3
  import { DynamicModule } from './modules';
5
4
  import { Type } from './type.interface';
6
5
  /**
@@ -18,14 +17,14 @@ export interface INestApplicationContext {
18
17
  * Retrieves an instance of either injectable or controller, otherwise, throws exception.
19
18
  * @returns {TResult}
20
19
  */
21
- get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, options?: {
20
+ get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options?: {
22
21
  strict: boolean;
23
22
  }): TResult;
24
23
  /**
25
24
  * Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
26
25
  * @returns {Promise<TResult>}
27
26
  */
28
- resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, contextId?: {
27
+ resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
29
28
  id: number;
30
29
  }, options?: {
31
30
  strict: boolean;
@@ -43,7 +42,8 @@ export interface INestApplicationContext {
43
42
  */
44
43
  close(): Promise<void>;
45
44
  /**
46
- * Sets custom logger service
45
+ * Sets custom logger service.
46
+ * Flushes buffered logs if auto flush is on.
47
47
  * @returns {void}
48
48
  */
49
49
  useLogger(logger: LoggerService | LogLevel[] | false): void;
@@ -5,7 +5,7 @@ import { VersioningType } from '../enums/version-type.enum';
5
5
  * @publicApi
6
6
  */
7
7
  export declare const VERSION_NEUTRAL: unique symbol;
8
- export declare type VersionValue = string | string[] | typeof VERSION_NEUTRAL;
8
+ export declare type VersionValue = string | typeof VERSION_NEUTRAL | Array<string | typeof VERSION_NEUTRAL>;
9
9
  /**
10
10
  * @publicApi
11
11
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "8.2.0",
3
+ "version": "8.2.4",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -115,18 +115,18 @@ let ParseArrayPipe = class ParseArrayPipe {
115
115
  if (this.options.items === Number) {
116
116
  const value = originalValue !== null && originalValue !== '' ? +originalValue : NaN;
117
117
  if (isNaN(value)) {
118
- throw this.exceptionFactory(`${typeof index !== 'undefined' ? `[${index}] ` : ''}item must be a number`);
118
+ throw this.exceptionFactory(`${shared_utils_1.isUndefined(index) ? '' : `[${index}] `}item must be a number`);
119
119
  }
120
120
  return value;
121
121
  }
122
122
  else if (this.options.items === String) {
123
- if (typeof originalValue !== 'string') {
123
+ if (!shared_utils_1.isString(originalValue)) {
124
124
  return `${originalValue}`;
125
125
  }
126
126
  }
127
127
  else if (this.options.items === Boolean) {
128
128
  if (typeof originalValue !== 'boolean') {
129
- throw this.exceptionFactory(`${typeof index !== 'undefined' ? `[${index}] ` : ''}item must be a boolean value`);
129
+ throw this.exceptionFactory(`${shared_utils_1.isUndefined(index) ? '' : `[${index}] `}item must be a boolean value`);
130
130
  }
131
131
  }
132
132
  return originalValue;
@@ -38,7 +38,7 @@ let ParseEnumPipe = class ParseEnumPipe {
38
38
  }
39
39
  isEnum(value) {
40
40
  const enumValues = Object.keys(this.enumType).map(item => this.enumType[item]);
41
- return enumValues.indexOf(value) >= 0;
41
+ return enumValues.includes(value);
42
42
  }
43
43
  };
44
44
  ParseEnumPipe = tslib_1.__decorate([
@@ -121,7 +121,7 @@ let ValidationPipe = class ValidationPipe {
121
121
  delete value.__proto__;
122
122
  const keys = Object.keys(value);
123
123
  iterare_1.iterate(keys)
124
- .filter(key => typeof value[key] === 'object' && value[key])
124
+ .filter(key => shared_utils_1.isObject(value[key]) && value[key])
125
125
  .forEach(key => this.stripProtoKeys(value[key]));
126
126
  }
127
127
  isPrimitive(value) {
@@ -147,7 +147,7 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
147
147
  return { messages: args, context: this.context };
148
148
  }
149
149
  const lastElement = args[args.length - 1];
150
- const isContext = typeof lastElement === 'string';
150
+ const isContext = shared_utils_1.isString(lastElement);
151
151
  if (!isContext) {
152
152
  return { messages: args, context: this.context };
153
153
  }
@@ -162,7 +162,7 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
162
162
  return { messages, context };
163
163
  }
164
164
  const lastElement = messages[messages.length - 1];
165
- const isStack = typeof lastElement === 'string';
165
+ const isStack = shared_utils_1.isString(lastElement);
166
166
  if (!isStack) {
167
167
  return { messages, context };
168
168
  }
package/utils/is-uuid.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isUUID = void 0;
4
4
  const exceptions_1 = require("../exceptions");
5
+ const shared_utils_1 = require("./shared.utils");
5
6
  const uuid = {
6
7
  3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
7
8
  4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
@@ -9,7 +10,7 @@ const uuid = {
9
10
  all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
10
11
  };
11
12
  function isUUID(str, version = 'all') {
12
- if (typeof str !== 'string') {
13
+ if (!shared_utils_1.isString(str)) {
13
14
  throw new exceptions_1.BadRequestException('The value passed as UUID is not a string');
14
15
  }
15
16
  const pattern = uuid[version];