@nestjs/platform-express 10.4.10 → 11.0.0-next.1

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';
@@ -31,7 +31,7 @@ export declare class ExpressAdapter extends AbstractHttpAdapter<http.Server | ht
31
31
  appendHeader?(response: any, name: string, value: string): any;
32
32
  listen(port: string | number, callback?: () => void): Server;
33
33
  listen(port: string | number, hostname: string, callback?: () => void): Server;
34
- close(): Promise<unknown>;
34
+ close(): Promise<unknown> | undefined;
35
35
  set(...args: any[]): any;
36
36
  enable(...args: any[]): any;
37
37
  disable(...args: any[]): any;
@@ -46,7 +46,7 @@ export declare class ExpressAdapter extends AbstractHttpAdapter<http.Server | ht
46
46
  createMiddlewareFactory(requestMethod: RequestMethod): (path: string, callback: Function) => any;
47
47
  initHttpServer(options: NestApplicationOptions): void;
48
48
  registerParserMiddleware(prefix?: string, rawBody?: boolean): void;
49
- useBodyParser<Options = NestExpressBodyParserOptions>(type: NestExpressBodyParserType, rawBody: boolean, options?: Omit<Options, 'verify'>): this;
49
+ useBodyParser<Options extends NestExpressBodyParserOptions = NestExpressBodyParserOptions>(type: NestExpressBodyParserType, rawBody: boolean, options?: Omit<Options, 'verify'>): this;
50
50
  setLocal(key: string, value: any): this;
51
51
  getType(): string;
52
52
  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");
@@ -138,9 +139,20 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
138
139
  return this.use(cors(options));
139
140
  }
140
141
  createMiddlewareFactory(requestMethod) {
141
- return this.routerMethodFactory
142
- .get(this.instance, requestMethod)
143
- .bind(this.instance);
142
+ return (path, callback) => {
143
+ try {
144
+ const convertedPath = legacy_route_converter_1.LegacyRouteConverter.tryConvert(path);
145
+ return this.routerMethodFactory
146
+ .get(this.instance, requestMethod)
147
+ .call(this.instance, convertedPath, callback);
148
+ }
149
+ catch (e) {
150
+ if (e instanceof TypeError) {
151
+ legacy_route_converter_1.LegacyRouteConverter.printError(path);
152
+ }
153
+ throw e;
154
+ }
155
+ };
144
156
  }
145
157
  initHttpServer(options) {
146
158
  const isHttpsEnabled = options && options.httpsOptions;
@@ -287,6 +299,7 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
287
299
  };
288
300
  return handlerForHeaderVersioning;
289
301
  }
302
+ throw new Error('Unsupported versioning options');
290
303
  }
291
304
  trackOpenConnections() {
292
305
  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.10",
3
+ "version": "11.0.0-next.1",
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.10",
29
- "@nestjs/core": "10.4.10"
28
+ "@nestjs/common": "^11.0.0-next.1",
29
+ "@nestjs/core": "^11.0.0-next.1"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@nestjs/common": "^10.0.0",