@nestjs/core 8.2.3 → 8.3.0

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 (88) hide show
  1. package/LICENSE +1 -1
  2. package/Readme.md +8 -2
  3. package/adapters/index.js +1 -1
  4. package/application-config.js +4 -0
  5. package/discovery/discovery-module.js +2 -2
  6. package/discovery/discovery-service.js +5 -5
  7. package/discovery/index.js +2 -2
  8. package/errors/exceptions/invalid-class-module.exception.d.ts +4 -0
  9. package/errors/exceptions/invalid-class-module.exception.js +11 -0
  10. package/errors/exceptions/invalid-class-scope.exception.js +2 -2
  11. package/errors/exceptions/invalid-class.exception.js +1 -1
  12. package/errors/exceptions/invalid-middleware.exception.js +1 -1
  13. package/errors/exceptions/invalid-module.exception.js +1 -1
  14. package/errors/exceptions/undefined-dependency.exception.js +1 -1
  15. package/errors/exceptions/undefined-forwardref.exception.js +1 -1
  16. package/errors/exceptions/undefined-module.exception.js +1 -1
  17. package/errors/exceptions/unknown-dependencies.exception.js +1 -1
  18. package/errors/exceptions/unknown-export.exception.js +1 -1
  19. package/errors/messages.d.ts +2 -1
  20. package/errors/messages.js +22 -9
  21. package/exceptions/base-exception-filter-context.js +3 -3
  22. package/exceptions/base-exception-filter.js +6 -6
  23. package/exceptions/exceptions-handler.js +1 -1
  24. package/exceptions/external-exception-filter-context.js +2 -2
  25. package/exceptions/external-exceptions-handler.js +1 -1
  26. package/exceptions/index.js +1 -1
  27. package/guards/guards-consumer.js +2 -2
  28. package/guards/guards-context-creator.js +4 -4
  29. package/helpers/context-utils.js +8 -4
  30. package/helpers/external-context-creator.js +3 -3
  31. package/helpers/index.js +2 -2
  32. package/helpers/interfaces/index.js +2 -2
  33. package/helpers/messages.js +10 -8
  34. package/hooks/before-app-shutdown.hook.js +5 -5
  35. package/hooks/index.js +5 -5
  36. package/hooks/on-app-bootstrap.hook.js +5 -5
  37. package/hooks/on-app-shutdown.hook.js +5 -5
  38. package/hooks/on-module-destroy.hook.js +5 -5
  39. package/hooks/on-module-init.hook.js +5 -5
  40. package/index.js +12 -12
  41. package/injector/compiler.js +1 -1
  42. package/injector/helpers/transient-instances.js +2 -2
  43. package/injector/index.js +5 -5
  44. package/injector/injector.js +13 -13
  45. package/injector/inquirer/index.js +1 -1
  46. package/injector/instance-links-host.js +1 -1
  47. package/injector/instance-loader.js +1 -1
  48. package/injector/instance-wrapper.js +7 -7
  49. package/injector/internal-core-module.js +3 -3
  50. package/injector/module-ref.js +1 -1
  51. package/injector/module-token-factory.js +5 -4
  52. package/injector/module.js +18 -18
  53. package/injector/modules-container.js +1 -1
  54. package/interceptors/interceptors-consumer.js +4 -4
  55. package/interceptors/interceptors-context-creator.js +4 -4
  56. package/metadata-scanner.js +4 -4
  57. package/middleware/builder.js +3 -3
  58. package/middleware/container.d.ts +0 -1
  59. package/middleware/container.js +2 -6
  60. package/middleware/index.js +1 -1
  61. package/middleware/middleware-module.js +6 -6
  62. package/middleware/routes-mapper.js +6 -6
  63. package/middleware/utils.js +6 -6
  64. package/nest-application-context.d.ts +5 -0
  65. package/nest-application-context.js +18 -8
  66. package/nest-application.js +13 -14
  67. package/nest-factory.js +9 -6
  68. package/package.json +2 -2
  69. package/pipes/pipes-context-creator.js +4 -4
  70. package/router/index.js +2 -2
  71. package/router/interfaces/index.js +1 -1
  72. package/router/route-path-factory.js +21 -16
  73. package/router/router-exception-filters.js +2 -2
  74. package/router/router-execution-context.js +7 -6
  75. package/router/router-explorer.js +12 -12
  76. package/router/router-module.js +6 -6
  77. package/router/router-response-controller.d.ts +5 -2
  78. package/router/router-response-controller.js +19 -10
  79. package/router/routes-resolver.js +6 -3
  80. package/router/sse-stream.d.ts +8 -2
  81. package/router/sse-stream.js +7 -10
  82. package/router/utils/exclude-route.util.js +1 -1
  83. package/router/utils/flatten-route-paths.util.js +2 -2
  84. package/router/utils/index.js +2 -2
  85. package/scanner.d.ts +18 -2
  86. package/scanner.js +43 -14
  87. package/services/index.js +1 -1
  88. package/services/reflector.service.js +2 -2
@@ -6,9 +6,9 @@ const iterare_1 = require("iterare");
6
6
  class MetadataScanner {
7
7
  scanFromPrototype(instance, prototype, callback) {
8
8
  const methodNames = new Set(this.getAllFilteredMethodNames(prototype));
9
- return iterare_1.iterate(methodNames)
9
+ return (0, iterare_1.iterate)(methodNames)
10
10
  .map(callback)
11
- .filter(metadata => !shared_utils_1.isNil(metadata))
11
+ .filter(metadata => !(0, shared_utils_1.isNil)(metadata))
12
12
  .toArray();
13
13
  }
14
14
  *getAllFilteredMethodNames(prototype) {
@@ -17,10 +17,10 @@ class MetadataScanner {
17
17
  if (descriptor.set || descriptor.get) {
18
18
  return false;
19
19
  }
20
- return !shared_utils_1.isConstructor(prop) && shared_utils_1.isFunction(prototype[prop]);
20
+ return !(0, shared_utils_1.isConstructor)(prop) && (0, shared_utils_1.isFunction)(prototype[prop]);
21
21
  };
22
22
  do {
23
- yield* iterare_1.iterate(Object.getOwnPropertyNames(prototype))
23
+ yield* (0, iterare_1.iterate)(Object.getOwnPropertyNames(prototype))
24
24
  .filter(isMethod)
25
25
  .toArray();
26
26
  } while ((prototype = Reflect.getPrototypeOf(prototype)) &&
@@ -11,7 +11,7 @@ class MiddlewareBuilder {
11
11
  this.middlewareCollection = new Set();
12
12
  }
13
13
  apply(...middleware) {
14
- return new MiddlewareBuilder.ConfigProxy(this, dependencies_decorator_1.flatten(middleware));
14
+ return new MiddlewareBuilder.ConfigProxy(this, (0, dependencies_decorator_1.flatten)(middleware));
15
15
  }
16
16
  build() {
17
17
  return [...this.middlewareCollection];
@@ -38,7 +38,7 @@ MiddlewareBuilder.ConfigProxy = class {
38
38
  const { middlewareCollection } = this.builder;
39
39
  const forRoutes = this.getRoutesFlatList(routes);
40
40
  const configuration = {
41
- middleware: utils_1.filterMiddleware(this.middleware, this.excludedRoutes, this.builder.getHttpAdapter()),
41
+ middleware: (0, utils_1.filterMiddleware)(this.middleware, this.excludedRoutes, this.builder.getHttpAdapter()),
42
42
  forRoutes,
43
43
  };
44
44
  middlewareCollection.add(configuration);
@@ -46,7 +46,7 @@ MiddlewareBuilder.ConfigProxy = class {
46
46
  }
47
47
  getRoutesFlatList(routes) {
48
48
  const { routesMapper } = this.builder;
49
- return iterare_1.iterate(routes)
49
+ return (0, iterare_1.iterate)(routes)
50
50
  .map(route => routesMapper.mapRouteToRouteInfo(route))
51
51
  .flatten()
52
52
  .toArray();
@@ -11,5 +11,4 @@ export declare class MiddlewareContainer {
11
11
  getConfigurations(): Map<string, Set<MiddlewareConfiguration>>;
12
12
  insertConfig(configList: MiddlewareConfiguration[], moduleKey: string): void;
13
13
  private getTargetConfig;
14
- private getClassScope;
15
14
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MiddlewareContainer = void 0;
4
- const constants_1 = require("@nestjs/common/constants");
5
4
  const instance_wrapper_1 = require("../injector/instance-wrapper");
5
+ const get_class_scope_1 = require("../helpers/get-class-scope");
6
6
  class MiddlewareContainer {
7
7
  constructor(container) {
8
8
  this.container = container;
@@ -26,7 +26,7 @@ class MiddlewareContainer {
26
26
  const insertMiddleware = (metatype) => {
27
27
  const token = metatype;
28
28
  middleware.set(token, new instance_wrapper_1.InstanceWrapper({
29
- scope: this.getClassScope(metatype),
29
+ scope: (0, get_class_scope_1.getClassScope)(metatype),
30
30
  name: token,
31
31
  metatype,
32
32
  token,
@@ -43,9 +43,5 @@ class MiddlewareContainer {
43
43
  }
44
44
  return this.configurationSets.get(moduleName);
45
45
  }
46
- getClassScope(type) {
47
- const metadata = Reflect.getMetadata(constants_1.SCOPE_OPTIONS_METADATA, type);
48
- return metadata && metadata.scope;
49
- }
50
46
  }
51
47
  exports.MiddlewareContainer = MiddlewareContainer;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./builder"), exports);
4
+ (0, tslib_1.__exportStar)(require("./builder"), exports);
@@ -80,7 +80,7 @@ class MiddlewareModule {
80
80
  for (const metatype of middlewareCollection) {
81
81
  const collection = middlewareContainer.getMiddlewareCollection(moduleKey);
82
82
  const instanceWrapper = collection.get(metatype);
83
- if (shared_utils_1.isUndefined(instanceWrapper)) {
83
+ if ((0, shared_utils_1.isUndefined)(instanceWrapper)) {
84
84
  throw new runtime_exception_1.RuntimeException();
85
85
  }
86
86
  if (instanceWrapper.isTransient) {
@@ -91,7 +91,7 @@ class MiddlewareModule {
91
91
  }
92
92
  async bindHandler(wrapper, applicationRef, method, path, moduleRef, collection) {
93
93
  const { instance, metatype } = wrapper;
94
- if (shared_utils_1.isUndefined(instance === null || instance === void 0 ? void 0 : instance.use)) {
94
+ if ((0, shared_utils_1.isUndefined)(instance === null || instance === void 0 ? void 0 : instance.use)) {
95
95
  throw new invalid_middleware_exception_1.InvalidMiddlewareException(metatype.name);
96
96
  }
97
97
  const isStatic = wrapper.isDependencyTreeStatic();
@@ -135,11 +135,11 @@ class MiddlewareModule {
135
135
  const prefix = this.config.getGlobalPrefix();
136
136
  const excludedRoutes = this.config.getGlobalPrefixOptions().exclude;
137
137
  if (Array.isArray(excludedRoutes) &&
138
- utils_1.isRouteExcluded(excludedRoutes, path, method)) {
139
- path = shared_utils_1.addLeadingSlash(path);
138
+ (0, utils_1.isRouteExcluded)(excludedRoutes, path, method)) {
139
+ path = (0, shared_utils_1.addLeadingSlash)(path);
140
140
  }
141
141
  else {
142
- const basePath = shared_utils_1.addLeadingSlash(prefix);
142
+ const basePath = (0, shared_utils_1.addLeadingSlash)(prefix);
143
143
  if ((basePath === null || basePath === void 0 ? void 0 : basePath.endsWith('/')) && (path === null || path === void 0 ? void 0 : path.startsWith('/'))) {
144
144
  // strip slash when a wildcard is being used
145
145
  // and global prefix has been set
@@ -147,7 +147,7 @@ class MiddlewareModule {
147
147
  }
148
148
  path = basePath + path;
149
149
  }
150
- const isMethodAll = utils_1.isRequestMethodAll(method);
150
+ const isMethodAll = (0, utils_1.isRequestMethodAll)(method);
151
151
  const requestMethod = request_method_enum_1.RequestMethod[method];
152
152
  const router = await applicationRef.createMiddlewareFactory(method);
153
153
  router(path, isMethodAll
@@ -12,11 +12,11 @@ class RoutesMapper {
12
12
  this.routerExplorer = new router_explorer_1.RouterExplorer(new metadata_scanner_1.MetadataScanner(), container);
13
13
  }
14
14
  mapRouteToRouteInfo(route) {
15
- if (shared_utils_1.isString(route)) {
15
+ if ((0, shared_utils_1.isString)(route)) {
16
16
  const defaultRequestMethod = -1;
17
17
  return [
18
18
  {
19
- path: shared_utils_1.addLeadingSlash(route),
19
+ path: (0, shared_utils_1.addLeadingSlash)(route),
20
20
  method: defaultRequestMethod,
21
21
  },
22
22
  ];
@@ -25,7 +25,7 @@ class RoutesMapper {
25
25
  if (this.isRouteInfo(routePathOrPaths, route)) {
26
26
  return [
27
27
  {
28
- path: shared_utils_1.addLeadingSlash(route.path),
28
+ path: (0, shared_utils_1.addLeadingSlash)(route.path),
29
29
  method: route.method,
30
30
  },
31
31
  ];
@@ -41,7 +41,7 @@ class RoutesMapper {
41
41
  var _a;
42
42
  return (_a = item.path) === null || _a === void 0 ? void 0 : _a.map(p => {
43
43
  let path = modulePath !== null && modulePath !== void 0 ? modulePath : '';
44
- path += this.normalizeGlobalPath(routePath) + shared_utils_1.addLeadingSlash(p);
44
+ path += this.normalizeGlobalPath(routePath) + (0, shared_utils_1.addLeadingSlash)(p);
45
45
  return {
46
46
  path,
47
47
  method: item.requestMethod,
@@ -52,10 +52,10 @@ class RoutesMapper {
52
52
  .reduce(concatPaths, []);
53
53
  }
54
54
  isRouteInfo(path, objectOrClass) {
55
- return shared_utils_1.isUndefined(path);
55
+ return (0, shared_utils_1.isUndefined)(path);
56
56
  }
57
57
  normalizeGlobalPath(path) {
58
- const prefix = shared_utils_1.addLeadingSlash(path);
58
+ const prefix = (0, shared_utils_1.addLeadingSlash)(path);
59
59
  return prefix === '/' ? '' : prefix;
60
60
  }
61
61
  getRoutePath(route) {
@@ -15,11 +15,11 @@ const mapToExcludeRoute = (routes) => {
15
15
  };
16
16
  exports.mapToExcludeRoute = mapToExcludeRoute;
17
17
  const filterMiddleware = (middleware, routes, httpAdapter) => {
18
- const excludedRoutes = exports.mapToExcludeRoute(routes);
19
- return iterare_1.iterate([])
18
+ const excludedRoutes = (0, exports.mapToExcludeRoute)(routes);
19
+ return (0, iterare_1.iterate)([])
20
20
  .concat(middleware)
21
21
  .filter(shared_utils_1.isFunction)
22
- .map((item) => exports.mapToClass(item, excludedRoutes, httpAdapter))
22
+ .map((item) => (0, exports.mapToClass)(item, excludedRoutes, httpAdapter))
23
23
  .toArray();
24
24
  };
25
25
  exports.filterMiddleware = filterMiddleware;
@@ -63,10 +63,10 @@ function isMiddlewareClass(middleware) {
63
63
  const middlewareArr = middlewareStr.split(' ');
64
64
  return (middlewareArr[0] === 'function' &&
65
65
  /[A-Z]/.test((_a = middlewareArr[1]) === null || _a === void 0 ? void 0 : _a[0]) &&
66
- typeof ((_b = middleware.prototype) === null || _b === void 0 ? void 0 : _b.use) === 'function');
66
+ (0, shared_utils_1.isFunction)((_b = middleware.prototype) === null || _b === void 0 ? void 0 : _b.use));
67
67
  }
68
68
  exports.isMiddlewareClass = isMiddlewareClass;
69
- function assignToken(metatype, token = uuid_1.v4()) {
69
+ function assignToken(metatype, token = (0, uuid_1.v4)()) {
70
70
  Object.defineProperty(metatype, 'name', { value: token });
71
71
  return metatype;
72
72
  }
@@ -81,6 +81,6 @@ function isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter) {
81
81
  const pathname = queryParamsIndex >= 0
82
82
  ? originalUrl.slice(0, queryParamsIndex)
83
83
  : originalUrl;
84
- return utils_1.isRouteExcluded(excludedRoutes, pathname, common_1.RequestMethod[reqMethod]);
84
+ return (0, utils_1.isRouteExcluded)(excludedRoutes, pathname, common_1.RequestMethod[reqMethod]);
85
85
  }
86
86
  exports.isMiddlewareRouteExcluded = isMiddlewareRouteExcluded;
@@ -14,6 +14,7 @@ export declare class NestApplicationContext implements INestApplicationContext {
14
14
  private contextModule;
15
15
  protected isInitialized: boolean;
16
16
  protected readonly injector: Injector;
17
+ private shouldFlushLogsOnOverride;
17
18
  private readonly activeShutdownSignals;
18
19
  private readonly moduleCompiler;
19
20
  private shutdownCleanupRef?;
@@ -40,6 +41,10 @@ export declare class NestApplicationContext implements INestApplicationContext {
40
41
  close(): Promise<void>;
41
42
  useLogger(logger: LoggerService | LogLevel[] | false): void;
42
43
  flushLogs(): void;
44
+ /**
45
+ * Define that it must flush logs right after defining a custom logger.
46
+ */
47
+ flushLogsOnOverride(): void;
43
48
  /**
44
49
  * Enables the usage of shutdown hooks. Will call the
45
50
  * `onApplicationShutdown` function of a provider if the
@@ -24,6 +24,7 @@ class NestApplicationContext {
24
24
  this.contextModule = contextModule;
25
25
  this.isInitialized = false;
26
26
  this.injector = new injector_1.Injector();
27
+ this.shouldFlushLogsOnOverride = false;
27
28
  this.activeShutdownSignals = new Array();
28
29
  this.moduleCompiler = new compiler_1.ModuleCompiler();
29
30
  }
@@ -55,7 +56,7 @@ class NestApplicationContext {
55
56
  ? this.find(typeOrToken)
56
57
  : this.find(typeOrToken, this.contextModule);
57
58
  }
58
- resolve(typeOrToken, contextId = context_id_factory_1.createContextId(), options = { strict: false }) {
59
+ resolve(typeOrToken, contextId = (0, context_id_factory_1.createContextId)(), options = { strict: false }) {
59
60
  return this.resolvePerContext(typeOrToken, this.contextModule, contextId, options);
60
61
  }
61
62
  registerRequestByContextId(request, contextId) {
@@ -85,10 +86,19 @@ class NestApplicationContext {
85
86
  }
86
87
  useLogger(logger) {
87
88
  common_1.Logger.overrideLogger(logger);
89
+ if (this.shouldFlushLogsOnOverride) {
90
+ this.flushLogs();
91
+ }
88
92
  }
89
93
  flushLogs() {
90
94
  common_1.Logger.flush();
91
95
  }
96
+ /**
97
+ * Define that it must flush logs right after defining a custom logger.
98
+ */
99
+ flushLogsOnOverride() {
100
+ this.shouldFlushLogsOnOverride = true;
101
+ }
92
102
  /**
93
103
  * Enables the usage of shutdown hooks. Will call the
94
104
  * `onApplicationShutdown` function of a provider if the
@@ -99,7 +109,7 @@ class NestApplicationContext {
99
109
  * @returns {this} The Nest application context instance
100
110
  */
101
111
  enableShutdownHooks(signals = []) {
102
- if (shared_utils_1.isEmpty(signals)) {
112
+ if ((0, shared_utils_1.isEmpty)(signals)) {
103
113
  signals = Object.keys(common_1.ShutdownSignal).map((key) => common_1.ShutdownSignal[key]);
104
114
  }
105
115
  else {
@@ -107,7 +117,7 @@ class NestApplicationContext {
107
117
  // process shouldn't listen to the same signal more than once.
108
118
  signals = Array.from(new Set(signals));
109
119
  }
110
- signals = iterare_1.iterate(signals)
120
+ signals = (0, iterare_1.iterate)(signals)
111
121
  .map((signal) => signal.toString().toUpperCase().trim())
112
122
  // filter out the signals which is already listening to
113
123
  .filter(signal => !this.activeShutdownSignals.includes(signal))
@@ -166,7 +176,7 @@ class NestApplicationContext {
166
176
  async callInitHook() {
167
177
  const modulesSortedByDistance = this.getModulesSortedByDistance();
168
178
  for (const module of modulesSortedByDistance) {
169
- await hooks_1.callModuleInitHook(module);
179
+ await (0, hooks_1.callModuleInitHook)(module);
170
180
  }
171
181
  }
172
182
  /**
@@ -176,7 +186,7 @@ class NestApplicationContext {
176
186
  async callDestroyHook() {
177
187
  const modulesSortedByDistance = this.getModulesSortedByDistance();
178
188
  for (const module of modulesSortedByDistance) {
179
- await hooks_1.callModuleDestroyHook(module);
189
+ await (0, hooks_1.callModuleDestroyHook)(module);
180
190
  }
181
191
  }
182
192
  /**
@@ -186,7 +196,7 @@ class NestApplicationContext {
186
196
  async callBootstrapHook() {
187
197
  const modulesSortedByDistance = this.getModulesSortedByDistance();
188
198
  for (const module of modulesSortedByDistance) {
189
- await hooks_1.callModuleBootstrapHook(module);
199
+ await (0, hooks_1.callModuleBootstrapHook)(module);
190
200
  }
191
201
  }
192
202
  /**
@@ -196,7 +206,7 @@ class NestApplicationContext {
196
206
  async callShutdownHook(signal) {
197
207
  const modulesSortedByDistance = this.getModulesSortedByDistance();
198
208
  for (const module of modulesSortedByDistance) {
199
- await hooks_1.callAppShutdownHook(module, signal);
209
+ await (0, hooks_1.callAppShutdownHook)(module, signal);
200
210
  }
201
211
  }
202
212
  /**
@@ -206,7 +216,7 @@ class NestApplicationContext {
206
216
  async callBeforeShutdownHook(signal) {
207
217
  const modulesSortedByDistance = this.getModulesSortedByDistance();
208
218
  for (const module of modulesSortedByDistance) {
209
- await hooks_1.callBeforeAppShutdownHook(module, signal);
219
+ await (0, hooks_1.callBeforeAppShutdownHook)(module, signal);
210
220
  }
211
221
  }
212
222
  find(typeOrToken, contextModule) {
@@ -15,8 +15,8 @@ const container_1 = require("./middleware/container");
15
15
  const middleware_module_1 = require("./middleware/middleware-module");
16
16
  const nest_application_context_1 = require("./nest-application-context");
17
17
  const routes_resolver_1 = require("./router/routes-resolver");
18
- const { SocketModule } = optional_require_1.optionalRequire('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
19
- const { MicroservicesModule } = optional_require_1.optionalRequire('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module'));
18
+ const { SocketModule } = (0, optional_require_1.optionalRequire)('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
19
+ const { MicroservicesModule } = (0, optional_require_1.optionalRequire)('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module'));
20
20
  /**
21
21
  * @publicApi
22
22
  */
@@ -43,7 +43,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
43
43
  this.socketModule && (await this.socketModule.close());
44
44
  this.microservicesModule && (await this.microservicesModule.close());
45
45
  this.httpAdapter && (await this.httpAdapter.close());
46
- await Promise.all(iterare_1.iterate(this.microservices).map(async (microservice) => {
46
+ await Promise.all((0, iterare_1.iterate)(this.microservices).map(async (microservice) => {
47
47
  microservice.setIsTerminated(true);
48
48
  await microservice.close();
49
49
  }));
@@ -61,8 +61,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
61
61
  if (!this.appOptions || !this.appOptions.cors) {
62
62
  return undefined;
63
63
  }
64
- const passCustomOptions = shared_utils_1.isObject(this.appOptions.cors) ||
65
- typeof this.appOptions.cors === 'function';
64
+ const passCustomOptions = (0, shared_utils_1.isObject)(this.appOptions.cors) || (0, shared_utils_1.isFunction)(this.appOptions.cors);
66
65
  if (!passCustomOptions) {
67
66
  return this.enableCors();
68
67
  }
@@ -107,7 +106,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
107
106
  async registerRouter() {
108
107
  await this.registerMiddleware(this.httpAdapter);
109
108
  const prefix = this.config.getGlobalPrefix();
110
- const basePath = shared_utils_1.addLeadingSlash(prefix);
109
+ const basePath = (0, shared_utils_1.addLeadingSlash)(prefix);
111
110
  this.routesResolver.resolve(this.httpAdapter, basePath);
112
111
  }
113
112
  async registerRouterHooks() {
@@ -115,7 +114,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
115
114
  this.routesResolver.registerExceptionHandler();
116
115
  }
117
116
  connectMicroservice(microserviceOptions, hybridAppOptions = {}) {
118
- const { NestMicroservice } = load_package_util_1.loadPackage('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
117
+ const { NestMicroservice } = (0, load_package_util_1.loadPackage)('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
119
118
  const { inheritAppConfig } = hybridAppOptions;
120
119
  const applicationConfig = inheritAppConfig
121
120
  ? this.config
@@ -161,7 +160,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
161
160
  reject(e);
162
161
  };
163
162
  this.httpServer.once('error', errorHandler);
164
- const isCallbackInOriginalArgs = shared_utils_1.isFunction(args[args.length - 1]);
163
+ const isCallbackInOriginalArgs = (0, shared_utils_1.isFunction)(args[args.length - 1]);
165
164
  const listenFnArgs = isCallbackInOriginalArgs
166
165
  ? args.slice(0, args.length - 1)
167
166
  : args;
@@ -200,8 +199,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
200
199
  });
201
200
  }
202
201
  formatAddress(address) {
203
- if (typeof address === 'string') {
204
- if (os_1.platform() === 'win32') {
202
+ if ((0, shared_utils_1.isString)(address)) {
203
+ if ((0, os_1.platform)() === 'win32') {
205
204
  return address;
206
205
  }
207
206
  const basePath = encodeURIComponent(address);
@@ -225,15 +224,15 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
225
224
  this.config.setGlobalPrefix(prefix);
226
225
  if (options) {
227
226
  const exclude = options === null || options === void 0 ? void 0 : options.exclude.map((route) => {
228
- if (shared_utils_1.isString(route)) {
227
+ if ((0, shared_utils_1.isString)(route)) {
229
228
  return {
230
229
  requestMethod: common_1.RequestMethod.ALL,
231
- pathRegex: pathToRegexp(shared_utils_1.addLeadingSlash(route)),
230
+ pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route)),
232
231
  };
233
232
  }
234
233
  return {
235
234
  requestMethod: route.method,
236
- pathRegex: pathToRegexp(shared_utils_1.addLeadingSlash(route.path)),
235
+ pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route.path)),
237
236
  };
238
237
  });
239
238
  this.config.setGlobalPrefixOptions(Object.assign(Object.assign({}, options), { exclude }));
@@ -276,7 +275,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
276
275
  }
277
276
  host() {
278
277
  const address = this.httpServer.address();
279
- if (typeof address === 'string') {
278
+ if ((0, shared_utils_1.isString)(address)) {
280
279
  return undefined;
281
280
  }
282
281
  return address && address.address;
package/nest-factory.js CHANGED
@@ -49,7 +49,7 @@ class NestFactoryStatic {
49
49
  * contains a reference to the NestMicroservice instance.
50
50
  */
51
51
  async createMicroservice(module, options) {
52
- const { NestMicroservice } = load_package_util_1.loadPackage('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
52
+ const { NestMicroservice } = (0, load_package_util_1.loadPackage)('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
53
53
  const applicationConfig = new application_config_1.ApplicationConfig();
54
54
  const container = new container_1.NestContainer(applicationConfig);
55
55
  this.setAbortOnError(options);
@@ -74,6 +74,9 @@ class NestFactoryStatic {
74
74
  const modules = container.getModules().values();
75
75
  const root = modules.next().value;
76
76
  const context = this.createNestInstance(new nest_application_context_1.NestApplicationContext(container, [], root));
77
+ if (this.autoFlushLogs) {
78
+ context.flushLogsOnOverride();
79
+ }
77
80
  return context.init();
78
81
  }
79
82
  createNestInstance(instance) {
@@ -102,7 +105,7 @@ class NestFactoryStatic {
102
105
  if (this.abortOnError) {
103
106
  process.abort();
104
107
  }
105
- rethrow_1.rethrow(err);
108
+ (0, rethrow_1.rethrow)(err);
106
109
  }
107
110
  createProxy(target) {
108
111
  const proxy = this.createExceptionProxy();
@@ -116,7 +119,7 @@ class NestFactoryStatic {
116
119
  if (!(prop in receiver)) {
117
120
  return;
118
121
  }
119
- if (shared_utils_1.isFunction(receiver[prop])) {
122
+ if ((0, shared_utils_1.isFunction)(receiver[prop])) {
120
123
  return this.createExceptionZone(receiver, prop);
121
124
  }
122
125
  return receiver[prop];
@@ -137,7 +140,7 @@ class NestFactoryStatic {
137
140
  return;
138
141
  }
139
142
  const { logger, bufferLogs, autoFlushLogs } = options;
140
- if (logger !== true && !shared_utils_1.isNil(logger)) {
143
+ if (logger !== true && !(0, shared_utils_1.isNil)(logger)) {
141
144
  logger_service_1.Logger.overrideLogger(logger);
142
145
  }
143
146
  if (bufferLogs) {
@@ -146,7 +149,7 @@ class NestFactoryStatic {
146
149
  this.autoFlushLogs = autoFlushLogs !== null && autoFlushLogs !== void 0 ? autoFlushLogs : true;
147
150
  }
148
151
  createHttpAdapter(httpServer) {
149
- const { ExpressAdapter } = load_adapter_1.loadAdapter('@nestjs/platform-express', 'HTTP', () => require('@nestjs/platform-express'));
152
+ const { ExpressAdapter } = (0, load_adapter_1.loadAdapter)('@nestjs/platform-express', 'HTTP', () => require('@nestjs/platform-express'));
150
153
  return new ExpressAdapter(httpServer);
151
154
  }
152
155
  isHttpServer(serverOrOptions) {
@@ -173,7 +176,7 @@ class NestFactoryStatic {
173
176
  return mapToProxy(result);
174
177
  };
175
178
  }
176
- if (shared_utils_1.isFunction(receiver[prop])) {
179
+ if ((0, shared_utils_1.isFunction)(receiver[prop])) {
177
180
  return (...args) => {
178
181
  const result = receiver[prop](...args);
179
182
  return mapToProxy(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "8.2.3",
3
+ "version": "8.3.0",
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.2.3"
39
+ "@nestjs/common": "8.3.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@nestjs/common": "^8.0.0",
@@ -17,13 +17,13 @@ class PipesContextCreator extends context_creator_1.ContextCreator {
17
17
  return this.createContext(instance, callback, constants_1.PIPES_METADATA, contextId, inquirerId);
18
18
  }
19
19
  createConcreteContext(metadata, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
20
- if (shared_utils_1.isEmpty(metadata)) {
20
+ if ((0, shared_utils_1.isEmpty)(metadata)) {
21
21
  return [];
22
22
  }
23
- return iterare_1.iterate(metadata)
23
+ return (0, iterare_1.iterate)(metadata)
24
24
  .filter((pipe) => pipe && (pipe.name || pipe.transform))
25
25
  .map(pipe => this.getPipeInstance(pipe, contextId, inquirerId))
26
- .filter(pipe => pipe && pipe.transform && shared_utils_1.isFunction(pipe.transform))
26
+ .filter(pipe => pipe && pipe.transform && (0, shared_utils_1.isFunction)(pipe.transform))
27
27
  .toArray();
28
28
  }
29
29
  getPipeInstance(pipe, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
@@ -58,7 +58,7 @@ class PipesContextCreator extends context_creator_1.ContextCreator {
58
58
  return globalPipes;
59
59
  }
60
60
  const scopedPipeWrappers = this.config.getGlobalRequestPipes();
61
- const scopedPipes = iterare_1.iterate(scopedPipeWrappers)
61
+ const scopedPipes = (0, iterare_1.iterate)(scopedPipeWrappers)
62
62
  .map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
63
63
  .filter(host => !!host)
64
64
  .map(host => host.instance)
package/router/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RouterModule = void 0;
4
4
  const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./interfaces"), exports);
6
- tslib_1.__exportStar(require("./request"), exports);
5
+ (0, tslib_1.__exportStar)(require("./interfaces"), exports);
6
+ (0, tslib_1.__exportStar)(require("./request"), exports);
7
7
  var router_module_1 = require("./router-module");
8
8
  Object.defineProperty(exports, "RouterModule", { enumerable: true, get: function () { return router_module_1.RouterModule; } });
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./routes.interface"), exports);
4
+ (0, tslib_1.__exportStar)(require("./routes.interface"), exports);
@@ -11,16 +11,21 @@ class RoutePathFactory {
11
11
  create(metadata, requestMethod) {
12
12
  var _a;
13
13
  let paths = [''];
14
- const version = this.getVersion(metadata);
15
- if (version && ((_a = metadata.versioningOptions) === null || _a === void 0 ? void 0 : _a.type) === common_1.VersioningType.URI) {
14
+ const versionOrVersions = this.getVersion(metadata);
15
+ if (versionOrVersions &&
16
+ ((_a = metadata.versioningOptions) === null || _a === void 0 ? void 0 : _a.type) === common_1.VersioningType.URI) {
16
17
  const versionPrefix = this.getVersionPrefix(metadata.versioningOptions);
17
- // Version Neutral - Do not include version in URL
18
- if (version !== common_1.VERSION_NEUTRAL) {
19
- if (Array.isArray(version)) {
20
- paths = common_1.flatten(paths.map(path => version.map(v => path + `/${versionPrefix}${v}`)));
21
- }
22
- else {
23
- paths = paths.map(path => path + `/${versionPrefix}${version}`);
18
+ if (Array.isArray(versionOrVersions)) {
19
+ paths = (0, common_1.flatten)(paths.map(path => versionOrVersions.map(version =>
20
+ // Version Neutral - Do not include version in URL
21
+ version === common_1.VERSION_NEUTRAL
22
+ ? path
23
+ : `${path}/${versionPrefix}${version}`)));
24
+ }
25
+ else {
26
+ // Version Neutral - Do not include version in URL
27
+ if (versionOrVersions !== common_1.VERSION_NEUTRAL) {
28
+ paths = paths.map(path => `${path}/${versionPrefix}${versionOrVersions}`);
24
29
  }
25
30
  }
26
31
  }
@@ -32,12 +37,12 @@ class RoutePathFactory {
32
37
  if (this.isExcludedFromGlobalPrefix(path, requestMethod)) {
33
38
  return path;
34
39
  }
35
- return shared_utils_1.stripEndSlash(metadata.globalPrefix || '') + path;
40
+ return (0, shared_utils_1.stripEndSlash)(metadata.globalPrefix || '') + path;
36
41
  });
37
42
  }
38
43
  return paths
39
- .map(path => shared_utils_1.addLeadingSlash(path || '/'))
40
- .map(path => (path !== '/' ? shared_utils_1.stripEndSlash(path) : path));
44
+ .map(path => (0, shared_utils_1.addLeadingSlash)(path || '/'))
45
+ .map(path => (path !== '/' ? (0, shared_utils_1.stripEndSlash)(path) : path));
41
46
  }
42
47
  getVersion(metadata) {
43
48
  // The version will be either the path version or the controller version,
@@ -60,21 +65,21 @@ class RoutePathFactory {
60
65
  if (!fragmentToAppend) {
61
66
  return paths;
62
67
  }
63
- const concatPaths = (a, b) => shared_utils_1.stripEndSlash(a) + shared_utils_1.addLeadingSlash(b);
68
+ const concatPaths = (a, b) => (0, shared_utils_1.stripEndSlash)(a) + (0, shared_utils_1.addLeadingSlash)(b);
64
69
  if (Array.isArray(fragmentToAppend)) {
65
70
  const paths2dArray = paths.map(path => fragmentToAppend.map(fragment => concatPaths(path, fragment)));
66
- return common_1.flatten(paths2dArray);
71
+ return (0, common_1.flatten)(paths2dArray);
67
72
  }
68
73
  return paths.map(path => concatPaths(path, fragmentToAppend));
69
74
  }
70
75
  isExcludedFromGlobalPrefix(path, requestMethod) {
71
- if (shared_utils_1.isUndefined(requestMethod)) {
76
+ if ((0, shared_utils_1.isUndefined)(requestMethod)) {
72
77
  return false;
73
78
  }
74
79
  const options = this.applicationConfig.getGlobalPrefixOptions();
75
80
  const excludedRoutes = options.exclude;
76
81
  return (Array.isArray(excludedRoutes) &&
77
- utils_1.isRouteExcluded(excludedRoutes, path, requestMethod));
82
+ (0, utils_1.isRouteExcluded)(excludedRoutes, path, requestMethod));
78
83
  }
79
84
  }
80
85
  exports.RoutePathFactory = RoutePathFactory;
@@ -17,7 +17,7 @@ class RouterExceptionFilters extends base_exception_filter_context_1.BaseExcepti
17
17
  this.moduleContext = moduleKey;
18
18
  const exceptionHandler = new exceptions_handler_1.ExceptionsHandler(this.applicationRef);
19
19
  const filters = this.createContext(instance, callback, constants_1.EXCEPTION_FILTERS_METADATA, contextId, inquirerId);
20
- if (shared_utils_1.isEmpty(filters)) {
20
+ if ((0, shared_utils_1.isEmpty)(filters)) {
21
21
  return exceptionHandler;
22
22
  }
23
23
  exceptionHandler.setCustomFilters(filters.reverse());
@@ -29,7 +29,7 @@ class RouterExceptionFilters extends base_exception_filter_context_1.BaseExcepti
29
29
  return globalFilters;
30
30
  }
31
31
  const scopedFilterWrappers = this.config.getGlobalRequestFilters();
32
- const scopedFilters = iterare_1.iterate(scopedFilterWrappers)
32
+ const scopedFilters = (0, iterare_1.iterate)(scopedFilterWrappers)
33
33
  .map(wrapper => wrapper.getInstanceByContextId(contextId, inquirerId))
34
34
  .filter(host => !!host)
35
35
  .map(host => host.instance)