@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.
- package/adapters/http-adapter.d.ts +15 -2
- package/adapters/http-adapter.js +24 -1
- package/errors/exception-handler.d.ts +1 -2
- package/errors/exception-handler.js +1 -6
- package/errors/exceptions/undefined-dependency.exception.d.ts +2 -2
- package/errors/exceptions/undefined-dependency.exception.js +2 -2
- package/errors/exceptions/unknown-dependencies.exception.d.ts +2 -2
- package/errors/exceptions-zone.d.ts +2 -2
- package/errors/messages.d.ts +2 -2
- package/errors/messages.js +3 -3
- package/exceptions/base-exception-filter-context.js +1 -1
- package/exceptions/base-exception-filter.d.ts +2 -2
- package/exceptions/base-exception-filter.js +2 -3
- package/exceptions/exceptions-handler.d.ts +2 -2
- package/exceptions/exceptions-handler.js +2 -2
- package/exceptions/external-exception-filter-context.d.ts +1 -1
- package/exceptions/external-exception-filter-context.js +1 -1
- package/exceptions/external-exception-filter.js +3 -2
- package/exceptions/external-exceptions-handler.d.ts +2 -2
- package/exceptions/external-exceptions-handler.js +2 -2
- package/guards/guards-context-creator.d.ts +1 -1
- package/guards/guards-context-creator.js +2 -2
- package/helpers/execution-context-host.d.ts +1 -1
- package/helpers/external-context-creator.d.ts +1 -1
- package/helpers/external-context-creator.js +8 -8
- package/helpers/router-method-factory.js +7 -0
- package/injector/abstract-instance-resolver.js +2 -2
- package/injector/compiler.d.ts +9 -8
- package/injector/compiler.js +20 -14
- package/injector/container.d.ts +8 -7
- package/injector/container.js +13 -5
- package/injector/helpers/silent-logger.js +0 -1
- package/injector/injector.d.ts +5 -5
- package/injector/injector.js +7 -7
- package/injector/inquirer/inquirer-providers.js +0 -1
- package/injector/instance-wrapper.d.ts +4 -4
- package/injector/instance-wrapper.js +4 -4
- package/injector/lazy-module-loader/lazy-module-loader.d.ts +1 -1
- package/injector/module-ref.js +1 -0
- package/injector/module.d.ts +2 -2
- package/injector/module.js +7 -3
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.d.ts +15 -0
- package/injector/opaque-key-factory/by-reference-module-opaque-key-factory.js +40 -0
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.d.ts +15 -0
- package/injector/opaque-key-factory/deep-hashed-module-opaque-key-factory.js +83 -0
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.d.ts +18 -0
- package/injector/opaque-key-factory/interfaces/module-opaque-key-factory.interface.js +2 -0
- package/inspector/noop-graph-inspector.js +0 -1
- package/inspector/serialized-graph.d.ts +2 -2
- package/interceptors/interceptors-context-creator.d.ts +1 -1
- package/interceptors/interceptors-context-creator.js +2 -2
- package/metadata-scanner.d.ts +1 -1
- package/middleware/builder.d.ts +1 -1
- package/middleware/builder.js +2 -3
- package/middleware/middleware-module.js +1 -1
- package/middleware/route-info-path-extractor.js +6 -2
- package/middleware/utils.js +22 -11
- package/nest-application-context.d.ts +3 -3
- package/nest-application-context.js +16 -6
- package/nest-application.js +2 -2
- package/nest-factory.d.ts +7 -5
- package/nest-factory.js +1 -1
- package/package.json +3 -3
- package/pipes/pipes-context-creator.d.ts +1 -1
- package/pipes/pipes-context-creator.js +2 -2
- package/repl/assign-to-object.util.d.ts +1 -1
- package/router/interfaces/route-params-factory.interface.d.ts +1 -1
- package/router/legacy-route-converter.d.ts +13 -0
- package/router/legacy-route-converter.js +48 -0
- package/router/request/request-providers.js +0 -1
- package/router/route-params-factory.d.ts +2 -2
- package/router/route-params-factory.js +1 -0
- package/router/route-path-factory.d.ts +1 -1
- package/router/router-exception-filters.d.ts +1 -1
- package/router/router-exception-filters.js +1 -1
- package/router/router-execution-context.d.ts +2 -2
- package/router/router-execution-context.js +1 -1
- package/router/router-explorer.js +17 -5
- package/router/router-proxy.d.ts +3 -3
- package/router/sse-stream.js +1 -1
- package/router/utils/flatten-route-paths.util.d.ts +5 -1
- package/scanner.d.ts +2 -2
- package/scanner.js +6 -6
- package/services/reflector.service.d.ts +3 -3
- 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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
}
|
package/nest-application.js
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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": "
|
|
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": "
|
|
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": "
|
|
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
|
}
|
|
@@ -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
|
|
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
|
}
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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('", "')}"]`
|
package/router/router-proxy.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExceptionsHandler } from '../exceptions/exceptions-handler';
|
|
2
|
-
export type RouterProxyCallback = <TRequest, TResponse>(req
|
|
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
|
|
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
|
}
|
package/router/sse-stream.js
CHANGED
|
@@ -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);
|
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
|
-
|
|
203
|
-
if (!moduleRef ||
|
|
201
|
+
const calculateDistance = (moduleRef, distance = 1, modulesStack = []) => {
|
|
202
|
+
const localModulesStack = [...modulesStack];
|
|
203
|
+
if (!moduleRef || localModulesStack.includes(moduleRef)) {
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
|
-
|
|
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<
|
|
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<
|
|
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<
|
|
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);
|