@nestjs/core 10.4.11 → 11.0.0-next.2

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 (85) hide show
  1. package/adapters/http-adapter.d.ts +15 -2
  2. package/adapters/http-adapter.js +24 -1
  3. package/errors/exception-handler.d.ts +1 -2
  4. package/errors/exception-handler.js +1 -6
  5. package/errors/exceptions/undefined-dependency.exception.d.ts +2 -2
  6. package/errors/exceptions/undefined-dependency.exception.js +2 -2
  7. package/errors/exceptions/unknown-dependencies.exception.d.ts +2 -2
  8. package/errors/exceptions-zone.d.ts +2 -2
  9. package/errors/messages.d.ts +2 -2
  10. package/errors/messages.js +3 -3
  11. package/exceptions/base-exception-filter-context.js +1 -1
  12. package/exceptions/base-exception-filter.d.ts +2 -2
  13. package/exceptions/base-exception-filter.js +2 -3
  14. package/exceptions/exceptions-handler.d.ts +2 -2
  15. package/exceptions/exceptions-handler.js +2 -2
  16. package/exceptions/external-exception-filter-context.d.ts +1 -1
  17. package/exceptions/external-exception-filter-context.js +1 -1
  18. package/exceptions/external-exception-filter.js +3 -2
  19. package/exceptions/external-exceptions-handler.d.ts +2 -2
  20. package/exceptions/external-exceptions-handler.js +2 -2
  21. package/guards/guards-context-creator.d.ts +1 -1
  22. package/guards/guards-context-creator.js +2 -2
  23. package/helpers/execution-context-host.d.ts +1 -1
  24. package/helpers/external-context-creator.d.ts +1 -1
  25. package/helpers/external-context-creator.js +8 -8
  26. package/helpers/router-method-factory.js +7 -0
  27. package/injector/abstract-instance-resolver.js +2 -2
  28. package/injector/compiler.d.ts +9 -8
  29. package/injector/compiler.js +20 -14
  30. package/injector/container.d.ts +8 -7
  31. package/injector/container.js +13 -5
  32. package/injector/helpers/silent-logger.js +0 -1
  33. package/injector/injector.d.ts +5 -5
  34. package/injector/injector.js +7 -7
  35. package/injector/inquirer/inquirer-providers.js +0 -1
  36. package/injector/instance-wrapper.d.ts +4 -4
  37. package/injector/instance-wrapper.js +4 -4
  38. package/injector/lazy-module-loader/lazy-module-loader.d.ts +1 -1
  39. package/injector/module-ref.js +1 -0
  40. package/injector/module.d.ts +2 -2
  41. package/injector/module.js +7 -3
  42. package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.d.ts +15 -0
  43. package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.js +40 -0
  44. package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.d.ts +15 -0
  45. package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.js +83 -0
  46. package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.d.ts +18 -0
  47. package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.js +2 -0
  48. package/inspector/noop-graph-inspector.js +0 -1
  49. package/inspector/serialized-graph.d.ts +2 -2
  50. package/interceptors/interceptors-context-creator.d.ts +1 -1
  51. package/interceptors/interceptors-context-creator.js +2 -2
  52. package/metadata-scanner.d.ts +1 -1
  53. package/middleware/builder.d.ts +1 -1
  54. package/middleware/builder.js +2 -3
  55. package/middleware/middleware-module.js +1 -1
  56. package/middleware/route-info-path-extractor.js +6 -2
  57. package/middleware/utils.js +22 -11
  58. package/nest-application-context.d.ts +3 -3
  59. package/nest-application-context.js +16 -6
  60. package/nest-application.js +2 -2
  61. package/nest-factory.d.ts +7 -5
  62. package/nest-factory.js +1 -1
  63. package/package.json +3 -3
  64. package/pipes/pipes-context-creator.d.ts +1 -1
  65. package/pipes/pipes-context-creator.js +2 -2
  66. package/repl/assign-to-object.util.d.ts +1 -1
  67. package/router/interfaces/route-params-factory.interface.d.ts +1 -1
  68. package/router/legacy-route-converter.d.ts +13 -0
  69. package/router/legacy-route-converter.js +48 -0
  70. package/router/request/request-providers.js +0 -1
  71. package/router/route-params-factory.d.ts +2 -2
  72. package/router/route-params-factory.js +1 -0
  73. package/router/route-path-factory.d.ts +1 -1
  74. package/router/router-exception-filters.d.ts +1 -1
  75. package/router/router-exception-filters.js +1 -1
  76. package/router/router-execution-context.d.ts +2 -2
  77. package/router/router-execution-context.js +1 -1
  78. package/router/router-explorer.js +17 -5
  79. package/router/router-proxy.d.ts +3 -3
  80. package/router/sse-stream.js +1 -1
  81. package/router/utils/flatten-route-paths.util.d.ts +5 -1
  82. package/scanner.d.ts +2 -2
  83. package/scanner.js +6 -6
  84. package/services/reflector.service.d.ts +3 -3
  85. package/services/reflector.service.js +7 -0
@@ -9,7 +9,6 @@ const exceptions_1 = require("./errors/exceptions");
9
9
  const context_id_factory_1 = require("./helpers/context-id-factory");
10
10
  const hooks_1 = require("./hooks");
11
11
  const abstract_instance_resolver_1 = require("./injector/abstract-instance-resolver");
12
- const compiler_1 = require("./injector/compiler");
13
12
  const injector_1 = require("./injector/injector");
14
13
  const instance_links_host_1 = require("./injector/instance-links-host");
15
14
  /**
@@ -34,8 +33,8 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
34
33
  });
35
34
  this.shouldFlushLogsOnOverride = false;
36
35
  this.activeShutdownSignals = new Array();
37
- this.moduleCompiler = new compiler_1.ModuleCompiler();
38
36
  this.injector = new injector_1.Injector();
37
+ this.moduleCompiler = container.getModuleCompiler();
39
38
  if (this.appOptions.preview) {
40
39
  this.printInPreviewModeWarning();
41
40
  }
@@ -48,18 +47,26 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
48
47
  * Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
49
48
  * @returns {INestApplicationContext}
50
49
  */
51
- select(moduleType) {
50
+ select(moduleType, selectOptions) {
52
51
  const modulesContainer = this.container.getModules();
53
52
  const contextModuleCtor = this.contextModule.metatype;
54
53
  const scope = this.scope.concat(contextModuleCtor);
55
54
  const moduleTokenFactory = this.container.getModuleTokenFactory();
56
55
  const { type, dynamicMetadata } = this.moduleCompiler.extractMetadata(moduleType);
57
- const token = moduleTokenFactory.create(type, dynamicMetadata);
56
+ const token = dynamicMetadata
57
+ ? moduleTokenFactory.createForDynamic(type, dynamicMetadata, moduleType)
58
+ : moduleTokenFactory.createForStatic(type, moduleType);
58
59
  const selectedModule = modulesContainer.get(token);
59
60
  if (!selectedModule) {
60
61
  throw new exceptions_1.UnknownModuleException(type.name);
61
62
  }
62
- return new NestApplicationContext(this.container, this.appOptions, selectedModule, scope);
63
+ const options = typeof selectOptions?.abortOnError !== 'undefined'
64
+ ? {
65
+ ...this.appOptions,
66
+ ...selectOptions,
67
+ }
68
+ : this.appOptions;
69
+ return new NestApplicationContext(this.container, options, selectedModule, scope);
63
70
  }
64
71
  /**
65
72
  * Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
@@ -97,6 +104,7 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
97
104
  if (this.isInitialized) {
98
105
  return this;
99
106
  }
107
+ /* eslint-disable-next-line no-async-promise-executor */
100
108
  this.initializationPromise = new Promise(async (resolve, reject) => {
101
109
  try {
102
110
  await this.callInitHook();
@@ -239,7 +247,9 @@ class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstan
239
247
  * modules and its children.
240
248
  */
241
249
  async callDestroyHook() {
242
- const modulesSortedByDistance = this.getModulesToTriggerHooksOn();
250
+ const modulesSortedByDistance = [
251
+ ...this.getModulesToTriggerHooksOn(),
252
+ ].reverse();
243
253
  for (const module of modulesSortedByDistance) {
244
254
  await (0, hooks_1.callModuleDestroyHook)(module);
245
255
  }
@@ -92,7 +92,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
92
92
  return this;
93
93
  }
94
94
  this.applyOptions();
95
- await this.httpAdapter?.init();
95
+ await this.httpAdapter?.init?.();
96
96
  const useBodyParser = this.appOptions && this.appOptions.bodyParser !== false;
97
97
  useBodyParser && this.registerParserMiddleware();
98
98
  await this.registerModules();
@@ -154,7 +154,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
154
154
  }
155
155
  const [parserType, ...otherArgs] = args;
156
156
  const rawBody = !!this.appOptions.rawBody;
157
- this.httpAdapter.useBodyParser(...[parserType, rawBody, ...otherArgs]);
157
+ this.httpAdapter.useBodyParser?.(...[parserType, rawBody, ...otherArgs]);
158
158
  return this;
159
159
  }
160
160
  enableCors(options) {
package/nest-factory.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { INestApplication, INestApplicationContext, INestMicroservice } from '@nestjs/common';
1
+ import { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, INestMicroservice, Type } from '@nestjs/common';
2
2
  import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface';
3
3
  import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
4
4
  import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
5
5
  import { AbstractHttpAdapter } from './adapters/http-adapter';
6
+ type IEntryNestModule = Type<any> | DynamicModule | ForwardReference | Promise<IEntryNestModule>;
6
7
  /**
7
8
  * @publicApi
8
9
  */
@@ -19,7 +20,7 @@ export declare class NestFactoryStatic {
19
20
  * @returns A promise that, when resolved,
20
21
  * contains a reference to the NestApplication instance.
21
22
  */
22
- create<T extends INestApplication = INestApplication>(module: any, options?: NestApplicationOptions): Promise<T>;
23
+ create<T extends INestApplication = INestApplication>(module: IEntryNestModule, options?: NestApplicationOptions): Promise<T>;
23
24
  /**
24
25
  * Creates an instance of NestApplication with the specified `httpAdapter`.
25
26
  *
@@ -31,7 +32,7 @@ export declare class NestFactoryStatic {
31
32
  * @returns A promise that, when resolved,
32
33
  * contains a reference to the NestApplication instance.
33
34
  */
34
- create<T extends INestApplication = INestApplication>(module: any, httpAdapter: AbstractHttpAdapter, options?: NestApplicationOptions): Promise<T>;
35
+ create<T extends INestApplication = INestApplication>(module: IEntryNestModule, httpAdapter: AbstractHttpAdapter, options?: NestApplicationOptions): Promise<T>;
35
36
  /**
36
37
  * Creates an instance of NestMicroservice.
37
38
  *
@@ -41,7 +42,7 @@ export declare class NestFactoryStatic {
41
42
  * @returns A promise that, when resolved,
42
43
  * contains a reference to the NestMicroservice instance.
43
44
  */
44
- createMicroservice<T extends object>(moduleCls: any, options?: NestMicroserviceOptions & T): Promise<INestMicroservice>;
45
+ createMicroservice<T extends object>(moduleCls: IEntryNestModule, options?: NestMicroserviceOptions & T): Promise<INestMicroservice>;
45
46
  /**
46
47
  * Creates an instance of NestApplicationContext.
47
48
  *
@@ -51,7 +52,7 @@ export declare class NestFactoryStatic {
51
52
  * @returns A promise that, when resolved,
52
53
  * contains a reference to the NestApplicationContext instance.
53
54
  */
54
- createApplicationContext(moduleCls: any, options?: NestApplicationContextOptions): Promise<INestApplicationContext>;
55
+ createApplicationContext(moduleCls: IEntryNestModule, options?: NestApplicationContextOptions): Promise<INestApplicationContext>;
55
56
  private createNestInstance;
56
57
  private initialize;
57
58
  private handleInitializationError;
@@ -79,3 +80,4 @@ export declare class NestFactoryStatic {
79
80
  * @publicApi
80
81
  */
81
82
  export declare const NestFactory: NestFactoryStatic;
83
+ export {};
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?.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 () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "10.4.11",
3
+ "version": "11.0.0-next.2",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -31,12 +31,12 @@
31
31
  "@nuxtjs/opencollective": "0.3.2",
32
32
  "fast-safe-stringify": "2.1.1",
33
33
  "iterare": "1.2.1",
34
- "path-to-regexp": "3.3.0",
34
+ "path-to-regexp": "8.2.0",
35
35
  "tslib": "2.7.0",
36
36
  "uid": "2.0.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "10.4.11"
39
+ "@nestjs/common": "^11.0.0-next.2"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@nestjs/common": "^10.0.0",
@@ -7,7 +7,7 @@ export declare class PipesContextCreator extends ContextCreator {
7
7
  private readonly container;
8
8
  private readonly config?;
9
9
  private moduleContext;
10
- constructor(container: NestContainer, config?: ApplicationConfig);
10
+ constructor(container: NestContainer, config?: ApplicationConfig | undefined);
11
11
  create(instance: Controller, callback: (...args: unknown[]) => unknown, moduleKey: string, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): PipeTransform[];
12
12
  createConcreteContext<T extends any[], R extends any[]>(metadata: T, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): R;
13
13
  getPipeInstance(pipe: Function | PipeTransform, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): PipeTransform | null;
@@ -23,11 +23,11 @@ class PipesContextCreator extends context_creator_1.ContextCreator {
23
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 && (0, 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) {
30
- const isObject = pipe.transform;
30
+ const isObject = !!pipe.transform;
31
31
  if (isObject) {
32
32
  return pipe;
33
33
  }
@@ -2,4 +2,4 @@
2
2
  * Similar to `Object.assign` but copying properties descriptors from `source`
3
3
  * as well.
4
4
  */
5
- export declare function assignToObject<T, U>(target: T, source: U): T & U;
5
+ export declare function assignToObject<T, U extends object>(target: T, source: U): T & U;
@@ -4,5 +4,5 @@ export interface IRouteParamsFactory {
4
4
  req: TRequest;
5
5
  res: TResponse;
6
6
  next: Function;
7
- }): TResult;
7
+ }): TResult | null;
8
8
  }
@@ -0,0 +1,13 @@
1
+ export declare class LegacyRouteConverter {
2
+ private static readonly logger;
3
+ /**
4
+ * Convert legacy routes to the new format (syntax).
5
+ * path-to-regexp used by Express>=v5 and @fastify/middie>=v9 no longer support unnamed wildcards.
6
+ * This method attempts to convert the old syntax to the new one, and logs an error if it fails.
7
+ * @param route The route to convert.
8
+ * @returns The converted route, or the original route if it cannot be converted.
9
+ */
10
+ static tryConvert(route: string): string;
11
+ static printError(route: string): void;
12
+ static printWarning(route: string): void;
13
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LegacyRouteConverter = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const UNSUPPORTED_PATH_MESSAGE = (text, route) => `Unsupported route path: "${route}". In previous versions, the symbols ?, *, and + were used to denote optional or repeating path parameters. The latest version of "path-to-regexp" now requires the use of named parameters. For example, instead of using a route like /users/* to capture all routes starting with "/users", you should use /users/*path. For more details, refer to the migration guide.`;
6
+ class LegacyRouteConverter {
7
+ /**
8
+ * Convert legacy routes to the new format (syntax).
9
+ * path-to-regexp used by Express>=v5 and @fastify/middie>=v9 no longer support unnamed wildcards.
10
+ * This method attempts to convert the old syntax to the new one, and logs an error if it fails.
11
+ * @param route The route to convert.
12
+ * @returns The converted route, or the original route if it cannot be converted.
13
+ */
14
+ static tryConvert(route) {
15
+ // Normalize path to eliminate additional conditions.
16
+ const routeWithLeadingSlash = route.startsWith('/') ? route : `/${route}`;
17
+ const normalizedRoute = route.endsWith('/')
18
+ ? routeWithLeadingSlash
19
+ : `${routeWithLeadingSlash}/`;
20
+ if (normalizedRoute.endsWith('/(.*)/')) {
21
+ // Skip printing warning for the "all" wildcard.
22
+ if (normalizedRoute !== '/(.*)/') {
23
+ this.printWarning(route);
24
+ }
25
+ return route.replace('(.*)', '*path');
26
+ }
27
+ if (normalizedRoute.endsWith('/*/')) {
28
+ // Skip printing warning for the "all" wildcard.
29
+ if (normalizedRoute !== '/*/') {
30
+ this.printWarning(route);
31
+ }
32
+ return route.replace('*', '*path');
33
+ }
34
+ if (normalizedRoute.endsWith('/+/')) {
35
+ this.printWarning(route);
36
+ return route.replace('/+', '/*path');
37
+ }
38
+ return route;
39
+ }
40
+ static printError(route) {
41
+ this.logger.error(UNSUPPORTED_PATH_MESSAGE `${route}`);
42
+ }
43
+ static printWarning(route) {
44
+ this.logger.warn(UNSUPPORTED_PATH_MESSAGE `${route}` + ' Attempting to convert...');
45
+ }
46
+ }
47
+ exports.LegacyRouteConverter = LegacyRouteConverter;
48
+ LegacyRouteConverter.logger = new common_1.Logger(LegacyRouteConverter.name);
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requestProvider = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const request_constants_1 = require("./request-constants");
6
- // eslint-disable-next-line @typescript-eslint/no-empty-function
7
6
  const noop = () => { };
8
7
  exports.requestProvider = {
9
8
  provide: request_constants_1.REQUEST,
@@ -1,9 +1,9 @@
1
1
  import { RouteParamtypes } from '@nestjs/common/enums/route-paramtypes.enum';
2
2
  import { IRouteParamsFactory } from './interfaces/route-params-factory.interface';
3
3
  export declare class RouteParamsFactory implements IRouteParamsFactory {
4
- exchangeKeyForValue<TRequest extends Record<string, any> = any, TResponse = any, TResult = any>(key: RouteParamtypes | string, data: string | object | any, { req, res, next }: {
4
+ exchangeKeyForValue<TRequest extends Record<string, any> = any, TResponse = any, TResult = any>(key: RouteParamtypes | string, data: string, { req, res, next }: {
5
5
  req: TRequest;
6
6
  res: TResponse;
7
7
  next: Function;
8
- }): TResult;
8
+ }): TResult | null;
9
9
  }
@@ -18,6 +18,7 @@ class RouteParamsFactory {
18
18
  case route_paramtypes_enum_1.RouteParamtypes.PARAM:
19
19
  return data ? req.params[data] : req.params;
20
20
  case route_paramtypes_enum_1.RouteParamtypes.HOST:
21
+ /* eslint-disable-next-line no-case-declarations */
21
22
  const hosts = req.hosts || {};
22
23
  return data ? hosts[data] : hosts;
23
24
  case route_paramtypes_enum_1.RouteParamtypes.QUERY:
@@ -6,7 +6,7 @@ export declare class RoutePathFactory {
6
6
  private readonly applicationConfig;
7
7
  constructor(applicationConfig: ApplicationConfig);
8
8
  create(metadata: RoutePathMetadata, requestMethod?: RequestMethod): string[];
9
- getVersion(metadata: RoutePathMetadata): VersionValue;
9
+ getVersion(metadata: RoutePathMetadata): VersionValue | undefined;
10
10
  getVersionPrefix(versioningOptions: VersioningOptions): string;
11
11
  appendToAllIfDefined(paths: string[], fragmentToAppend: string | string[] | undefined): string[];
12
12
  isExcludedFromGlobalPrefix(path: string, requestMethod?: RequestMethod, versionOrVersions?: VersionValue, versioningOptions?: VersioningOptions): boolean;
@@ -9,6 +9,6 @@ export declare class RouterExceptionFilters extends BaseExceptionFilterContext {
9
9
  private readonly config;
10
10
  private readonly applicationRef;
11
11
  constructor(container: NestContainer, config: ApplicationConfig, applicationRef: HttpServer);
12
- create(instance: Controller, callback: RouterProxyCallback, moduleKey: string, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): ExceptionsHandler;
12
+ create(instance: Controller, callback: RouterProxyCallback, moduleKey: string | undefined, contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): ExceptionsHandler;
13
13
  getGlobalMetadata<T extends unknown[]>(contextId?: import("../injector/instance-wrapper").ContextId, inquirerId?: string): T;
14
14
  }
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RouterExceptionFilters = void 0;
4
4
  const constants_1 = require("@nestjs/common/constants");
5
5
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
+ const iterare_1 = require("iterare");
6
7
  const base_exception_filter_context_1 = require("../exceptions/base-exception-filter-context");
7
8
  const exceptions_handler_1 = require("../exceptions/exceptions-handler");
8
9
  const constants_2 = require("../injector/constants");
9
- const iterare_1 = require("iterare");
10
10
  class RouterExceptionFilters extends base_exception_filter_context_1.BaseExceptionFilterContext {
11
11
  constructor(container, config, applicationRef) {
12
12
  super(container);
@@ -45,10 +45,10 @@ export declare class RouterExecutionContext {
45
45
  data: unknown;
46
46
  }, pipes: PipeTransform[]): Promise<unknown>;
47
47
  isPipeable(type: number | string): boolean;
48
- createGuardsFn<TContext extends string = ContextType>(guards: CanActivate[], instance: Controller, callback: (...args: any[]) => any, contextType?: TContext): (args: any[]) => Promise<void> | null;
48
+ createGuardsFn<TContext extends string = ContextType>(guards: CanActivate[], instance: Controller, callback: (...args: any[]) => any, contextType?: TContext): ((args: any[]) => Promise<void>) | null;
49
49
  createPipesFn(pipes: PipeTransform[], paramsOptions: (ParamProperties & {
50
50
  metatype?: any;
51
- })[]): <TRequest, TResponse>(args: any[], req: TRequest, res: TResponse, next: Function) => Promise<void>;
51
+ })[]): (<TRequest, TResponse>(args: any[], req: TRequest, res: TResponse, next: Function) => Promise<void>) | null;
52
52
  createHandleResponseFn(callback: (...args: unknown[]) => unknown, isResponseHandled: boolean, redirectResponse?: RedirectResponse, httpStatusCode?: number): HandleResponseFn;
53
53
  private isResponseHandled;
54
54
  }
@@ -108,7 +108,7 @@ class RouterExecutionContext {
108
108
  }
109
109
  const numericType = Number(type);
110
110
  const extractValue = (req, res, next) => this.paramsFactory.exchangeKeyForValue(numericType, data, {
111
- req,
111
+ req: req,
112
112
  res,
113
113
  next,
114
114
  });
@@ -6,7 +6,7 @@ const enums_1 = require("@nestjs/common/enums");
6
6
  const exceptions_1 = require("@nestjs/common/exceptions");
7
7
  const logger_service_1 = require("@nestjs/common/services/logger.service");
8
8
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
9
- const pathToRegexp = require("path-to-regexp");
9
+ const path_to_regexp_1 = require("path-to-regexp");
10
10
  const unknown_request_mapping_exception_1 = require("../errors/exceptions/unknown-request-mapping.exception");
11
11
  const guards_1 = require("../guards");
12
12
  const context_id_factory_1 = require("../helpers/context-id-factory");
@@ -102,7 +102,10 @@ class RouterExplorer {
102
102
  },
103
103
  };
104
104
  this.copyMetadataToCallback(targetCallback, routeHandler);
105
- routerMethodRef(path, routeHandler);
105
+ const normalizedPath = router.normalizePath
106
+ ? router.normalizePath(path)
107
+ : path;
108
+ routerMethodRef(normalizedPath, routeHandler);
106
109
  this.graphInspector.insertEntrypointDefinition(entrypointDefinition, instanceWrapper.id);
107
110
  });
108
111
  const pathsToLog = this.routePathFactory.create({
@@ -127,9 +130,18 @@ class RouterExplorer {
127
130
  const httpAdapterRef = this.container.getHttpAdapterRef();
128
131
  const hosts = Array.isArray(host) ? host : [host];
129
132
  const hostRegExps = hosts.map((host) => {
130
- const keys = [];
131
- const regexp = pathToRegexp(host, keys);
132
- return { regexp, keys };
133
+ if (typeof host === 'string') {
134
+ try {
135
+ return (0, path_to_regexp_1.pathToRegexp)(host);
136
+ }
137
+ catch (e) {
138
+ if (e instanceof TypeError) {
139
+ this.logger.error(`Unsupported host "${host}" syntax. In past releases, ?, *, and + were used to denote optional or repeating path parameters. The latest version of "path-to-regexp" now requires the use of named parameters. For example, instead of using a route like /users/* to capture all routes starting with "/users", you should use /users/*path. Please see the migration guide for more information.`);
140
+ }
141
+ throw e;
142
+ }
143
+ }
144
+ return { regexp: host, keys: [] };
133
145
  });
134
146
  const unsupportedFilteringErrorMessage = Array.isArray(host)
135
147
  ? `HTTP adapter does not support filtering on hosts: ["${host.join('", "')}"]`
@@ -1,6 +1,6 @@
1
1
  import { ExceptionsHandler } from '../exceptions/exceptions-handler';
2
- export type RouterProxyCallback = <TRequest, TResponse>(req?: TRequest, res?: TResponse, next?: () => void) => void;
2
+ export type RouterProxyCallback = <TRequest, TResponse>(req: TRequest, res: TResponse, next: () => void) => void | Promise<void>;
3
3
  export declare class RouterProxy {
4
- createProxy(targetCallback: RouterProxyCallback, exceptionsHandler: ExceptionsHandler): <TRequest, TResponse>(req: TRequest, res: TResponse, next: () => void) => Promise<TResponse>;
5
- createExceptionLayerProxy(targetCallback: <TError, TRequest, TResponse>(err: TError, req: TRequest, res: TResponse, next: () => void) => void, exceptionsHandler: ExceptionsHandler): <TError, TRequest, TResponse>(err: TError, req: TRequest, res: TResponse, next: () => void) => Promise<TResponse>;
4
+ createProxy(targetCallback: RouterProxyCallback, exceptionsHandler: ExceptionsHandler): <TRequest, TResponse>(req: TRequest, res: TResponse, next: () => void) => Promise<TResponse | undefined>;
5
+ createExceptionLayerProxy(targetCallback: <TError, TRequest, TResponse>(err: TError, req: TRequest, res: TResponse, next: () => void) => void | Promise<void>, exceptionsHandler: ExceptionsHandler): <TError, TRequest, TResponse>(err: TError, req: TRequest, res: TResponse, next: () => void) => Promise<TResponse | undefined>;
6
6
  }
@@ -49,7 +49,7 @@ class SseStream extends stream_1.Transform {
49
49
  // NGINX support https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-buffering
50
50
  'X-Accel-Buffering': 'no',
51
51
  });
52
- destination.flushHeaders();
52
+ destination.flushHeaders?.();
53
53
  }
54
54
  destination.write('\n');
55
55
  return super.pipe(destination, options);
@@ -1,2 +1,6 @@
1
+ import { Type } from '@nestjs/common';
1
2
  import { Routes } from '../interfaces/routes.interface';
2
- export declare function flattenRoutePaths(routes: Routes): any[];
3
+ export declare function flattenRoutePaths(routes: Routes): {
4
+ module: Type;
5
+ path: string;
6
+ }[];
package/scanner.d.ts CHANGED
@@ -46,8 +46,8 @@ export declare class DependenciesScanner {
46
46
  calculateModulesDistance(): void;
47
47
  insertImport(related: any, token: string, context: string): Promise<void>;
48
48
  isCustomProvider(provider: Provider): provider is ClassProvider | ValueProvider | FactoryProvider | ExistingProvider;
49
- insertProvider(provider: Provider, token: string): string | symbol | Function | InstanceWrapper<unknown>;
50
- insertInjectable(injectable: Type<Injectable> | object, token: string, host: Type<Injectable>, subtype: EnhancerSubtype, methodKey?: string): InstanceWrapper<any>;
49
+ insertProvider(provider: Provider, token: string): string | symbol | Function | InstanceWrapper<unknown> | undefined;
50
+ insertInjectable(injectable: Type<Injectable> | object, token: string, host: Type<Injectable>, subtype: EnhancerSubtype, methodKey?: string): InstanceWrapper<any> | undefined;
51
51
  insertExportedProvider(exportedProvider: Type<Injectable> | ForwardReference, token: string): void;
52
52
  insertController(controller: Type<Controller>, token: string): void;
53
53
  private insertOrOverrideModule;
package/scanner.js CHANGED
@@ -29,9 +29,9 @@ class DependenciesScanner {
29
29
  overrides: options?.overrides,
30
30
  });
31
31
  await this.scanModulesForDependencies();
32
- this.calculateModulesDistance();
33
32
  this.addScopedEnhancersMetadata();
34
33
  this.container.bindGlobalScope();
34
+ this.calculateModulesDistance();
35
35
  }
36
36
  async scanForModules({ moduleDefinition, lazy, scope = [], ctxRegistry = [], overrides = [], }) {
37
37
  const { moduleRef: moduleInstance, inserted: moduleInserted } = (await this.insertOrOverrideModule(moduleDefinition, overrides, scope)) ??
@@ -198,19 +198,19 @@ class DependenciesScanner {
198
198
  const modulesGenerator = this.container.getModules().values();
199
199
  // Skip "InternalCoreModule" from calculating distance
200
200
  modulesGenerator.next();
201
- const modulesStack = [];
202
- const calculateDistance = (moduleRef, distance = 1) => {
203
- if (!moduleRef || modulesStack.includes(moduleRef)) {
201
+ const calculateDistance = (moduleRef, distance = 1, modulesStack = []) => {
202
+ const localModulesStack = [...modulesStack];
203
+ if (!moduleRef || localModulesStack.includes(moduleRef)) {
204
204
  return;
205
205
  }
206
- modulesStack.push(moduleRef);
206
+ localModulesStack.push(moduleRef);
207
207
  const moduleImports = moduleRef.imports;
208
208
  moduleImports.forEach(importedModuleRef => {
209
209
  if (importedModuleRef) {
210
210
  if (distance > importedModuleRef.distance) {
211
211
  importedModuleRef.distance = distance;
212
212
  }
213
- calculateDistance(importedModuleRef, distance + 1);
213
+ calculateDistance(importedModuleRef, distance + 1, localModulesStack);
214
214
  }
215
215
  });
216
216
  };
@@ -66,7 +66,7 @@ export declare class Reflector {
66
66
  * @param targets context (decorated objects) to retrieve metadata from
67
67
  *
68
68
  */
69
- getAll<T extends ReflectableDecorator<any>>(decorator: T, targets: (Type<any> | Function)[]): T extends ReflectableDecorator<infer R> ? R extends Array<any> ? R : R[] : unknown;
69
+ getAll<TParam = any, TTransformed = TParam>(decorator: ReflectableDecorator<TParam, TTransformed>, targets: (Type<any> | Function)[]): TTransformed extends Array<any> ? TTransformed : TTransformed[];
70
70
  /**
71
71
  * Retrieve metadata for a specified key for a specified set of targets.
72
72
  *
@@ -82,7 +82,7 @@ export declare class Reflector {
82
82
  * @param targets context (decorated objects) to retrieve metadata from
83
83
  *
84
84
  */
85
- getAllAndMerge<T extends ReflectableDecorator<any>>(decorator: T, targets: (Type<any> | Function)[]): T extends ReflectableDecorator<infer R> ? R : unknown;
85
+ getAllAndMerge<TParam = any, TTransformed = TParam>(decorator: ReflectableDecorator<TParam, TTransformed>, targets: (Type<any> | Function)[]): TTransformed extends Array<any> ? TTransformed : TTransformed extends object ? TTransformed : TTransformed[];
86
86
  /**
87
87
  * Retrieve metadata for a specified key for a specified set of targets and merge results.
88
88
  *
@@ -98,7 +98,7 @@ export declare class Reflector {
98
98
  * @param targets context (decorated objects) to retrieve metadata from
99
99
  *
100
100
  */
101
- getAllAndOverride<T extends ReflectableDecorator<any>>(decorator: T, targets: (Type<any> | Function)[]): T extends ReflectableDecorator<infer R> ? R : unknown;
101
+ getAllAndOverride<TParam = any, TTransformed = TParam>(decorator: ReflectableDecorator<TParam, TTransformed>, targets: (Type<any> | Function)[]): TTransformed;
102
102
  /**
103
103
  * Retrieve metadata for a specified key for a specified set of targets and return a first not undefined value.
104
104
  *
@@ -60,6 +60,13 @@ class Reflector {
60
60
  if ((0, shared_utils_1.isEmpty)(metadataCollection)) {
61
61
  return metadataCollection;
62
62
  }
63
+ if (metadataCollection.length === 1) {
64
+ const value = metadataCollection[0];
65
+ if ((0, shared_utils_1.isObject)(value)) {
66
+ return value;
67
+ }
68
+ return metadataCollection;
69
+ }
63
70
  return metadataCollection.reduce((a, b) => {
64
71
  if (Array.isArray(a)) {
65
72
  return a.concat(b);