@nestjs/common 9.3.9 → 9.3.11
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/cache/interceptors/cache.interceptor.d.ts +1 -0
- package/cache/interceptors/cache.interceptor.js +9 -1
- package/decorators/core/controller.decorator.d.ts +1 -1
- package/package.json +1 -1
- package/pipes/file/file-validator.interface.d.ts +2 -1
- package/pipes/file/file-validator.interface.js +2 -1
- package/pipes/file/max-file-size.validator.d.ts +1 -1
- package/pipes/file/max-file-size.validator.js +1 -1
- package/pipes/file/parse-file.pipe.d.ts +3 -3
- package/pipes/file/parse-file.pipe.js +14 -16
- package/pipes/parse-array.pipe.js +5 -3
|
@@ -13,6 +13,7 @@ export declare class CacheInterceptor implements NestInterceptor {
|
|
|
13
13
|
protected readonly reflector: any;
|
|
14
14
|
protected readonly httpAdapterHost: HttpAdapterHost;
|
|
15
15
|
protected allowedMethods: string[];
|
|
16
|
+
private cacheManagerIsv5OrGreater;
|
|
16
17
|
constructor(cacheManager: any, reflector: any);
|
|
17
18
|
intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
|
|
18
19
|
protected trackBy(context: ExecutionContext): string | undefined;
|
|
@@ -7,6 +7,7 @@ const operators_1 = require("rxjs/operators");
|
|
|
7
7
|
const decorators_1 = require("../../decorators");
|
|
8
8
|
const file_stream_1 = require("../../file-stream");
|
|
9
9
|
const logger_service_1 = require("../../services/logger.service");
|
|
10
|
+
const load_package_util_1 = require("../../utils/load-package.util");
|
|
10
11
|
const shared_utils_1 = require("../../utils/shared.utils");
|
|
11
12
|
const cache_constants_1 = require("../cache.constants");
|
|
12
13
|
const HTTP_ADAPTER_HOST = 'HttpAdapterHost';
|
|
@@ -21,6 +22,10 @@ let CacheInterceptor = class CacheInterceptor {
|
|
|
21
22
|
this.cacheManager = cacheManager;
|
|
22
23
|
this.reflector = reflector;
|
|
23
24
|
this.allowedMethods = ['GET'];
|
|
25
|
+
// We need to check if the cache-manager package is v5 or greater
|
|
26
|
+
// because the set method signature changed in v5
|
|
27
|
+
const cacheManagerPackage = (0, load_package_util_1.loadPackage)('cache-manager', 'CacheModule', () => require('cache-manager'));
|
|
28
|
+
this.cacheManagerIsv5OrGreater = 'memoryStore' in cacheManagerPackage;
|
|
24
29
|
}
|
|
25
30
|
async intercept(context, next) {
|
|
26
31
|
var _a;
|
|
@@ -41,7 +46,10 @@ let CacheInterceptor = class CacheInterceptor {
|
|
|
41
46
|
if (response instanceof file_stream_1.StreamableFile) {
|
|
42
47
|
return;
|
|
43
48
|
}
|
|
44
|
-
const args =
|
|
49
|
+
const args = [key, response];
|
|
50
|
+
if (!(0, shared_utils_1.isNil)(ttl)) {
|
|
51
|
+
args.push(this.cacheManagerIsv5OrGreater ? ttl : { ttl });
|
|
52
|
+
}
|
|
45
53
|
try {
|
|
46
54
|
await this.cacheManager.set(...args);
|
|
47
55
|
}
|
|
@@ -57,7 +57,7 @@ export declare function Controller(): ClassDecorator;
|
|
|
57
57
|
* It defines a class that provides a context for one or more message or event
|
|
58
58
|
* handlers.
|
|
59
59
|
*
|
|
60
|
-
* @param {string
|
|
60
|
+
* @param {string|Array} prefix string that defines a `route path prefix`. The prefix
|
|
61
61
|
* is pre-pended to the path specified in any request decorator in the class.
|
|
62
62
|
*
|
|
63
63
|
* @see [Routing](https://docs.nestjs.com/controllers#routing)
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Interface describing FileValidators, which can be added to a
|
|
2
|
+
* Interface describing FileValidators, which can be added to a ParseFilePipe
|
|
3
3
|
*
|
|
4
|
+
* @see {ParseFilePipe}
|
|
4
5
|
* @publicApi
|
|
5
6
|
*/
|
|
6
7
|
export declare abstract class FileValidator<TValidationOptions = Record<string, any>> {
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FileValidator = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Interface describing FileValidators, which can be added to a
|
|
5
|
+
* Interface describing FileValidators, which can be added to a ParseFilePipe
|
|
6
6
|
*
|
|
7
|
+
* @see {ParseFilePipe}
|
|
7
8
|
* @publicApi
|
|
8
9
|
*/
|
|
9
10
|
class FileValidator {
|
|
@@ -5,7 +5,7 @@ export type MaxFileSizeValidatorOptions = {
|
|
|
5
5
|
/**
|
|
6
6
|
* Defines the built-in MaxSize File Validator
|
|
7
7
|
*
|
|
8
|
-
* @see [File Validators](https://docs.nestjs.com/techniques/file-upload#
|
|
8
|
+
* @see [File Validators](https://docs.nestjs.com/techniques/file-upload#file-validation)
|
|
9
9
|
*
|
|
10
10
|
* @publicApi
|
|
11
11
|
*/
|
|
@@ -5,7 +5,7 @@ const file_validator_interface_1 = require("./file-validator.interface");
|
|
|
5
5
|
/**
|
|
6
6
|
* Defines the built-in MaxSize File Validator
|
|
7
7
|
*
|
|
8
|
-
* @see [File Validators](https://docs.nestjs.com/techniques/file-upload#
|
|
8
|
+
* @see [File Validators](https://docs.nestjs.com/techniques/file-upload#file-validation)
|
|
9
9
|
*
|
|
10
10
|
* @publicApi
|
|
11
11
|
*/
|
|
@@ -4,8 +4,8 @@ import { ParseFileOptions } from './parse-file-options.interface';
|
|
|
4
4
|
/**
|
|
5
5
|
* Defines the built-in ParseFile Pipe. This pipe can be used to validate incoming files
|
|
6
6
|
* with `@UploadedFile()` decorator. You can use either other specific built-in validators
|
|
7
|
-
* or provide one of your own, simply implementing it through
|
|
8
|
-
*
|
|
7
|
+
* or provide one of your own, simply implementing it through FileValidator interface
|
|
8
|
+
* and adding it to ParseFilePipe's constructor.
|
|
9
9
|
*
|
|
10
10
|
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
11
11
|
*
|
|
@@ -17,7 +17,7 @@ export declare class ParseFilePipe implements PipeTransform<any> {
|
|
|
17
17
|
private readonly fileIsRequired;
|
|
18
18
|
constructor(options?: ParseFileOptions);
|
|
19
19
|
transform(value: any): Promise<any>;
|
|
20
|
-
private
|
|
20
|
+
private validateFilesOrFile;
|
|
21
21
|
private thereAreNoFilesIn;
|
|
22
22
|
protected validate(file: any): Promise<any>;
|
|
23
23
|
private validateOrThrow;
|
|
@@ -9,8 +9,8 @@ const shared_utils_1 = require("../../utils/shared.utils");
|
|
|
9
9
|
/**
|
|
10
10
|
* Defines the built-in ParseFile Pipe. This pipe can be used to validate incoming files
|
|
11
11
|
* with `@UploadedFile()` decorator. You can use either other specific built-in validators
|
|
12
|
-
* or provide one of your own, simply implementing it through
|
|
13
|
-
*
|
|
12
|
+
* or provide one of your own, simply implementing it through FileValidator interface
|
|
13
|
+
* and adding it to ParseFilePipe's constructor.
|
|
14
14
|
*
|
|
15
15
|
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
16
16
|
*
|
|
@@ -26,24 +26,22 @@ let ParseFilePipe = class ParseFilePipe {
|
|
|
26
26
|
this.fileIsRequired = fileIsRequired !== null && fileIsRequired !== void 0 ? fileIsRequired : true;
|
|
27
27
|
}
|
|
28
28
|
async transform(value) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
return value;
|
|
29
|
+
const areThereAnyFilesIn = this.thereAreNoFilesIn(value);
|
|
30
|
+
if (areThereAnyFilesIn && this.fileIsRequired) {
|
|
31
|
+
throw this.exceptionFactory('File is required');
|
|
34
32
|
}
|
|
35
|
-
if (this.validators.length) {
|
|
36
|
-
|
|
37
|
-
await this.validateFiles(value);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
await this.validate(value);
|
|
41
|
-
}
|
|
33
|
+
if (!areThereAnyFilesIn && this.validators.length) {
|
|
34
|
+
await this.validateFilesOrFile(value);
|
|
42
35
|
}
|
|
43
36
|
return value;
|
|
44
37
|
}
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
async validateFilesOrFile(value) {
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
await Promise.all(value.map(f => this.validate(f)));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
await this.validate(value);
|
|
44
|
+
}
|
|
47
45
|
}
|
|
48
46
|
thereAreNoFilesIn(value) {
|
|
49
47
|
const isEmptyArray = Array.isArray(value) && (0, shared_utils_1.isEmpty)(value);
|
|
@@ -62,10 +62,12 @@ let ParseArrayPipe = class ParseArrayPipe {
|
|
|
62
62
|
};
|
|
63
63
|
const isExpectedTypePrimitive = this.isExpectedTypePrimitive();
|
|
64
64
|
const toClassInstance = (item, index) => {
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if (this.options.items !== String) {
|
|
66
|
+
try {
|
|
67
|
+
item = JSON.parse(item);
|
|
68
|
+
}
|
|
69
|
+
catch (_a) { }
|
|
67
70
|
}
|
|
68
|
-
catch (_a) { }
|
|
69
71
|
if (isExpectedTypePrimitive) {
|
|
70
72
|
return this.validatePrimitive(item, index);
|
|
71
73
|
}
|