@nestia/core 2.6.2 → 2.6.3
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 +4 -4
- package/src/decorators/EncryptedBody.ts +105 -105
- package/src/decorators/EncryptedModule.ts +96 -96
- package/src/decorators/PlainBody.ts +75 -75
- package/src/decorators/SwaggerCustomizer.ts +116 -116
- package/src/decorators/TypedBody.ts +62 -62
- package/src/decorators/TypedException.ts +90 -90
- package/src/decorators/TypedFormData.ts +219 -219
- package/src/decorators/TypedQuery.ts +251 -251
- package/src/decorators/TypedRoute.ts +144 -144
- package/src/decorators/internal/get_path_and_querify.ts +106 -106
- package/src/decorators/internal/load_controller.ts +51 -51
- package/src/decorators/internal/validate_request_body.ts +72 -72
- package/src/decorators/internal/validate_request_form_data.ts +75 -75
- package/src/decorators/internal/validate_request_headers.ts +83 -83
- package/src/decorators/internal/validate_request_query.ts +71 -71
- package/src/module.ts +16 -16
- package/src/options/IRequestFormDataProps.ts +27 -27
- package/src/programmers/PlainBodyProgrammer.ts +52 -52
- package/src/programmers/TypedExceptionProgrammer.ts +71 -71
- package/src/programmers/TypedFormDataBodyProgrammer.ts +108 -108
- package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
- package/src/structures/ISwagger.ts +91 -91
- package/src/structures/ISwaggerComponents.ts +29 -29
- package/src/structures/ISwaggerInfo.ts +80 -80
- package/src/structures/ISwaggerRoute.ts +50 -50
- package/src/structures/ISwaggerSecurityScheme.ts +65 -65
- package/src/transformers/NodeTransformer.ts +16 -16
- package/src/transformers/ParameterDecoratorTransformer.ts +120 -120
- package/src/transformers/TypedExceptionTransformer.ts +48 -48
- package/src/transformers/TypedRouteTransformer.ts +88 -88
- package/src/utils/Singleton.ts +20 -20
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { BadRequestException } from "@nestjs/common";
|
|
2
|
-
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
-
|
|
4
|
-
import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
|
|
5
|
-
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const validate_request_body =
|
|
11
|
-
(method: string) =>
|
|
12
|
-
<T>(validator?: IRequestBodyValidator<T>) => {
|
|
13
|
-
if (!validator) return () => NoTransformConfigureError(method);
|
|
14
|
-
else if (validator.type === "assert") return assert(validator.assert);
|
|
15
|
-
else if (validator.type === "is") return is(validator.is);
|
|
16
|
-
else if (validator.type === "validate") return validate(validator.validate);
|
|
17
|
-
return () =>
|
|
18
|
-
new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
const assert =
|
|
25
|
-
<T>(closure: (data: T) => T) =>
|
|
26
|
-
(input: T) => {
|
|
27
|
-
try {
|
|
28
|
-
closure(input);
|
|
29
|
-
return null;
|
|
30
|
-
} catch (exp) {
|
|
31
|
-
if (typia.is<TypeGuardError>(exp)) {
|
|
32
|
-
return new BadRequestException({
|
|
33
|
-
path: exp.path,
|
|
34
|
-
reason: exp.message,
|
|
35
|
-
expected: exp.expected,
|
|
36
|
-
value: exp.value,
|
|
37
|
-
message: MESSAGE,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
throw exp;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
const is =
|
|
48
|
-
<T>(closure: (data: T) => boolean) =>
|
|
49
|
-
(input: T) => {
|
|
50
|
-
const success: boolean = closure(input);
|
|
51
|
-
return success ? null : new BadRequestException(MESSAGE);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
const validate =
|
|
58
|
-
<T>(closure: (data: T) => IValidation<T>) =>
|
|
59
|
-
(input: T) => {
|
|
60
|
-
const result: IValidation<T> = closure(input);
|
|
61
|
-
return result.success
|
|
62
|
-
? null
|
|
63
|
-
: new BadRequestException({
|
|
64
|
-
errors: result.errors,
|
|
65
|
-
message: MESSAGE,
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
const MESSAGE = "Request body data is not following the promised type.";
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
+
|
|
4
|
+
import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
|
|
5
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const validate_request_body =
|
|
11
|
+
(method: string) =>
|
|
12
|
+
<T>(validator?: IRequestBodyValidator<T>) => {
|
|
13
|
+
if (!validator) return () => NoTransformConfigureError(method);
|
|
14
|
+
else if (validator.type === "assert") return assert(validator.assert);
|
|
15
|
+
else if (validator.type === "is") return is(validator.is);
|
|
16
|
+
else if (validator.type === "validate") return validate(validator.validate);
|
|
17
|
+
return () =>
|
|
18
|
+
new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
const assert =
|
|
25
|
+
<T>(closure: (data: T) => T) =>
|
|
26
|
+
(input: T) => {
|
|
27
|
+
try {
|
|
28
|
+
closure(input);
|
|
29
|
+
return null;
|
|
30
|
+
} catch (exp) {
|
|
31
|
+
if (typia.is<TypeGuardError>(exp)) {
|
|
32
|
+
return new BadRequestException({
|
|
33
|
+
path: exp.path,
|
|
34
|
+
reason: exp.message,
|
|
35
|
+
expected: exp.expected,
|
|
36
|
+
value: exp.value,
|
|
37
|
+
message: MESSAGE,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
throw exp;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
const is =
|
|
48
|
+
<T>(closure: (data: T) => boolean) =>
|
|
49
|
+
(input: T) => {
|
|
50
|
+
const success: boolean = closure(input);
|
|
51
|
+
return success ? null : new BadRequestException(MESSAGE);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
const validate =
|
|
58
|
+
<T>(closure: (data: T) => IValidation<T>) =>
|
|
59
|
+
(input: T) => {
|
|
60
|
+
const result: IValidation<T> = closure(input);
|
|
61
|
+
return result.success
|
|
62
|
+
? null
|
|
63
|
+
: new BadRequestException({
|
|
64
|
+
errors: result.errors,
|
|
65
|
+
message: MESSAGE,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
const MESSAGE = "Request body data is not following the promised type.";
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { BadRequestException } from "@nestjs/common";
|
|
2
|
-
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
-
|
|
4
|
-
import { IRequestFormDataProps } from "../../options/IRequestFormDataProps";
|
|
5
|
-
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const validate_request_form_data = <T>(
|
|
11
|
-
props?: IRequestFormDataProps<T>,
|
|
12
|
-
) => {
|
|
13
|
-
if (!props) return () => NoTransformConfigureError("TypedFormData.Bpdu");
|
|
14
|
-
else if (props.validator.type === "assert")
|
|
15
|
-
return assert(props.validator.assert);
|
|
16
|
-
else if (props.validator.type === "is") return is(props.validator.is);
|
|
17
|
-
else if (props.validator.type === "validate")
|
|
18
|
-
return validate(props.validator.validate);
|
|
19
|
-
return () =>
|
|
20
|
-
new Error(
|
|
21
|
-
`Error on nestia.core.TypedFormData.Body(): invalid typed validator.`,
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
const assert =
|
|
29
|
-
<T>(closure: (input: FormData) => T) =>
|
|
30
|
-
(input: FormData): T | BadRequestException => {
|
|
31
|
-
try {
|
|
32
|
-
return closure(input);
|
|
33
|
-
} catch (exp) {
|
|
34
|
-
if (typia.is<TypeGuardError>(exp)) {
|
|
35
|
-
return new BadRequestException({
|
|
36
|
-
path: exp.path,
|
|
37
|
-
reason: exp.message,
|
|
38
|
-
expected: exp.expected,
|
|
39
|
-
value: exp.value,
|
|
40
|
-
message: MESSAGE,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
throw exp;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
const is =
|
|
51
|
-
<T>(closure: (input: FormData) => T | null) =>
|
|
52
|
-
(input: FormData): T | BadRequestException => {
|
|
53
|
-
const result: T | null = closure(input);
|
|
54
|
-
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
*/
|
|
60
|
-
const validate =
|
|
61
|
-
<T>(closure: (input: FormData) => IValidation<T>) =>
|
|
62
|
-
(input: FormData): T | BadRequestException => {
|
|
63
|
-
const result: IValidation<T> = closure(input);
|
|
64
|
-
return result.success
|
|
65
|
-
? result.data
|
|
66
|
-
: new BadRequestException({
|
|
67
|
-
errors: result.errors,
|
|
68
|
-
message: MESSAGE,
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @internal
|
|
74
|
-
*/
|
|
75
|
-
const MESSAGE = "Request multipart data is not following the promised type.";
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
+
|
|
4
|
+
import { IRequestFormDataProps } from "../../options/IRequestFormDataProps";
|
|
5
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const validate_request_form_data = <T>(
|
|
11
|
+
props?: IRequestFormDataProps<T>,
|
|
12
|
+
) => {
|
|
13
|
+
if (!props) return () => NoTransformConfigureError("TypedFormData.Bpdu");
|
|
14
|
+
else if (props.validator.type === "assert")
|
|
15
|
+
return assert(props.validator.assert);
|
|
16
|
+
else if (props.validator.type === "is") return is(props.validator.is);
|
|
17
|
+
else if (props.validator.type === "validate")
|
|
18
|
+
return validate(props.validator.validate);
|
|
19
|
+
return () =>
|
|
20
|
+
new Error(
|
|
21
|
+
`Error on nestia.core.TypedFormData.Body(): invalid typed validator.`,
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
const assert =
|
|
29
|
+
<T>(closure: (input: FormData) => T) =>
|
|
30
|
+
(input: FormData): T | BadRequestException => {
|
|
31
|
+
try {
|
|
32
|
+
return closure(input);
|
|
33
|
+
} catch (exp) {
|
|
34
|
+
if (typia.is<TypeGuardError>(exp)) {
|
|
35
|
+
return new BadRequestException({
|
|
36
|
+
path: exp.path,
|
|
37
|
+
reason: exp.message,
|
|
38
|
+
expected: exp.expected,
|
|
39
|
+
value: exp.value,
|
|
40
|
+
message: MESSAGE,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
throw exp;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
const is =
|
|
51
|
+
<T>(closure: (input: FormData) => T | null) =>
|
|
52
|
+
(input: FormData): T | BadRequestException => {
|
|
53
|
+
const result: T | null = closure(input);
|
|
54
|
+
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
const validate =
|
|
61
|
+
<T>(closure: (input: FormData) => IValidation<T>) =>
|
|
62
|
+
(input: FormData): T | BadRequestException => {
|
|
63
|
+
const result: IValidation<T> = closure(input);
|
|
64
|
+
return result.success
|
|
65
|
+
? result.data
|
|
66
|
+
: new BadRequestException({
|
|
67
|
+
errors: result.errors,
|
|
68
|
+
message: MESSAGE,
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
const MESSAGE = "Request multipart data is not following the promised type.";
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { BadRequestException } from "@nestjs/common";
|
|
2
|
-
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
-
|
|
4
|
-
import { IRequestHeadersValidator } from "../../options/IRequestHeadersValidator";
|
|
5
|
-
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const validate_request_headers = <T>(
|
|
11
|
-
validator?: IRequestHeadersValidator<T>,
|
|
12
|
-
) => {
|
|
13
|
-
if (!validator) return () => NoTransformConfigureError("TypedHeaders");
|
|
14
|
-
else if (validator.type === "assert") return assert(validator.assert);
|
|
15
|
-
else if (validator.type === "is") return is(validator.is);
|
|
16
|
-
else if (validator.type === "validate") return validate(validator.validate);
|
|
17
|
-
return () =>
|
|
18
|
-
new Error(`Error on nestia.core.TypedHeaders(): invalid typed validator.`);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
const assert =
|
|
25
|
-
<T>(closure: (input: Record<string, string | string[] | undefined>) => T) =>
|
|
26
|
-
(
|
|
27
|
-
input: Record<string, string | string[] | undefined>,
|
|
28
|
-
): T | BadRequestException => {
|
|
29
|
-
try {
|
|
30
|
-
return closure(input);
|
|
31
|
-
} catch (exp) {
|
|
32
|
-
if (typia.is<TypeGuardError>(exp)) {
|
|
33
|
-
return new BadRequestException({
|
|
34
|
-
path: exp.path,
|
|
35
|
-
reason: exp.message,
|
|
36
|
-
expected: exp.expected,
|
|
37
|
-
value: exp.value,
|
|
38
|
-
message: MESSAGE,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
throw exp;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
const is =
|
|
49
|
-
<T>(
|
|
50
|
-
closure: (input: Record<string, string | string[] | undefined>) => T | null,
|
|
51
|
-
) =>
|
|
52
|
-
(
|
|
53
|
-
input: Record<string, string | string[] | undefined>,
|
|
54
|
-
): T | BadRequestException => {
|
|
55
|
-
const result: T | null = closure(input);
|
|
56
|
-
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
62
|
-
const validate =
|
|
63
|
-
<T>(
|
|
64
|
-
closure: (
|
|
65
|
-
input: Record<string, string | string[] | undefined>,
|
|
66
|
-
) => IValidation<T>,
|
|
67
|
-
) =>
|
|
68
|
-
(
|
|
69
|
-
input: Record<string, string | string[] | undefined>,
|
|
70
|
-
): T | BadRequestException => {
|
|
71
|
-
const result: IValidation<T> = closure(input);
|
|
72
|
-
return result.success
|
|
73
|
-
? result.data
|
|
74
|
-
: new BadRequestException({
|
|
75
|
-
errors: result.errors,
|
|
76
|
-
message: MESSAGE,
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @internal
|
|
82
|
-
*/
|
|
83
|
-
const MESSAGE = "Request headers data is not following the promised type.";
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
+
|
|
4
|
+
import { IRequestHeadersValidator } from "../../options/IRequestHeadersValidator";
|
|
5
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const validate_request_headers = <T>(
|
|
11
|
+
validator?: IRequestHeadersValidator<T>,
|
|
12
|
+
) => {
|
|
13
|
+
if (!validator) return () => NoTransformConfigureError("TypedHeaders");
|
|
14
|
+
else if (validator.type === "assert") return assert(validator.assert);
|
|
15
|
+
else if (validator.type === "is") return is(validator.is);
|
|
16
|
+
else if (validator.type === "validate") return validate(validator.validate);
|
|
17
|
+
return () =>
|
|
18
|
+
new Error(`Error on nestia.core.TypedHeaders(): invalid typed validator.`);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
const assert =
|
|
25
|
+
<T>(closure: (input: Record<string, string | string[] | undefined>) => T) =>
|
|
26
|
+
(
|
|
27
|
+
input: Record<string, string | string[] | undefined>,
|
|
28
|
+
): T | BadRequestException => {
|
|
29
|
+
try {
|
|
30
|
+
return closure(input);
|
|
31
|
+
} catch (exp) {
|
|
32
|
+
if (typia.is<TypeGuardError>(exp)) {
|
|
33
|
+
return new BadRequestException({
|
|
34
|
+
path: exp.path,
|
|
35
|
+
reason: exp.message,
|
|
36
|
+
expected: exp.expected,
|
|
37
|
+
value: exp.value,
|
|
38
|
+
message: MESSAGE,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
throw exp;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
const is =
|
|
49
|
+
<T>(
|
|
50
|
+
closure: (input: Record<string, string | string[] | undefined>) => T | null,
|
|
51
|
+
) =>
|
|
52
|
+
(
|
|
53
|
+
input: Record<string, string | string[] | undefined>,
|
|
54
|
+
): T | BadRequestException => {
|
|
55
|
+
const result: T | null = closure(input);
|
|
56
|
+
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
const validate =
|
|
63
|
+
<T>(
|
|
64
|
+
closure: (
|
|
65
|
+
input: Record<string, string | string[] | undefined>,
|
|
66
|
+
) => IValidation<T>,
|
|
67
|
+
) =>
|
|
68
|
+
(
|
|
69
|
+
input: Record<string, string | string[] | undefined>,
|
|
70
|
+
): T | BadRequestException => {
|
|
71
|
+
const result: IValidation<T> = closure(input);
|
|
72
|
+
return result.success
|
|
73
|
+
? result.data
|
|
74
|
+
: new BadRequestException({
|
|
75
|
+
errors: result.errors,
|
|
76
|
+
message: MESSAGE,
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
const MESSAGE = "Request headers data is not following the promised type.";
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { BadRequestException } from "@nestjs/common";
|
|
2
|
-
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
-
|
|
4
|
-
import { IRequestQueryValidator } from "../../options/IRequestQueryValidator";
|
|
5
|
-
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const validate_request_query = <T>(
|
|
11
|
-
validator?: IRequestQueryValidator<T>,
|
|
12
|
-
) => {
|
|
13
|
-
if (!validator) return () => NoTransformConfigureError("TypedQuery");
|
|
14
|
-
else if (validator.type === "assert") return assert(validator.assert);
|
|
15
|
-
else if (validator.type === "is") return is(validator.is);
|
|
16
|
-
else if (validator.type === "validate") return validate(validator.validate);
|
|
17
|
-
return () =>
|
|
18
|
-
new Error(`Error on nestia.core.TypedQuery(): invalid typed validator.`);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
const assert =
|
|
25
|
-
<T>(closure: (input: URLSearchParams) => T) =>
|
|
26
|
-
(input: URLSearchParams): T | BadRequestException => {
|
|
27
|
-
try {
|
|
28
|
-
return closure(input);
|
|
29
|
-
} catch (exp) {
|
|
30
|
-
if (typia.is<TypeGuardError>(exp)) {
|
|
31
|
-
return new BadRequestException({
|
|
32
|
-
path: exp.path,
|
|
33
|
-
reason: exp.message,
|
|
34
|
-
expected: exp.expected,
|
|
35
|
-
value: exp.value,
|
|
36
|
-
message: MESSAGE,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
throw exp;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
const is =
|
|
47
|
-
<T>(closure: (input: URLSearchParams) => T | null) =>
|
|
48
|
-
(input: URLSearchParams): T | BadRequestException => {
|
|
49
|
-
const result: T | null = closure(input);
|
|
50
|
-
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
const validate =
|
|
57
|
-
<T>(closure: (input: URLSearchParams) => IValidation<T>) =>
|
|
58
|
-
(input: URLSearchParams): T | BadRequestException => {
|
|
59
|
-
const result: IValidation<T> = closure(input);
|
|
60
|
-
return result.success
|
|
61
|
-
? result.data
|
|
62
|
-
: new BadRequestException({
|
|
63
|
-
errors: result.errors,
|
|
64
|
-
message: MESSAGE,
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @internal
|
|
70
|
-
*/
|
|
71
|
-
const MESSAGE = "Request query data is not following the promised type.";
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
+
|
|
4
|
+
import { IRequestQueryValidator } from "../../options/IRequestQueryValidator";
|
|
5
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const validate_request_query = <T>(
|
|
11
|
+
validator?: IRequestQueryValidator<T>,
|
|
12
|
+
) => {
|
|
13
|
+
if (!validator) return () => NoTransformConfigureError("TypedQuery");
|
|
14
|
+
else if (validator.type === "assert") return assert(validator.assert);
|
|
15
|
+
else if (validator.type === "is") return is(validator.is);
|
|
16
|
+
else if (validator.type === "validate") return validate(validator.validate);
|
|
17
|
+
return () =>
|
|
18
|
+
new Error(`Error on nestia.core.TypedQuery(): invalid typed validator.`);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
const assert =
|
|
25
|
+
<T>(closure: (input: URLSearchParams) => T) =>
|
|
26
|
+
(input: URLSearchParams): T | BadRequestException => {
|
|
27
|
+
try {
|
|
28
|
+
return closure(input);
|
|
29
|
+
} catch (exp) {
|
|
30
|
+
if (typia.is<TypeGuardError>(exp)) {
|
|
31
|
+
return new BadRequestException({
|
|
32
|
+
path: exp.path,
|
|
33
|
+
reason: exp.message,
|
|
34
|
+
expected: exp.expected,
|
|
35
|
+
value: exp.value,
|
|
36
|
+
message: MESSAGE,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
throw exp;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
const is =
|
|
47
|
+
<T>(closure: (input: URLSearchParams) => T | null) =>
|
|
48
|
+
(input: URLSearchParams): T | BadRequestException => {
|
|
49
|
+
const result: T | null = closure(input);
|
|
50
|
+
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
const validate =
|
|
57
|
+
<T>(closure: (input: URLSearchParams) => IValidation<T>) =>
|
|
58
|
+
(input: URLSearchParams): T | BadRequestException => {
|
|
59
|
+
const result: IValidation<T> = closure(input);
|
|
60
|
+
return result.success
|
|
61
|
+
? result.data
|
|
62
|
+
: new BadRequestException({
|
|
63
|
+
errors: result.errors,
|
|
64
|
+
message: MESSAGE,
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
const MESSAGE = "Request query data is not following the promised type.";
|
package/src/module.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export * from "./decorators/DynamicModule";
|
|
2
|
-
export * from "./decorators/EncryptedBody";
|
|
3
|
-
export * from "./decorators/EncryptedController";
|
|
4
|
-
export * from "./decorators/EncryptedModule";
|
|
5
|
-
export * from "./decorators/EncryptedRoute";
|
|
6
|
-
export * from "./utils/ExceptionManager";
|
|
7
|
-
export * from "./decorators/PlainBody";
|
|
8
|
-
export * from "./decorators/SwaggerCustomizer";
|
|
9
|
-
export * from "./decorators/TypedBody";
|
|
10
|
-
export * from "./decorators/TypedException";
|
|
11
|
-
export * from "./decorators/TypedHeaders";
|
|
12
|
-
export * from "./decorators/TypedFormData";
|
|
13
|
-
export * from "./decorators/TypedParam";
|
|
14
|
-
export * from "./decorators/TypedRoute";
|
|
15
|
-
export * from "./decorators/TypedQuery";
|
|
16
|
-
export * from "./options/INestiaTransformOptions";
|
|
1
|
+
export * from "./decorators/DynamicModule";
|
|
2
|
+
export * from "./decorators/EncryptedBody";
|
|
3
|
+
export * from "./decorators/EncryptedController";
|
|
4
|
+
export * from "./decorators/EncryptedModule";
|
|
5
|
+
export * from "./decorators/EncryptedRoute";
|
|
6
|
+
export * from "./utils/ExceptionManager";
|
|
7
|
+
export * from "./decorators/PlainBody";
|
|
8
|
+
export * from "./decorators/SwaggerCustomizer";
|
|
9
|
+
export * from "./decorators/TypedBody";
|
|
10
|
+
export * from "./decorators/TypedException";
|
|
11
|
+
export * from "./decorators/TypedHeaders";
|
|
12
|
+
export * from "./decorators/TypedFormData";
|
|
13
|
+
export * from "./decorators/TypedParam";
|
|
14
|
+
export * from "./decorators/TypedRoute";
|
|
15
|
+
export * from "./decorators/TypedQuery";
|
|
16
|
+
export * from "./options/INestiaTransformOptions";
|