@nestjs/common 9.1.5 → 9.2.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/Readme.md +3 -1
- package/cache/cache.providers.js +14 -8
- package/cache/interfaces/cache-manager.interface.d.ts +4 -3
- package/exceptions/bad-gateway.exception.d.ts +4 -4
- package/exceptions/bad-gateway.exception.js +5 -4
- package/exceptions/bad-request.exception.d.ts +4 -4
- package/exceptions/bad-request.exception.js +5 -4
- package/exceptions/conflict.exception.d.ts +4 -4
- package/exceptions/conflict.exception.js +5 -4
- package/exceptions/forbidden.exception.d.ts +4 -4
- package/exceptions/forbidden.exception.js +5 -4
- package/exceptions/gateway-timeout.exception.d.ts +4 -4
- package/exceptions/gateway-timeout.exception.js +5 -4
- package/exceptions/gone.exception.d.ts +4 -4
- package/exceptions/gone.exception.js +5 -4
- package/exceptions/http-version-not-supported.exception.d.ts +4 -4
- package/exceptions/http-version-not-supported.exception.js +5 -4
- package/exceptions/http.exception.d.ts +33 -5
- package/exceptions/http.exception.js +54 -9
- package/exceptions/im-a-teapot.exception.d.ts +4 -4
- package/exceptions/im-a-teapot.exception.js +5 -4
- package/exceptions/internal-server-error.exception.d.ts +4 -4
- package/exceptions/internal-server-error.exception.js +5 -4
- package/exceptions/method-not-allowed.exception.d.ts +4 -4
- package/exceptions/method-not-allowed.exception.js +5 -4
- package/exceptions/misdirected.exception.d.ts +4 -4
- package/exceptions/misdirected.exception.js +5 -4
- package/exceptions/not-acceptable.exception.d.ts +4 -4
- package/exceptions/not-acceptable.exception.js +5 -4
- package/exceptions/not-found.exception.d.ts +4 -4
- package/exceptions/not-found.exception.js +5 -4
- package/exceptions/not-implemented.exception.d.ts +4 -4
- package/exceptions/not-implemented.exception.js +5 -4
- package/exceptions/payload-too-large.exception.d.ts +4 -4
- package/exceptions/payload-too-large.exception.js +5 -4
- package/exceptions/precondition-failed.exception.d.ts +4 -4
- package/exceptions/precondition-failed.exception.js +5 -4
- package/exceptions/request-timeout.exception.d.ts +4 -4
- package/exceptions/request-timeout.exception.js +5 -4
- package/exceptions/service-unavailable.exception.d.ts +4 -4
- package/exceptions/service-unavailable.exception.js +5 -4
- package/exceptions/unauthorized.exception.d.ts +4 -4
- package/exceptions/unauthorized.exception.js +5 -4
- package/exceptions/unprocessable-entity.exception.d.ts +4 -4
- package/exceptions/unprocessable-entity.exception.js +5 -4
- package/exceptions/unsupported-media-type.exception.d.ts +4 -4
- package/exceptions/unsupported-media-type.exception.js +5 -4
- package/interfaces/middleware/middleware-configuration.interface.d.ts +2 -0
- package/interfaces/nest-application-context.interface.d.ts +66 -4
- package/interfaces/nest-application-options.interface.d.ts +5 -0
- package/package.json +2 -2
- package/pipes/file/parse-file-pipe.builder.d.ts +2 -0
- package/pipes/file/parse-file-pipe.builder.js +5 -3
- package/services/console-logger.service.d.ts +2 -0
- package/services/console-logger.service.js +12 -7
|
@@ -20,7 +20,7 @@ class UnprocessableEntityException extends http_exception_1.HttpException {
|
|
|
20
20
|
* @usageNotes
|
|
21
21
|
* The HTTP response status code will be 422.
|
|
22
22
|
* - The `objectOrError` argument defines the JSON response body or the message string.
|
|
23
|
-
* - The `
|
|
23
|
+
* - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
|
|
24
24
|
*
|
|
25
25
|
* By default, the JSON response body contains two properties:
|
|
26
26
|
* - `statusCode`: this will be the value 422.
|
|
@@ -33,10 +33,11 @@ class UnprocessableEntityException extends http_exception_1.HttpException {
|
|
|
33
33
|
* and return it as the JSON response body.
|
|
34
34
|
*
|
|
35
35
|
* @param objectOrError string or object describing the error condition.
|
|
36
|
-
* @param
|
|
36
|
+
* @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
|
|
37
37
|
*/
|
|
38
|
-
constructor(objectOrError,
|
|
39
|
-
|
|
38
|
+
constructor(objectOrError, descriptionOrOptions = 'Unprocessable Entity') {
|
|
39
|
+
const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
|
|
40
|
+
super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.UNPROCESSABLE_ENTITY), http_status_enum_1.HttpStatus.UNPROCESSABLE_ENTITY, httpExceptionOptions);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
exports.UnprocessableEntityException = UnprocessableEntityException;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HttpException } from './http.exception';
|
|
1
|
+
import { HttpException, HttpExceptionOptions } from './http.exception';
|
|
2
2
|
/**
|
|
3
3
|
* Defines an HTTP exception for *Unsupported Media Type* type errors.
|
|
4
4
|
*
|
|
@@ -16,7 +16,7 @@ export declare class UnsupportedMediaTypeException extends HttpException {
|
|
|
16
16
|
* @usageNotes
|
|
17
17
|
* The HTTP response status code will be 415.
|
|
18
18
|
* - The `objectOrError` argument defines the JSON response body or the message string.
|
|
19
|
-
* - The `
|
|
19
|
+
* - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
|
|
20
20
|
*
|
|
21
21
|
* By default, the JSON response body contains two properties:
|
|
22
22
|
* - `statusCode`: this will be the value 415.
|
|
@@ -29,7 +29,7 @@ export declare class UnsupportedMediaTypeException extends HttpException {
|
|
|
29
29
|
* and return it as the JSON response body.
|
|
30
30
|
*
|
|
31
31
|
* @param objectOrError string or object describing the error condition.
|
|
32
|
-
* @param
|
|
32
|
+
* @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
|
|
33
33
|
*/
|
|
34
|
-
constructor(objectOrError?: string | object | any,
|
|
34
|
+
constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
|
|
35
35
|
}
|
|
@@ -20,7 +20,7 @@ class UnsupportedMediaTypeException extends http_exception_1.HttpException {
|
|
|
20
20
|
* @usageNotes
|
|
21
21
|
* The HTTP response status code will be 415.
|
|
22
22
|
* - The `objectOrError` argument defines the JSON response body or the message string.
|
|
23
|
-
* - The `
|
|
23
|
+
* - The `descriptionOrOptions` argument contains either a short description of the HTTP error or an options object used to provide an underlying error cause.
|
|
24
24
|
*
|
|
25
25
|
* By default, the JSON response body contains two properties:
|
|
26
26
|
* - `statusCode`: this will be the value 415.
|
|
@@ -33,10 +33,11 @@ class UnsupportedMediaTypeException extends http_exception_1.HttpException {
|
|
|
33
33
|
* and return it as the JSON response body.
|
|
34
34
|
*
|
|
35
35
|
* @param objectOrError string or object describing the error condition.
|
|
36
|
-
* @param
|
|
36
|
+
* @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
|
|
37
37
|
*/
|
|
38
|
-
constructor(objectOrError,
|
|
39
|
-
|
|
38
|
+
constructor(objectOrError, descriptionOrOptions = 'Unsupported Media Type') {
|
|
39
|
+
const { description, httpExceptionOptions } = http_exception_1.HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);
|
|
40
|
+
super(http_exception_1.HttpException.createBody(objectOrError, description, http_status_enum_1.HttpStatus.UNSUPPORTED_MEDIA_TYPE), http_status_enum_1.HttpStatus.UNSUPPORTED_MEDIA_TYPE, httpExceptionOptions);
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { RequestMethod } from '../../enums';
|
|
2
2
|
import { Type } from '../type.interface';
|
|
3
|
+
import { VersionValue } from '../version-options.interface';
|
|
3
4
|
export interface RouteInfo {
|
|
4
5
|
path: string;
|
|
5
6
|
method: RequestMethod;
|
|
7
|
+
version?: VersionValue;
|
|
6
8
|
}
|
|
7
9
|
export interface MiddlewareConfiguration<T = any> {
|
|
8
10
|
middleware: T;
|
|
@@ -2,6 +2,19 @@ import { ShutdownSignal } from '../enums/shutdown-signal.enum';
|
|
|
2
2
|
import { LoggerService, LogLevel } from '../services/logger.service';
|
|
3
3
|
import { DynamicModule } from './modules';
|
|
4
4
|
import { Type } from './type.interface';
|
|
5
|
+
export interface GetOrResolveOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If enabled, lookup will only be performed in the host module.
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
strict?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* If enabled, instead of returning a first instance registered under a given token,
|
|
13
|
+
* a list of instances will be returned.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
each?: boolean;
|
|
17
|
+
}
|
|
5
18
|
/**
|
|
6
19
|
* Interface defining NestApplicationContext.
|
|
7
20
|
*
|
|
@@ -17,18 +30,67 @@ export interface INestApplicationContext {
|
|
|
17
30
|
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
|
18
31
|
* @returns {TResult}
|
|
19
32
|
*/
|
|
20
|
-
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol
|
|
21
|
-
|
|
33
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): TResult;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves an instance of either injectable or controller, otherwise, throws exception.
|
|
36
|
+
* @returns {TResult}
|
|
37
|
+
*/
|
|
38
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
39
|
+
strict?: boolean;
|
|
40
|
+
each?: undefined | false;
|
|
22
41
|
}): TResult;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
|
|
44
|
+
* @returns {Array<TResult>}
|
|
45
|
+
*/
|
|
46
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options: {
|
|
47
|
+
strict?: boolean;
|
|
48
|
+
each: true;
|
|
49
|
+
}): Array<TResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
52
|
+
* @returns {TResult | Array<TResult>}
|
|
53
|
+
*/
|
|
54
|
+
get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, options?: GetOrResolveOptions): TResult | Array<TResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
57
|
+
* @returns {Array<TResult>}
|
|
58
|
+
*/
|
|
59
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): Promise<TResult>;
|
|
23
60
|
/**
|
|
24
61
|
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
25
|
-
* @returns {
|
|
62
|
+
* @returns {Array<TResult>}
|
|
63
|
+
*/
|
|
64
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
65
|
+
id: number;
|
|
66
|
+
}): Promise<TResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
|
|
69
|
+
* @returns {Array<TResult>}
|
|
26
70
|
*/
|
|
27
71
|
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
28
72
|
id: number;
|
|
29
73
|
}, options?: {
|
|
30
|
-
strict
|
|
74
|
+
strict?: boolean;
|
|
75
|
+
each?: undefined | false;
|
|
31
76
|
}): Promise<TResult>;
|
|
77
|
+
/**
|
|
78
|
+
* Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
|
|
79
|
+
* @returns {Array<TResult>}
|
|
80
|
+
*/
|
|
81
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
82
|
+
id: number;
|
|
83
|
+
}, options?: {
|
|
84
|
+
strict?: boolean;
|
|
85
|
+
each: true;
|
|
86
|
+
}): Promise<Array<TResult>>;
|
|
87
|
+
/**
|
|
88
|
+
* Resolves transient or request-scoped instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
|
|
89
|
+
* @returns {Promise<TResult | Array<TResult>>}
|
|
90
|
+
*/
|
|
91
|
+
resolve<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol, contextId?: {
|
|
92
|
+
id: number;
|
|
93
|
+
}, options?: GetOrResolveOptions): Promise<TResult | Array<TResult>>;
|
|
32
94
|
/**
|
|
33
95
|
* Registers the request/context object for a given context ID (DI container sub-tree).
|
|
34
96
|
* @returns {void}
|
|
@@ -21,4 +21,9 @@ export interface NestApplicationOptions extends NestApplicationContextOptions {
|
|
|
21
21
|
* Whether to register the raw request body on the request. Use `req.rawBody`.
|
|
22
22
|
*/
|
|
23
23
|
rawBody?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Force close open HTTP connections. Useful if restarting your application hangs due to
|
|
26
|
+
* keep-alive connections in the HTTP adapter.
|
|
27
|
+
*/
|
|
28
|
+
forceCloseConnections?: boolean;
|
|
24
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/common",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"homepage": "https://nestjs.com",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"iterare": "1.2.1",
|
|
21
|
-
"tslib": "2.4.
|
|
21
|
+
"tslib": "2.4.1",
|
|
22
22
|
"uuid": "9.0.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FileTypeValidatorOptions } from './file-type.validator';
|
|
2
|
+
import { FileValidator } from './file-validator.interface';
|
|
2
3
|
import { MaxFileSizeValidatorOptions } from './max-file-size.validator';
|
|
3
4
|
import { ParseFileOptions } from './parse-file-options.interface';
|
|
4
5
|
import { ParseFilePipe } from './parse-file.pipe';
|
|
@@ -6,5 +7,6 @@ export declare class ParseFilePipeBuilder {
|
|
|
6
7
|
private validators;
|
|
7
8
|
addMaxSizeValidator(options: MaxFileSizeValidatorOptions): this;
|
|
8
9
|
addFileTypeValidator(options: FileTypeValidatorOptions): this;
|
|
10
|
+
addValidator(validator: FileValidator): this;
|
|
9
11
|
build(additionalOptions?: Omit<ParseFileOptions, 'validators'>): ParseFilePipe;
|
|
10
12
|
}
|
|
@@ -9,11 +9,13 @@ class ParseFilePipeBuilder {
|
|
|
9
9
|
this.validators = [];
|
|
10
10
|
}
|
|
11
11
|
addMaxSizeValidator(options) {
|
|
12
|
-
this.
|
|
13
|
-
return this;
|
|
12
|
+
return this.addValidator(new max_file_size_validator_1.MaxFileSizeValidator(options));
|
|
14
13
|
}
|
|
15
14
|
addFileTypeValidator(options) {
|
|
16
|
-
this.
|
|
15
|
+
return this.addValidator(new file_type_validator_1.FileTypeValidator(options));
|
|
16
|
+
}
|
|
17
|
+
addValidator(validator) {
|
|
18
|
+
this.validators.push(validator);
|
|
17
19
|
return this;
|
|
18
20
|
}
|
|
19
21
|
build(additionalOptions) {
|
|
@@ -65,11 +65,13 @@ export declare class ConsoleLogger implements LoggerService {
|
|
|
65
65
|
protected getTimestamp(): string;
|
|
66
66
|
protected printMessages(messages: unknown[], context?: string, logLevel?: LogLevel, writeStreamType?: 'stdout' | 'stderr'): void;
|
|
67
67
|
protected formatPid(pid: number): string;
|
|
68
|
+
protected formatContext(context: string): string;
|
|
68
69
|
protected formatMessage(logLevel: LogLevel, message: unknown, pidMessage: string, formattedLogLevel: string, contextMessage: string, timestampDiff: string): string;
|
|
69
70
|
protected stringifyMessage(message: unknown, logLevel: LogLevel): string;
|
|
70
71
|
protected colorize(message: string, logLevel: LogLevel): string;
|
|
71
72
|
protected printStackTrace(stack: string): void;
|
|
72
73
|
private updateAndGetTimestampDiff;
|
|
74
|
+
protected formatTimestampDiff(timestampDiff: number): string;
|
|
73
75
|
private getContextAndMessagesToPrint;
|
|
74
76
|
private getContextAndStackAndMessagesToPrint;
|
|
75
77
|
private getColorByLogLevel;
|
|
@@ -3,8 +3,7 @@ var ConsoleLogger_1;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ConsoleLogger = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
const
|
|
7
|
-
const optional_decorator_1 = require("../decorators/core/optional.decorator");
|
|
6
|
+
const core_1 = require("../decorators/core");
|
|
8
7
|
const cli_colors_util_1 = require("../utils/cli-colors.util");
|
|
9
8
|
const shared_utils_1 = require("../utils/shared.utils");
|
|
10
9
|
const utils_1 = require("./utils");
|
|
@@ -116,7 +115,7 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
|
|
|
116
115
|
printMessages(messages, context = '', logLevel = 'log', writeStreamType) {
|
|
117
116
|
messages.forEach(message => {
|
|
118
117
|
const pidMessage = this.formatPid(process.pid);
|
|
119
|
-
const contextMessage =
|
|
118
|
+
const contextMessage = this.formatContext(context);
|
|
120
119
|
const timestampDiff = this.updateAndGetTimestampDiff();
|
|
121
120
|
const formattedLogLevel = logLevel.toUpperCase().padStart(7, ' ');
|
|
122
121
|
const formattedMessage = this.formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff);
|
|
@@ -126,6 +125,9 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
|
|
|
126
125
|
formatPid(pid) {
|
|
127
126
|
return `[Nest] ${pid} - `;
|
|
128
127
|
}
|
|
128
|
+
formatContext(context) {
|
|
129
|
+
return context ? (0, cli_colors_util_1.yellow)(`[${context}] `) : '';
|
|
130
|
+
}
|
|
129
131
|
formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff) {
|
|
130
132
|
const output = this.stringifyMessage(message, logLevel);
|
|
131
133
|
pidMessage = this.colorize(pidMessage, logLevel);
|
|
@@ -151,11 +153,14 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
|
|
|
151
153
|
var _a;
|
|
152
154
|
const includeTimestamp = ConsoleLogger_1.lastTimestampAt && ((_a = this.options) === null || _a === void 0 ? void 0 : _a.timestamp);
|
|
153
155
|
const result = includeTimestamp
|
|
154
|
-
?
|
|
156
|
+
? this.formatTimestampDiff(Date.now() - ConsoleLogger_1.lastTimestampAt)
|
|
155
157
|
: '';
|
|
156
158
|
ConsoleLogger_1.lastTimestampAt = Date.now();
|
|
157
159
|
return result;
|
|
158
160
|
}
|
|
161
|
+
formatTimestampDiff(timestampDiff) {
|
|
162
|
+
return (0, cli_colors_util_1.yellow)(` +${timestampDiff}ms`);
|
|
163
|
+
}
|
|
159
164
|
getContextAndMessagesToPrint(args) {
|
|
160
165
|
if ((args === null || args === void 0 ? void 0 : args.length) <= 1) {
|
|
161
166
|
return { messages: args, context: this.context };
|
|
@@ -202,9 +207,9 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
|
|
|
202
207
|
}
|
|
203
208
|
};
|
|
204
209
|
ConsoleLogger = ConsoleLogger_1 = tslib_1.__decorate([
|
|
205
|
-
(0,
|
|
206
|
-
tslib_1.__param(0, (0,
|
|
207
|
-
tslib_1.__param(1, (0,
|
|
210
|
+
(0, core_1.Injectable)(),
|
|
211
|
+
tslib_1.__param(0, (0, core_1.Optional)()),
|
|
212
|
+
tslib_1.__param(1, (0, core_1.Optional)()),
|
|
208
213
|
tslib_1.__metadata("design:paramtypes", [String, Object])
|
|
209
214
|
], ConsoleLogger);
|
|
210
215
|
exports.ConsoleLogger = ConsoleLogger;
|