@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.
- package/Readme.md +25 -45
- package/adapters/http-adapter.d.ts +2 -0
- package/adapters/http-adapter.js +3 -0
- package/application-config.d.ts +8 -2
- package/application-config.js +14 -0
- package/errors/exceptions/index.d.ts +1 -0
- package/errors/exceptions/index.js +1 -0
- package/errors/exceptions/invalid-class-module.exception.d.ts +1 -1
- package/errors/exceptions/invalid-class-module.exception.js +2 -2
- package/errors/exceptions/invalid-module.exception.d.ts +1 -1
- package/errors/exceptions/invalid-module.exception.js +2 -2
- package/errors/exceptions/route-conflict.exception.d.ts +4 -0
- package/errors/exceptions/route-conflict.exception.js +7 -0
- package/errors/messages.d.ts +5 -2
- package/errors/messages.js +37 -4
- package/exceptions/base-exception-filter.js +8 -3
- package/helpers/barrier.js +4 -1
- package/helpers/handler-metadata-storage.d.ts +1 -0
- package/helpers/router-method-factory.d.ts +1 -0
- package/helpers/router-method-factory.js +1 -0
- package/hooks/before-app-shutdown.hook.js +11 -2
- package/hooks/on-app-shutdown.hook.js +11 -2
- package/hooks/on-module-destroy.hook.js +11 -2
- package/injector/container.js +2 -2
- package/injector/helpers/transient-instances.d.ts +12 -0
- package/injector/helpers/transient-instances.js +28 -0
- package/injector/injector.d.ts +4 -3
- package/injector/injector.js +34 -13
- package/injector/instance-wrapper.d.ts +2 -0
- package/injector/instance-wrapper.js +25 -0
- package/injector/internal-core-module/internal-core-module-factory.js +1 -1
- package/injector/module.d.ts +6 -0
- package/injector/module.js +8 -0
- package/interceptors/interceptors-consumer.js +32 -7
- package/middleware/builder.js +5 -1
- package/nest-application-context.js +1 -1
- package/nest-application.d.ts +3 -1
- package/nest-application.js +96 -6
- package/package.json +3 -14
- package/router/interfaces/index.d.ts +3 -0
- package/router/interfaces/index.js +3 -0
- package/router/interfaces/resolved-route.interface.d.ts +32 -0
- package/router/interfaces/resolved-route.interface.js +1 -0
- package/router/interfaces/resolver.interface.d.ts +5 -1
- package/router/interfaces/route-conflict.interface.d.ts +14 -0
- package/router/interfaces/route-conflict.interface.js +1 -0
- package/router/interfaces/route-resolution-options.interface.d.ts +24 -0
- package/router/interfaces/route-resolution-options.interface.js +1 -0
- package/router/legacy-route-converter.d.ts +1 -1
- package/router/legacy-route-converter.js +24 -13
- package/router/route-conflict-detector.d.ts +71 -0
- package/router/route-conflict-detector.js +276 -0
- package/router/route-specificity-sorter.d.ts +23 -0
- package/router/route-specificity-sorter.js +59 -0
- package/router/router-execution-context.d.ts +1 -0
- package/router/router-execution-context.js +26 -3
- package/router/router-explorer.d.ts +11 -2
- package/router/router-explorer.js +61 -19
- package/router/router-response-controller.d.ts +1 -0
- package/router/router-response-controller.js +126 -49
- package/router/routes-resolver.d.ts +7 -4
- package/router/routes-resolver.js +9 -7
- package/router/sse-stream.d.ts +1 -0
- package/router/sse-stream.js +24 -13
- 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/
|
|
64
|
-
<td><a href="https://mojam.co" target="_blank"><img src="https://
|
|
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/
|
|
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/
|
|
75
|
-
<td><a href="https://github.com/Sanofi-IADC" target="_blank"><img src="https://docs.nestjs.com/assets/sponsors/sanofi.png" width="
|
|
76
|
-
<td><a href="https://nx.dev" target="_blank"><img src="https://nestjs.com/img/
|
|
77
|
-
<td><a href="https://intrinsic.ventures/" target="_blank"><img src="https://nestjs.com/img/
|
|
78
|
-
<td><a href="https://jetbrains.com/" target="_blank"><img src="https://nestjs.com/img/
|
|
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/
|
|
82
|
-
<td><a href="https://www.movavi.com/imovie-for-windows.html" target="_blank"><img src="https://
|
|
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/
|
|
91
|
-
<td><a href="https://
|
|
92
|
-
<td><a href="https://
|
|
93
|
-
<td align="center" valign="middle"><a href="https://
|
|
94
|
-
<td align="center" valign="middle"><a href="https://
|
|
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://
|
|
98
|
-
<td align="center" valign="middle"><a href="https://
|
|
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://
|
|
107
|
-
<td align="center" valign="middle"><a href="https://
|
|
108
|
-
<td align="center" valign="middle"><a href="https://
|
|
109
|
-
<td align="center" valign="middle"><a href="https://
|
|
110
|
-
<td align="center" valign="middle"><a href="https://
|
|
111
|
-
<td align="center" valign="middle"><a href="https://
|
|
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;
|
package/adapters/http-adapter.js
CHANGED
package/application-config.d.ts
CHANGED
|
@@ -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
|
}
|
package/application-config.js
CHANGED
|
@@ -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
|
}
|
package/errors/messages.d.ts
CHANGED
|
@@ -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()).";
|
package/errors/messages.js
CHANGED
|
@@ -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
|
-
|
|
124
|
-
|
|
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
|
|
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
|
-
|
|
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([
|
package/helpers/barrier.js
CHANGED
|
@@ -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
|
|
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[];
|
|
@@ -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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
48
|
+
try {
|
|
49
|
+
await moduleClassInstance.onModuleDestroy();
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
Logger.error(err, err?.stack);
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
}
|
package/injector/container.js
CHANGED
|
@@ -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:
|
|
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:
|
|
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
|
+
}
|
package/injector/injector.d.ts
CHANGED
|
@@ -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
|
|
77
|
-
reflectOptionalParams
|
|
78
|
-
reflectSelfParams
|
|
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;
|