@nestjs/core 9.1.5 → 9.2.0
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 +3 -1
- package/errors/exceptions/index.d.ts +8 -0
- package/errors/exceptions/index.js +11 -0
- package/errors/exceptions/unknown-request-mapping.exception.d.ts +2 -1
- package/errors/exceptions/unknown-request-mapping.exception.js +2 -2
- package/errors/messages.d.ts +1 -1
- package/errors/messages.js +8 -2
- package/guards/index.d.ts +3 -0
- package/guards/index.js +6 -0
- package/helpers/handler-metadata-storage.d.ts +1 -1
- package/injector/abstract-instance-resolver.d.ts +16 -0
- package/injector/abstract-instance-resolver.js +48 -0
- package/injector/container.js +8 -10
- package/injector/{silent-logger.d.ts → helpers/silent-logger.d.ts} +0 -0
- package/injector/{silent-logger.js → helpers/silent-logger.js} +0 -0
- package/injector/index.d.ts +1 -1
- package/injector/index.js +1 -1
- package/injector/injector.d.ts +1 -3
- package/injector/instance-links-host.d.ts +5 -1
- package/injector/instance-links-host.js +9 -6
- package/injector/instance-loader.js +1 -1
- package/injector/internal-core-module/index.d.ts +1 -0
- package/injector/internal-core-module/index.js +4 -0
- package/injector/{internal-core-module-factory.d.ts → internal-core-module/internal-core-module-factory.d.ts} +4 -4
- package/injector/{internal-core-module-factory.js → internal-core-module/internal-core-module-factory.js} +5 -5
- package/injector/{internal-core-module.d.ts → internal-core-module/internal-core-module.d.ts} +0 -0
- package/injector/{internal-core-module.js → internal-core-module/internal-core-module.js} +3 -3
- package/injector/{lazy-module-loader-options.interface.d.ts → lazy-module-loader/lazy-module-loader-options.interface.d.ts} +0 -0
- package/injector/{lazy-module-loader-options.interface.js → lazy-module-loader/lazy-module-loader-options.interface.js} +0 -0
- package/injector/{lazy-module-loader.d.ts → lazy-module-loader/lazy-module-loader.d.ts} +5 -5
- package/injector/{lazy-module-loader.js → lazy-module-loader/lazy-module-loader.js} +2 -2
- package/injector/module-ref.d.ts +70 -11
- package/injector/module-ref.js +3 -28
- package/injector/module.d.ts +1 -2
- package/injector/module.js +9 -8
- package/interceptors/index.d.ts +2 -0
- package/interceptors/index.js +5 -0
- package/middleware/builder.d.ts +1 -2
- package/middleware/middleware-module.d.ts +4 -1
- package/middleware/middleware-module.js +13 -6
- package/middleware/routes-mapper.d.ts +3 -0
- package/middleware/routes-mapper.js +32 -17
- package/nest-application-context.d.ts +77 -12
- package/nest-application-context.js +40 -33
- package/nest-application.d.ts +1 -2
- package/nest-application.js +2 -1
- package/package.json +3 -3
- package/pipes/index.d.ts +3 -0
- package/pipes/index.js +6 -0
- package/repl/repl-context.js +1 -1
- package/repl/repl.d.ts +2 -2
- package/router/router-execution-context.d.ts +1 -2
- package/router/router-execution-context.js +7 -6
- package/router/router-explorer.d.ts +1 -1
- package/router/router-explorer.js +3 -3
- package/router/routes-resolver.d.ts +1 -2
- package/scanner.js +1 -1
package/middleware/builder.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { HttpServer, MiddlewareConsumer, Type } from '@nestjs/common/interfaces';
|
|
2
|
-
import { MiddlewareConfigProxy } from '@nestjs/common/interfaces/middleware';
|
|
3
|
-
import { MiddlewareConfiguration } from '@nestjs/common/interfaces/middleware/middleware-configuration.interface';
|
|
2
|
+
import { MiddlewareConfigProxy, MiddlewareConfiguration } from '@nestjs/common/interfaces/middleware';
|
|
4
3
|
import { RoutesMapper } from './routes-mapper';
|
|
5
4
|
export declare class MiddlewareBuilder implements MiddlewareConsumer {
|
|
6
5
|
private readonly routesMapper;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { HttpServer } from '@nestjs/common';
|
|
2
|
-
import { MiddlewareConfiguration, RouteInfo } from '@nestjs/common/interfaces/middleware
|
|
2
|
+
import { MiddlewareConfiguration, RouteInfo } from '@nestjs/common/interfaces/middleware';
|
|
3
3
|
import { ApplicationConfig } from '../application-config';
|
|
4
4
|
import { NestContainer } from '../injector/container';
|
|
5
5
|
import { Injector } from '../injector/injector';
|
|
6
6
|
import { Module } from '../injector/module';
|
|
7
|
+
import { RoutePathFactory } from '../router/route-path-factory';
|
|
7
8
|
import { MiddlewareContainer } from './container';
|
|
8
9
|
export declare class MiddlewareModule {
|
|
10
|
+
private readonly routePathFactory;
|
|
9
11
|
private readonly routerProxy;
|
|
10
12
|
private readonly exceptionFiltersCache;
|
|
11
13
|
private injector;
|
|
@@ -15,6 +17,7 @@ export declare class MiddlewareModule {
|
|
|
15
17
|
private config;
|
|
16
18
|
private container;
|
|
17
19
|
private httpAdapter;
|
|
20
|
+
constructor(routePathFactory: RoutePathFactory);
|
|
18
21
|
register(middlewareContainer: MiddlewareContainer, container: NestContainer, config: ApplicationConfig, injector: Injector, httpAdapter: HttpServer): Promise<void>;
|
|
19
22
|
resolveMiddleware(middlewareContainer: MiddlewareContainer, modules: Map<string, Module>): Promise<void>;
|
|
20
23
|
loadConfiguration(middlewareContainer: MiddlewareContainer, moduleRef: Module, moduleKey: string): Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MiddlewareModule = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
4
5
|
const request_method_enum_1 = require("@nestjs/common/enums/request-method.enum");
|
|
5
6
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
7
|
const invalid_middleware_exception_1 = require("../errors/exceptions/invalid-middleware.exception");
|
|
@@ -16,7 +17,8 @@ const builder_1 = require("./builder");
|
|
|
16
17
|
const resolver_1 = require("./resolver");
|
|
17
18
|
const routes_mapper_1 = require("./routes-mapper");
|
|
18
19
|
class MiddlewareModule {
|
|
19
|
-
constructor() {
|
|
20
|
+
constructor(routePathFactory) {
|
|
21
|
+
this.routePathFactory = routePathFactory;
|
|
20
22
|
this.routerProxy = new router_proxy_1.RouterProxy();
|
|
21
23
|
this.exceptionFiltersCache = new WeakMap();
|
|
22
24
|
}
|
|
@@ -86,10 +88,10 @@ class MiddlewareModule {
|
|
|
86
88
|
if (instanceWrapper.isTransient) {
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
89
|
-
await this.bindHandler(instanceWrapper, applicationRef, routeInfo
|
|
91
|
+
await this.bindHandler(instanceWrapper, applicationRef, routeInfo, moduleRef, collection);
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
async bindHandler(wrapper, applicationRef,
|
|
94
|
+
async bindHandler(wrapper, applicationRef, routeInfo, moduleRef, collection) {
|
|
93
95
|
const { instance, metatype } = wrapper;
|
|
94
96
|
if ((0, shared_utils_1.isUndefined)(instance === null || instance === void 0 ? void 0 : instance.use)) {
|
|
95
97
|
throw new invalid_middleware_exception_1.InvalidMiddlewareException(metatype.name);
|
|
@@ -97,9 +99,9 @@ class MiddlewareModule {
|
|
|
97
99
|
const isStatic = wrapper.isDependencyTreeStatic();
|
|
98
100
|
if (isStatic) {
|
|
99
101
|
const proxy = await this.createProxy(instance);
|
|
100
|
-
return this.registerHandler(applicationRef,
|
|
102
|
+
return this.registerHandler(applicationRef, routeInfo, proxy);
|
|
101
103
|
}
|
|
102
|
-
await this.registerHandler(applicationRef,
|
|
104
|
+
await this.registerHandler(applicationRef, routeInfo, async (req, res, next) => {
|
|
103
105
|
try {
|
|
104
106
|
const contextId = context_id_factory_1.ContextIdFactory.getByRequest(req);
|
|
105
107
|
if (!req[request_constants_1.REQUEST_CONTEXT_ID]) {
|
|
@@ -131,7 +133,7 @@ class MiddlewareModule {
|
|
|
131
133
|
const middleware = instance.use.bind(instance);
|
|
132
134
|
return this.routerProxy.createProxy(middleware, exceptionsHandler);
|
|
133
135
|
}
|
|
134
|
-
async registerHandler(applicationRef, method,
|
|
136
|
+
async registerHandler(applicationRef, { path, method, version }, proxy) {
|
|
135
137
|
const prefix = this.config.getGlobalPrefix();
|
|
136
138
|
const excludedRoutes = this.config.getGlobalPrefixOptions().exclude;
|
|
137
139
|
if ((Array.isArray(excludedRoutes) &&
|
|
@@ -148,6 +150,11 @@ class MiddlewareModule {
|
|
|
148
150
|
}
|
|
149
151
|
path = basePath + path;
|
|
150
152
|
}
|
|
153
|
+
const applicationVersioningConfig = this.config.getVersioning();
|
|
154
|
+
if (version && applicationVersioningConfig.type === common_1.VersioningType.URI) {
|
|
155
|
+
const versionPrefix = this.routePathFactory.getVersionPrefix(applicationVersioningConfig);
|
|
156
|
+
path = `/${versionPrefix}${version.toString()}${path}`;
|
|
157
|
+
}
|
|
151
158
|
const isMethodAll = (0, utils_1.isRequestMethodAll)(method);
|
|
152
159
|
const requestMethod = request_method_enum_1.RequestMethod[method];
|
|
153
160
|
const router = await applicationRef.createMiddlewareFactory(method);
|
|
@@ -5,6 +5,9 @@ export declare class RoutesMapper {
|
|
|
5
5
|
private readonly routerExplorer;
|
|
6
6
|
constructor(container: NestContainer);
|
|
7
7
|
mapRouteToRouteInfo(route: Type<any> | RouteInfo | string): RouteInfo[];
|
|
8
|
+
private getRouteInfoFromPath;
|
|
9
|
+
private getRouteInfoFromObject;
|
|
10
|
+
private getRouteInfoFromController;
|
|
8
11
|
private isRouteInfo;
|
|
9
12
|
private normalizeGlobalPath;
|
|
10
13
|
private getRoutePath;
|
|
@@ -13,39 +13,54 @@ class RoutesMapper {
|
|
|
13
13
|
}
|
|
14
14
|
mapRouteToRouteInfo(route) {
|
|
15
15
|
if ((0, shared_utils_1.isString)(route)) {
|
|
16
|
-
|
|
17
|
-
return [
|
|
18
|
-
{
|
|
19
|
-
path: (0, shared_utils_1.addLeadingSlash)(route),
|
|
20
|
-
method: defaultRequestMethod,
|
|
21
|
-
},
|
|
22
|
-
];
|
|
16
|
+
return this.getRouteInfoFromPath(route);
|
|
23
17
|
}
|
|
24
18
|
const routePathOrPaths = this.getRoutePath(route);
|
|
25
19
|
if (this.isRouteInfo(routePathOrPaths, route)) {
|
|
26
|
-
return
|
|
27
|
-
{
|
|
28
|
-
path: (0, shared_utils_1.addLeadingSlash)(route.path),
|
|
29
|
-
method: route.method,
|
|
30
|
-
},
|
|
31
|
-
];
|
|
20
|
+
return this.getRouteInfoFromObject(route);
|
|
32
21
|
}
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
return this.getRouteInfoFromController(route, routePathOrPaths);
|
|
23
|
+
}
|
|
24
|
+
getRouteInfoFromPath(routePath) {
|
|
25
|
+
const defaultRequestMethod = -1;
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
path: (0, shared_utils_1.addLeadingSlash)(routePath),
|
|
29
|
+
method: defaultRequestMethod,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
getRouteInfoFromObject(routeInfoObject) {
|
|
34
|
+
const routeInfo = {
|
|
35
|
+
path: (0, shared_utils_1.addLeadingSlash)(routeInfoObject.path),
|
|
36
|
+
method: routeInfoObject.method,
|
|
37
|
+
};
|
|
38
|
+
if (routeInfoObject.version) {
|
|
39
|
+
routeInfo.version = routeInfoObject.version;
|
|
40
|
+
}
|
|
41
|
+
return [routeInfo];
|
|
42
|
+
}
|
|
43
|
+
getRouteInfoFromController(controller, routePath) {
|
|
44
|
+
const controllerPaths = this.routerExplorer.scanForPaths(Object.create(controller), controller.prototype);
|
|
45
|
+
const moduleRef = this.getHostModuleOfController(controller);
|
|
35
46
|
const modulePath = this.getModulePath(moduleRef === null || moduleRef === void 0 ? void 0 : moduleRef.metatype);
|
|
36
47
|
const concatPaths = (acc, currentValue) => acc.concat(currentValue);
|
|
37
48
|
return []
|
|
38
|
-
.concat(
|
|
49
|
+
.concat(routePath)
|
|
39
50
|
.map(routePath => controllerPaths
|
|
40
51
|
.map(item => {
|
|
41
52
|
var _a;
|
|
42
53
|
return (_a = item.path) === null || _a === void 0 ? void 0 : _a.map(p => {
|
|
43
54
|
let path = modulePath !== null && modulePath !== void 0 ? modulePath : '';
|
|
44
55
|
path += this.normalizeGlobalPath(routePath) + (0, shared_utils_1.addLeadingSlash)(p);
|
|
45
|
-
|
|
56
|
+
const routeInfo = {
|
|
46
57
|
path,
|
|
47
58
|
method: item.requestMethod,
|
|
48
59
|
};
|
|
60
|
+
if (item.version) {
|
|
61
|
+
routeInfo.version = item.version;
|
|
62
|
+
}
|
|
63
|
+
return routeInfo;
|
|
49
64
|
});
|
|
50
65
|
})
|
|
51
66
|
.reduce(concatPaths, []))
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { INestApplicationContext, LoggerService, LogLevel, ShutdownSignal } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { DynamicModule, Type } from '@nestjs/common/interfaces';
|
|
3
|
+
import { AbstractInstanceResolver } from './injector/abstract-instance-resolver';
|
|
4
4
|
import { NestContainer } from './injector/container';
|
|
5
5
|
import { Injector } from './injector/injector';
|
|
6
|
+
import { InstanceLinksHost } from './injector/instance-links-host';
|
|
6
7
|
import { ContextId } from './injector/instance-wrapper';
|
|
7
8
|
import { Module } from './injector/module';
|
|
8
9
|
/**
|
|
9
10
|
* @publicApi
|
|
10
11
|
*/
|
|
11
|
-
export declare class NestApplicationContext implements INestApplicationContext {
|
|
12
|
+
export declare class NestApplicationContext extends AbstractInstanceResolver implements INestApplicationContext {
|
|
12
13
|
protected readonly container: NestContainer;
|
|
13
14
|
private readonly scope;
|
|
14
15
|
private contextModule;
|
|
@@ -20,16 +21,71 @@ export declare class NestApplicationContext implements INestApplicationContext {
|
|
|
20
21
|
private shutdownCleanupRef?;
|
|
21
22
|
private _instanceLinksHost;
|
|
22
23
|
private _moduleRefsByDistance?;
|
|
23
|
-
|
|
24
|
+
protected get instanceLinksHost(): InstanceLinksHost;
|
|
24
25
|
constructor(container: NestContainer, scope?: Type<any>[], contextModule?: Module);
|
|
25
26
|
selectContextModule(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
|
|
29
|
+
* @returns {INestApplicationContext}
|
|
30
|
+
*/
|
|
26
31
|
select<T>(moduleType: Type<T> | DynamicModule): INestApplicationContext;
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
|
34
|
+
* @returns {TResult}
|
|
35
|
+
*/
|
|
36
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): TResult;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
|
39
|
+
* @returns {TResult}
|
|
40
|
+
*/
|
|
41
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
42
|
+
strict?: boolean;
|
|
43
|
+
each?: undefined | false;
|
|
29
44
|
}): TResult;
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
|
|
47
|
+
* @returns {Array<TResult>}
|
|
48
|
+
*/
|
|
49
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
50
|
+
strict?: boolean;
|
|
51
|
+
each: true;
|
|
52
|
+
}): Array<TResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
55
|
+
* @returns {Array<TResult>}
|
|
56
|
+
*/
|
|
57
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): Promise<TResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
60
|
+
* @returns {Array<TResult>}
|
|
61
|
+
*/
|
|
62
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
63
|
+
id: number;
|
|
64
|
+
}): Promise<TResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
67
|
+
* @returns {Array<TResult>}
|
|
68
|
+
*/
|
|
69
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
70
|
+
id: number;
|
|
71
|
+
}, options?: {
|
|
72
|
+
strict?: boolean;
|
|
73
|
+
each?: undefined | false;
|
|
32
74
|
}): Promise<TResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
|
|
77
|
+
* @returns {Array<TResult>}
|
|
78
|
+
*/
|
|
79
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
80
|
+
id: number;
|
|
81
|
+
}, options?: {
|
|
82
|
+
strict?: boolean;
|
|
83
|
+
each: true;
|
|
84
|
+
}): Promise<Array<TResult>>;
|
|
85
|
+
/**
|
|
86
|
+
* Registers the request/context object for a given context ID (DI container sub-tree).
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
33
89
|
registerRequestByContextId<T = any>(request: T, contextId: ContextId): void;
|
|
34
90
|
/**
|
|
35
91
|
* Initializes the Nest application.
|
|
@@ -38,8 +94,21 @@ export declare class NestApplicationContext implements INestApplicationContext {
|
|
|
38
94
|
* @returns {Promise<this>} The NestApplicationContext instance as Promise
|
|
39
95
|
*/
|
|
40
96
|
init(): Promise<this>;
|
|
97
|
+
/**
|
|
98
|
+
* Terminates the application
|
|
99
|
+
* @returns {Promise<void>}
|
|
100
|
+
*/
|
|
41
101
|
close(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Sets custom logger service.
|
|
104
|
+
* Flushes buffered logs if auto flush is on.
|
|
105
|
+
* @returns {void}
|
|
106
|
+
*/
|
|
42
107
|
useLogger(logger: LoggerService | LogLevel[] | false): void;
|
|
108
|
+
/**
|
|
109
|
+
* Prints buffered logs and detaches buffer.
|
|
110
|
+
* @returns {void}
|
|
111
|
+
*/
|
|
43
112
|
flushLogs(): void;
|
|
44
113
|
/**
|
|
45
114
|
* Define that it must flush logs right after defining a custom logger.
|
|
@@ -92,9 +161,5 @@ export declare class NestApplicationContext implements INestApplicationContext {
|
|
|
92
161
|
* modules and children.
|
|
93
162
|
*/
|
|
94
163
|
protected callBeforeShutdownHook(signal?: string): Promise<void>;
|
|
95
|
-
protected find<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, contextModule?: Module): TResult;
|
|
96
|
-
protected resolvePerContext<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol, contextModule: Module, contextId: ContextId, options?: {
|
|
97
|
-
strict: boolean;
|
|
98
|
-
}): Promise<TResult>;
|
|
99
164
|
private getModulesSortedByDistance;
|
|
100
165
|
}
|
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NestApplicationContext = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
const interfaces_1 = require("@nestjs/common/interfaces");
|
|
6
5
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
7
6
|
const iterare_1 = require("iterare");
|
|
8
7
|
const constants_1 = require("./constants");
|
|
9
|
-
const
|
|
10
|
-
const unknown_element_exception_1 = require("./errors/exceptions/unknown-element.exception");
|
|
11
|
-
const unknown_module_exception_1 = require("./errors/exceptions/unknown-module.exception");
|
|
8
|
+
const exceptions_1 = require("./errors/exceptions");
|
|
12
9
|
const context_id_factory_1 = require("./helpers/context-id-factory");
|
|
13
10
|
const hooks_1 = require("./hooks");
|
|
11
|
+
const abstract_instance_resolver_1 = require("./injector/abstract-instance-resolver");
|
|
14
12
|
const compiler_1 = require("./injector/compiler");
|
|
15
13
|
const injector_1 = require("./injector/injector");
|
|
16
14
|
const instance_links_host_1 = require("./injector/instance-links-host");
|
|
17
15
|
/**
|
|
18
16
|
* @publicApi
|
|
19
17
|
*/
|
|
20
|
-
class NestApplicationContext {
|
|
18
|
+
class NestApplicationContext extends abstract_instance_resolver_1.AbstractInstanceResolver {
|
|
21
19
|
constructor(container, scope = new Array(), contextModule = null) {
|
|
20
|
+
super();
|
|
22
21
|
this.container = container;
|
|
23
22
|
this.scope = scope;
|
|
24
23
|
this.contextModule = contextModule;
|
|
@@ -38,6 +37,10 @@ class NestApplicationContext {
|
|
|
38
37
|
const modules = this.container.getModules().values();
|
|
39
38
|
this.contextModule = modules.next().value;
|
|
40
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
|
|
42
|
+
* @returns {INestApplicationContext}
|
|
43
|
+
*/
|
|
41
44
|
select(moduleType) {
|
|
42
45
|
const modulesContainer = this.container.getModules();
|
|
43
46
|
const contextModuleCtor = this.contextModule.metatype;
|
|
@@ -47,18 +50,34 @@ class NestApplicationContext {
|
|
|
47
50
|
const token = moduleTokenFactory.create(type, dynamicMetadata);
|
|
48
51
|
const selectedModule = modulesContainer.get(token);
|
|
49
52
|
if (!selectedModule) {
|
|
50
|
-
throw new
|
|
53
|
+
throw new exceptions_1.UnknownModuleException();
|
|
51
54
|
}
|
|
52
55
|
return new NestApplicationContext(this.container, scope, selectedModule);
|
|
53
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
59
|
+
* @returns {TResult | Array<TResult>}
|
|
60
|
+
*/
|
|
54
61
|
get(typeOrToken, options = { strict: false }) {
|
|
62
|
+
var _a;
|
|
55
63
|
return !(options && options.strict)
|
|
56
|
-
? this.find(typeOrToken)
|
|
57
|
-
: this.find(typeOrToken,
|
|
64
|
+
? this.find(typeOrToken, options)
|
|
65
|
+
: this.find(typeOrToken, {
|
|
66
|
+
moduleId: (_a = this.contextModule) === null || _a === void 0 ? void 0 : _a.id,
|
|
67
|
+
each: options.each,
|
|
68
|
+
});
|
|
58
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolves transient or request-scoped instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
72
|
+
* @returns {Promise<TResult | Array<TResult>>}
|
|
73
|
+
*/
|
|
59
74
|
resolve(typeOrToken, contextId = (0, context_id_factory_1.createContextId)(), options = { strict: false }) {
|
|
60
75
|
return this.resolvePerContext(typeOrToken, this.contextModule, contextId, options);
|
|
61
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Registers the request/context object for a given context ID (DI container sub-tree).
|
|
79
|
+
* @returns {void}
|
|
80
|
+
*/
|
|
62
81
|
registerRequestByContextId(request, contextId) {
|
|
63
82
|
this.container.registerRequestProvider(request, contextId);
|
|
64
83
|
}
|
|
@@ -77,6 +96,10 @@ class NestApplicationContext {
|
|
|
77
96
|
this.isInitialized = true;
|
|
78
97
|
return this;
|
|
79
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Terminates the application
|
|
101
|
+
* @returns {Promise<void>}
|
|
102
|
+
*/
|
|
80
103
|
async close() {
|
|
81
104
|
await this.callDestroyHook();
|
|
82
105
|
await this.callBeforeShutdownHook();
|
|
@@ -84,12 +107,21 @@ class NestApplicationContext {
|
|
|
84
107
|
await this.callShutdownHook();
|
|
85
108
|
this.unsubscribeFromProcessSignals();
|
|
86
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Sets custom logger service.
|
|
112
|
+
* Flushes buffered logs if auto flush is on.
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
87
115
|
useLogger(logger) {
|
|
88
116
|
common_1.Logger.overrideLogger(logger);
|
|
89
117
|
if (this.shouldFlushLogsOnOverride) {
|
|
90
118
|
this.flushLogs();
|
|
91
119
|
}
|
|
92
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Prints buffered logs and detaches buffer.
|
|
123
|
+
* @returns {void}
|
|
124
|
+
*/
|
|
93
125
|
flushLogs() {
|
|
94
126
|
common_1.Logger.flush();
|
|
95
127
|
}
|
|
@@ -218,31 +250,6 @@ class NestApplicationContext {
|
|
|
218
250
|
await (0, hooks_1.callBeforeAppShutdownHook)(module, signal);
|
|
219
251
|
}
|
|
220
252
|
}
|
|
221
|
-
find(typeOrToken, contextModule) {
|
|
222
|
-
const moduleId = contextModule && contextModule.id;
|
|
223
|
-
const { wrapperRef } = this.instanceLinksHost.get(typeOrToken, moduleId);
|
|
224
|
-
if (wrapperRef.scope === interfaces_1.Scope.REQUEST ||
|
|
225
|
-
wrapperRef.scope === interfaces_1.Scope.TRANSIENT) {
|
|
226
|
-
throw new invalid_class_scope_exception_1.InvalidClassScopeException(typeOrToken);
|
|
227
|
-
}
|
|
228
|
-
return wrapperRef.instance;
|
|
229
|
-
}
|
|
230
|
-
async resolvePerContext(typeOrToken, contextModule, contextId, options) {
|
|
231
|
-
const isStrictModeEnabled = options && options.strict;
|
|
232
|
-
const instanceLink = isStrictModeEnabled
|
|
233
|
-
? this.instanceLinksHost.get(typeOrToken, contextModule.id)
|
|
234
|
-
: this.instanceLinksHost.get(typeOrToken);
|
|
235
|
-
const { wrapperRef, collection } = instanceLink;
|
|
236
|
-
if (wrapperRef.isDependencyTreeStatic() && !wrapperRef.isTransient) {
|
|
237
|
-
return this.get(typeOrToken, options);
|
|
238
|
-
}
|
|
239
|
-
const ctorHost = wrapperRef.instance || { constructor: typeOrToken };
|
|
240
|
-
const instance = await this.injector.loadPerContext(ctorHost, wrapperRef.host, collection, contextId, wrapperRef);
|
|
241
|
-
if (!instance) {
|
|
242
|
-
throw new unknown_element_exception_1.UnknownElementException();
|
|
243
|
-
}
|
|
244
|
-
return instance;
|
|
245
|
-
}
|
|
246
253
|
getModulesSortedByDistance() {
|
|
247
254
|
if (this._moduleRefsByDistance) {
|
|
248
255
|
return this._moduleRefsByDistance;
|
package/nest-application.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CanActivate, ExceptionFilter, HttpServer, INestApplication, INestMicroservice, NestHybridApplicationOptions, NestInterceptor, PipeTransform, VersioningOptions, WebSocketAdapter } from '@nestjs/common';
|
|
2
|
+
import { GlobalPrefixOptions, NestApplicationOptions } from '@nestjs/common/interfaces';
|
|
2
3
|
import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
3
|
-
import { GlobalPrefixOptions } from '@nestjs/common/interfaces/global-prefix-options.interface';
|
|
4
|
-
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
|
|
5
4
|
import { AbstractHttpAdapter } from './adapters';
|
|
6
5
|
import { ApplicationConfig } from './application-config';
|
|
7
6
|
import { NestContainer } from './injector/container';
|
package/nest-application.js
CHANGED
|
@@ -14,6 +14,7 @@ const optional_require_1 = require("./helpers/optional-require");
|
|
|
14
14
|
const container_1 = require("./middleware/container");
|
|
15
15
|
const middleware_module_1 = require("./middleware/middleware-module");
|
|
16
16
|
const nest_application_context_1 = require("./nest-application-context");
|
|
17
|
+
const route_path_factory_1 = require("./router/route-path-factory");
|
|
17
18
|
const routes_resolver_1 = require("./router/routes-resolver");
|
|
18
19
|
const { SocketModule } = (0, optional_require_1.optionalRequire)('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
|
|
19
20
|
const { MicroservicesModule } = (0, optional_require_1.optionalRequire)('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module'));
|
|
@@ -29,7 +30,6 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
29
30
|
this.logger = new logger_service_1.Logger(NestApplication.name, {
|
|
30
31
|
timestamp: true,
|
|
31
32
|
});
|
|
32
|
-
this.middlewareModule = new middleware_module_1.MiddlewareModule();
|
|
33
33
|
this.middlewareContainer = new container_1.MiddlewareContainer(this.container);
|
|
34
34
|
this.microservicesModule = MicroservicesModule && new MicroservicesModule();
|
|
35
35
|
this.socketModule = SocketModule && new SocketModule();
|
|
@@ -37,6 +37,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
37
37
|
this.isListening = false;
|
|
38
38
|
this.selectContextModule();
|
|
39
39
|
this.registerHttpServer();
|
|
40
|
+
this.middlewareModule = new middleware_module_1.MiddlewareModule(new route_path_factory_1.RoutePathFactory(config));
|
|
40
41
|
this.routesResolver = new routes_resolver_1.RoutesResolver(this.container, this.config, this.injector);
|
|
41
42
|
}
|
|
42
43
|
async dispose() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/core",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"iterare": "1.2.1",
|
|
33
33
|
"object-hash": "3.0.0",
|
|
34
34
|
"path-to-regexp": "3.2.0",
|
|
35
|
-
"tslib": "2.4.
|
|
35
|
+
"tslib": "2.4.1",
|
|
36
36
|
"uuid": "9.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "9.
|
|
39
|
+
"@nestjs/common": "9.2.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@nestjs/common": "^9.0.0",
|
package/pipes/index.d.ts
ADDED
package/pipes/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./params-token-factory"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./pipes-consumer"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./pipes-context-creator"), exports);
|
package/repl/repl-context.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.ReplContext = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const application_config_1 = require("../application-config");
|
|
6
6
|
const injector_1 = require("../injector");
|
|
7
|
-
const internal_core_module_1 = require("../injector/internal-core-module");
|
|
7
|
+
const internal_core_module_1 = require("../injector/internal-core-module/internal-core-module");
|
|
8
8
|
const native_functions_1 = require("./native-functions");
|
|
9
9
|
class ReplContext {
|
|
10
10
|
constructor(app, nativeFunctionsClassRefs) {
|
package/repl/repl.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Type } from '@nestjs/common';
|
|
3
|
-
export declare function repl(module: Type): Promise<import("repl").REPLServer>;
|
|
2
|
+
import { DynamicModule, Type } from '@nestjs/common';
|
|
3
|
+
export declare function repl(module: Type | DynamicModule): Promise<import("repl").REPLServer>;
|
|
@@ -2,8 +2,7 @@ import { CanActivate, HttpServer, ParamData, PipeTransform, RequestMethod } from
|
|
|
2
2
|
import { RouteParamMetadata } from '@nestjs/common/decorators';
|
|
3
3
|
import { RouteParamtypes } from '@nestjs/common/enums/route-paramtypes.enum';
|
|
4
4
|
import { ContextType, Controller } from '@nestjs/common/interfaces';
|
|
5
|
-
import { GuardsConsumer } from '../guards
|
|
6
|
-
import { GuardsContextCreator } from '../guards/guards-context-creator';
|
|
5
|
+
import { GuardsConsumer, GuardsContextCreator } from '../guards';
|
|
7
6
|
import { ExecutionContextHost } from '../helpers/execution-context-host';
|
|
8
7
|
import { HandleResponseFn, HandlerMetadata } from '../helpers/handler-metadata-storage';
|
|
9
8
|
import { InterceptorsConsumer } from '../interceptors/interceptors-consumer';
|
|
@@ -5,10 +5,10 @@ const common_1 = require("@nestjs/common");
|
|
|
5
5
|
const constants_1 = require("@nestjs/common/constants");
|
|
6
6
|
const route_paramtypes_enum_1 = require("@nestjs/common/enums/route-paramtypes.enum");
|
|
7
7
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
8
|
-
const
|
|
8
|
+
const guards_1 = require("../guards");
|
|
9
9
|
const context_utils_1 = require("../helpers/context-utils");
|
|
10
10
|
const handler_metadata_storage_1 = require("../helpers/handler-metadata-storage");
|
|
11
|
-
const
|
|
11
|
+
const constants_2 = require("../injector/constants");
|
|
12
12
|
const router_response_controller_1 = require("./router-response-controller");
|
|
13
13
|
class RouterExecutionContext {
|
|
14
14
|
constructor(paramsFactory, pipesContextCreator, pipesConsumer, guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, applicationRef) {
|
|
@@ -24,7 +24,7 @@ class RouterExecutionContext {
|
|
|
24
24
|
this.contextUtils = new context_utils_1.ContextUtils();
|
|
25
25
|
this.responseController = new router_response_controller_1.RouterResponseController(applicationRef);
|
|
26
26
|
}
|
|
27
|
-
create(instance, callback, methodName, moduleKey, requestMethod, contextId =
|
|
27
|
+
create(instance, callback, methodName, moduleKey, requestMethod, contextId = constants_2.STATIC_CONTEXT, inquirerId) {
|
|
28
28
|
const contextType = 'http';
|
|
29
29
|
const { argsLength, fnHandleResponse, paramtypes, getParamsMetadata, httpStatusCode, responseHeaders, hasCustomHeaders, } = this.getMetadata(instance, callback, methodName, moduleKey, requestMethod, contextType);
|
|
30
30
|
const paramsOptions = this.contextUtils.mergeParamsMetatypes(getParamsMetadata(moduleKey, contextId, inquirerId), paramtypes);
|
|
@@ -57,7 +57,7 @@ class RouterExecutionContext {
|
|
|
57
57
|
const argsLength = this.contextUtils.getArgumentsLength(keys, metadata);
|
|
58
58
|
const paramtypes = this.contextUtils.reflectCallbackParamtypes(instance, methodName);
|
|
59
59
|
const contextFactory = this.contextUtils.getContextFactory(contextType, instance, callback);
|
|
60
|
-
const getParamsMetadata = (moduleKey, contextId =
|
|
60
|
+
const getParamsMetadata = (moduleKey, contextId = constants_2.STATIC_CONTEXT, inquirerId) => this.exchangeKeysForValues(keys, metadata, moduleKey, contextId, inquirerId, contextFactory);
|
|
61
61
|
const paramsMetadata = getParamsMetadata(moduleKey);
|
|
62
62
|
const isResponseHandled = this.isResponseHandled(instance, methodName, paramsMetadata);
|
|
63
63
|
const httpRedirectResponse = this.reflectRedirect(callback);
|
|
@@ -95,7 +95,7 @@ class RouterExecutionContext {
|
|
|
95
95
|
reflectSse(callback) {
|
|
96
96
|
return Reflect.getMetadata(constants_1.SSE_METADATA, callback);
|
|
97
97
|
}
|
|
98
|
-
exchangeKeysForValues(keys, metadata, moduleContext, contextId =
|
|
98
|
+
exchangeKeysForValues(keys, metadata, moduleContext, contextId = constants_2.STATIC_CONTEXT, inquirerId, contextFactory) {
|
|
99
99
|
this.pipesContextCreator.setModuleContext(moduleContext);
|
|
100
100
|
return keys.map(key => {
|
|
101
101
|
const { index, data, pipes: pipesCollection } = metadata[key];
|
|
@@ -133,7 +133,7 @@ class RouterExecutionContext {
|
|
|
133
133
|
const canActivateFn = async (args) => {
|
|
134
134
|
const canActivate = await this.guardsConsumer.tryActivate(guards, args, instance, callback, contextType);
|
|
135
135
|
if (!canActivate) {
|
|
136
|
-
throw new common_1.ForbiddenException(
|
|
136
|
+
throw new common_1.ForbiddenException(guards_1.FORBIDDEN_MESSAGE);
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
return guards.length ? canActivateFn : null;
|
|
@@ -174,6 +174,7 @@ class RouterExecutionContext {
|
|
|
174
174
|
result = await this.responseController.transformToResult(result);
|
|
175
175
|
!isResponseHandled &&
|
|
176
176
|
(await this.responseController.apply(result, res, httpStatusCode));
|
|
177
|
+
return res;
|
|
177
178
|
};
|
|
178
179
|
}
|
|
179
180
|
isResponseHandled(instance, methodName, paramsMetadata) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpServer } from '@nestjs/common';
|
|
2
|
-
import { RequestMethod } from '@nestjs/common/enums
|
|
2
|
+
import { RequestMethod } from '@nestjs/common/enums';
|
|
3
3
|
import { Controller } from '@nestjs/common/interfaces/controllers/controller.interface';
|
|
4
4
|
import { Type } from '@nestjs/common/interfaces/type.interface';
|
|
5
5
|
import { VersionValue } from '@nestjs/common/interfaces/version-options.interface';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RouterExplorer = void 0;
|
|
4
4
|
const constants_1 = require("@nestjs/common/constants");
|
|
5
|
-
const
|
|
5
|
+
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");
|
|
@@ -53,7 +53,7 @@ class RouterExplorer {
|
|
|
53
53
|
extractRouterPath(metatype) {
|
|
54
54
|
const path = Reflect.getMetadata(constants_1.PATH_METADATA, metatype);
|
|
55
55
|
if ((0, shared_utils_1.isUndefined)(path)) {
|
|
56
|
-
throw new unknown_request_mapping_exception_1.UnknownRequestMappingException();
|
|
56
|
+
throw new unknown_request_mapping_exception_1.UnknownRequestMappingException(metatype);
|
|
57
57
|
}
|
|
58
58
|
if (Array.isArray(path)) {
|
|
59
59
|
return path.map(p => (0, shared_utils_1.addLeadingSlash)(p));
|
|
@@ -109,7 +109,7 @@ class RouterExplorer {
|
|
|
109
109
|
let routeHandler = this.applyHostFilter(host, proxy);
|
|
110
110
|
paths.forEach(path => {
|
|
111
111
|
if (isVersioned &&
|
|
112
|
-
routePathMetadata.versioningOptions.type !==
|
|
112
|
+
routePathMetadata.versioningOptions.type !== enums_1.VersioningType.URI) {
|
|
113
113
|
// All versioning (except for URI Versioning) is done via the "Version Filter"
|
|
114
114
|
routeHandler = this.applyVersionFilter(router, routePathMetadata, routeHandler);
|
|
115
115
|
}
|