@nestjs/core 8.0.9 → 8.1.1

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
@@ -79,7 +79,7 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
79
79
  <a href="https://neoteric.eu/" target="_blank"><img src="https://nestjs.com/img/neoteric-cut.png" width="120" valign="middle" /></a> </td><td>
80
80
  <a href="http://gojob.com" target="_blank"><img src="http://nestjs.com/img/gojob-logo.png" valign="middle" width="100" /></a> </td><td>
81
81
  <a href="http://www.leogistics.com" target="_blank"><img src="https://nestjs.com/img/leogistics-logo.jpeg" width="150" valign="middle" /></td><td>
82
- <a href="http://www.meetdandy.com" target="_blank"><img src="https://nestjs.com/img/dandy-roles-logo.svg" width="150" valign="middle" /></td><td>
82
+ <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
83
  <a href="https://www.castlecraft.in" target="_blank"><img src="https://nestjs.com/img/castlecraft-logo.png" width="150" valign="middle" /></td>
84
84
  <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>
85
85
 
package/index.js CHANGED
@@ -4,7 +4,7 @@ exports.NestFactory = exports.APP_PIPE = exports.APP_INTERCEPTOR = exports.APP_G
4
4
  const tslib_1 = require("tslib");
5
5
  /*
6
6
  * Nest @core
7
- * Copyright(c) 2017 - 2020 Kamil Mysliwiec
7
+ * Copyright(c) 2017 - 2021 Kamil Mysliwiec
8
8
  * https://nestjs.com
9
9
  * MIT Licensed
10
10
  */
@@ -40,6 +40,7 @@ export interface InjectorDependencyContext {
40
40
  dependencies?: InjectorDependency[];
41
41
  }
42
42
  export declare class Injector {
43
+ private logger;
43
44
  loadPrototype<T>({ token }: InstanceWrapper<T>, collection: Map<InstanceToken, InstanceWrapper<T>>, contextId?: ContextId): void;
44
45
  loadInstance<T>(wrapper: InstanceWrapper<T>, collection: Map<InstanceToken, InstanceWrapper>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
45
46
  loadMiddleware(wrapper: InstanceWrapper, collection: Map<InstanceToken, InstanceWrapper>, moduleRef: Module, contextId?: ContextId, inquirer?: InstanceWrapper): Promise<void>;
@@ -71,4 +72,9 @@ export declare class Injector {
71
72
  private isInquirerRequest;
72
73
  private isInquirer;
73
74
  private addDependencyMetadata;
75
+ private getTokenName;
76
+ private printResolvingDependenciesLog;
77
+ private printLookingForProviderLog;
78
+ private printFoundInModuleLog;
79
+ private isDebugMode;
74
80
  }
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Injector = void 0;
4
+ const common_1 = require("@nestjs/common");
4
5
  const constants_1 = require("@nestjs/common/constants");
6
+ const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
5
7
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
8
  const iterare_1 = require("iterare");
7
9
  const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
@@ -11,6 +13,9 @@ const constants_2 = require("./constants");
11
13
  const inquirer_1 = require("./inquirer");
12
14
  const instance_wrapper_1 = require("./instance-wrapper");
13
15
  class Injector {
16
+ constructor() {
17
+ this.logger = new common_1.Logger('InjectorLogger');
18
+ }
14
19
  loadPrototype({ token }, collection, contextId = constants_2.STATIC_CONTEXT) {
15
20
  if (!collection) {
16
21
  return;
@@ -145,6 +150,8 @@ class Injector {
145
150
  return param.forwardRef();
146
151
  }
147
152
  async resolveComponentInstance(moduleRef, token, dependencyContext, wrapper, contextId = constants_2.STATIC_CONTEXT, inquirer, keyOrIndex) {
153
+ this.printResolvingDependenciesLog(token, inquirer);
154
+ this.printLookingForProviderLog(token, moduleRef);
148
155
  const providers = moduleRef.providers;
149
156
  const instanceWrapper = await this.lookupComponent(providers, moduleRef, Object.assign(Object.assign({}, dependencyContext), { name: token }), wrapper, contextId, inquirer, keyOrIndex);
150
157
  return this.resolveComponentHost(moduleRef, instanceWrapper, contextId, inquirer);
@@ -182,6 +189,7 @@ class Injector {
182
189
  }
183
190
  if (providers.has(name)) {
184
191
  const instanceWrapper = providers.get(name);
192
+ this.printFoundInModuleLog(name, moduleRef);
185
193
  this.addDependencyMetadata(keyOrIndex, wrapper, instanceWrapper);
186
194
  return instanceWrapper;
187
195
  }
@@ -207,6 +215,7 @@ class Injector {
207
215
  if (moduleRegistry.includes(relatedModule.id)) {
208
216
  continue;
209
217
  }
218
+ this.printLookingForProviderLog(name, relatedModule);
210
219
  moduleRegistry.push(relatedModule.id);
211
220
  const { providers, exports } = relatedModule;
212
221
  if (!exports.has(name) || !providers.has(name)) {
@@ -217,6 +226,7 @@ class Injector {
217
226
  }
218
227
  continue;
219
228
  }
229
+ this.printFoundInModuleLog(name, relatedModule);
220
230
  instanceWrapperRef = providers.get(name);
221
231
  this.addDependencyMetadata(keyOrIndex, wrapper, instanceWrapperRef);
222
232
  const inquirerId = this.getInquirerId(inquirer);
@@ -351,5 +361,40 @@ class Injector {
351
361
  ? hostWrapper.addPropertiesMetadata(keyOrIndex, instanceWrapper)
352
362
  : hostWrapper.addCtorMetadata(keyOrIndex, instanceWrapper);
353
363
  }
364
+ getTokenName(token) {
365
+ return shared_utils_1.isFunction(token) ? token.name : token.toString();
366
+ }
367
+ printResolvingDependenciesLog(token, inquirer) {
368
+ var _a;
369
+ if (!this.isDebugMode()) {
370
+ return;
371
+ }
372
+ const tokenName = this.getTokenName(token);
373
+ const dependentName = (_a = inquirer === null || inquirer === void 0 ? void 0 : inquirer.name) !== null && _a !== void 0 ? _a : 'unknown';
374
+ const isAlias = dependentName === tokenName;
375
+ const messageToPrint = `Resolving dependency ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in the ')}${cli_colors_util_1.clc.yellow(dependentName)}${cli_colors_util_1.clc.green(` provider ${isAlias ? '(alias)' : ''}`)}`;
376
+ this.logger.log(messageToPrint);
377
+ }
378
+ printLookingForProviderLog(token, moduleRef) {
379
+ var _a, _b;
380
+ if (!this.isDebugMode()) {
381
+ return;
382
+ }
383
+ const tokenName = this.getTokenName(token);
384
+ const moduleRefName = (_b = (_a = moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'unknown';
385
+ this.logger.log(`Looking for ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in ')}${cli_colors_util_1.clc.magentaBright(moduleRefName)}`);
386
+ }
387
+ printFoundInModuleLog(token, moduleRef) {
388
+ var _a, _b;
389
+ if (!this.isDebugMode()) {
390
+ return;
391
+ }
392
+ const tokenName = this.getTokenName(token);
393
+ const moduleRefName = (_b = (_a = moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'unknown';
394
+ this.logger.log(`Found ${cli_colors_util_1.clc.cyanBright(tokenName)}${cli_colors_util_1.clc.green(' in ')}${cli_colors_util_1.clc.magentaBright(moduleRefName)}`);
395
+ }
396
+ isDebugMode() {
397
+ return !!process.env.NEST_DEBUG;
398
+ }
354
399
  }
355
400
  exports.Injector = Injector;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MiddlewareModule = void 0;
4
4
  const request_method_enum_1 = require("@nestjs/common/enums/request-method.enum");
5
5
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
+ const utils_1 = require("../router/utils");
6
7
  const invalid_middleware_exception_1 = require("../errors/exceptions/invalid-middleware.exception");
7
8
  const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
8
9
  const context_id_factory_1 = require("../helpers/context-id-factory");
@@ -14,7 +15,6 @@ const router_proxy_1 = require("../router/router-proxy");
14
15
  const builder_1 = require("./builder");
15
16
  const resolver_1 = require("./resolver");
16
17
  const routes_mapper_1 = require("./routes-mapper");
17
- const utils_1 = require("./utils");
18
18
  class MiddlewareModule {
19
19
  constructor() {
20
20
  this.routerProxy = new router_proxy_1.RouterProxy();
@@ -133,16 +133,24 @@ class MiddlewareModule {
133
133
  }
134
134
  async registerHandler(applicationRef, method, path, proxy) {
135
135
  const prefix = this.config.getGlobalPrefix();
136
- const basePath = shared_utils_1.addLeadingSlash(prefix);
137
- if ((basePath === null || basePath === void 0 ? void 0 : basePath.endsWith('/')) && (path === null || path === void 0 ? void 0 : path.startsWith('/'))) {
138
- // strip slash when a wildcard is being used
139
- // and global prefix has been set
140
- path = path === null || path === void 0 ? void 0 : path.slice(1);
136
+ const excludedRoutes = this.config.getGlobalPrefixOptions().exclude;
137
+ if (Array.isArray(excludedRoutes) &&
138
+ utils_1.isRouteExcluded(excludedRoutes, path, method)) {
139
+ path = shared_utils_1.addLeadingSlash(path);
140
+ }
141
+ else {
142
+ const basePath = shared_utils_1.addLeadingSlash(prefix);
143
+ if ((basePath === null || basePath === void 0 ? void 0 : basePath.endsWith('/')) && (path === null || path === void 0 ? void 0 : path.startsWith('/'))) {
144
+ // strip slash when a wildcard is being used
145
+ // and global prefix has been set
146
+ path = path === null || path === void 0 ? void 0 : path.slice(1);
147
+ }
148
+ path = basePath + path;
141
149
  }
142
150
  const isMethodAll = utils_1.isRequestMethodAll(method);
143
151
  const requestMethod = request_method_enum_1.RequestMethod[method];
144
152
  const router = await applicationRef.createMiddlewareFactory(method);
145
- router(basePath + path, isMethodAll
153
+ router(path, isMethodAll
146
154
  ? proxy
147
155
  : (req, res, next) => {
148
156
  if (applicationRef.getRequestMethod(req) === requestMethod) {
@@ -1,12 +1,8 @@
1
- import { RequestMethod } from '@nestjs/common';
2
1
  import { HttpServer, RouteInfo, Type } from '@nestjs/common/interfaces';
3
- declare type RouteInfoRegex = RouteInfo & {
4
- regex: RegExp;
5
- };
6
- export declare const isRequestMethodAll: (method: RequestMethod) => boolean;
7
- export declare const filterMiddleware: <T extends Function | Type<any> = any>(middleware: T[], excludedRoutes: RouteInfo[], httpAdapter: HttpServer) => Type<any>[];
8
- export declare const mapToClass: <T extends Function | Type<any>>(middleware: T, excludedRoutes: RouteInfoRegex[], httpAdapter: HttpServer) => Type<any>;
2
+ import { ExcludeRouteMetadata } from '../router/interfaces/exclude-route-metadata.interface';
3
+ export declare const mapToExcludeRoute: (routes: RouteInfo[]) => ExcludeRouteMetadata[];
4
+ export declare const filterMiddleware: <T extends Function | Type<any> = any>(middleware: T[], routes: RouteInfo[], httpAdapter: HttpServer) => Type<any>[];
5
+ export declare const mapToClass: <T extends Function | Type<any>>(middleware: T, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer) => Type<any>;
9
6
  export declare function isMiddlewareClass(middleware: any): middleware is Type<any>;
10
7
  export declare function assignToken(metatype: Type<any>, token?: any): Type<any>;
11
- export declare function isRouteExcluded(req: Record<string, any>, excludedRoutes: RouteInfoRegex[], httpAdapter: HttpServer): boolean;
12
- export {};
8
+ export declare function isMiddlewareRouteExcluded(req: Record<string, any>, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer): boolean;
@@ -1,21 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRouteExcluded = exports.assignToken = exports.isMiddlewareClass = exports.mapToClass = exports.filterMiddleware = exports.isRequestMethodAll = void 0;
3
+ exports.isMiddlewareRouteExcluded = exports.assignToken = exports.isMiddlewareClass = exports.mapToClass = exports.filterMiddleware = exports.mapToExcludeRoute = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
6
  const iterare_1 = require("iterare");
7
7
  const pathToRegexp = require("path-to-regexp");
8
8
  const uuid_1 = require("uuid");
9
- const isRequestMethodAll = (method) => {
10
- return common_1.RequestMethod.ALL === method || method === -1;
9
+ const utils_1 = require("../router/utils");
10
+ const mapToExcludeRoute = (routes) => {
11
+ return routes.map(({ path, method }) => ({
12
+ pathRegex: pathToRegexp(path),
13
+ requestMethod: method,
14
+ }));
11
15
  };
12
- exports.isRequestMethodAll = isRequestMethodAll;
13
- const filterMiddleware = (middleware, excludedRoutes, httpAdapter) => {
14
- const excluded = excludedRoutes.map(route => (Object.assign(Object.assign({}, route), { regex: pathToRegexp(route.path) })));
16
+ exports.mapToExcludeRoute = mapToExcludeRoute;
17
+ const filterMiddleware = (middleware, routes, httpAdapter) => {
18
+ const excludedRoutes = exports.mapToExcludeRoute(routes);
15
19
  return iterare_1.iterate([])
16
20
  .concat(middleware)
17
21
  .filter(shared_utils_1.isFunction)
18
- .map((item) => exports.mapToClass(item, excluded, httpAdapter))
22
+ .map((item) => exports.mapToClass(item, excludedRoutes, httpAdapter))
19
23
  .toArray();
20
24
  };
21
25
  exports.filterMiddleware = filterMiddleware;
@@ -27,7 +31,7 @@ const mapToClass = (middleware, excludedRoutes, httpAdapter) => {
27
31
  const MiddlewareHost = class extends middleware {
28
32
  use(...params) {
29
33
  const [req, _, next] = params;
30
- const isExcluded = isRouteExcluded(req, excludedRoutes, httpAdapter);
34
+ const isExcluded = isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter);
31
35
  if (isExcluded) {
32
36
  return next();
33
37
  }
@@ -40,7 +44,7 @@ const mapToClass = (middleware, excludedRoutes, httpAdapter) => {
40
44
  constructor() {
41
45
  this.use = (...params) => {
42
46
  const [req, _, next] = params;
43
- const isExcluded = isRouteExcluded(req, excludedRoutes, httpAdapter);
47
+ const isExcluded = isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter);
44
48
  if (isExcluded) {
45
49
  return next();
46
50
  }
@@ -67,7 +71,7 @@ function assignToken(metatype, token = uuid_1.v4()) {
67
71
  return metatype;
68
72
  }
69
73
  exports.assignToken = assignToken;
70
- function isRouteExcluded(req, excludedRoutes, httpAdapter) {
74
+ function isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter) {
71
75
  if (excludedRoutes.length <= 0) {
72
76
  return false;
73
77
  }
@@ -77,12 +81,6 @@ function isRouteExcluded(req, excludedRoutes, httpAdapter) {
77
81
  const pathname = queryParamsIndex >= 0
78
82
  ? originalUrl.slice(0, queryParamsIndex)
79
83
  : originalUrl;
80
- const isExcluded = excludedRoutes.some(({ method, regex }) => {
81
- if (exports.isRequestMethodAll(method) || common_1.RequestMethod[method] === reqMethod) {
82
- return regex.exec(pathname);
83
- }
84
- return false;
85
- });
86
- return isExcluded;
84
+ return utils_1.isRouteExcluded(excludedRoutes, pathname, common_1.RequestMethod[reqMethod]);
87
85
  }
88
- exports.isRouteExcluded = isRouteExcluded;
86
+ exports.isMiddlewareRouteExcluded = isMiddlewareRouteExcluded;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "8.0.9",
3
+ "version": "8.1.1",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "uuid": "8.3.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "8.0.9"
39
+ "@nestjs/common": "8.1.1"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@nestjs/common": "^8.0.0",
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RoutePathFactory = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
+ const utils_1 = require("./utils");
6
7
  class RoutePathFactory {
7
8
  constructor(applicationConfig) {
8
9
  this.applicationConfig = applicationConfig;
@@ -71,16 +72,9 @@ class RoutePathFactory {
71
72
  return false;
72
73
  }
73
74
  const options = this.applicationConfig.getGlobalPrefixOptions();
74
- if (!options.exclude) {
75
- return false;
76
- }
77
- return options.exclude.some(route => {
78
- if (!route.pathRegex.exec(path)) {
79
- return false;
80
- }
81
- return (route.requestMethod === common_1.RequestMethod.ALL ||
82
- route.requestMethod === requestMethod);
83
- });
75
+ const excludedRoutes = options.exclude;
76
+ return (Array.isArray(excludedRoutes) &&
77
+ utils_1.isRouteExcluded(excludedRoutes, path, requestMethod));
84
78
  }
85
79
  }
86
80
  exports.RoutePathFactory = RoutePathFactory;
@@ -108,10 +108,11 @@ class RoutesResolver {
108
108
  return Reflect.getMetadata(constants_1.HOST_METADATA, metatype);
109
109
  }
110
110
  getVersionMetadata(metatype) {
111
- const isVersioningEnabled = this.applicationConfig.getVersioning();
112
- return isVersioningEnabled
113
- ? Reflect.getMetadata(constants_1.VERSION_METADATA, metatype)
114
- : undefined;
111
+ var _a;
112
+ const versioningConfig = this.applicationConfig.getVersioning();
113
+ if (versioningConfig) {
114
+ return ((_a = Reflect.getMetadata(constants_1.VERSION_METADATA, metatype)) !== null && _a !== void 0 ? _a : versioningConfig.defaultVersion);
115
+ }
115
116
  }
116
117
  }
117
118
  exports.RoutesResolver = RoutesResolver;
@@ -0,0 +1,4 @@
1
+ import { RequestMethod } from '@nestjs/common';
2
+ import { ExcludeRouteMetadata } from '../interfaces/exclude-route-metadata.interface';
3
+ export declare const isRequestMethodAll: (method: RequestMethod) => boolean;
4
+ export declare function isRouteExcluded(excludedRoutes: ExcludeRouteMetadata[], path: string, requestMethod?: RequestMethod): boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRouteExcluded = exports.isRequestMethodAll = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const isRequestMethodAll = (method) => {
6
+ return common_1.RequestMethod.ALL === method || method === -1;
7
+ };
8
+ exports.isRequestMethodAll = isRequestMethodAll;
9
+ function isRouteExcluded(excludedRoutes, path, requestMethod) {
10
+ return excludedRoutes.some(route => {
11
+ if (exports.isRequestMethodAll(route.requestMethod) ||
12
+ route.requestMethod === requestMethod) {
13
+ return route.pathRegex.exec(path);
14
+ }
15
+ return false;
16
+ });
17
+ }
18
+ exports.isRouteExcluded = isRouteExcluded;
@@ -1 +1,2 @@
1
+ export * from './exclude-route.util';
1
2
  export * from './flatten-route-paths.util';
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./exclude-route.util"), exports);
4
5
  tslib_1.__exportStar(require("./flatten-route-paths.util"), exports);