@nestjs/platform-express 9.3.0-beta.2 → 9.3.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.
- package/adapters/express-adapter.d.ts +4 -1
- package/adapters/express-adapter.js +7 -0
- package/interfaces/index.d.ts +1 -0
- package/interfaces/index.js +1 -0
- package/interfaces/nest-express-application.interface.d.ts +16 -0
- package/interfaces/nest-express-body-parser-options.interface.d.ts +2 -0
- package/interfaces/nest-express-body-parser-options.interface.js +2 -0
- package/multer/interfaces/files-upload-module.interface.d.ts +1 -1
- package/multer/multer/multer.constants.d.ts +7 -0
- package/multer/multer/multer.constants.js +10 -1
- package/multer/multer/multer.utils.js +7 -0
- package/package.json +3 -3
|
@@ -5,8 +5,10 @@ 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
|
+
import { NestExpressBodyParserOptions } from '../interfaces/nest-express-body-parser-options.interface';
|
|
8
10
|
import { ServeStaticOptions } from '../interfaces/serve-static-options.interface';
|
|
9
|
-
|
|
11
|
+
type VersionedRoute = <TRequest extends Record<string, any> = any, TResponse = any>(req: TRequest, res: TResponse, next: () => void) => any;
|
|
10
12
|
export declare class ExpressAdapter extends AbstractHttpAdapter {
|
|
11
13
|
private readonly routerMethodFactory;
|
|
12
14
|
private readonly logger;
|
|
@@ -38,6 +40,7 @@ export declare class ExpressAdapter extends AbstractHttpAdapter {
|
|
|
38
40
|
createMiddlewareFactory(requestMethod: RequestMethod): (path: string, callback: Function) => any;
|
|
39
41
|
initHttpServer(options: NestApplicationOptions): void;
|
|
40
42
|
registerParserMiddleware(prefix?: string, rawBody?: boolean): void;
|
|
43
|
+
useBodyParser<Options extends bodyparser.Options = bodyparser.Options>(type: keyof bodyparser.BodyParser, rawBody: boolean, options?: NestExpressBodyParserOptions<Options>): this;
|
|
41
44
|
setLocal(key: string, value: any): this;
|
|
42
45
|
getType(): string;
|
|
43
46
|
applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): VersionedRoute;
|
|
@@ -6,6 +6,7 @@ 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
8
|
const body_parser_1 = require("body-parser");
|
|
9
|
+
const bodyparser = require("body-parser");
|
|
9
10
|
const cors = require("cors");
|
|
10
11
|
const express = require("express");
|
|
11
12
|
const http = require("http");
|
|
@@ -148,6 +149,12 @@ class ExpressAdapter extends http_adapter_1.AbstractHttpAdapter {
|
|
|
148
149
|
.filter(parser => !this.isMiddlewareApplied(parser))
|
|
149
150
|
.forEach(parserKey => this.use(parserMiddleware[parserKey]));
|
|
150
151
|
}
|
|
152
|
+
useBodyParser(type, rawBody, options) {
|
|
153
|
+
const parserOptions = (0, get_body_parser_options_util_1.getBodyParserOptions)(rawBody, options || {});
|
|
154
|
+
const parser = bodyparser[type](parserOptions);
|
|
155
|
+
this.use(parser);
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
151
158
|
setLocal(key, value) {
|
|
152
159
|
this.instance.locals[key] = value;
|
|
153
160
|
return this;
|
package/interfaces/index.d.ts
CHANGED
package/interfaces/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Server } from 'net';
|
|
3
3
|
import { INestApplication } from '@nestjs/common';
|
|
4
|
+
import * as bodyparser from 'body-parser';
|
|
5
|
+
import { NestExpressBodyParserOptions } from './nest-express-body-parser-options.interface';
|
|
4
6
|
import { ServeStaticOptions } from './serve-static-options.interface';
|
|
5
7
|
/**
|
|
6
8
|
* Interface describing methods on NestExpressApplication.
|
|
@@ -63,6 +65,20 @@ export interface NestExpressApplication extends INestApplication {
|
|
|
63
65
|
* @returns {this}
|
|
64
66
|
*/
|
|
65
67
|
useStaticAssets(path: string, options?: ServeStaticOptions): this;
|
|
68
|
+
/**
|
|
69
|
+
* Register Express body parsers on the fly. Will respect
|
|
70
|
+
* the application's `rawBody` option.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const app = await NestFactory.create<NestExpressApplication>(
|
|
74
|
+
* AppModule,
|
|
75
|
+
* { rawBody: true }
|
|
76
|
+
* );
|
|
77
|
+
* app.useBodyParser('json', { limit: '50mb' });
|
|
78
|
+
*
|
|
79
|
+
* @returns {this}
|
|
80
|
+
*/
|
|
81
|
+
useBodyParser<Options extends bodyparser.Options = bodyparser.Options>(parser: keyof bodyparser.BodyParser, options?: NestExpressBodyParserOptions<Options>): this;
|
|
66
82
|
/**
|
|
67
83
|
* Sets one or multiple base directories for templates (views).
|
|
68
84
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
|
|
2
2
|
import { MulterOptions } from './multer-options.interface';
|
|
3
|
-
export
|
|
3
|
+
export type MulterModuleOptions = MulterOptions;
|
|
4
4
|
export interface MulterOptionsFactory {
|
|
5
5
|
createMulterOptions(): Promise<MulterModuleOptions> | MulterModuleOptions;
|
|
6
6
|
}
|
|
@@ -6,4 +6,11 @@ export declare const multerExceptions: {
|
|
|
6
6
|
LIMIT_FIELD_VALUE: string;
|
|
7
7
|
LIMIT_FIELD_COUNT: string;
|
|
8
8
|
LIMIT_UNEXPECTED_FILE: string;
|
|
9
|
+
MISSING_FIELD_NAME: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const busboyExceptions: {
|
|
12
|
+
MULTIPART_BOUNDARY_NOT_FOUND: string;
|
|
13
|
+
MULTIPART_MALFORMED_PART_HEADER: string;
|
|
14
|
+
MULTIPART_UNEXPECTED_END_OF_FORM: string;
|
|
15
|
+
MULTIPART_UNEXPECTED_END_OF_FILE: string;
|
|
9
16
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.multerExceptions = void 0;
|
|
3
|
+
exports.busboyExceptions = exports.multerExceptions = void 0;
|
|
4
4
|
exports.multerExceptions = {
|
|
5
|
+
// from https://github.com/expressjs/multer/blob/master/lib/multer-error.js
|
|
5
6
|
LIMIT_PART_COUNT: 'Too many parts',
|
|
6
7
|
LIMIT_FILE_SIZE: 'File too large',
|
|
7
8
|
LIMIT_FILE_COUNT: 'Too many files',
|
|
@@ -9,4 +10,12 @@ exports.multerExceptions = {
|
|
|
9
10
|
LIMIT_FIELD_VALUE: 'Field value too long',
|
|
10
11
|
LIMIT_FIELD_COUNT: 'Too many fields',
|
|
11
12
|
LIMIT_UNEXPECTED_FILE: 'Unexpected field',
|
|
13
|
+
MISSING_FIELD_NAME: 'Field name missing',
|
|
14
|
+
};
|
|
15
|
+
exports.busboyExceptions = {
|
|
16
|
+
// from https://github.com/mscdex/busboy/blob/master/lib/types/multipart.js
|
|
17
|
+
MULTIPART_BOUNDARY_NOT_FOUND: 'Multipart: Boundary not found',
|
|
18
|
+
MULTIPART_MALFORMED_PART_HEADER: 'Malformed part header',
|
|
19
|
+
MULTIPART_UNEXPECTED_END_OF_FORM: 'Unexpected end of form',
|
|
20
|
+
MULTIPART_UNEXPECTED_END_OF_FILE: 'Unexpected end of file',
|
|
12
21
|
};
|
|
@@ -16,7 +16,14 @@ function transformException(error) {
|
|
|
16
16
|
case multer_constants_1.multerExceptions.LIMIT_FIELD_COUNT:
|
|
17
17
|
case multer_constants_1.multerExceptions.LIMIT_UNEXPECTED_FILE:
|
|
18
18
|
case multer_constants_1.multerExceptions.LIMIT_PART_COUNT:
|
|
19
|
+
case multer_constants_1.multerExceptions.MISSING_FIELD_NAME:
|
|
19
20
|
return new common_1.BadRequestException(error.message);
|
|
21
|
+
case multer_constants_1.busboyExceptions.MULTIPART_BOUNDARY_NOT_FOUND:
|
|
22
|
+
return new common_1.BadRequestException(error.message);
|
|
23
|
+
case multer_constants_1.busboyExceptions.MULTIPART_MALFORMED_PART_HEADER:
|
|
24
|
+
case multer_constants_1.busboyExceptions.MULTIPART_UNEXPECTED_END_OF_FORM:
|
|
25
|
+
case multer_constants_1.busboyExceptions.MULTIPART_UNEXPECTED_END_OF_FILE:
|
|
26
|
+
return new common_1.BadRequestException(`Multipart: ${error.message}`);
|
|
20
27
|
}
|
|
21
28
|
return error;
|
|
22
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/platform-express",
|
|
3
|
-
"version": "9.3.0
|
|
3
|
+
"version": "9.3.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.4.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@nestjs/common": "
|
|
28
|
-
"@nestjs/core": "
|
|
27
|
+
"@nestjs/common": "9.3.0",
|
|
28
|
+
"@nestjs/core": "9.3.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@nestjs/common": "^9.0.0",
|