@nestjs/core 9.3.0 → 9.3.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/index.js +1 -1
- package/injector/compiler.d.ts +3 -3
- package/injector/compiler.js +5 -1
- package/injector/injector.js +3 -1
- package/inspector/uuid-factory.js +1 -1
- package/middleware/middleware-module.d.ts +1 -4
- package/middleware/middleware-module.js +7 -27
- package/middleware/route-info-path-extractor.d.ts +8 -0
- package/middleware/route-info-path-extractor.js +38 -0
- package/middleware/utils.d.ts +1 -1
- package/middleware/utils.js +14 -5
- package/nest-application.js +5 -17
- package/package.json +3 -3
- package/router/interfaces/exclude-route-metadata.interface.d.ts +3 -0
- package/router/utils/exclude-route.util.js +2 -1
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.NestFactory = exports.APP_PIPE = exports.APP_INTERCEPTOR = exports.APP_G
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/*
|
|
6
6
|
* Nest @core
|
|
7
|
-
* Copyright(c) 2017 -
|
|
7
|
+
* Copyright(c) 2017 - 2023 Kamil Mysliwiec
|
|
8
8
|
* https://nestjs.com
|
|
9
9
|
* MIT Licensed
|
|
10
10
|
*/
|
package/injector/compiler.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamicModule, Type } from '@nestjs/common/interfaces';
|
|
1
|
+
import { DynamicModule, ForwardReference, Type } from '@nestjs/common/interfaces';
|
|
2
2
|
import { ModuleTokenFactory } from './module-token-factory';
|
|
3
3
|
export interface ModuleFactory {
|
|
4
4
|
type: Type<any>;
|
|
@@ -9,9 +9,9 @@ export declare class ModuleCompiler {
|
|
|
9
9
|
private readonly moduleTokenFactory;
|
|
10
10
|
constructor(moduleTokenFactory?: ModuleTokenFactory);
|
|
11
11
|
compile(metatype: Type<any> | DynamicModule | Promise<DynamicModule>): Promise<ModuleFactory>;
|
|
12
|
-
extractMetadata(metatype: Type<any> | DynamicModule): {
|
|
12
|
+
extractMetadata(metatype: Type<any> | ForwardReference | DynamicModule): {
|
|
13
13
|
type: Type<any>;
|
|
14
14
|
dynamicMetadata?: Partial<DynamicModule> | undefined;
|
|
15
15
|
};
|
|
16
|
-
isDynamicModule(module: Type<any> | DynamicModule): module is DynamicModule;
|
|
16
|
+
isDynamicModule(module: Type<any> | DynamicModule | ForwardReference): module is DynamicModule;
|
|
17
17
|
}
|
package/injector/compiler.js
CHANGED
|
@@ -14,7 +14,11 @@ class ModuleCompiler {
|
|
|
14
14
|
}
|
|
15
15
|
extractMetadata(metatype) {
|
|
16
16
|
if (!this.isDynamicModule(metatype)) {
|
|
17
|
-
return {
|
|
17
|
+
return {
|
|
18
|
+
type: (metatype === null || metatype === void 0 ? void 0 : metatype.forwardRef)
|
|
19
|
+
? metatype.forwardRef()
|
|
20
|
+
: metatype,
|
|
21
|
+
};
|
|
18
22
|
}
|
|
19
23
|
const { module: type } = metatype, dynamicMetadata = tslib_1.__rest(metatype, ["module"]);
|
|
20
24
|
return { type, dynamicMetadata };
|
package/injector/injector.js
CHANGED
|
@@ -162,7 +162,9 @@ class Injector {
|
|
|
162
162
|
];
|
|
163
163
|
}
|
|
164
164
|
reflectConstructorParams(type) {
|
|
165
|
-
const paramtypes = [
|
|
165
|
+
const paramtypes = [
|
|
166
|
+
...(Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, type) || []),
|
|
167
|
+
];
|
|
166
168
|
const selfParams = this.reflectSelfParams(type);
|
|
167
169
|
selfParams.forEach(({ index, param }) => (paramtypes[index] = param));
|
|
168
170
|
return paramtypes;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UuidFactory = exports.UuidFactoryMode = void 0;
|
|
4
|
-
const random_string_generator_util_1 = require("
|
|
4
|
+
const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
|
|
5
5
|
const deterministic_uuid_registry_1 = require("./deterministic-uuid-registry");
|
|
6
6
|
var UuidFactoryMode;
|
|
7
7
|
(function (UuidFactoryMode) {
|
|
@@ -6,10 +6,8 @@ import { NestContainer } from '../injector/container';
|
|
|
6
6
|
import { Injector } from '../injector/injector';
|
|
7
7
|
import { Module } from '../injector/module';
|
|
8
8
|
import { GraphInspector } from '../inspector/graph-inspector';
|
|
9
|
-
import { RoutePathFactory } from '../router/route-path-factory';
|
|
10
9
|
import { MiddlewareContainer } from './container';
|
|
11
10
|
export declare class MiddlewareModule<TAppOptions extends NestApplicationContextOptions = NestApplicationContextOptions> {
|
|
12
|
-
private readonly routePathFactory;
|
|
13
11
|
private readonly routerProxy;
|
|
14
12
|
private readonly exceptionFiltersCache;
|
|
15
13
|
private readonly logger;
|
|
@@ -17,12 +15,11 @@ export declare class MiddlewareModule<TAppOptions extends NestApplicationContext
|
|
|
17
15
|
private routerExceptionFilter;
|
|
18
16
|
private routesMapper;
|
|
19
17
|
private resolver;
|
|
20
|
-
private config;
|
|
21
18
|
private container;
|
|
22
19
|
private httpAdapter;
|
|
23
20
|
private graphInspector;
|
|
24
21
|
private appOptions;
|
|
25
|
-
|
|
22
|
+
private routeInfoPathExtractor;
|
|
26
23
|
register(middlewareContainer: MiddlewareContainer, container: NestContainer, config: ApplicationConfig, injector: Injector, httpAdapter: HttpServer, graphInspector: GraphInspector, options: TAppOptions): Promise<void>;
|
|
27
24
|
resolveMiddleware(middlewareContainer: MiddlewareContainer, modules: Map<string, Module>): Promise<void>;
|
|
28
25
|
loadConfiguration(middlewareContainer: MiddlewareContainer, moduleRef: Module, moduleKey: string): Promise<void>;
|
|
@@ -15,10 +15,10 @@ const router_proxy_1 = require("../router/router-proxy");
|
|
|
15
15
|
const utils_1 = require("../router/utils");
|
|
16
16
|
const builder_1 = require("./builder");
|
|
17
17
|
const resolver_1 = require("./resolver");
|
|
18
|
+
const route_info_path_extractor_1 = require("./route-info-path-extractor");
|
|
18
19
|
const routes_mapper_1 = require("./routes-mapper");
|
|
19
20
|
class MiddlewareModule {
|
|
20
|
-
constructor(
|
|
21
|
-
this.routePathFactory = routePathFactory;
|
|
21
|
+
constructor() {
|
|
22
22
|
this.routerProxy = new router_proxy_1.RouterProxy();
|
|
23
23
|
this.exceptionFiltersCache = new WeakMap();
|
|
24
24
|
this.logger = new common_1.Logger(MiddlewareModule.name);
|
|
@@ -29,7 +29,7 @@ class MiddlewareModule {
|
|
|
29
29
|
this.routerExceptionFilter = new router_exception_filters_1.RouterExceptionFilters(container, config, appRef);
|
|
30
30
|
this.routesMapper = new routes_mapper_1.RoutesMapper(container);
|
|
31
31
|
this.resolver = new resolver_1.MiddlewareResolver(middlewareContainer, injector);
|
|
32
|
-
this.
|
|
32
|
+
this.routeInfoPathExtractor = new route_info_path_extractor_1.RouteInfoPathExtractor(config);
|
|
33
33
|
this.injector = injector;
|
|
34
34
|
this.container = container;
|
|
35
35
|
this.httpAdapter = httpAdapter;
|
|
@@ -153,29 +153,9 @@ class MiddlewareModule {
|
|
|
153
153
|
const middleware = instance.use.bind(instance);
|
|
154
154
|
return this.routerProxy.createProxy(middleware, exceptionsHandler);
|
|
155
155
|
}
|
|
156
|
-
async registerHandler(applicationRef,
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const isAWildcard = ['*', '/*', '(.*)', '/(.*)'].includes(path);
|
|
160
|
-
if ((Array.isArray(excludedRoutes) &&
|
|
161
|
-
(0, utils_1.isRouteExcluded)(excludedRoutes, path, method)) ||
|
|
162
|
-
isAWildcard) {
|
|
163
|
-
path = (0, shared_utils_1.addLeadingSlash)(path);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
const basePath = (0, shared_utils_1.addLeadingSlash)(prefix);
|
|
167
|
-
if ((basePath === null || basePath === void 0 ? void 0 : basePath.endsWith('/')) && (path === null || path === void 0 ? void 0 : path.startsWith('/'))) {
|
|
168
|
-
// strip slash when a wildcard is being used
|
|
169
|
-
// and global prefix has been set
|
|
170
|
-
path = path === null || path === void 0 ? void 0 : path.slice(1);
|
|
171
|
-
}
|
|
172
|
-
path = basePath + path;
|
|
173
|
-
}
|
|
174
|
-
const applicationVersioningConfig = this.config.getVersioning();
|
|
175
|
-
if (version && applicationVersioningConfig.type === common_1.VersioningType.URI) {
|
|
176
|
-
const versionPrefix = this.routePathFactory.getVersionPrefix(applicationVersioningConfig);
|
|
177
|
-
path = `/${versionPrefix}${version.toString()}${path}`;
|
|
178
|
-
}
|
|
156
|
+
async registerHandler(applicationRef, routeInfo, proxy) {
|
|
157
|
+
const { method } = routeInfo;
|
|
158
|
+
const paths = this.routeInfoPathExtractor.extractPathsFrom(routeInfo);
|
|
179
159
|
const isMethodAll = (0, utils_1.isRequestMethodAll)(method);
|
|
180
160
|
const requestMethod = request_method_enum_1.RequestMethod[method];
|
|
181
161
|
const router = await applicationRef.createMiddlewareFactory(method);
|
|
@@ -187,7 +167,7 @@ class MiddlewareModule {
|
|
|
187
167
|
}
|
|
188
168
|
return next();
|
|
189
169
|
};
|
|
190
|
-
router(path, middlewareFunction);
|
|
170
|
+
paths.forEach(path => router(path, middlewareFunction));
|
|
191
171
|
}
|
|
192
172
|
getContextId(request, isTreeDurable) {
|
|
193
173
|
const contextId = context_id_factory_1.ContextIdFactory.getByRequest(request);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RouteInfo } from '@nestjs/common/interfaces';
|
|
2
|
+
import { ApplicationConfig } from '../application-config';
|
|
3
|
+
export declare class RouteInfoPathExtractor {
|
|
4
|
+
private readonly applicationConfig;
|
|
5
|
+
private routePathFactory;
|
|
6
|
+
constructor(applicationConfig: ApplicationConfig);
|
|
7
|
+
extractPathsFrom({ path, method, version }: RouteInfo): string[];
|
|
8
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteInfoPathExtractor = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
|
+
const utils_1 = require("../router/utils");
|
|
7
|
+
const route_path_factory_1 = require("./../router/route-path-factory");
|
|
8
|
+
class RouteInfoPathExtractor {
|
|
9
|
+
constructor(applicationConfig) {
|
|
10
|
+
this.applicationConfig = applicationConfig;
|
|
11
|
+
this.routePathFactory = new route_path_factory_1.RoutePathFactory(applicationConfig);
|
|
12
|
+
}
|
|
13
|
+
extractPathsFrom({ path, method, version }) {
|
|
14
|
+
const prefixPath = (0, shared_utils_1.stripEndSlash)((0, shared_utils_1.addLeadingSlash)(this.applicationConfig.getGlobalPrefix()));
|
|
15
|
+
const excludedRoutes = this.applicationConfig.getGlobalPrefixOptions().exclude;
|
|
16
|
+
const applicationVersioningConfig = this.applicationConfig.getVersioning();
|
|
17
|
+
let versionPath = '';
|
|
18
|
+
if (version && (applicationVersioningConfig === null || applicationVersioningConfig === void 0 ? void 0 : applicationVersioningConfig.type) === common_1.VersioningType.URI) {
|
|
19
|
+
const versionPrefix = this.routePathFactory.getVersionPrefix(applicationVersioningConfig);
|
|
20
|
+
versionPath = (0, shared_utils_1.addLeadingSlash)(versionPrefix + version.toString());
|
|
21
|
+
}
|
|
22
|
+
const isAWildcard = ['*', '/*', '/*/', '(.*)', '/(.*)'].includes(path);
|
|
23
|
+
if (isAWildcard) {
|
|
24
|
+
return Array.isArray(excludedRoutes)
|
|
25
|
+
? [
|
|
26
|
+
prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path),
|
|
27
|
+
...excludedRoutes.map(route => versionPath + (0, shared_utils_1.addLeadingSlash)(route.path)),
|
|
28
|
+
]
|
|
29
|
+
: [prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path)];
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(excludedRoutes) &&
|
|
32
|
+
(0, utils_1.isRouteExcluded)(excludedRoutes, path, method)) {
|
|
33
|
+
return [versionPath + (0, shared_utils_1.addLeadingSlash)(path)];
|
|
34
|
+
}
|
|
35
|
+
return [prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path)];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.RouteInfoPathExtractor = RouteInfoPathExtractor;
|
package/middleware/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpServer, RouteInfo, Type } from '@nestjs/common/interfaces';
|
|
2
2
|
import { ExcludeRouteMetadata } from '../router/interfaces/exclude-route-metadata.interface';
|
|
3
|
-
export declare const mapToExcludeRoute: (routes: RouteInfo[]) => ExcludeRouteMetadata[];
|
|
3
|
+
export declare const mapToExcludeRoute: (routes: (string | RouteInfo)[]) => ExcludeRouteMetadata[];
|
|
4
4
|
export declare const filterMiddleware: <T extends Function | Type<any> = any>(middleware: T[], routes: RouteInfo[], httpAdapter: HttpServer) => Type<any>[];
|
|
5
5
|
export declare const mapToClass: <T extends Function | Type<any>>(middleware: T, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer) => Type<any>;
|
|
6
6
|
export declare function isMiddlewareClass(middleware: any): middleware is Type<any>;
|
package/middleware/utils.js
CHANGED
|
@@ -8,11 +8,20 @@ const pathToRegexp = require("path-to-regexp");
|
|
|
8
8
|
const uuid_1 = require("uuid");
|
|
9
9
|
const utils_1 = require("../router/utils");
|
|
10
10
|
const mapToExcludeRoute = (routes) => {
|
|
11
|
-
return routes.map(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
return routes.map(route => {
|
|
12
|
+
if ((0, shared_utils_1.isString)(route)) {
|
|
13
|
+
return {
|
|
14
|
+
path: route,
|
|
15
|
+
requestMethod: common_1.RequestMethod.ALL,
|
|
16
|
+
pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route)),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
path: route.path,
|
|
21
|
+
requestMethod: route.method,
|
|
22
|
+
pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route.path)),
|
|
23
|
+
};
|
|
24
|
+
});
|
|
16
25
|
};
|
|
17
26
|
exports.mapToExcludeRoute = mapToExcludeRoute;
|
|
18
27
|
const filterMiddleware = (middleware, routes, httpAdapter) => {
|
package/nest-application.js
CHANGED
|
@@ -7,15 +7,14 @@ const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
|
|
7
7
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
8
8
|
const iterare_1 = require("iterare");
|
|
9
9
|
const os_1 = require("os");
|
|
10
|
-
const pathToRegexp = require("path-to-regexp");
|
|
11
10
|
const application_config_1 = require("./application-config");
|
|
12
11
|
const constants_1 = require("./constants");
|
|
13
12
|
const optional_require_1 = require("./helpers/optional-require");
|
|
14
13
|
const injector_1 = require("./injector/injector");
|
|
15
14
|
const container_1 = require("./middleware/container");
|
|
16
15
|
const middleware_module_1 = require("./middleware/middleware-module");
|
|
16
|
+
const utils_1 = require("./middleware/utils");
|
|
17
17
|
const nest_application_context_1 = require("./nest-application-context");
|
|
18
|
-
const route_path_factory_1 = require("./router/route-path-factory");
|
|
19
18
|
const routes_resolver_1 = require("./router/routes-resolver");
|
|
20
19
|
const { SocketModule } = (0, optional_require_1.optionalRequire)('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
|
|
21
20
|
const { MicroservicesModule } = (0, optional_require_1.optionalRequire)('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module'));
|
|
@@ -39,7 +38,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
39
38
|
this.selectContextModule();
|
|
40
39
|
this.registerHttpServer();
|
|
41
40
|
this.injector = new injector_1.Injector({ preview: this.appOptions.preview });
|
|
42
|
-
this.middlewareModule = new middleware_module_1.MiddlewareModule(
|
|
41
|
+
this.middlewareModule = new middleware_module_1.MiddlewareModule();
|
|
43
42
|
this.routesResolver = new routes_resolver_1.RoutesResolver(this.container, this.config, this.injector, this.graphInspector);
|
|
44
43
|
}
|
|
45
44
|
async dispose() {
|
|
@@ -234,20 +233,9 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
|
|
234
233
|
setGlobalPrefix(prefix, options) {
|
|
235
234
|
this.config.setGlobalPrefix(prefix);
|
|
236
235
|
if (options) {
|
|
237
|
-
const exclude = options === null || options === void 0 ? void 0 : options.exclude
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
requestMethod: common_1.RequestMethod.ALL,
|
|
241
|
-
pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route)),
|
|
242
|
-
path: route,
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
requestMethod: route.method,
|
|
247
|
-
pathRegex: pathToRegexp((0, shared_utils_1.addLeadingSlash)(route.path)),
|
|
248
|
-
path: route.path,
|
|
249
|
-
};
|
|
250
|
-
});
|
|
236
|
+
const exclude = (options === null || options === void 0 ? void 0 : options.exclude)
|
|
237
|
+
? (0, utils_1.mapToExcludeRoute)(options.exclude)
|
|
238
|
+
: [];
|
|
251
239
|
this.config.setGlobalPrefixOptions(Object.assign(Object.assign({}, options), { exclude }));
|
|
252
240
|
}
|
|
253
241
|
return this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/core",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.2",
|
|
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.
|
|
35
|
+
"tslib": "2.5.0",
|
|
36
36
|
"uuid": "9.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nestjs/common": "9.3.
|
|
39
|
+
"@nestjs/common": "9.3.2"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@nestjs/common": "^9.0.0",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isRouteExcluded = exports.isRequestMethodAll = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
6
|
const isRequestMethodAll = (method) => {
|
|
6
7
|
return common_1.RequestMethod.ALL === method || method === -1;
|
|
7
8
|
};
|
|
@@ -10,7 +11,7 @@ function isRouteExcluded(excludedRoutes, path, requestMethod) {
|
|
|
10
11
|
return excludedRoutes.some(route => {
|
|
11
12
|
if ((0, exports.isRequestMethodAll)(route.requestMethod) ||
|
|
12
13
|
route.requestMethod === requestMethod) {
|
|
13
|
-
return route.pathRegex.exec(path);
|
|
14
|
+
return route.pathRegex.exec((0, shared_utils_1.addLeadingSlash)(path));
|
|
14
15
|
}
|
|
15
16
|
return false;
|
|
16
17
|
});
|