@nestjs/core 12.0.0-alpha.4 → 12.0.0-alpha.6

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 (65) hide show
  1. package/Readme.md +25 -45
  2. package/adapters/http-adapter.d.ts +2 -0
  3. package/adapters/http-adapter.js +3 -0
  4. package/application-config.d.ts +8 -2
  5. package/application-config.js +14 -0
  6. package/errors/exceptions/index.d.ts +1 -0
  7. package/errors/exceptions/index.js +1 -0
  8. package/errors/exceptions/invalid-class-module.exception.d.ts +1 -1
  9. package/errors/exceptions/invalid-class-module.exception.js +2 -2
  10. package/errors/exceptions/invalid-module.exception.d.ts +1 -1
  11. package/errors/exceptions/invalid-module.exception.js +2 -2
  12. package/errors/exceptions/route-conflict.exception.d.ts +4 -0
  13. package/errors/exceptions/route-conflict.exception.js +7 -0
  14. package/errors/messages.d.ts +5 -2
  15. package/errors/messages.js +37 -4
  16. package/exceptions/base-exception-filter.js +8 -3
  17. package/helpers/barrier.js +4 -1
  18. package/helpers/handler-metadata-storage.d.ts +1 -0
  19. package/helpers/router-method-factory.d.ts +1 -0
  20. package/helpers/router-method-factory.js +1 -0
  21. package/hooks/before-app-shutdown.hook.js +11 -2
  22. package/hooks/on-app-shutdown.hook.js +11 -2
  23. package/hooks/on-module-destroy.hook.js +11 -2
  24. package/injector/container.js +2 -2
  25. package/injector/helpers/transient-instances.d.ts +12 -0
  26. package/injector/helpers/transient-instances.js +28 -0
  27. package/injector/injector.d.ts +4 -3
  28. package/injector/injector.js +34 -13
  29. package/injector/instance-wrapper.d.ts +2 -0
  30. package/injector/instance-wrapper.js +25 -0
  31. package/injector/internal-core-module/internal-core-module-factory.js +1 -1
  32. package/injector/module.d.ts +6 -0
  33. package/injector/module.js +8 -0
  34. package/interceptors/interceptors-consumer.js +32 -7
  35. package/middleware/builder.js +5 -1
  36. package/nest-application-context.js +1 -1
  37. package/nest-application.d.ts +3 -1
  38. package/nest-application.js +96 -6
  39. package/package.json +3 -14
  40. package/router/interfaces/index.d.ts +3 -0
  41. package/router/interfaces/index.js +3 -0
  42. package/router/interfaces/resolved-route.interface.d.ts +32 -0
  43. package/router/interfaces/resolved-route.interface.js +1 -0
  44. package/router/interfaces/resolver.interface.d.ts +5 -1
  45. package/router/interfaces/route-conflict.interface.d.ts +14 -0
  46. package/router/interfaces/route-conflict.interface.js +1 -0
  47. package/router/interfaces/route-resolution-options.interface.d.ts +24 -0
  48. package/router/interfaces/route-resolution-options.interface.js +1 -0
  49. package/router/legacy-route-converter.d.ts +1 -1
  50. package/router/legacy-route-converter.js +24 -13
  51. package/router/route-conflict-detector.d.ts +71 -0
  52. package/router/route-conflict-detector.js +276 -0
  53. package/router/route-specificity-sorter.d.ts +23 -0
  54. package/router/route-specificity-sorter.js +59 -0
  55. package/router/router-execution-context.d.ts +1 -0
  56. package/router/router-execution-context.js +26 -3
  57. package/router/router-explorer.d.ts +11 -2
  58. package/router/router-explorer.js +61 -19
  59. package/router/router-response-controller.d.ts +1 -0
  60. package/router/router-response-controller.js +126 -49
  61. package/router/routes-resolver.d.ts +7 -4
  62. package/router/routes-resolver.js +9 -7
  63. package/router/sse-stream.d.ts +1 -0
  64. package/router/sse-stream.js +24 -13
  65. package/scanner.js +13 -6
package/Readme.md CHANGED
@@ -59,11 +59,11 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
59
59
 
60
60
  <table style="text-align:center;">
61
61
  <tr>
62
- <td><a href="https://trilon.io" target="_blank"><img src="https://nestjs.com/img/trilon.svg" width="200" valign="middle" /></a></td>
63
- <td><a href="https://microsoft.com/" target="_blank"><img src="https://nestjs.com/img/logos/microsoft-logo.png" width="180" valign="middle" /></a></td>
64
- <td><a href="https://mojam.co" target="_blank"><img src="https://nestjs.com/img/logos/mojam-logo.png" width="80" valign="middle" /></a></td>
62
+ <td><a href="https://trilon.io" target="_blank"><img src="https://nestjs.com/img/github/trilon-logo.svg" width="200" valign="middle" /></a></td>
63
+ <td><a href="https://microsoft.com/" target="_blank"><img src="https://nestjs.com/img/github/microsoft-logo.png" width="180" valign="middle" /></a></td>
64
+ <td><a href="https://mojam.co" target="_blank"><img src="https://images.opencollective.com/mojamco/981e9de/logo/256.png?height=256" width="80" valign="middle" /></a></td>
65
65
  <td><a href="https://valor-software.com/" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/valor-software.png" width="170" valign="middle" /></a></td>
66
- <td><a href="https://serpapi.com/" target="_blank"><img src="https://nestjs.com/img/logos/serpapi-logo.png" width="150" valign="middle" /></a></td>
66
+ <td><a href="https://serpapi.com/" target="_blank"><img src="https://nestjs.com/img/github/serpapi-logo.png" width="150" valign="middle" /></a></td>
67
67
  </tr>
68
68
  </table>
69
69
 
@@ -71,15 +71,15 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
71
71
 
72
72
  <table style="text-align:center;">
73
73
  <tr>
74
- <td><a href="https://www.redhat.com" target="_blank"><img src="https://nestjs.com/img/logos/red-hat-logo.svg" width="200" valign="middle" /></a></td>
75
- <td><a href="https://github.com/Sanofi-IADC" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/sanofi.png" width="180" valign="middle" /></a></td>
76
- <td><a href="https://nx.dev" target="_blank"><img src="https://nestjs.com/img/logos/nx-logo.png" height="45" valign="middle" /></a></td>
77
- <td><a href="https://intrinsic.ventures/" target="_blank"><img src="https://nestjs.com/img/logos/intrinisic-logo.png" width="210" valign="middle" /></a></td>
78
- <td><a href="https://jetbrains.com/" target="_blank"><img src="https://nestjs.com/img/logos/jetbrains-logo.svg" width="90" valign="middle" /></a></td>
74
+ <td><a href="https://www.redhat.com" target="_blank"><img src="https://nestjs.com/img/github/red-hat-logo.svg" width="150" valign="middle" /></a></td>
75
+ <td><a href="https://github.com/Sanofi-IADC" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/sanofi.png" width="120" valign="middle" /></a></td>
76
+ <td><a href="https://nx.dev" target="_blank"><img src="https://nestjs.com/img/github/nx-logo.png" height="45" valign="middle" /></a></td>
77
+ <td><a href="https://intrinsic.ventures/" target="_blank"><img src="https://nestjs.com/img/github/intrinisic-logo.png" width="150" valign="middle" /></a></td>
78
+ <td><a href="https://jetbrains.com/" target="_blank"><img src="https://nestjs.com/img/github/jetbrains-logo.svg" width="70" valign="middle" /></a></td>
79
79
  </tr>
80
80
  <tr>
81
- <td><a href="https://snyk.co/nestjs" target="_blank"><img src="https://nestjs.com/img/logos/snyk-logo-black.png" width="185" valign="middle" /></a></td>
82
- <td><a href="https://www.movavi.com/imovie-for-windows.html" target="_blank"><img src="https://nestjs.com/img/logos/movavi-logo.svg" width="105" valign="middle" /></a></td>
81
+ <td><a href="https://snyk.co/nestjs" target="_blank"><img src="https://nestjs.com/img/github/snyk-logo-black.png" width="125" valign="middle" /></a></td>
82
+ <td align="center"><a href="https://www.movavi.com/imovie-for-windows.html" target="_blank"><img src="https://images.opencollective.com/movavi/1fb15e5/avatar/256.png?height=256" width="60" valign="middle" /></a></td>
83
83
  </tr>
84
84
  </table>
85
85
 
@@ -87,15 +87,15 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
87
87
 
88
88
  <table style="text-align:center;">
89
89
  <tr>
90
- <td><a href="https://www.mercedes-benz.com/" target="_blank"><img src="https://nestjs.com/img/logos/mercedes-logo.png" width="100" valign="middle" /></a></td>
91
- <td><a href="https://www.dinii.jp/" target="_blank"><img src="https://nestjs.com/img/logos/dinii-logo.png" width="65" valign="middle" /></a></td>
92
- <td><a href="https://handsontable.com/docs/react-data-grid/?utm_source=NestJS_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship_2024" target="_blank"><img src="https://nestjs.com/img/logos/handsontable-dark-logo.svg#2" width="150" valign="middle" /></a></td>
93
- <td align="center" valign="middle"><a href="https://www.itflashcards.com/" target="_blank"><img src="https://nestjs.com/img/logos/it_flashcards-logo.png" width="170" valign="middle" /></a></td>
94
- <td align="center" valign="middle"><a href="https://arcjet.com/?ref=nestjs" target="_blank"><img src="https://nestjs.com/img/logos/arcjet-logo.svg" width="170" valign="middle" /></a></td>
95
- <td align="center" valign="middle"><a href="https://crawljobs.com" target="_blank"><img src="https://nestjs.com/img/logos/crawljobs-logo.svg" width="130" valign="middle" /></a></td>
90
+ <td><a href="https://www.mercedes-benz.com/" target="_blank"><img src="https://nestjs.com/img/github/mercedes-logo.png" width="100" valign="middle" /></a></td>
91
+ <td><a href="https://handsontable.com/docs/react-data-grid/?utm_source=NestJS_GH&utm_medium=sponsorship&utm_campaign=library_sponsorship_2024" target="_blank"><img src="https://nestjs.com/img/github/handsontable-dark-logo.svg#2" width="150" valign="middle" /></a></td>
92
+ <td align="center" valign="middle"><a href="https://www.itflashcards.com/" target="_blank"><img src="https://nestjs.com/img/github/it_flashcards-logo.png" width="170" valign="middle" /></a></td>
93
+ <td align="center" valign="middle"><a href="https://arcjet.com/?ref=nestjs" target="_blank"><img src="https://nestjs.com/img/github/arcjet-logo.svg" width="170" valign="middle" /></a></td>
94
+ <td align="center" valign="middle"><a href="https://pandektes.com" target="_blank"><img src="https://nestjs.com/img/github/pandektes-logo.png" width="65" valign="middle" /></a></td>
96
95
  </tr><tr>
97
- <td align="center" valign="middle"><a href="https://pandektes.com" target="_blank"><img src="https://nestjs.com/img/logos/pandektes-logo.png" width="65" valign="middle" /></a></td>
98
- <td align="center" valign="middle"><a href="https://www.fintechcrafts.com/" target="_blank"><img src="https://nestjs.com/img/logos/fintechcrafts-logo.svg" width="65" valign="middle" /></a></td>
96
+ <td align="center" valign="middle"><a href="https://www.fintechcrafts.com/" target="_blank"><img src="https://opencollective-production.s3.us-west-1.amazonaws.com/account-avatar/935813df-48a9-4b41-b923-7d70b5621c6b/2026-05-06%2010%2021%2033.png" width="65" valign="middle" /></a></td>
97
+ <td align="center" valign="middle"><a href="https://talordata.com/?campaignid=Ya5Xpw2gmhyee6Tg&utm_source=nestjs&utm_term=nestjs" target="_blank"><img src="https://images.opencollective.com/elowen/9ccac7f/avatar/512.png" width="65" valign="middle" /></a></td>
98
+ <td align="center" valign="middle"><a href="https://memory2.co/" target="_blank"><img src="https://images.opencollective.com/memory-squared/bbe37f5/avatar/256.png?height=50" width="65" valign="middle" /></a></td>
99
99
  </tr>
100
100
  </table>
101
101
 
@@ -103,32 +103,12 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
103
103
 
104
104
  <table>
105
105
  <tr>
106
- <td align="center" valign="middle"><a href="https://www.swingdev.io" target="_blank"><img src="https://nestjs.com/img/logos/swingdev-logo.svg#1" width="110" valign="middle" /></a></td>
107
- <td align="center" valign="middle"><a href="https://www.novologic.com/" target="_blank"><img src="https://nestjs.com/img/logos/novologic.png" width="110" valign="middle" /></a></td>
108
- <td align="center" valign="middle"><a href="https://mantro.net/" target="_blank"><img src="https://nestjs.com/img/logos/mantro-logo.svg" width="95" valign="middle" /></a></td>
109
- <td align="center" valign="middle"><a href="https://triplebyte.com/" target="_blank"><img src="https://nestjs.com/img/logos/triplebyte.png" width="107" valign="middle" /></a></td>
110
- <td align="center" valign="middle"><a href="https://nearpod.com/" target="_blank"><img src="https://nestjs.com/img/logos/nearpod-logo.svg" width="100" valign="middle" /></a></td>
111
- <td align="center" valign="middle"><a href="https://genuinebee.com/" target="_blank"><img src="https://nestjs.com/img/logos/genuinebee.svg" width="97" valign="middle" /></a></td>
112
- </tr>
113
- <tr>
114
- <td align="center" valign="middle"><a href="https://vpn-review.com/vpn-for-torrenting" target="_blank"><img src="https://nestjs.com/img/logos/vpn-review-logo.png" width="85" valign="middle" /></a></td>
115
- <td align="center" valign="middle"><a href="https://lambda-it.ch/" target="_blank"><img src="https://nestjs.com/img/logos/lambda-it-logo.svg" width="115" valign="middle" /></a></td>
116
- <td align="center" valign="middle"><a href="https://rocketech.it/cases/?utm_source=google&utm_medium=badge&utm_campaign=nestjs" target="_blank"><img src="https://nestjs.com/img/logos/rocketech-logo.svg" width="110" valign="middle" /></a></td>
117
- <td align="center" valign="middle"><a href="https://www.anonymistic.com/" target="_blank"><img src="https://nestjs.com/img/logos/anonymistic-logo.png" width="125" valign="middle" /></a></td>
118
- <td align="center" valign="middle"><a href="https://www.naologic.com/" target="_blank"><img src="https://nestjs.com/img/logos/naologic-logo.svg" width="125" valign="middle" /></a></td>
119
- <td align="center" valign="middle"><a href="https://triplecore.io" target="_blank"><img src="https://nestjs.com/img/logos/triplecore-logo.svg" width="50" valign="middle" /></a></td>
120
- </tr>
121
- <tr>
122
- <td align="center" valign="middle"><a href="https://polygon-software.ch/" target="_blank"><img src="https://nestjs.com/img/logos/polygon-logo.svg" width="120" valign="middle" /></a></td>
123
- <td align="center" valign="middle"><a href="https://boringowl.io/" target="_blank"><img src="https://nestjs.com/img/logos/boringowl-logo.svg" width="120" valign="middle" /></a></td>
124
- <td align="center" valign="middle"><a href="https://nordbot.app/" target="_blank"><img src="https://nestjs.com/img/logos/nordbot-logo.png" width="120" valign="middle" /></a></td>
125
- <td align="center" valign="middle"><a href="https://doppio.sh/" target="_blank"><img src="https://nestjs.com/img/logos/dopiosh-logo.png" width="50" valign="middle" /></a></td>
126
- <td align="center" valign="middle"><a href="https://www.hingehealth.com/" target="_blank"><img src="https://nestjs.com/img/logos/hinge-health-logo.svg" width="100" valign="middle" /></a></td>
127
- <td align="center" valign="middle"><a href="https://www.tripoffice.com/" target="_blank"><img src="https://nestjs.com/img/logos/tripoffice-logo.png" width="140" valign="middle" /></a></td>
128
- </tr>
129
- <tr>
130
- <td align="center" valign="middle"><a href="https://solcellsforetag.se/" target="_blank"><img src="https://nestjs.com/img/logos/solcellsforetag-logo.svg" width="140" valign="middle" /></a></td>
131
- <td align="center" valign="middle"><a href="https://www.route4me.com/" target="_blank"><img src="https://nestjs.com/img/logos/route4me-logo.svg" width="100" valign="middle" /></a></td>
106
+ <td align="center" valign="middle"><a href="https://mantro.net/" target="_blank"><img src="https://nestjs.com/img/github/mantro-logo.svg" width="95" valign="middle" /></a></td>
107
+ <td align="center" valign="middle"><a href="https://triplebyte.com/" target="_blank"><img src="https://nestjs.com/img/github/triplebyte-logo.png" width="107" valign="middle" /></a></td>
108
+ <td align="center" valign="middle"><a href="https://nearpod.com/" target="_blank"><img src="https://nestjs.com/img/github/nearpod-logo.svg" width="100" valign="middle" /></a></td>
109
+ <td align="center" valign="middle"><a href="https://www.naologic.com/" target="_blank"><img src="https://nestjs.com/img/github/naologic-logo.svg" width="125" valign="middle" /></a></td>
110
+ <td align="center" valign="middle"><a href="https://triplecore.io" target="_blank"><img src="https://nestjs.com/img/github/triplecore-logo.svg" width="50" valign="middle" /></a>
111
+ <td align="center" valign="middle"><a href="https://www.hingehealth.com/" target="_blank"><img src="https://nestjs.com/img/github/hinge-health-logo.svg" width="100" valign="middle" /></a></td>
132
112
  </tr>
133
113
  </table>
134
114
 
@@ -41,6 +41,8 @@ export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any,
41
41
  all(path: any, handler: RequestHandler): any;
42
42
  search(handler: RequestHandler): any;
43
43
  search(path: any, handler: RequestHandler): any;
44
+ query(handler: RequestHandler): any;
45
+ query(path: any, handler: RequestHandler): any;
44
46
  options(handler: RequestHandler): any;
45
47
  options(path: any, handler: RequestHandler): any;
46
48
  listen(port: string | number, callback?: () => void): any;
@@ -57,6 +57,9 @@ export class AbstractHttpAdapter {
57
57
  search(...args) {
58
58
  return this.instance.search(...args);
59
59
  }
60
+ query(...args) {
61
+ return this.instance.query(...args);
62
+ }
60
63
  options(...args) {
61
64
  return this.instance.options(...args);
62
65
  }
@@ -1,7 +1,7 @@
1
- import type { CanActivate, ExceptionFilter, NestInterceptor, PipeTransform, PreRequestHook, VersioningOptions, WebSocketAdapter } from '@nestjs/common';
1
+ import type { CanActivate, ExceptionFilter, NestInterceptor, PipeTransform, PreRequestHook, RouteConflictPolicy, RouteResolutionStrategy, VersioningOptions, WebSocketAdapter } from '@nestjs/common';
2
+ import type { GlobalPrefixOptions } from '@nestjs/common/internal';
2
3
  import { InstanceWrapper } from './injector/instance-wrapper.js';
3
4
  import { ExcludeRouteMetadata } from './router/interfaces/exclude-route-metadata.interface.js';
4
- import type { GlobalPrefixOptions } from '@nestjs/common/internal';
5
5
  export declare class ApplicationConfig {
6
6
  private ioAdapter;
7
7
  private globalPrefix;
@@ -12,6 +12,8 @@ export declare class ApplicationConfig {
12
12
  private globalGuards;
13
13
  private globalPreRequestHooks;
14
14
  private versioningOptions;
15
+ private routeConflictPolicy;
16
+ private routeResolutionStrategy;
15
17
  private readonly globalRequestPipes;
16
18
  private readonly globalRequestFilters;
17
19
  private readonly globalRequestInterceptors;
@@ -47,4 +49,8 @@ export declare class ApplicationConfig {
47
49
  getGlobalPreRequestHooks(): PreRequestHook[];
48
50
  enableVersioning(options: VersioningOptions): void;
49
51
  getVersioning(): VersioningOptions | undefined;
52
+ setRouteConflictPolicy(policy: RouteConflictPolicy | undefined): void;
53
+ getRouteConflictPolicy(): RouteConflictPolicy | undefined;
54
+ setRouteResolutionStrategy(strategy: RouteResolutionStrategy | undefined): void;
55
+ getRouteResolutionStrategy(): RouteResolutionStrategy | undefined;
50
56
  }
@@ -8,6 +8,8 @@ export class ApplicationConfig {
8
8
  globalGuards = [];
9
9
  globalPreRequestHooks = [];
10
10
  versioningOptions;
11
+ routeConflictPolicy;
12
+ routeResolutionStrategy;
11
13
  globalRequestPipes = [];
12
14
  globalRequestFilters = [];
13
15
  globalRequestInterceptors = [];
@@ -109,4 +111,16 @@ export class ApplicationConfig {
109
111
  getVersioning() {
110
112
  return this.versioningOptions;
111
113
  }
114
+ setRouteConflictPolicy(policy) {
115
+ this.routeConflictPolicy = policy;
116
+ }
117
+ getRouteConflictPolicy() {
118
+ return this.routeConflictPolicy;
119
+ }
120
+ setRouteResolutionStrategy(strategy) {
121
+ this.routeResolutionStrategy = strategy;
122
+ }
123
+ getRouteResolutionStrategy() {
124
+ return this.routeResolutionStrategy;
125
+ }
112
126
  }
@@ -3,6 +3,7 @@ export * from './runtime.exception.js';
3
3
  export * from './unknown-element.exception.js';
4
4
  export * from './invalid-class-scope.exception.js';
5
5
  export * from './invalid-class.exception.js';
6
+ export * from './route-conflict.exception.js';
6
7
  export * from './unknown-export.exception.js';
7
8
  export * from './unknown-module.exception.js';
8
9
  export * from './undefined-forwardref.exception.js';
@@ -3,6 +3,7 @@ export * from './runtime.exception.js';
3
3
  export * from './unknown-element.exception.js';
4
4
  export * from './invalid-class-scope.exception.js';
5
5
  export * from './invalid-class.exception.js';
6
+ export * from './route-conflict.exception.js';
6
7
  export * from './unknown-export.exception.js';
7
8
  export * from './unknown-module.exception.js';
8
9
  export * from './undefined-forwardref.exception.js';
@@ -1,4 +1,4 @@
1
1
  import { RuntimeException } from './runtime.exception.js';
2
2
  export declare class InvalidClassModuleException extends RuntimeException {
3
- constructor(metatypeUsedAsAModule: any, scope: any[]);
3
+ constructor(metatypeUsedAsAModule: any, scope: any[], classKind: 'provider' | 'controller' | 'filter');
4
4
  }
@@ -1,7 +1,7 @@
1
1
  import { USING_INVALID_CLASS_AS_A_MODULE_MESSAGE } from '../messages.js';
2
2
  import { RuntimeException } from './runtime.exception.js';
3
3
  export class InvalidClassModuleException extends RuntimeException {
4
- constructor(metatypeUsedAsAModule, scope) {
5
- super(USING_INVALID_CLASS_AS_A_MODULE_MESSAGE(metatypeUsedAsAModule, scope));
4
+ constructor(metatypeUsedAsAModule, scope, classKind) {
5
+ super(USING_INVALID_CLASS_AS_A_MODULE_MESSAGE(metatypeUsedAsAModule, scope, classKind));
6
6
  }
7
7
  }
@@ -1,4 +1,4 @@
1
1
  import { RuntimeException } from './runtime.exception.js';
2
2
  export declare class InvalidModuleException extends RuntimeException {
3
- constructor(parentModule: any, index: number, scope: any[]);
3
+ constructor(parentModule: any, index: number, scope: any[], receivedValue: unknown);
4
4
  }
@@ -1,7 +1,7 @@
1
1
  import { INVALID_MODULE_MESSAGE } from '../messages.js';
2
2
  import { RuntimeException } from './runtime.exception.js';
3
3
  export class InvalidModuleException extends RuntimeException {
4
- constructor(parentModule, index, scope) {
5
- super(INVALID_MODULE_MESSAGE(parentModule, index, scope));
4
+ constructor(parentModule, index, scope, receivedValue) {
5
+ super(INVALID_MODULE_MESSAGE(parentModule, index, scope, receivedValue));
6
6
  }
7
7
  }
@@ -0,0 +1,4 @@
1
+ import { RuntimeException } from './runtime.exception.js';
2
+ export declare class RouteConflictException extends RuntimeException {
3
+ constructor(messages: string[]);
4
+ }
@@ -0,0 +1,7 @@
1
+ import { ROUTE_CONFLICT_MESSAGE } from '../messages.js';
2
+ import { RuntimeException } from './runtime.exception.js';
3
+ export class RouteConflictException extends RuntimeException {
4
+ constructor(messages) {
5
+ super(ROUTE_CONFLICT_MESSAGE(messages));
6
+ }
7
+ }
@@ -4,13 +4,16 @@ import { Module } from '../injector/module.js';
4
4
  export declare const UNKNOWN_DEPENDENCIES_MESSAGE: (type: string | symbol, unknownDependencyContext: InjectorDependencyContext, moduleRef: Module | undefined) => string;
5
5
  export declare const INVALID_MIDDLEWARE_MESSAGE: (text: TemplateStringsArray, name: string) => string;
6
6
  export declare const UNDEFINED_FORWARDREF_MESSAGE: (scope: Type<any>[]) => string;
7
- export declare const INVALID_MODULE_MESSAGE: (parentModule: any, index: number, scope: any[]) => string;
8
- export declare const USING_INVALID_CLASS_AS_A_MODULE_MESSAGE: (metatypeUsedAsAModule: Type | ForwardReference, scope: any[]) => string;
7
+ export declare const INVALID_MODULE_MESSAGE: (parentModule: any, index: number, scope: any[], receivedValue: unknown) => string;
8
+ export declare const USING_INVALID_CLASS_AS_A_MODULE_MESSAGE: (metatypeUsedAsAModule: Type | ForwardReference, scope: any[], classKind: "provider" | "controller" | "filter") => string;
9
9
  export declare const UNDEFINED_MODULE_MESSAGE: (parentModule: any, index: number, scope: any[]) => string;
10
10
  export declare const UNKNOWN_EXPORT_MESSAGE: (token: string | symbol | undefined, module: string) => string;
11
11
  export declare const INVALID_CLASS_MESSAGE: (text: TemplateStringsArray, value: any) => string;
12
12
  export declare const INVALID_CLASS_SCOPE_MESSAGE: (text: TemplateStringsArray, name: string | undefined) => string;
13
13
  export declare const UNKNOWN_REQUEST_MAPPING: (metatype: Type) => string;
14
+ export declare const ROUTE_CONFLICT_MESSAGE: (messages: string[]) => string;
15
+ export declare const DUPLICATE_ROUTE_MESSAGE: (method: string, path: string, firstHandlerLabel: string, secondHandlerLabel: string) => string;
16
+ export declare const SHADOWED_ROUTE_MESSAGE: (method: string, shadowedPath: string, shadowedHandlerLabel: string, winnerPath: string, winnerHandlerLabel: string) => string;
14
17
  export declare const INVALID_MIDDLEWARE_CONFIGURATION = "An invalid middleware configuration has been passed inside the module 'configure()' method.";
15
18
  export declare const UNHANDLED_RUNTIME_EXCEPTION = "Unhandled Runtime Exception.";
16
19
  export declare const INVALID_EXCEPTION_FILTER = "Invalid exception filters (@UseFilters()).";
@@ -111,17 +111,43 @@ export const UNDEFINED_FORWARDREF_MESSAGE = (scope) => `Nest cannot create the m
111
111
  (Read more: https://docs.nestjs.com/fundamentals/circular-dependency)
112
112
  Scope [${stringifyScope(scope)}]
113
113
  `;
114
- export const INVALID_MODULE_MESSAGE = (parentModule, index, scope) => {
114
+ export const INVALID_MODULE_MESSAGE = (parentModule, index, scope, receivedValue) => {
115
115
  const parentModuleName = parentModule?.name || 'module';
116
+ let formattedValue;
117
+ let receivedType;
118
+ if (receivedValue === null) {
119
+ formattedValue = 'null';
120
+ receivedType = 'null';
121
+ }
122
+ else if (typeof receivedValue === 'string') {
123
+ formattedValue = `"${receivedValue}"`;
124
+ receivedType = 'string';
125
+ }
126
+ else {
127
+ formattedValue = String(receivedValue);
128
+ receivedType = typeof receivedValue;
129
+ }
116
130
  return `Nest cannot create the ${parentModuleName} instance.
117
131
  Received an unexpected value at index [${index}] of the ${parentModuleName} "imports" array.
132
+ The received value \`${formattedValue}\` is of type "${receivedType}".
118
133
 
119
134
  Scope [${stringifyScope(scope)}]`;
120
135
  };
121
- export const USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = (metatypeUsedAsAModule, scope) => {
136
+ export const USING_INVALID_CLASS_AS_A_MODULE_MESSAGE = (metatypeUsedAsAModule, scope, classKind) => {
122
137
  const metatypeNameQuote = `"${getInstanceName(metatypeUsedAsAModule)}"`;
123
- return `Classes annotated with @Injectable(), @Catch(), and @Controller() decorators must not appear in the "imports" array of a module.
124
- Please remove ${metatypeNameQuote} (including forwarded occurrences, if any) from all of the "imports" arrays.
138
+ let hint;
139
+ switch (classKind) {
140
+ case 'controller':
141
+ hint = `${metatypeNameQuote} is decorated with @Controller() and cannot appear in the "imports" array of a module. Please move ${metatypeNameQuote} to the "controllers" array of the importing module instead.`;
142
+ break;
143
+ case 'provider':
144
+ hint = `${metatypeNameQuote} is decorated with @Injectable() and cannot appear in the "imports" array of a module. Please move ${metatypeNameQuote} to the "providers" array of the importing module instead.`;
145
+ break;
146
+ case 'filter':
147
+ hint = `${metatypeNameQuote} is decorated with @Catch() and cannot appear in the "imports" array of a module. Please move ${metatypeNameQuote} to the "providers" array (using the APP_FILTER token to apply it globally) or apply it via @UseFilters() instead.`;
148
+ break;
149
+ }
150
+ return `${hint}
125
151
 
126
152
  Scope [${stringifyScope(scope)}]
127
153
  `;
@@ -155,6 +181,13 @@ export const UNKNOWN_REQUEST_MAPPING = (metatype) => {
155
181
  ? `An invalid controller has been detected. "${className}" does not have the @Controller() decorator but it is being listed in the "controllers" array of some module.`
156
182
  : `An invalid controller has been detected. Perhaps, one of your controllers is missing the @Controller() decorator.`;
157
183
  };
184
+ export const ROUTE_CONFLICT_MESSAGE = (messages) => [
185
+ 'Conflicting HTTP routes detected:',
186
+ ...messages.map(message => ` - ${message}`),
187
+ `Adjust route declarations or relax the 'routeConflictPolicy' option passed to NestFactory.create() to allow the application to start.`,
188
+ ].join('\n');
189
+ export const DUPLICATE_ROUTE_MESSAGE = (method, path, firstHandlerLabel, secondHandlerLabel) => `Duplicate route: ${method} ${path} is registered by both ${firstHandlerLabel} and ${secondHandlerLabel}.`;
190
+ export const SHADOWED_ROUTE_MESSAGE = (method, shadowedPath, shadowedHandlerLabel, winnerPath, winnerHandlerLabel) => `Route ${method} ${shadowedPath} (${shadowedHandlerLabel}) is shadowed by ${method} ${winnerPath} (${winnerHandlerLabel}). The first-registered route will match all matching requests on order-sensitive adapters.`;
158
191
  export const INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`;
159
192
  export const UNHANDLED_RUNTIME_EXCEPTION = `Unhandled Runtime Exception.`;
160
193
  export const INVALID_EXCEPTION_FILTER = `Invalid exception filters (@UseFilters()).`;
@@ -63,16 +63,21 @@ export class BaseExceptionFilter {
63
63
  if (!err || typeof err !== 'object') {
64
64
  return false;
65
65
  }
66
- if (err.constructor.name === 'FastifyError' &&
66
+ if (err.constructor?.name === 'FastifyError' &&
67
67
  typeof err.code === 'string' &&
68
68
  typeof err.statusCode === 'number') {
69
69
  return true;
70
70
  }
71
71
  // "http-errors" error signature
72
- return (typeof err.expose === 'boolean' &&
72
+ if (typeof err.expose === 'boolean' &&
73
73
  typeof err.statusCode === 'number' &&
74
74
  err.status === err.statusCode &&
75
- err instanceof Error);
75
+ err instanceof Error) {
76
+ return true;
77
+ }
78
+ // Plain "http error"-shaped values (e.g. objects thrown by third-party
79
+ // middleware) that carry a status code and a message
80
+ return !!(err.statusCode && err.message);
76
81
  }
77
82
  }
78
83
  __decorate([
@@ -12,6 +12,9 @@ export class Barrier {
12
12
  this.promise = new Promise(resolve => {
13
13
  this.resolve = resolve;
14
14
  });
15
+ if (targetCount === 0) {
16
+ this.resolve();
17
+ }
15
18
  }
16
19
  /**
17
20
  * Signal that a participant has reached the barrier.
@@ -20,7 +23,7 @@ export class Barrier {
20
23
  */
21
24
  signal() {
22
25
  this.currentCount += 1;
23
- if (this.currentCount === this.targetCount) {
26
+ if (this.currentCount >= this.targetCount) {
24
27
  this.resolve();
25
28
  }
26
29
  }
@@ -10,6 +10,7 @@ export type HandlerResponseBasicFn = <TResult, TResponse>(result: TResult, res:
10
10
  export type HandleSseResponseFn = <TResult extends Observable<unknown> = any, TResponse extends HeaderStream = any, TRequest extends IncomingMessage = any>(result: TResult, res: TResponse, req: TRequest) => any;
11
11
  export interface HandlerMetadata {
12
12
  argsLength: number;
13
+ isSseHandler: boolean;
13
14
  paramtypes: any[];
14
15
  httpStatusCode: number;
15
16
  responseHeaders: any[];
@@ -17,6 +17,7 @@ export declare const REQUEST_METHOD_MAP: {
17
17
  readonly 13: "move";
18
18
  readonly 14: "lock";
19
19
  readonly 15: "unlock";
20
+ readonly 16: "query";
20
21
  };
21
22
  export declare class RouterMethodFactory {
22
23
  get(target: HttpServer, requestMethod: RequestMethod): Function;
@@ -16,6 +16,7 @@ export const REQUEST_METHOD_MAP = {
16
16
  [RequestMethod.MOVE]: 'move',
17
17
  [RequestMethod.LOCK]: 'lock',
18
18
  [RequestMethod.UNLOCK]: 'unlock',
19
+ [RequestMethod.QUERY]: 'query',
19
20
  };
20
21
  export class RouterMethodFactory {
21
22
  get(target, requestMethod) {
@@ -1,3 +1,4 @@
1
+ import { Logger } from '@nestjs/common';
1
2
  import { isFunction, isNil } from '@nestjs/common/internal';
2
3
  import { iterate } from 'iterare';
3
4
  import { getInstancesGroupedByHierarchyLevel } from './utils/get-instances-grouped-by-hierarchy-level.js';
@@ -33,12 +34,20 @@ export async function callBeforeAppShutdownHook(moduleRef, signal) {
33
34
  const groupedInstances = getInstancesGroupedByHierarchyLevel(moduleRef.controllers, moduleRef.injectables, moduleRef.middlewares, providers);
34
35
  const levels = getSortedHierarchyLevels(groupedInstances, 'DESC');
35
36
  for (const level of levels) {
36
- await Promise.all(callOperator(groupedInstances.get(level), signal));
37
+ const results = await Promise.allSettled(callOperator(groupedInstances.get(level), signal));
38
+ results
39
+ .filter((result) => result.status === 'rejected')
40
+ .forEach(result => Logger.error(result.reason, result.reason?.stack));
37
41
  }
38
42
  const moduleClassInstance = moduleClassHost.instance;
39
43
  if (moduleClassInstance &&
40
44
  hasBeforeApplicationShutdownHook(moduleClassInstance) &&
41
45
  moduleClassHost.isDependencyTreeStatic()) {
42
- await moduleClassInstance.beforeApplicationShutdown(signal);
46
+ try {
47
+ await moduleClassInstance.beforeApplicationShutdown(signal);
48
+ }
49
+ catch (err) {
50
+ Logger.error(err, err?.stack);
51
+ }
43
52
  }
44
53
  }
@@ -1,3 +1,4 @@
1
+ import { Logger } from '@nestjs/common';
1
2
  import { isFunction, isNil } from '@nestjs/common/internal';
2
3
  import { iterate } from 'iterare';
3
4
  import { getInstancesGroupedByHierarchyLevel } from './utils/get-instances-grouped-by-hierarchy-level.js';
@@ -35,13 +36,21 @@ export async function callAppShutdownHook(moduleRef, signal) {
35
36
  const groupedInstances = getInstancesGroupedByHierarchyLevel(moduleRef.controllers, moduleRef.injectables, moduleRef.middlewares, providers);
36
37
  const levels = getSortedHierarchyLevels(groupedInstances, 'DESC');
37
38
  for (const level of levels) {
38
- await Promise.all(callOperator(groupedInstances.get(level), signal));
39
+ const results = await Promise.allSettled(callOperator(groupedInstances.get(level), signal));
40
+ results
41
+ .filter((result) => result.status === 'rejected')
42
+ .forEach(result => Logger.error(result.reason, result.reason?.stack));
39
43
  }
40
44
  // Call the instance itself
41
45
  const moduleClassInstance = moduleClassHost.instance;
42
46
  if (moduleClassInstance &&
43
47
  hasOnAppShutdownHook(moduleClassInstance) &&
44
48
  moduleClassHost.isDependencyTreeStatic()) {
45
- await moduleClassInstance.onApplicationShutdown(signal);
49
+ try {
50
+ await moduleClassInstance.onApplicationShutdown(signal);
51
+ }
52
+ catch (err) {
53
+ Logger.error(err, err?.stack);
54
+ }
46
55
  }
47
56
  }
@@ -1,3 +1,4 @@
1
+ import { Logger } from '@nestjs/common';
1
2
  import { isFunction, isNil } from '@nestjs/common/internal';
2
3
  import { iterate } from 'iterare';
3
4
  import { getInstancesGroupedByHierarchyLevel } from './utils/get-instances-grouped-by-hierarchy-level.js';
@@ -34,13 +35,21 @@ export async function callModuleDestroyHook(moduleRef) {
34
35
  const groupedInstances = getInstancesGroupedByHierarchyLevel(moduleRef.controllers, moduleRef.injectables, moduleRef.middlewares, providers);
35
36
  const levels = getSortedHierarchyLevels(groupedInstances, 'DESC');
36
37
  for (const level of levels) {
37
- await Promise.all(callOperator(groupedInstances.get(level)));
38
+ const results = await Promise.allSettled(callOperator(groupedInstances.get(level)));
39
+ results
40
+ .filter((result) => result.status === 'rejected')
41
+ .forEach(result => Logger.error(result.reason, result.reason?.stack));
38
42
  }
39
43
  // Call the module instance itself
40
44
  const moduleClassInstance = moduleClassHost.instance;
41
45
  if (moduleClassInstance &&
42
46
  hasOnModuleDestroyHook(moduleClassInstance) &&
43
47
  moduleClassHost.isDependencyTreeStatic()) {
44
- await moduleClassInstance.onModuleDestroy();
48
+ try {
49
+ await moduleClassInstance.onModuleDestroy();
50
+ }
51
+ catch (err) {
52
+ Logger.error(err, err?.stack);
53
+ }
45
54
  }
46
55
  }
@@ -66,7 +66,7 @@ export class NestContainer {
66
66
  if (this.modules.has(token)) {
67
67
  return {
68
68
  moduleRef: this.modules.get(token),
69
- inserted: true,
69
+ inserted: false,
70
70
  };
71
71
  }
72
72
  return {
@@ -92,7 +92,7 @@ export class NestContainer {
92
92
  type,
93
93
  dynamicMetadata,
94
94
  }, scope),
95
- inserted: false,
95
+ inserted: true,
96
96
  };
97
97
  }
98
98
  async setModule({ token, dynamicMetadata, type }, scope) {
@@ -0,0 +1,12 @@
1
+ import { InjectionToken } from '@nestjs/common';
2
+ import { InstanceWrapper } from '../instance-wrapper';
3
+ /**
4
+ * Returns the instances which are transient
5
+ * @param instances The instances which should be checked whether they are transient
6
+ */
7
+ export declare function getTransientInstances(instances: [InjectionToken, InstanceWrapper][]): InstanceWrapper[];
8
+ /**
9
+ * Returns the instances which are not transient
10
+ * @param instances The instances which should be checked whether they are transient
11
+ */
12
+ export declare function getNonTransientInstances(instances: [InjectionToken, InstanceWrapper][]): InstanceWrapper[];
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTransientInstances = getTransientInstances;
4
+ exports.getNonTransientInstances = getNonTransientInstances;
5
+ const iterare_1 = require("iterare");
6
+ /**
7
+ * Returns the instances which are transient
8
+ * @param instances The instances which should be checked whether they are transient
9
+ */
10
+ function getTransientInstances(instances) {
11
+ return (0, iterare_1.iterate)(instances)
12
+ .filter(([_, wrapper]) => wrapper.isDependencyTreeStatic())
13
+ .map(([_, wrapper]) => wrapper.getStaticTransientInstances())
14
+ .flatten()
15
+ .filter(item => !!item)
16
+ .map(({ instance }) => instance)
17
+ .toArray();
18
+ }
19
+ /**
20
+ * Returns the instances which are not transient
21
+ * @param instances The instances which should be checked whether they are transient
22
+ */
23
+ function getNonTransientInstances(instances) {
24
+ return (0, iterare_1.iterate)(instances)
25
+ .filter(([key, wrapper]) => wrapper.isDependencyTreeStatic() && !wrapper.isTransient)
26
+ .map(([key, { instance }]) => instance)
27
+ .toArray();
28
+ }
@@ -73,9 +73,9 @@ export declare class Injector {
73
73
  resolveConstructorParams<T>(wrapper: InstanceWrapper<T>, moduleRef: Module, inject: InjectorDependency[] | undefined, callback: (args: unknown[], depth?: number) => void | Promise<void>, resolutionContext?: ResolutionContext, parentInquirer?: InstanceWrapper): Promise<void>;
74
74
  getClassDependencies<T>(wrapper: InstanceWrapper<T>): [InjectorDependency[], number[]];
75
75
  getFactoryProviderDependencies<T>(wrapper: InstanceWrapper<T>): [InjectorDependency[], number[]];
76
- reflectConstructorParams<T>(type: Type<T>): any[];
77
- reflectOptionalParams<T>(type: Type<T>): any[];
78
- reflectSelfParams<T>(type: Type<T>): any[];
76
+ reflectConstructorParams(type: Type<unknown> | Function): any[];
77
+ reflectOptionalParams(type: Type<unknown> | Function): any[];
78
+ reflectSelfParams(type: Type<unknown> | Function): any[];
79
79
  resolveSingleParam<T>(wrapper: InstanceWrapper<T>, param: Type<any> | string | symbol, dependencyContext: InjectorDependencyContext, moduleRef: Module, resolutionContext?: ResolutionContext, keyOrIndex?: symbol | string | number): Promise<InstanceWrapper<any>>;
80
80
  resolveParamToken<T>(wrapper: InstanceWrapper<T>, param: Type<any> | string | symbol | ForwardReference): any;
81
81
  resolveComponentWrapper<T>(moduleRef: Module, token: InjectionToken, dependencyContext: InjectorDependencyContext, wrapper: InstanceWrapper<T>, resolutionContext?: ResolutionContext, keyOrIndex?: symbol | string | number): Promise<InstanceWrapper>;
@@ -107,6 +107,7 @@ export declare class Injector {
107
107
  private getEffectiveInquirerId;
108
108
  private getStaticTransientResolutionContext;
109
109
  private getEffectiveResolutionContext;
110
+ private hasDenseCtorMetadata;
110
111
  private resolveScopedComponentHost;
111
112
  private isInquirerRequest;
112
113
  private isInquirer;