@nestjs/common 10.0.3 → 10.0.5
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/package.json +2 -2
- package/pipes/parse-bool.pipe.d.ts +2 -0
- package/pipes/parse-bool.pipe.js +5 -0
- package/pipes/parse-enum.pipe.d.ts +2 -0
- package/pipes/parse-enum.pipe.js +6 -1
- package/pipes/parse-float.pipe.d.ts +2 -0
- package/pipes/parse-float.pipe.js +6 -1
- package/pipes/parse-int.pipe.d.ts +2 -0
- package/pipes/parse-int.pipe.js +5 -0
- package/pipes/parse-uuid.pipe.d.ts +2 -0
- package/pipes/parse-uuid.pipe.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/common",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.5",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"homepage": "https://nestjs.com",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"iterare": "1.2.1",
|
|
22
|
-
"tslib": "2.
|
|
22
|
+
"tslib": "2.6.0",
|
|
23
23
|
"uid": "2.0.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
@@ -6,6 +6,7 @@ import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
|
6
6
|
export interface ParseBoolPipeOptions {
|
|
7
7
|
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
8
8
|
exceptionFactory?: (error: string) => any;
|
|
9
|
+
optional?: boolean;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Defines the built-in ParseBool Pipe
|
|
@@ -15,6 +16,7 @@ export interface ParseBoolPipeOptions {
|
|
|
15
16
|
* @publicApi
|
|
16
17
|
*/
|
|
17
18
|
export declare class ParseBoolPipe implements PipeTransform<string | boolean, Promise<boolean>> {
|
|
19
|
+
protected readonly options?: ParseBoolPipeOptions;
|
|
18
20
|
protected exceptionFactory: (error: string) => any;
|
|
19
21
|
constructor(options?: ParseBoolPipeOptions);
|
|
20
22
|
/**
|
package/pipes/parse-bool.pipe.js
CHANGED
|
@@ -6,6 +6,7 @@ const injectable_decorator_1 = require("../decorators/core/injectable.decorator"
|
|
|
6
6
|
const optional_decorator_1 = require("../decorators/core/optional.decorator");
|
|
7
7
|
const http_status_enum_1 = require("../enums/http-status.enum");
|
|
8
8
|
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
9
|
+
const shared_utils_1 = require("../utils/shared.utils");
|
|
9
10
|
/**
|
|
10
11
|
* Defines the built-in ParseBool Pipe
|
|
11
12
|
*
|
|
@@ -15,6 +16,7 @@ const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
|
15
16
|
*/
|
|
16
17
|
let ParseBoolPipe = exports.ParseBoolPipe = class ParseBoolPipe {
|
|
17
18
|
constructor(options) {
|
|
19
|
+
this.options = options;
|
|
18
20
|
options = options || {};
|
|
19
21
|
const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST } = options;
|
|
20
22
|
this.exceptionFactory =
|
|
@@ -29,6 +31,9 @@ let ParseBoolPipe = exports.ParseBoolPipe = class ParseBoolPipe {
|
|
|
29
31
|
* @param metadata contains metadata about the currently processed route argument
|
|
30
32
|
*/
|
|
31
33
|
async transform(value, metadata) {
|
|
34
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
32
37
|
if (this.isTrue(value)) {
|
|
33
38
|
return true;
|
|
34
39
|
}
|
|
@@ -5,6 +5,7 @@ import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
|
5
5
|
* @publicApi
|
|
6
6
|
*/
|
|
7
7
|
export interface ParseEnumPipeOptions {
|
|
8
|
+
optional?: boolean;
|
|
8
9
|
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
9
10
|
exceptionFactory?: (error: string) => any;
|
|
10
11
|
}
|
|
@@ -17,6 +18,7 @@ export interface ParseEnumPipeOptions {
|
|
|
17
18
|
*/
|
|
18
19
|
export declare class ParseEnumPipe<T = any> implements PipeTransform<T> {
|
|
19
20
|
protected readonly enumType: T;
|
|
21
|
+
protected readonly options?: ParseEnumPipeOptions;
|
|
20
22
|
protected exceptionFactory: (error: string) => any;
|
|
21
23
|
constructor(enumType: T, options?: ParseEnumPipeOptions);
|
|
22
24
|
/**
|
package/pipes/parse-enum.pipe.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParseEnumPipe = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const index_1 = require("../index");
|
|
6
5
|
const core_1 = require("../decorators/core");
|
|
6
|
+
const index_1 = require("../index");
|
|
7
7
|
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
8
|
+
const shared_utils_1 = require("../utils/shared.utils");
|
|
8
9
|
/**
|
|
9
10
|
* Defines the built-in ParseEnum Pipe
|
|
10
11
|
*
|
|
@@ -15,6 +16,7 @@ const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
|
15
16
|
let ParseEnumPipe = exports.ParseEnumPipe = class ParseEnumPipe {
|
|
16
17
|
constructor(enumType, options) {
|
|
17
18
|
this.enumType = enumType;
|
|
19
|
+
this.options = options;
|
|
18
20
|
if (!enumType) {
|
|
19
21
|
throw new Error(`"ParseEnumPipe" requires "enumType" argument specified (to validate input values).`);
|
|
20
22
|
}
|
|
@@ -32,6 +34,9 @@ let ParseEnumPipe = exports.ParseEnumPipe = class ParseEnumPipe {
|
|
|
32
34
|
* @param metadata contains metadata about the currently processed route argument
|
|
33
35
|
*/
|
|
34
36
|
async transform(value, metadata) {
|
|
37
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
35
40
|
if (!this.isEnum(value)) {
|
|
36
41
|
throw this.exceptionFactory('Validation failed (enum string is expected)');
|
|
37
42
|
}
|
|
@@ -7,6 +7,7 @@ import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
|
7
7
|
export interface ParseFloatPipeOptions {
|
|
8
8
|
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
9
9
|
exceptionFactory?: (error: string) => any;
|
|
10
|
+
optional?: boolean;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Defines the built-in ParseFloat Pipe
|
|
@@ -16,6 +17,7 @@ export interface ParseFloatPipeOptions {
|
|
|
16
17
|
* @publicApi
|
|
17
18
|
*/
|
|
18
19
|
export declare class ParseFloatPipe implements PipeTransform<string> {
|
|
20
|
+
protected readonly options?: ParseFloatPipeOptions;
|
|
19
21
|
protected exceptionFactory: (error: string) => any;
|
|
20
22
|
constructor(options?: ParseFloatPipeOptions);
|
|
21
23
|
/**
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParseFloatPipe = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const index_1 = require("../index");
|
|
6
5
|
const core_1 = require("../decorators/core");
|
|
6
|
+
const index_1 = require("../index");
|
|
7
7
|
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
8
|
+
const shared_utils_1 = require("../utils/shared.utils");
|
|
8
9
|
/**
|
|
9
10
|
* Defines the built-in ParseFloat Pipe
|
|
10
11
|
*
|
|
@@ -14,6 +15,7 @@ const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
|
14
15
|
*/
|
|
15
16
|
let ParseFloatPipe = exports.ParseFloatPipe = class ParseFloatPipe {
|
|
16
17
|
constructor(options) {
|
|
18
|
+
this.options = options;
|
|
17
19
|
options = options || {};
|
|
18
20
|
const { exceptionFactory, errorHttpStatusCode = index_1.HttpStatus.BAD_REQUEST } = options;
|
|
19
21
|
this.exceptionFactory =
|
|
@@ -28,6 +30,9 @@ let ParseFloatPipe = exports.ParseFloatPipe = class ParseFloatPipe {
|
|
|
28
30
|
* @param metadata contains metadata about the currently processed route argument
|
|
29
31
|
*/
|
|
30
32
|
async transform(value, metadata) {
|
|
33
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
31
36
|
if (!this.isNumeric(value)) {
|
|
32
37
|
throw this.exceptionFactory('Validation failed (numeric string is expected)');
|
|
33
38
|
}
|
|
@@ -6,6 +6,7 @@ import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
|
6
6
|
export interface ParseIntPipeOptions {
|
|
7
7
|
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
8
8
|
exceptionFactory?: (error: string) => any;
|
|
9
|
+
optional?: boolean;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Defines the built-in ParseInt Pipe
|
|
@@ -15,6 +16,7 @@ export interface ParseIntPipeOptions {
|
|
|
15
16
|
* @publicApi
|
|
16
17
|
*/
|
|
17
18
|
export declare class ParseIntPipe implements PipeTransform<string> {
|
|
19
|
+
protected readonly options?: ParseIntPipeOptions;
|
|
18
20
|
protected exceptionFactory: (error: string) => any;
|
|
19
21
|
constructor(options?: ParseIntPipeOptions);
|
|
20
22
|
/**
|
package/pipes/parse-int.pipe.js
CHANGED
|
@@ -6,6 +6,7 @@ const injectable_decorator_1 = require("../decorators/core/injectable.decorator"
|
|
|
6
6
|
const optional_decorator_1 = require("../decorators/core/optional.decorator");
|
|
7
7
|
const http_status_enum_1 = require("../enums/http-status.enum");
|
|
8
8
|
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
9
|
+
const shared_utils_1 = require("../utils/shared.utils");
|
|
9
10
|
/**
|
|
10
11
|
* Defines the built-in ParseInt Pipe
|
|
11
12
|
*
|
|
@@ -15,6 +16,7 @@ const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
|
15
16
|
*/
|
|
16
17
|
let ParseIntPipe = exports.ParseIntPipe = class ParseIntPipe {
|
|
17
18
|
constructor(options) {
|
|
19
|
+
this.options = options;
|
|
18
20
|
options = options || {};
|
|
19
21
|
const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST } = options;
|
|
20
22
|
this.exceptionFactory =
|
|
@@ -29,6 +31,9 @@ let ParseIntPipe = exports.ParseIntPipe = class ParseIntPipe {
|
|
|
29
31
|
* @param metadata contains metadata about the currently processed route argument
|
|
30
32
|
*/
|
|
31
33
|
async transform(value, metadata) {
|
|
34
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
32
37
|
if (!this.isNumeric(value)) {
|
|
33
38
|
throw this.exceptionFactory('Validation failed (numeric string is expected)');
|
|
34
39
|
}
|
|
@@ -7,6 +7,7 @@ export interface ParseUUIDPipeOptions {
|
|
|
7
7
|
version?: '3' | '4' | '5';
|
|
8
8
|
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
9
9
|
exceptionFactory?: (errors: string) => any;
|
|
10
|
+
optional?: boolean;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Defines the built-in ParseUUID Pipe
|
|
@@ -16,6 +17,7 @@ export interface ParseUUIDPipeOptions {
|
|
|
16
17
|
* @publicApi
|
|
17
18
|
*/
|
|
18
19
|
export declare class ParseUUIDPipe implements PipeTransform<string> {
|
|
20
|
+
protected readonly options?: ParseUUIDPipeOptions;
|
|
19
21
|
protected static uuidRegExps: {
|
|
20
22
|
3: RegExp;
|
|
21
23
|
4: RegExp;
|
package/pipes/parse-uuid.pipe.js
CHANGED
|
@@ -17,6 +17,7 @@ const shared_utils_1 = require("../utils/shared.utils");
|
|
|
17
17
|
*/
|
|
18
18
|
let ParseUUIDPipe = exports.ParseUUIDPipe = ParseUUIDPipe_1 = class ParseUUIDPipe {
|
|
19
19
|
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
20
21
|
options = options || {};
|
|
21
22
|
const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST, version, } = options;
|
|
22
23
|
this.version = version;
|
|
@@ -25,6 +26,9 @@ let ParseUUIDPipe = exports.ParseUUIDPipe = ParseUUIDPipe_1 = class ParseUUIDPip
|
|
|
25
26
|
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
26
27
|
}
|
|
27
28
|
async transform(value, metadata) {
|
|
29
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
28
32
|
if (!this.isUUID(value, this.version)) {
|
|
29
33
|
throw this.exceptionFactory(`Validation failed (uuid${this.version ? ` v ${this.version}` : ''} is expected)`);
|
|
30
34
|
}
|