@nestjs/core 9.4.3 → 10.0.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.
Files changed (69) hide show
  1. package/adapters/http-adapter.d.ts +2 -0
  2. package/adapters/http-adapter.js +3 -0
  3. package/discovery/discovery-module.js +2 -3
  4. package/discovery/discovery-service.js +2 -3
  5. package/errors/exception-handler.js +1 -1
  6. package/errors/exceptions-zone.js +1 -1
  7. package/errors/messages.js +7 -8
  8. package/exceptions/base-exception-filter.js +2 -2
  9. package/exceptions/exceptions-handler.d.ts +1 -1
  10. package/exceptions/exceptions-handler.js +3 -6
  11. package/exceptions/external-exception-filter.js +1 -1
  12. package/exceptions/external-exceptions-handler.d.ts +1 -1
  13. package/exceptions/external-exceptions-handler.js +3 -6
  14. package/helpers/context-id-factory.js +1 -2
  15. package/helpers/context-utils.js +4 -1
  16. package/helpers/execution-context-host.js +1 -0
  17. package/injector/abstract-instance-resolver.js +1 -1
  18. package/injector/compiler.js +2 -3
  19. package/injector/container.d.ts +6 -1
  20. package/injector/container.js +23 -3
  21. package/injector/helpers/provider-classifier.js +2 -2
  22. package/injector/helpers/transient-instances.d.ts +3 -3
  23. package/injector/injector.d.ts +7 -7
  24. package/injector/injector.js +24 -20
  25. package/injector/instance-links-host.d.ts +4 -4
  26. package/injector/instance-links-host.js +1 -1
  27. package/injector/instance-wrapper.d.ts +4 -4
  28. package/injector/instance-wrapper.js +17 -10
  29. package/injector/internal-core-module/internal-core-module-factory.d.ts +2 -1
  30. package/injector/internal-core-module/internal-core-module-factory.js +2 -6
  31. package/injector/internal-core-module/internal-core-module.js +2 -3
  32. package/injector/lazy-module-loader/lazy-module-loader.d.ts +3 -1
  33. package/injector/lazy-module-loader/lazy-module-loader.js +7 -3
  34. package/injector/module.d.ts +12 -29
  35. package/injector/module.js +14 -32
  36. package/inspector/deterministic-uuid-registry.js +1 -1
  37. package/inspector/graph-inspector.js +18 -14
  38. package/inspector/initialize-on-preview.allowlist.js +1 -1
  39. package/inspector/partial-graph.host.js +2 -4
  40. package/inspector/serialized-graph.js +15 -8
  41. package/inspector/uuid-factory.js +2 -2
  42. package/interceptors/interceptors-consumer.js +4 -5
  43. package/middleware/builder.js +26 -3
  44. package/middleware/container.d.ts +2 -2
  45. package/middleware/container.js +1 -2
  46. package/middleware/middleware-module.js +4 -4
  47. package/middleware/route-info-path-extractor.js +1 -2
  48. package/middleware/routes-mapper.d.ts +5 -2
  49. package/middleware/routes-mapper.js +45 -26
  50. package/middleware/utils.js +2 -3
  51. package/nest-application-context.js +3 -5
  52. package/nest-application.js +9 -10
  53. package/nest-factory.js +3 -3
  54. package/package.json +6 -6
  55. package/repl/native-functions/help-repl-fn.js +1 -1
  56. package/repl/native-functions/methods-repl-fn.js +1 -1
  57. package/repl/repl-context.js +6 -5
  58. package/repl/repl-logger.js +1 -1
  59. package/repl/repl-native-commands.js +1 -1
  60. package/router/route-path-factory.d.ts +4 -2
  61. package/router/route-path-factory.js +20 -4
  62. package/router/router-execution-context.js +1 -2
  63. package/router/router-explorer.js +12 -2
  64. package/router/router-module.js +8 -6
  65. package/router/routes-resolver.js +3 -3
  66. package/router/sse-stream.js +9 -4
  67. package/scanner.d.ts +17 -3
  68. package/scanner.js +49 -10
  69. package/services/reflector.service.js +4 -1
@@ -21,6 +21,7 @@ class MiddlewareBuilder {
21
21
  return this.httpAdapter;
22
22
  }
23
23
  }
24
+ exports.MiddlewareBuilder = MiddlewareBuilder;
24
25
  MiddlewareBuilder.ConfigProxy = class {
25
26
  constructor(builder, middleware, routeInfoPathExtractor) {
26
27
  this.builder = builder;
@@ -32,12 +33,16 @@ MiddlewareBuilder.ConfigProxy = class {
32
33
  return this.excludedRoutes;
33
34
  }
34
35
  exclude(...routes) {
35
- this.excludedRoutes = this.getRoutesFlatList(routes).map(route => (Object.assign(Object.assign({}, route), { path: this.routeInfoPathExtractor.extractPathFrom(route) })));
36
+ this.excludedRoutes = this.getRoutesFlatList(routes).map(route => ({
37
+ ...route,
38
+ path: this.routeInfoPathExtractor.extractPathFrom(route),
39
+ }));
36
40
  return this;
37
41
  }
38
42
  forRoutes(...routes) {
39
43
  const { middlewareCollection } = this.builder;
40
- const forRoutes = this.getRoutesFlatList(routes);
44
+ const flattedRoutes = this.getRoutesFlatList(routes);
45
+ const forRoutes = this.removeOverlappedRoutes(flattedRoutes);
41
46
  const configuration = {
42
47
  middleware: (0, utils_1.filterMiddleware)(this.middleware, this.excludedRoutes, this.builder.getHttpAdapter()),
43
48
  forRoutes,
@@ -52,5 +57,23 @@ MiddlewareBuilder.ConfigProxy = class {
52
57
  .flatten()
53
58
  .toArray();
54
59
  }
60
+ removeOverlappedRoutes(routes) {
61
+ const regexMatchParams = /(:[^\/]*)/g;
62
+ const wildcard = '([^/]*)';
63
+ const routesWithRegex = routes
64
+ .filter(route => route.path.includes(':'))
65
+ .map(route => ({
66
+ path: route.path,
67
+ regex: new RegExp('^(' + route.path.replace(regexMatchParams, wildcard) + ')$', 'g'),
68
+ }));
69
+ return routes.filter(route => {
70
+ const isOverlapped = (v) => {
71
+ return route.path !== v.path && route.path.match(v.regex);
72
+ };
73
+ const routeMatch = routesWithRegex.find(isOverlapped);
74
+ if (routeMatch === undefined) {
75
+ return route;
76
+ }
77
+ });
78
+ }
55
79
  };
56
- exports.MiddlewareBuilder = MiddlewareBuilder;
@@ -1,13 +1,13 @@
1
+ import { InjectionToken } from '@nestjs/common';
1
2
  import { MiddlewareConfiguration } from '@nestjs/common/interfaces/middleware/middleware-configuration.interface';
2
3
  import { NestContainer } from '../injector/container';
3
4
  import { InstanceWrapper } from '../injector/instance-wrapper';
4
- import { InstanceToken } from '../injector/module';
5
5
  export declare class MiddlewareContainer {
6
6
  private readonly container;
7
7
  private readonly middleware;
8
8
  private readonly configurationSets;
9
9
  constructor(container: NestContainer);
10
- getMiddlewareCollection(moduleKey: string): Map<InstanceToken, InstanceWrapper>;
10
+ getMiddlewareCollection(moduleKey: string): Map<InjectionToken, InstanceWrapper>;
11
11
  getConfigurations(): Map<string, Set<MiddlewareConfiguration>>;
12
12
  insertConfig(configList: MiddlewareConfiguration[], moduleKey: string): void;
13
13
  private getTargetConfig;
@@ -25,12 +25,11 @@ class MiddlewareContainer {
25
25
  const targetConfig = this.getTargetConfig(moduleKey);
26
26
  const configurations = configList || [];
27
27
  const insertMiddleware = (metatype) => {
28
- var _a;
29
28
  const token = metatype;
30
29
  middleware.set(token, new instance_wrapper_1.InstanceWrapper({
31
30
  scope: (0, get_class_scope_1.getClassScope)(metatype),
32
31
  durable: (0, is_durable_1.isDurable)(metatype),
33
- name: (_a = token === null || token === void 0 ? void 0 : token.name) !== null && _a !== void 0 ? _a : token,
32
+ name: token?.name ?? token,
34
33
  metatype,
35
34
  token,
36
35
  }));
@@ -27,7 +27,7 @@ class MiddlewareModule {
27
27
  this.appOptions = options;
28
28
  const appRef = container.getHttpAdapterRef();
29
29
  this.routerExceptionFilter = new router_exception_filters_1.RouterExceptionFilters(container, config, appRef);
30
- this.routesMapper = new routes_mapper_1.RoutesMapper(container);
30
+ this.routesMapper = new routes_mapper_1.RoutesMapper(container, config);
31
31
  this.resolver = new resolver_1.MiddlewareResolver(middlewareContainer, injector);
32
32
  this.routeInfoPathExtractor = new route_info_path_extractor_1.RouteInfoPathExtractor(config);
33
33
  this.injector = injector;
@@ -90,7 +90,6 @@ class MiddlewareModule {
90
90
  }
91
91
  }
92
92
  async registerRouteMiddleware(middlewareContainer, routeInfo, config, moduleKey, applicationRef) {
93
- var _a;
94
93
  const middlewareCollection = [].concat(config.middleware);
95
94
  const moduleRef = this.container.getModuleByKey(moduleKey);
96
95
  for (const metatype of middlewareCollection) {
@@ -111,7 +110,8 @@ class MiddlewareModule {
111
110
  metadata: {
112
111
  key: routeInfo.path,
113
112
  path: routeInfo.path,
114
- requestMethod: (_a = request_method_enum_1.RequestMethod[routeInfo.method]) !== null && _a !== void 0 ? _a : 'ALL',
113
+ requestMethod: request_method_enum_1.RequestMethod[routeInfo.method] ??
114
+ 'ALL',
115
115
  version: routeInfo.version,
116
116
  },
117
117
  };
@@ -121,7 +121,7 @@ class MiddlewareModule {
121
121
  }
122
122
  async bindHandler(wrapper, applicationRef, routeInfo, moduleRef, collection) {
123
123
  const { instance, metatype } = wrapper;
124
- if ((0, shared_utils_1.isUndefined)(instance === null || instance === void 0 ? void 0 : instance.use)) {
124
+ if ((0, shared_utils_1.isUndefined)(instance?.use)) {
125
125
  throw new invalid_middleware_exception_1.InvalidMiddlewareException(metatype.name);
126
126
  }
127
127
  const isStatic = wrapper.isDependencyTreeStatic();
@@ -44,8 +44,7 @@ class RouteInfoPathExtractor {
44
44
  return this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path);
45
45
  }
46
46
  extractVersionPathFrom(version) {
47
- var _a;
48
- if (!version || ((_a = this.versioningConfig) === null || _a === void 0 ? void 0 : _a.type) !== common_1.VersioningType.URI)
47
+ if (!version || this.versioningConfig?.type !== common_1.VersioningType.URI)
49
48
  return '';
50
49
  const versionPrefix = this.routePathFactory.getVersionPrefix(this.versioningConfig);
51
50
  return (0, shared_utils_1.addLeadingSlash)(versionPrefix + version.toString());
@@ -1,10 +1,12 @@
1
1
  import { RouteInfo, Type } from '@nestjs/common/interfaces';
2
+ import { ApplicationConfig } from '../application-config';
2
3
  import { NestContainer } from '../injector/container';
3
4
  export declare class RoutesMapper {
4
5
  private readonly container;
6
+ private readonly applicationConfig;
5
7
  private readonly pathsExplorer;
6
- constructor(container: NestContainer);
7
- mapRouteToRouteInfo(route: Type<any> | RouteInfo | string): RouteInfo[];
8
+ constructor(container: NestContainer, applicationConfig: ApplicationConfig);
9
+ mapRouteToRouteInfo(controllerOrRoute: Type<any> | RouteInfo | string): RouteInfo[];
8
10
  private getRouteInfoFromPath;
9
11
  private getRouteInfoFromObject;
10
12
  private getRouteInfoFromController;
@@ -13,4 +15,5 @@ export declare class RoutesMapper {
13
15
  private getRoutePath;
14
16
  private getHostModuleOfController;
15
17
  private getModulePath;
18
+ private getVersionMetadata;
16
19
  }
@@ -2,24 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RoutesMapper = void 0;
4
4
  const constants_1 = require("@nestjs/common/constants");
5
+ const interfaces_1 = require("@nestjs/common/interfaces");
5
6
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
7
  const metadata_scanner_1 = require("../metadata-scanner");
7
8
  const paths_explorer_1 = require("../router/paths-explorer");
8
9
  const router_module_1 = require("../router/router-module");
9
10
  class RoutesMapper {
10
- constructor(container) {
11
+ constructor(container, applicationConfig) {
11
12
  this.container = container;
13
+ this.applicationConfig = applicationConfig;
12
14
  this.pathsExplorer = new paths_explorer_1.PathsExplorer(new metadata_scanner_1.MetadataScanner());
13
15
  }
14
- mapRouteToRouteInfo(route) {
15
- if ((0, shared_utils_1.isString)(route)) {
16
- return this.getRouteInfoFromPath(route);
16
+ mapRouteToRouteInfo(controllerOrRoute) {
17
+ if ((0, shared_utils_1.isString)(controllerOrRoute)) {
18
+ return this.getRouteInfoFromPath(controllerOrRoute);
17
19
  }
18
- const routePathOrPaths = this.getRoutePath(route);
19
- if (this.isRouteInfo(routePathOrPaths, route)) {
20
- return this.getRouteInfoFromObject(route);
20
+ const routePathOrPaths = this.getRoutePath(controllerOrRoute);
21
+ if (this.isRouteInfo(routePathOrPaths, controllerOrRoute)) {
22
+ return this.getRouteInfoFromObject(controllerOrRoute);
21
23
  }
22
- return this.getRouteInfoFromController(route, routePathOrPaths);
24
+ return this.getRouteInfoFromController(controllerOrRoute, routePathOrPaths);
23
25
  }
24
26
  getRouteInfoFromPath(routePath) {
25
27
  const defaultRequestMethod = -1;
@@ -42,27 +44,37 @@ class RoutesMapper {
42
44
  }
43
45
  getRouteInfoFromController(controller, routePath) {
44
46
  const controllerPaths = this.pathsExplorer.scanForPaths(Object.create(controller), controller.prototype);
47
+ const controllerVersion = this.getVersionMetadata(controller);
48
+ const versioningConfig = this.applicationConfig.getVersioning();
45
49
  const moduleRef = this.getHostModuleOfController(controller);
46
- const modulePath = this.getModulePath(moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype);
50
+ const modulePath = this.getModulePath(moduleRef?.metatype);
47
51
  const concatPaths = (acc, currentValue) => acc.concat(currentValue);
52
+ const toUndefinedIfNeural = (version) => version === interfaces_1.VERSION_NEUTRAL ? undefined : version;
53
+ const toRouteInfo = (item, prefix) => item.path
54
+ ?.map(p => {
55
+ let endpointPath = modulePath ?? '';
56
+ endpointPath += this.normalizeGlobalPath(prefix) + (0, shared_utils_1.addLeadingSlash)(p);
57
+ const routeInfo = {
58
+ path: endpointPath,
59
+ method: item.requestMethod,
60
+ };
61
+ const version = item.version ?? controllerVersion;
62
+ if (version && versioningConfig) {
63
+ if (typeof version !== 'string' && Array.isArray(version)) {
64
+ return version.map(v => ({
65
+ ...routeInfo,
66
+ version: toUndefinedIfNeural(v),
67
+ }));
68
+ }
69
+ routeInfo.version = toUndefinedIfNeural(version);
70
+ }
71
+ return routeInfo;
72
+ })
73
+ .flat();
48
74
  return []
49
75
  .concat(routePath)
50
76
  .map(routePath => controllerPaths
51
- .map(item => {
52
- var _a;
53
- return (_a = item.path) === null || _a === void 0 ? void 0 : _a.map(p => {
54
- let path = modulePath !== null && modulePath !== void 0 ? modulePath : '';
55
- path += this.normalizeGlobalPath(routePath) + (0, shared_utils_1.addLeadingSlash)(p);
56
- const routeInfo = {
57
- path,
58
- method: item.requestMethod,
59
- };
60
- if (item.version) {
61
- routeInfo.version = item.version;
62
- }
63
- return routeInfo;
64
- });
65
- })
77
+ .map(item => toRouteInfo(item, routePath))
66
78
  .reduce(concatPaths, []))
67
79
  .reduce(concatPaths, []);
68
80
  }
@@ -86,7 +98,7 @@ class RoutesMapper {
86
98
  return;
87
99
  }
88
100
  const modules = Array.from(modulesContainer.values()).filter(moduleRef => moduleRefsSet.has(moduleRef));
89
- return modules.find(({ routes }) => routes.has(metatype));
101
+ return modules.find(({ controllers }) => controllers.has(metatype));
90
102
  }
91
103
  getModulePath(metatype) {
92
104
  if (!metatype) {
@@ -94,7 +106,14 @@ class RoutesMapper {
94
106
  }
95
107
  const modulesContainer = this.container.getModules();
96
108
  const modulePath = Reflect.getMetadata(constants_1.MODULE_PATH + modulesContainer.applicationId, metatype);
97
- return modulePath !== null && modulePath !== void 0 ? modulePath : Reflect.getMetadata(constants_1.MODULE_PATH, metatype);
109
+ return modulePath ?? Reflect.getMetadata(constants_1.MODULE_PATH, metatype);
110
+ }
111
+ getVersionMetadata(metatype) {
112
+ const versioningConfig = this.applicationConfig.getVersioning();
113
+ if (versioningConfig) {
114
+ return (Reflect.getMetadata(constants_1.VERSION_METADATA, metatype) ??
115
+ versioningConfig.defaultVersion);
116
+ }
98
117
  }
99
118
  }
100
119
  exports.RoutesMapper = RoutesMapper;
@@ -65,15 +65,14 @@ const mapToClass = (middleware, excludedRoutes, httpAdapter) => {
65
65
  };
66
66
  exports.mapToClass = mapToClass;
67
67
  function isMiddlewareClass(middleware) {
68
- var _a, _b;
69
68
  const middlewareStr = middleware.toString();
70
69
  if (middlewareStr.substring(0, 5) === 'class') {
71
70
  return true;
72
71
  }
73
72
  const middlewareArr = middlewareStr.split(' ');
74
73
  return (middlewareArr[0] === 'function' &&
75
- /[A-Z]/.test((_a = middlewareArr[1]) === null || _a === void 0 ? void 0 : _a[0]) &&
76
- (0, shared_utils_1.isFunction)((_b = middleware.prototype) === null || _b === void 0 ? void 0 : _b.use));
74
+ /[A-Z]/.test(middlewareArr[1]?.[0]) &&
75
+ (0, shared_utils_1.isFunction)(middleware.prototype?.use));
77
76
  }
78
77
  exports.isMiddlewareClass = isMiddlewareClass;
79
78
  function assignToken(metatype, token = (0, uid_1.uid)(21)) {
@@ -66,11 +66,10 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
66
66
  * @returns {TResult | Array<TResult>}
67
67
  */
68
68
  get(typeOrToken, options = { strict: false }) {
69
- var _a;
70
69
  return !(options && options.strict)
71
70
  ? this.find(typeOrToken, options)
72
71
  : this.find(typeOrToken, {
73
- moduleId: (_a = this.contextModule) === null || _a === void 0 ? void 0 : _a.id,
72
+ moduleId: this.contextModule?.id,
74
73
  each: options.each,
75
74
  });
76
75
  }
@@ -193,7 +192,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
193
192
  process.kill(process.pid, signal);
194
193
  }
195
194
  catch (err) {
196
- common_1.Logger.error(constants_1.MESSAGES.ERROR_DURING_SHUTDOWN, err === null || err === void 0 ? void 0 : err.stack, NestApplicationContext.name);
195
+ common_1.Logger.error(constants_1.MESSAGES.ERROR_DURING_SHUTDOWN, err?.stack, NestApplicationContext.name);
197
196
  process.exit(1);
198
197
  }
199
198
  };
@@ -272,14 +271,13 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
272
271
  }
273
272
  }
274
273
  getModulesToTriggerHooksOn() {
275
- var _a;
276
274
  if (this._moduleRefsForHooksByDistance) {
277
275
  return this._moduleRefsForHooksByDistance;
278
276
  }
279
277
  const modulesContainer = this.container.getModules();
280
278
  const compareFn = (a, b) => b.distance - a.distance;
281
279
  const modulesSortedByDistance = Array.from(modulesContainer.values()).sort(compareFn);
282
- this._moduleRefsForHooksByDistance = ((_a = this.appOptions) === null || _a === void 0 ? void 0 : _a.preview)
280
+ this._moduleRefsForHooksByDistance = this.appOptions?.preview
283
281
  ? modulesSortedByDistance.filter(moduleRef => moduleRef.initOnPreview)
284
282
  : modulesSortedByDistance;
285
283
  return this._moduleRefsForHooksByDistance;
@@ -88,9 +88,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
88
88
  this.socketModule.register(this.container, this.config, this.graphInspector, this.appOptions, this.httpServer);
89
89
  }
90
90
  async init() {
91
- var _a;
92
91
  this.applyOptions();
93
- await ((_a = this.httpAdapter) === null || _a === void 0 ? void 0 : _a.init());
92
+ await this.httpAdapter?.init();
94
93
  const useBodyParser = this.appOptions && this.appOptions.bodyParser !== false;
95
94
  useBodyParser && this.registerParserMiddleware();
96
95
  await this.registerModules();
@@ -103,9 +102,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
103
102
  return this;
104
103
  }
105
104
  registerParserMiddleware() {
106
- var _a;
107
105
  const prefix = this.config.getGlobalPrefix();
108
- const rawBody = !!((_a = this.appOptions) === null || _a === void 0 ? void 0 : _a.rawBody);
106
+ const rawBody = !!this.appOptions?.rawBody;
109
107
  this.httpAdapter.registerParserMiddleware(prefix, rawBody);
110
108
  }
111
109
  async registerRouter() {
@@ -168,8 +166,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
168
166
  !this.isInitialized && (await this.init());
169
167
  return new Promise((resolve, reject) => {
170
168
  const errorHandler = (e) => {
171
- var _a;
172
- this.logger.error((_a = e === null || e === void 0 ? void 0 : e.toString) === null || _a === void 0 ? void 0 : _a.call(e));
169
+ this.logger.error(e?.toString?.());
173
170
  reject(e);
174
171
  };
175
172
  this.httpServer.once('error', errorHandler);
@@ -178,8 +175,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
178
175
  ? args.slice(0, args.length - 1)
179
176
  : args;
180
177
  this.httpAdapter.listen(port, ...listenFnArgs, (...originalCallbackArgs) => {
181
- var _a, _b;
182
- if ((_b = (_a = this.appOptions) === null || _a === void 0 ? void 0 : _a.autoFlushLogs) !== null && _b !== void 0 ? _b : true) {
178
+ if (this.appOptions?.autoFlushLogs ?? true) {
183
179
  this.flushLogs();
184
180
  }
185
181
  if (originalCallbackArgs[0] instanceof Error) {
@@ -233,10 +229,13 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
233
229
  setGlobalPrefix(prefix, options) {
234
230
  this.config.setGlobalPrefix(prefix);
235
231
  if (options) {
236
- const exclude = (options === null || options === void 0 ? void 0 : options.exclude)
232
+ const exclude = options?.exclude
237
233
  ? (0, utils_1.mapToExcludeRoute)(options.exclude)
238
234
  : [];
239
- this.config.setGlobalPrefixOptions(Object.assign(Object.assign({}, options), { exclude }));
235
+ this.config.setGlobalPrefixOptions({
236
+ ...options,
237
+ exclude,
238
+ });
240
239
  }
241
240
  return this;
242
241
  }
package/nest-factory.js CHANGED
@@ -100,7 +100,7 @@ class NestFactoryStatic {
100
100
  const dependenciesScanner = new scanner_1.DependenciesScanner(container, metadataScanner, graphInspector, config);
101
101
  container.setHttpAdapter(httpServer);
102
102
  const teardown = this.abortOnError === false ? rethrow_1.rethrow : undefined;
103
- await (httpServer === null || httpServer === void 0 ? void 0 : httpServer.init());
103
+ await httpServer?.init();
104
104
  try {
105
105
  this.logger.log(constants_1.MESSAGES.APPLICATION_START);
106
106
  await exceptions_zone_1.ExceptionsZone.asyncRun(async () => {
@@ -158,7 +158,7 @@ class NestFactoryStatic {
158
158
  if (bufferLogs) {
159
159
  logger_service_1.Logger.attachBuffer();
160
160
  }
161
- this.autoFlushLogs = autoFlushLogs !== null && autoFlushLogs !== void 0 ? autoFlushLogs : true;
161
+ this.autoFlushLogs = autoFlushLogs ?? true;
162
162
  }
163
163
  createHttpAdapter(httpServer) {
164
164
  const { ExpressAdapter } = (0, load_adapter_1.loadAdapter)('@nestjs/platform-express', 'HTTP', () => require('@nestjs/platform-express'));
@@ -200,7 +200,7 @@ class NestFactoryStatic {
200
200
  return proxy;
201
201
  }
202
202
  createGraphInspector(appOptions, container) {
203
- return (appOptions === null || appOptions === void 0 ? void 0 : appOptions.snapshot)
203
+ return appOptions?.snapshot
204
204
  ? new graph_inspector_1.GraphInspector(container)
205
205
  : noop_graph_inspector_1.NoopGraphInspector;
206
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "9.4.3",
3
+ "version": "10.0.1",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -36,13 +36,13 @@
36
36
  "uid": "2.0.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "9.4.3"
39
+ "@nestjs/common": "10.0.1"
40
40
  },
41
41
  "peerDependencies": {
42
- "@nestjs/common": "^9.0.0",
43
- "@nestjs/microservices": "^9.0.0",
44
- "@nestjs/platform-express": "^9.0.0",
45
- "@nestjs/websockets": "^9.0.0",
42
+ "@nestjs/common": "^10.0.0",
43
+ "@nestjs/microservices": "^10.0.0",
44
+ "@nestjs/platform-express": "^10.0.0",
45
+ "@nestjs/websockets": "^10.0.0",
46
46
  "reflect-metadata": "^0.1.12",
47
47
  "rxjs": "^7.1.0"
48
48
  },
@@ -24,6 +24,6 @@ class HelpReplFn extends repl_function_1.ReplFunction {
24
24
  '\n');
25
25
  }
26
26
  }
27
+ exports.HelpReplFn = HelpReplFn;
27
28
  HelpReplFn.buildHelpMessage = ({ name, description }) => cli_colors_util_1.clc.cyanBright(name) +
28
29
  (description ? ` ${cli_colors_util_1.clc.bold('-')} ${description}` : '');
29
- exports.HelpReplFn = HelpReplFn;
@@ -17,7 +17,7 @@ class MethodsReplFn extends repl_function_1.ReplFunction {
17
17
  action(token) {
18
18
  const proto = typeof token !== 'function'
19
19
  ? Object.getPrototypeOf(this.ctx.app.get(token))
20
- : token === null || token === void 0 ? void 0 : token.prototype;
20
+ : token?.prototype;
21
21
  const methods = this.metadataScanner.getAllMethodNames(proto);
22
22
  this.ctx.writeToStdout('\n');
23
23
  this.ctx.writeToStdout(`${cli_colors_util_1.clc.green('Methods')}:\n`);
@@ -41,7 +41,6 @@ class ReplContext {
41
41
  });
42
42
  }
43
43
  introspectCollection(moduleRef, moduleKey, collection) {
44
- var _a;
45
44
  const moduleDebugEntry = {};
46
45
  moduleRef[collection].forEach(({ token }) => {
47
46
  const stringifiedToken = this.stringifyToken(token);
@@ -62,21 +61,23 @@ class ReplContext {
62
61
  }
63
62
  moduleDebugEntry[stringifiedToken] = token;
64
63
  });
65
- this.debugRegistry[moduleKey] = Object.assign(Object.assign({}, (_a = this.debugRegistry) === null || _a === void 0 ? void 0 : _a[moduleKey]), { [collection]: moduleDebugEntry });
64
+ this.debugRegistry[moduleKey] = {
65
+ ...this.debugRegistry?.[moduleKey],
66
+ [collection]: moduleDebugEntry,
67
+ };
66
68
  }
67
69
  stringifyToken(token) {
68
70
  return typeof token !== 'string'
69
71
  ? typeof token === 'function'
70
72
  ? token.name
71
- : token === null || token === void 0 ? void 0 : token.toString()
73
+ : token?.toString()
72
74
  : `"${token}"`;
73
75
  }
74
76
  addNativeFunction(NativeFunctionRef) {
75
- var _a;
76
77
  const nativeFunction = new NativeFunctionRef(this);
77
78
  const nativeFunctions = [nativeFunction];
78
79
  this.nativeFunctions.set(nativeFunction.fnDefinition.name, nativeFunction);
79
- (_a = nativeFunction.fnDefinition.aliases) === null || _a === void 0 ? void 0 : _a.forEach(aliasName => {
80
+ nativeFunction.fnDefinition.aliases?.forEach(aliasName => {
80
81
  const aliasNativeFunction = Object.create(nativeFunction);
81
82
  aliasNativeFunction.fnDefinition = {
82
83
  name: aliasName,
@@ -14,9 +14,9 @@ class ReplLogger extends common_1.ConsoleLogger {
14
14
  return super.log.apply(this, Array.from(arguments));
15
15
  }
16
16
  }
17
+ exports.ReplLogger = ReplLogger;
17
18
  ReplLogger.ignoredContexts = [
18
19
  routes_resolver_1.RoutesResolver.name,
19
20
  router_explorer_1.RouterExplorer.name,
20
21
  nest_application_1.NestApplication.name,
21
22
  ];
22
- exports.ReplLogger = ReplLogger;
@@ -29,7 +29,7 @@ function defineDefaultCommandsOnRepl(replServer) {
29
29
  // getter property that outputs the helper message and returns undefined.
30
30
  // But if the command was retrieve from the `commands` object, it will
31
31
  // have a `help` property that returns the helper message.
32
- const helpMessage = nativeCommandOrFunction === null || nativeCommandOrFunction === void 0 ? void 0 : nativeCommandOrFunction.help;
32
+ const helpMessage = nativeCommandOrFunction?.help;
33
33
  if (helpMessage) {
34
34
  this.output.write(`${helpMessage}\n`);
35
35
  }
@@ -1,12 +1,14 @@
1
1
  import { RequestMethod, VersioningOptions } from '@nestjs/common';
2
+ import { VersionValue } from '@nestjs/common/interfaces';
2
3
  import { ApplicationConfig } from '../application-config';
3
4
  import { RoutePathMetadata } from './interfaces/route-path-metadata.interface';
4
5
  export declare class RoutePathFactory {
5
6
  private readonly applicationConfig;
6
7
  constructor(applicationConfig: ApplicationConfig);
7
8
  create(metadata: RoutePathMetadata, requestMethod?: RequestMethod): string[];
8
- getVersion(metadata: RoutePathMetadata): import("@nestjs/common/interfaces").VersionValue;
9
+ getVersion(metadata: RoutePathMetadata): VersionValue;
9
10
  getVersionPrefix(versioningOptions: VersioningOptions): string;
10
11
  appendToAllIfDefined(paths: string[], fragmentToAppend: string | string[] | undefined): string[];
11
- isExcludedFromGlobalPrefix(path: string, requestMethod?: RequestMethod): boolean;
12
+ isExcludedFromGlobalPrefix(path: string, requestMethod?: RequestMethod, versionOrVersions?: VersionValue, versioningOptions?: VersioningOptions): boolean;
13
+ private truncateVersionPrefixFromPath;
12
14
  }
@@ -9,11 +9,10 @@ class RoutePathFactory {
9
9
  this.applicationConfig = applicationConfig;
10
10
  }
11
11
  create(metadata, requestMethod) {
12
- var _a;
13
12
  let paths = [''];
14
13
  const versionOrVersions = this.getVersion(metadata);
15
14
  if (versionOrVersions &&
16
- ((_a = metadata.versioningOptions) === null || _a === void 0 ? void 0 : _a.type) === common_1.VersioningType.URI) {
15
+ metadata.versioningOptions?.type === common_1.VersioningType.URI) {
17
16
  const versionPrefix = this.getVersionPrefix(metadata.versioningOptions);
18
17
  if (Array.isArray(versionOrVersions)) {
19
18
  paths = (0, common_1.flatten)(paths.map(path => versionOrVersions.map(version =>
@@ -34,7 +33,7 @@ class RoutePathFactory {
34
33
  paths = this.appendToAllIfDefined(paths, metadata.methodPath);
35
34
  if (metadata.globalPrefix) {
36
35
  paths = paths.map(path => {
37
- if (this.isExcludedFromGlobalPrefix(path, requestMethod)) {
36
+ if (this.isExcludedFromGlobalPrefix(path, requestMethod, versionOrVersions, metadata.versioningOptions)) {
38
37
  return path;
39
38
  }
40
39
  return (0, shared_utils_1.stripEndSlash)(metadata.globalPrefix || '') + path;
@@ -72,14 +71,31 @@ class RoutePathFactory {
72
71
  }
73
72
  return paths.map(path => concatPaths(path, fragmentToAppend));
74
73
  }
75
- isExcludedFromGlobalPrefix(path, requestMethod) {
74
+ isExcludedFromGlobalPrefix(path, requestMethod, versionOrVersions, versioningOptions) {
76
75
  if ((0, shared_utils_1.isUndefined)(requestMethod)) {
77
76
  return false;
78
77
  }
79
78
  const options = this.applicationConfig.getGlobalPrefixOptions();
80
79
  const excludedRoutes = options.exclude;
80
+ if (versionOrVersions &&
81
+ versionOrVersions !== common_1.VERSION_NEUTRAL &&
82
+ versioningOptions?.type === common_1.VersioningType.URI) {
83
+ path = this.truncateVersionPrefixFromPath(path, versionOrVersions, versioningOptions);
84
+ }
81
85
  return (Array.isArray(excludedRoutes) &&
82
86
  (0, utils_1.isRouteExcluded)(excludedRoutes, path, requestMethod));
83
87
  }
88
+ truncateVersionPrefixFromPath(path, versionValue, versioningOptions) {
89
+ if (typeof versionValue !== 'string') {
90
+ versionValue.forEach(version => {
91
+ if (typeof version === 'string') {
92
+ path = this.truncateVersionPrefixFromPath(path, version, versioningOptions);
93
+ }
94
+ });
95
+ return path;
96
+ }
97
+ const prefix = `/${this.getVersionPrefix(versioningOptions)}${versionValue}`;
98
+ return path.startsWith(prefix) ? path.replace(prefix, '') : path;
99
+ }
84
100
  }
85
101
  exports.RoutePathFactory = RoutePathFactory;
@@ -166,8 +166,7 @@ class RouterExecutionContext {
166
166
  const isSseHandler = !!this.reflectSse(callback);
167
167
  if (isSseHandler) {
168
168
  return (result, res, req) => {
169
- var _a;
170
- this.responseController.sse(result, res.raw || res, req.raw || req, { additionalHeaders: (_a = res.getHeaders) === null || _a === void 0 ? void 0 : _a.call(res) });
169
+ this.responseController.sse(result, res.raw || res, req.raw || req, { additionalHeaders: res.getHeaders?.() });
171
170
  };
172
171
  }
173
172
  return async (result, res) => {
@@ -104,7 +104,10 @@ class RouterExplorer {
104
104
  routerMethodRef(path, routeHandler);
105
105
  this.graphInspector.insertEntrypointDefinition(entrypointDefinition, instanceWrapper.id);
106
106
  });
107
- const pathsToLog = this.routePathFactory.create(Object.assign(Object.assign({}, routePathMetadata), { versioningOptions: undefined }), requestMethod);
107
+ const pathsToLog = this.routePathFactory.create({
108
+ ...routePathMetadata,
109
+ versioningOptions: undefined,
110
+ }, requestMethod);
108
111
  pathsToLog.forEach(path => {
109
112
  if (isVersioned) {
110
113
  const version = this.routePathFactory.getVersion(routePathMetadata);
@@ -136,7 +139,14 @@ class RouterExplorer {
136
139
  for (const exp of hostRegExps) {
137
140
  const match = hostname.match(exp.regexp);
138
141
  if (match) {
139
- exp.keys.forEach((key, i) => (req.hosts[key.name] = match[i + 1]));
142
+ if (exp.keys.length > 0) {
143
+ exp.keys.forEach((key, i) => (req.hosts[key.name] = match[i + 1]));
144
+ }
145
+ else if (exp.regexp && match.groups) {
146
+ for (const groupName in match.groups) {
147
+ req.hosts[groupName] = match.groups[groupName];
148
+ }
149
+ }
140
150
  return handler(req, res, next);
141
151
  }
142
152
  }