@nestjs/core 10.3.1 → 10.3.3

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.
@@ -25,8 +25,8 @@ export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any,
25
25
  patch(path: any, handler: RequestHandler): any;
26
26
  all(handler: RequestHandler): any;
27
27
  all(path: any, handler: RequestHandler): any;
28
- search(port: string | number, callback?: () => void): any;
29
- search(port: string | number, hostname: string, callback?: () => void): any;
28
+ search(handler: RequestHandler): any;
29
+ search(path: any, handler: RequestHandler): any;
30
30
  options(handler: RequestHandler): any;
31
31
  options(path: any, handler: RequestHandler): any;
32
32
  listen(port: string | number, callback?: () => void): any;
@@ -50,7 +50,9 @@ export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any,
50
50
  abstract setErrorHandler(handler: Function, prefix?: string): any;
51
51
  abstract setNotFoundHandler(handler: Function, prefix?: string): any;
52
52
  abstract isHeadersSent(response: any): any;
53
+ abstract getHeader?(response: any, name: string): any;
53
54
  abstract setHeader(response: any, name: string, value: string): any;
55
+ abstract appendHeader?(response: any, name: string, value: string): any;
54
56
  abstract registerParserMiddleware(prefix?: string, rawBody?: boolean): any;
55
57
  abstract enableCors(options: CorsOptions | CorsOptionsDelegate<TRequest>, prefix?: string): any;
56
58
  abstract createMiddlewareFactory(requestMethod: RequestMethod): ((path: string, callback: Function) => any) | Promise<(path: string, callback: Function) => any>;
@@ -34,8 +34,8 @@ class AbstractHttpAdapter {
34
34
  all(...args) {
35
35
  return this.instance.all(...args);
36
36
  }
37
- search(port, hostname, callback) {
38
- return this.instance.search(port, hostname, callback);
37
+ search(...args) {
38
+ return this.instance.search(...args);
39
39
  }
40
40
  options(...args) {
41
41
  return this.instance.options(...args);
@@ -2,29 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RouterMethodFactory = void 0;
4
4
  const request_method_enum_1 = require("@nestjs/common/enums/request-method.enum");
5
+ const REQUEST_METHOD_MAP = {
6
+ [request_method_enum_1.RequestMethod.GET]: 'get',
7
+ [request_method_enum_1.RequestMethod.POST]: 'post',
8
+ [request_method_enum_1.RequestMethod.PUT]: 'put',
9
+ [request_method_enum_1.RequestMethod.DELETE]: 'delete',
10
+ [request_method_enum_1.RequestMethod.PATCH]: 'patch',
11
+ [request_method_enum_1.RequestMethod.ALL]: 'all',
12
+ [request_method_enum_1.RequestMethod.OPTIONS]: 'options',
13
+ [request_method_enum_1.RequestMethod.HEAD]: 'head',
14
+ [request_method_enum_1.RequestMethod.SEARCH]: 'search',
15
+ };
5
16
  class RouterMethodFactory {
6
17
  get(target, requestMethod) {
7
- switch (requestMethod) {
8
- case request_method_enum_1.RequestMethod.POST:
9
- return target.post;
10
- case request_method_enum_1.RequestMethod.ALL:
11
- return target.all;
12
- case request_method_enum_1.RequestMethod.DELETE:
13
- return target.delete;
14
- case request_method_enum_1.RequestMethod.PUT:
15
- return target.put;
16
- case request_method_enum_1.RequestMethod.PATCH:
17
- return target.patch;
18
- case request_method_enum_1.RequestMethod.OPTIONS:
19
- return target.options;
20
- case request_method_enum_1.RequestMethod.HEAD:
21
- return target.head;
22
- case request_method_enum_1.RequestMethod.GET:
23
- return target.get;
24
- default: {
25
- return target.use;
26
- }
18
+ const methodName = REQUEST_METHOD_MAP[requestMethod];
19
+ const method = target[methodName];
20
+ if (!method) {
21
+ return target.use;
27
22
  }
23
+ return method;
28
24
  }
29
25
  }
30
26
  exports.RouterMethodFactory = RouterMethodFactory;
@@ -34,10 +34,15 @@ MiddlewareBuilder.ConfigProxy = class {
34
34
  return this.excludedRoutes;
35
35
  }
36
36
  exclude(...routes) {
37
- this.excludedRoutes = this.getRoutesFlatList(routes).map(route => ({
38
- ...route,
39
- path: this.routeInfoPathExtractor.extractPathFrom(route),
40
- }));
37
+ this.excludedRoutes = this.getRoutesFlatList(routes).reduce((excludedRoutes, route) => {
38
+ for (const routePath of this.routeInfoPathExtractor.extractPathFrom(route)) {
39
+ excludedRoutes.push({
40
+ ...route,
41
+ path: routePath,
42
+ });
43
+ }
44
+ return excludedRoutes;
45
+ }, []);
41
46
  return this;
42
47
  }
43
48
  forRoutes(...routes) {
@@ -2,14 +2,14 @@ import { RouteInfo } from '@nestjs/common/interfaces';
2
2
  import { ApplicationConfig } from '../application-config';
3
3
  export declare class RouteInfoPathExtractor {
4
4
  private readonly applicationConfig;
5
- private routePathFactory;
5
+ private readonly routePathFactory;
6
6
  private readonly prefixPath;
7
7
  private readonly excludedGlobalPrefixRoutes;
8
8
  private readonly versioningConfig?;
9
9
  constructor(applicationConfig: ApplicationConfig);
10
10
  extractPathsFrom({ path, method, version }: RouteInfo): string[];
11
- extractPathFrom(route: RouteInfo): string;
11
+ extractPathFrom(route: RouteInfo): string[];
12
12
  private isAWildcard;
13
- private extractNonWildcardPathFrom;
13
+ private extractNonWildcardPathsFrom;
14
14
  private extractVersionPathFrom;
15
15
  }
@@ -15,39 +15,51 @@ class RouteInfoPathExtractor {
15
15
  this.versioningConfig = this.applicationConfig.getVersioning();
16
16
  }
17
17
  extractPathsFrom({ path, method, version }) {
18
- const versionPath = this.extractVersionPathFrom(version);
18
+ const versionPaths = this.extractVersionPathFrom(version);
19
19
  if (this.isAWildcard(path)) {
20
+ const entries = versionPaths.length > 0
21
+ ? versionPaths.map(versionPath => this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path))
22
+ : [this.prefixPath + (0, shared_utils_1.addLeadingSlash)(path)];
20
23
  return Array.isArray(this.excludedGlobalPrefixRoutes)
21
24
  ? [
22
- this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path),
23
- ...this.excludedGlobalPrefixRoutes.map(route => versionPath + (0, shared_utils_1.addLeadingSlash)(route.path)),
25
+ ...entries,
26
+ ...this.excludedGlobalPrefixRoutes.map(route => versionPaths + (0, shared_utils_1.addLeadingSlash)(route.path)),
24
27
  ]
25
- : [this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path)];
28
+ : entries;
26
29
  }
27
- return [this.extractNonWildcardPathFrom({ path, method, version })];
30
+ return this.extractNonWildcardPathsFrom({ path, method, version });
28
31
  }
29
32
  extractPathFrom(route) {
30
33
  if (this.isAWildcard(route.path) && !route.version) {
31
- return (0, shared_utils_1.addLeadingSlash)(route.path);
34
+ return [(0, shared_utils_1.addLeadingSlash)(route.path)];
32
35
  }
33
- return this.extractNonWildcardPathFrom(route);
36
+ return this.extractNonWildcardPathsFrom(route);
34
37
  }
35
38
  isAWildcard(path) {
36
39
  return ['*', '/*', '/*/', '(.*)', '/(.*)'].includes(path);
37
40
  }
38
- extractNonWildcardPathFrom({ path, method, version, }) {
39
- const versionPath = this.extractVersionPathFrom(version);
41
+ extractNonWildcardPathsFrom({ path, method, version, }) {
42
+ const versionPaths = this.extractVersionPathFrom(version);
40
43
  if (Array.isArray(this.excludedGlobalPrefixRoutes) &&
41
44
  (0, utils_1.isRouteExcluded)(this.excludedGlobalPrefixRoutes, path, method)) {
42
- return versionPath + (0, shared_utils_1.addLeadingSlash)(path);
45
+ if (!versionPaths.length) {
46
+ return [(0, shared_utils_1.addLeadingSlash)(path)];
47
+ }
48
+ return versionPaths.map(versionPath => versionPath + (0, shared_utils_1.addLeadingSlash)(path));
43
49
  }
44
- return this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path);
50
+ if (!versionPaths.length) {
51
+ return [this.prefixPath + (0, shared_utils_1.addLeadingSlash)(path)];
52
+ }
53
+ return versionPaths.map(versionPath => this.prefixPath + versionPath + (0, shared_utils_1.addLeadingSlash)(path));
45
54
  }
46
- extractVersionPathFrom(version) {
47
- if (!version || this.versioningConfig?.type !== common_1.VersioningType.URI)
48
- return '';
55
+ extractVersionPathFrom(versionValue) {
56
+ if (!versionValue || this.versioningConfig?.type !== common_1.VersioningType.URI)
57
+ return [];
49
58
  const versionPrefix = this.routePathFactory.getVersionPrefix(this.versioningConfig);
50
- return (0, shared_utils_1.addLeadingSlash)(versionPrefix + version.toString());
59
+ if (Array.isArray(versionValue)) {
60
+ return versionValue.map(version => (0, shared_utils_1.addLeadingSlash)(versionPrefix + version.toString()));
61
+ }
62
+ return [(0, shared_utils_1.addLeadingSlash)(versionPrefix + versionValue.toString())];
51
63
  }
52
64
  }
53
65
  exports.RouteInfoPathExtractor = RouteInfoPathExtractor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/core",
3
- "version": "10.3.1",
3
+ "version": "10.3.3",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@core)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -36,14 +36,14 @@
36
36
  "uid": "2.0.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/common": "10.3.1"
39
+ "@nestjs/common": "10.3.3"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@nestjs/common": "^10.0.0",
43
43
  "@nestjs/microservices": "^10.0.0",
44
44
  "@nestjs/platform-express": "^10.0.0",
45
45
  "@nestjs/websockets": "^10.0.0",
46
- "reflect-metadata": "^0.1.12",
46
+ "reflect-metadata": "^0.1.12 || ^0.2.0",
47
47
  "rxjs": "^7.1.0"
48
48
  },
49
49
  "peerDependenciesMeta": {