@nestjs/platform-express 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.
@@ -1,9 +1,9 @@
1
- import type { Server } from 'http';
2
1
  import { RequestMethod, VersioningOptions } from '@nestjs/common';
3
2
  import { VersionValue } from '@nestjs/common/interfaces';
4
3
  import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
5
4
  import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
6
5
  import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
6
+ import type { Server } from 'http';
7
7
  import * as http from 'http';
8
8
  import * as https from 'https';
9
9
  import { NestExpressBodyParserOptions } from '../interfaces/nest-express-body-parser-options.interface';
@@ -26,12 +26,13 @@ export declare class ExpressAdapter extends AbstractHttpAdapter<http.Server | ht
26
26
  setErrorHandler(handler: Function, prefix?: string): any;
27
27
  setNotFoundHandler(handler: Function, prefix?: string): any;
28
28
  isHeadersSent(response: any): boolean;
29
- getHeader?(response: any, name: string): any;
29
+ getHeader(response: any, name: string): any;
30
30
  setHeader(response: any, name: string, value: string): any;
31
- appendHeader?(response: any, name: string, value: string): any;
31
+ appendHeader(response: any, name: string, value: string): any;
32
+ normalizePath(path: string): string;
32
33
  listen(port: string | number, callback?: () => void): Server;
33
34
  listen(port: string | number, hostname: string, callback?: () => void): Server;
34
- close(): Promise<unknown>;
35
+ close(): Promise<unknown> | undefined;
35
36
  set(...args: any[]): any;
36
37
  enable(...args: any[]): any;
37
38
  disable(...args: any[]): any;
@@ -46,7 +47,7 @@ export declare class ExpressAdapter extends AbstractHttpAdapter<http.Server | ht
46
47
  createMiddlewareFactory(requestMethod: RequestMethod): (path: string, callback: Function) => any;
47
48
  initHttpServer(options: NestApplicationOptions): void;
48
49
  registerParserMiddleware(prefix?: string, rawBody?: boolean): void;
49
- useBodyParser<Options = NestExpressBodyParserOptions>(type: NestExpressBodyParserType, rawBody: boolean, options?: Omit<Options, 'verify'>): this;
50
+ useBodyParser<Options extends NestExpressBodyParserOptions = NestExpressBodyParserOptions>(type: NestExpressBodyParserType, rawBody: boolean, options?: Omit<Options, 'verify'>): this;
50
51
  setLocal(key: string, value: any): this;
51
52
  getType(): string;
52
53
  applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): VersionedRoute;
@@ -5,8 +5,9 @@ const common_1 = require("@nestjs/common");
5
5
  const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
6
  const http_adapter_1 = require("@nestjs/core/adapters/http-adapter");
7
7
  const router_method_factory_1 = require("@nestjs/core/helpers/router-method-factory");
8
- const body_parser_1 = require("body-parser");
8
+ const legacy_route_converter_1 = require("@nestjs/core/router/legacy-route-converter");
9
9
  const bodyparser = require("body-parser");
10
+ const body_parser_1 = require("body-parser");
10
11
  const cors = require("cors");
11
12
  const express = require("express");
12
13
  const http = require("http");
@@ -91,6 +92,18 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
91
92
  appendHeader(response, name, value) {
92
93
  return response.append(name, value);
93
94
  }
95
+ normalizePath(path) {
96
+ try {
97
+ const convertedPath = legacy_route_converter_1.LegacyRouteConverter.tryConvert(path);
98
+ return convertedPath;
99
+ }
100
+ catch (e) {
101
+ if (e instanceof TypeError) {
102
+ legacy_route_converter_1.LegacyRouteConverter.printError(path);
103
+ }
104
+ throw e;
105
+ }
106
+ }
94
107
  listen(port, ...args) {
95
108
  return this.httpServer.listen(port, ...args);
96
109
  }
@@ -138,9 +151,20 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
138
151
  return this.use(cors(options));
139
152
  }
140
153
  createMiddlewareFactory(requestMethod) {
141
- return this.routerMethodFactory
142
- .get(this.instance, requestMethod)
143
- .bind(this.instance);
154
+ return (path, callback) => {
155
+ try {
156
+ const convertedPath = legacy_route_converter_1.LegacyRouteConverter.tryConvert(path);
157
+ return this.routerMethodFactory
158
+ .get(this.instance, requestMethod)
159
+ .call(this.instance, convertedPath, callback);
160
+ }
161
+ catch (e) {
162
+ if (e instanceof TypeError) {
163
+ legacy_route_converter_1.LegacyRouteConverter.printError(path);
164
+ }
165
+ throw e;
166
+ }
167
+ };
144
168
  }
145
169
  initHttpServer(options) {
146
170
  const isHttpsEnabled = options && options.httpsOptions;
@@ -287,6 +311,7 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
287
311
  };
288
312
  return handlerForHeaderVersioning;
289
313
  }
314
+ throw new Error('Unsupported versioning options');
290
315
  }
291
316
  trackOpenConnections() {
292
317
  this.httpServer.on('connection', (socket) => {
@@ -1,2 +1,2 @@
1
1
  import type { NestExpressBodyParserOptions } from '../../interfaces';
2
- export declare function getBodyParserOptions<Options = NestExpressBodyParserOptions>(rawBody: boolean, options?: Omit<Options, 'verify'> | undefined): Options;
2
+ export declare function getBodyParserOptions<Options = NestExpressBodyParserOptions>(rawBody: boolean, options?: Omit<Options, 'verify'>): Options;
@@ -1 +1,6 @@
1
- export declare function transformException(error: Error | undefined): Error;
1
+ import { HttpException } from '@nestjs/common';
2
+ export declare function transformException(error: (Error & {
3
+ field?: string;
4
+ }) | undefined): HttpException | (Error & {
5
+ field?: string;
6
+ }) | undefined;
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformException = transformException;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const multer_constants_1 = require("./multer.constants");
6
+ // Multer may add in a 'field' property to the error
7
+ // https://github.com/expressjs/multer/blob/aa42bea6ac7d0cb8fcb279b15a7278cda805dc63/lib/multer-error.js#L19
6
8
  function transformException(error) {
7
9
  if (!error || error instanceof common_1.HttpException) {
8
10
  return error;
@@ -17,6 +19,9 @@ function transformException(error) {
17
19
  case multer_constants_1.multerExceptions.LIMIT_UNEXPECTED_FILE:
18
20
  case multer_constants_1.multerExceptions.LIMIT_PART_COUNT:
19
21
  case multer_constants_1.multerExceptions.MISSING_FIELD_NAME:
22
+ if (error.field) {
23
+ return new common_1.BadRequestException(`${error.message} - ${error.field}`);
24
+ }
20
25
  return new common_1.BadRequestException(error.message);
21
26
  case multer_constants_1.busboyExceptions.MULTIPART_BOUNDARY_NOT_FOUND:
22
27
  return new common_1.BadRequestException(error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-express",
3
- "version": "10.4.11",
3
+ "version": "11.0.0-next.2",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -20,13 +20,13 @@
20
20
  "dependencies": {
21
21
  "body-parser": "1.20.3",
22
22
  "cors": "2.8.5",
23
- "express": "4.21.1",
23
+ "express": "5.0.1",
24
24
  "multer": "1.4.4-lts.1",
25
25
  "tslib": "2.7.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@nestjs/common": "10.4.11",
29
- "@nestjs/core": "10.4.11"
28
+ "@nestjs/common": "^11.0.0-next.2",
29
+ "@nestjs/core": "^11.0.0-next.2"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@nestjs/common": "^10.0.0",