@nestjs/platform-express 9.3.11 → 9.4.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.
@@ -5,8 +5,8 @@ import { VersionValue } from '@nestjs/common/interfaces';
5
5
  import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
6
6
  import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';
7
7
  import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
8
- import * as bodyparser from 'body-parser';
9
8
  import { NestExpressBodyParserOptions } from '../interfaces/nest-express-body-parser-options.interface';
9
+ import { NestExpressBodyParserType } from '../interfaces/nest-express-body-parser.interface';
10
10
  import { ServeStaticOptions } from '../interfaces/serve-static-options.interface';
11
11
  type VersionedRoute = <TRequest extends Record<string, any> = any, TResponse = any>(req: TRequest, res: TResponse, next: () => void) => any;
12
12
  /**
@@ -43,7 +43,7 @@ export declare class ExpressAdapter extends AbstractHttpAdapter {
43
43
  createMiddlewareFactory(requestMethod: RequestMethod): (path: string, callback: Function) => any;
44
44
  initHttpServer(options: NestApplicationOptions): void;
45
45
  registerParserMiddleware(prefix?: string, rawBody?: boolean): void;
46
- useBodyParser<Options extends bodyparser.Options = bodyparser.Options>(type: keyof bodyparser.BodyParser, rawBody: boolean, options?: NestExpressBodyParserOptions<Options>): this;
46
+ useBodyParser<Options = NestExpressBodyParserOptions>(type: NestExpressBodyParserType, rawBody: boolean, options?: Omit<Options, 'verify'>): this;
47
47
  setLocal(key: string, value: any): this;
48
48
  getType(): string;
49
49
  applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): VersionedRoute;
@@ -149,7 +149,9 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
149
149
  }
150
150
  registerParserMiddleware(prefix, rawBody) {
151
151
  const bodyParserJsonOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody);
152
- const bodyParserUrlencodedOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody, { extended: true });
152
+ const bodyParserUrlencodedOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody, {
153
+ extended: true,
154
+ });
153
155
  const parserMiddleware = {
154
156
  jsonParser: (0, body_parser_1.json)(bodyParserJsonOptions),
155
157
  urlencodedParser: (0, body_parser_1.urlencoded)(bodyParserUrlencodedOptions),
@@ -159,7 +161,7 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
159
161
  .forEach(parserKey => this.use(parserMiddleware[parserKey]));
160
162
  }
161
163
  useBodyParser(type, rawBody, options) {
162
- const parserOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody, options || {});
164
+ const parserOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody, options);
163
165
  const parser = bodyparser[type](parserOptions);
164
166
  this.use(parser);
165
167
  return this;
@@ -1,2 +1,2 @@
1
- import type { Options } from 'body-parser';
2
- export declare function getBodyParserOptions<ParserOptions extends Options>(rawBody: boolean, options?: ParserOptions | undefined): ParserOptions;
1
+ import type { NestExpressBodyParserOptions } from '../../interfaces';
2
+ export declare function getBodyParserOptions<Options = NestExpressBodyParserOptions>(rawBody: boolean, options?: Omit<Options, 'verify'> | undefined): Options;
@@ -8,7 +8,7 @@ const rawBodyParser = (req, _res, buffer) => {
8
8
  return true;
9
9
  };
10
10
  function getBodyParserOptions(rawBody, options) {
11
- let parserOptions = options !== null && options !== void 0 ? options : {};
11
+ let parserOptions = (options || {});
12
12
  if (rawBody === true) {
13
13
  parserOptions = Object.assign(Object.assign({}, parserOptions), { verify: rawBodyParser });
14
14
  }
@@ -1,2 +1,3 @@
1
1
  export * from './nest-express-application.interface';
2
- export * from './nest-express-body-parser-options.interface';
2
+ export { NestExpressBodyParserOptions } from './nest-express-body-parser-options.interface';
3
+ export * from './nest-express-body-parser.interface';
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./nest-express-application.interface"), exports);
5
- tslib_1.__exportStar(require("./nest-express-body-parser-options.interface"), exports);
5
+ tslib_1.__exportStar(require("./nest-express-body-parser.interface"), exports);
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import { Server } from 'http';
3
3
  import { INestApplication } from '@nestjs/common';
4
- import * as bodyparser from 'body-parser';
5
4
  import { NestExpressBodyParserOptions } from './nest-express-body-parser-options.interface';
6
5
  import { ServeStaticOptions } from './serve-static-options.interface';
6
+ import { NestExpressBodyParserType } from './nest-express-body-parser.interface';
7
7
  /**
8
8
  * Interface describing methods on NestExpressApplication.
9
9
  *
@@ -78,7 +78,7 @@ export interface NestExpressApplication extends INestApplication {
78
78
  *
79
79
  * @returns {this}
80
80
  */
81
- useBodyParser<Options extends bodyparser.Options = bodyparser.Options>(parser: keyof bodyparser.BodyParser, options?: NestExpressBodyParserOptions<Options>): this;
81
+ useBodyParser<Options = NestExpressBodyParserOptions>(parser: NestExpressBodyParserType, options?: Omit<Options, 'verify'>): this;
82
82
  /**
83
83
  * Sets one or multiple base directories for templates (views).
84
84
  *
@@ -1,2 +1,22 @@
1
- import type { Options } from 'body-parser';
2
- export type NestExpressBodyParserOptions<T extends Options = Options> = Omit<T, 'verify'>;
1
+ /// <reference types="node" />
2
+ import type { IncomingMessage } from 'http';
3
+ /**
4
+ * Type alias to keep compatibility with @types/body-parser
5
+ * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/dcd1673c4fa18a15ea8cd8ff8af7d563bb6dc8e6/types/body-parser/index.d.ts#L48-L66#L48-L66
6
+ * @publicApi
7
+ */
8
+ export interface NestExpressBodyParserOptions {
9
+ /** When set to true, then deflated (compressed) bodies will be inflated; when false, deflated bodies are rejected. Defaults to true. */
10
+ inflate?: boolean | undefined;
11
+ /**
12
+ * Controls the maximum request body size. If this is a number,
13
+ * then the value specifies the number of bytes; if it is a string,
14
+ * the value is passed to the bytes library for parsing. Defaults to '100kb'.
15
+ */
16
+ limit?: number | string | undefined;
17
+ /**
18
+ * The type option is used to determine what media type the middleware will parse
19
+ */
20
+ type?: string | string[] | ((req: IncomingMessage) => any) | undefined;
21
+ [key: string]: unknown;
22
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Interface defining possible body parser types, to be used with `NestExpressApplication.useBodyParser()`.
3
+ */
4
+ export type NestExpressBodyParserType = 'json' | 'urlencoded' | 'text' | 'raw';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-express",
3
- "version": "9.3.11",
3
+ "version": "9.4.0",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -24,8 +24,8 @@
24
24
  "tslib": "2.5.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@nestjs/common": "9.3.11",
28
- "@nestjs/core": "9.3.11"
27
+ "@nestjs/common": "9.4.0",
28
+ "@nestjs/core": "9.4.0"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@nestjs/common": "^9.0.0",