@nestia/core 2.6.3-dev.20240328 → 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 +3 -3
- 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,50 +1,50 @@
|
|
|
1
|
-
import { IJsonSchema } from "typia";
|
|
2
|
-
|
|
3
|
-
export interface ISwaggerRoute {
|
|
4
|
-
deprecated?: boolean;
|
|
5
|
-
security?: Record<string, string[]>[];
|
|
6
|
-
operationId?: string;
|
|
7
|
-
tags: string[];
|
|
8
|
-
parameters: ISwaggerRoute.IParameter[];
|
|
9
|
-
requestBody?: ISwaggerRoute.IRequestBody;
|
|
10
|
-
responses: ISwaggerRoute.IResponseBody;
|
|
11
|
-
summary?: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
}
|
|
14
|
-
export namespace ISwaggerRoute {
|
|
15
|
-
export interface IParameter {
|
|
16
|
-
name: string;
|
|
17
|
-
in: string;
|
|
18
|
-
schema: IJsonSchema;
|
|
19
|
-
required: boolean;
|
|
20
|
-
description?: string;
|
|
21
|
-
}
|
|
22
|
-
export interface IRequestBody {
|
|
23
|
-
description?: string;
|
|
24
|
-
content: IContent;
|
|
25
|
-
required: true;
|
|
26
|
-
"x-nestia-encrypted"?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export type IResponseBody = Record<
|
|
29
|
-
string,
|
|
30
|
-
{
|
|
31
|
-
description: string;
|
|
32
|
-
content?: IContent;
|
|
33
|
-
"x-nestia-encrypted"?: boolean;
|
|
34
|
-
}
|
|
35
|
-
>;
|
|
36
|
-
export interface IContent {
|
|
37
|
-
"application/x-www-form-urlencoded"?: {
|
|
38
|
-
schema: IJsonSchema;
|
|
39
|
-
};
|
|
40
|
-
"application/json"?: {
|
|
41
|
-
schema: IJsonSchema;
|
|
42
|
-
};
|
|
43
|
-
"text/plain"?: {
|
|
44
|
-
schema: IJsonSchema;
|
|
45
|
-
};
|
|
46
|
-
"multipart/form-data"?: {
|
|
47
|
-
schema: IJsonSchema;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
import { IJsonSchema } from "typia";
|
|
2
|
+
|
|
3
|
+
export interface ISwaggerRoute {
|
|
4
|
+
deprecated?: boolean;
|
|
5
|
+
security?: Record<string, string[]>[];
|
|
6
|
+
operationId?: string;
|
|
7
|
+
tags: string[];
|
|
8
|
+
parameters: ISwaggerRoute.IParameter[];
|
|
9
|
+
requestBody?: ISwaggerRoute.IRequestBody;
|
|
10
|
+
responses: ISwaggerRoute.IResponseBody;
|
|
11
|
+
summary?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
}
|
|
14
|
+
export namespace ISwaggerRoute {
|
|
15
|
+
export interface IParameter {
|
|
16
|
+
name: string;
|
|
17
|
+
in: string;
|
|
18
|
+
schema: IJsonSchema;
|
|
19
|
+
required: boolean;
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IRequestBody {
|
|
23
|
+
description?: string;
|
|
24
|
+
content: IContent;
|
|
25
|
+
required: true;
|
|
26
|
+
"x-nestia-encrypted"?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export type IResponseBody = Record<
|
|
29
|
+
string,
|
|
30
|
+
{
|
|
31
|
+
description: string;
|
|
32
|
+
content?: IContent;
|
|
33
|
+
"x-nestia-encrypted"?: boolean;
|
|
34
|
+
}
|
|
35
|
+
>;
|
|
36
|
+
export interface IContent {
|
|
37
|
+
"application/x-www-form-urlencoded"?: {
|
|
38
|
+
schema: IJsonSchema;
|
|
39
|
+
};
|
|
40
|
+
"application/json"?: {
|
|
41
|
+
schema: IJsonSchema;
|
|
42
|
+
};
|
|
43
|
+
"text/plain"?: {
|
|
44
|
+
schema: IJsonSchema;
|
|
45
|
+
};
|
|
46
|
+
"multipart/form-data"?: {
|
|
47
|
+
schema: IJsonSchema;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security scheme of Swagger Documents.
|
|
3
|
-
*
|
|
4
|
-
* `ISwaggerSecurityScheme` is a data structure representing content of
|
|
5
|
-
* `securitySchemes` in `swagger.json` file. It is composed with 5 types of security
|
|
6
|
-
* schemes as an union type like below.
|
|
7
|
-
*
|
|
8
|
-
* @reference https://swagger.io/specification/#security-scheme-object
|
|
9
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
10
|
-
*/
|
|
11
|
-
export type ISwaggerSecurityScheme =
|
|
12
|
-
| ISwaggerSecurityScheme.IHttpBasic
|
|
13
|
-
| ISwaggerSecurityScheme.IHttpBearer
|
|
14
|
-
| ISwaggerSecurityScheme.IApiKey
|
|
15
|
-
| ISwaggerSecurityScheme.IOpenId
|
|
16
|
-
| ISwaggerSecurityScheme.IOAuth2;
|
|
17
|
-
export namespace ISwaggerSecurityScheme {
|
|
18
|
-
export interface IHttpBasic {
|
|
19
|
-
type: "http";
|
|
20
|
-
scheme: "basic";
|
|
21
|
-
}
|
|
22
|
-
export interface IHttpBearer {
|
|
23
|
-
type: "http";
|
|
24
|
-
scheme: "bearer";
|
|
25
|
-
bearerFormat?: string;
|
|
26
|
-
}
|
|
27
|
-
export interface IApiKey {
|
|
28
|
-
type: "apiKey";
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @default header
|
|
32
|
-
*/
|
|
33
|
-
in?: "header" | "query" | "cookie";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @default Authorization
|
|
37
|
-
*/
|
|
38
|
-
name?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface IOpenId {
|
|
42
|
-
type: "openIdConnect";
|
|
43
|
-
openIdConnectUrl: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface IOAuth2 {
|
|
47
|
-
type: "oauth2";
|
|
48
|
-
flows: IOAuth2.IFlowSet;
|
|
49
|
-
description?: string;
|
|
50
|
-
}
|
|
51
|
-
export namespace IOAuth2 {
|
|
52
|
-
export interface IFlowSet {
|
|
53
|
-
authorizationCode?: IFlow;
|
|
54
|
-
implicit?: Omit<IFlow, "tokenUrl">;
|
|
55
|
-
password?: Omit<IFlow, "authorizationUrl">;
|
|
56
|
-
clientCredentials?: Omit<IFlow, "authorizationUrl">;
|
|
57
|
-
}
|
|
58
|
-
export interface IFlow {
|
|
59
|
-
authorizationUrl: string;
|
|
60
|
-
tokenUrl?: string;
|
|
61
|
-
refreshUrl?: string;
|
|
62
|
-
scopes?: Record<string, string>;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Security scheme of Swagger Documents.
|
|
3
|
+
*
|
|
4
|
+
* `ISwaggerSecurityScheme` is a data structure representing content of
|
|
5
|
+
* `securitySchemes` in `swagger.json` file. It is composed with 5 types of security
|
|
6
|
+
* schemes as an union type like below.
|
|
7
|
+
*
|
|
8
|
+
* @reference https://swagger.io/specification/#security-scheme-object
|
|
9
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
10
|
+
*/
|
|
11
|
+
export type ISwaggerSecurityScheme =
|
|
12
|
+
| ISwaggerSecurityScheme.IHttpBasic
|
|
13
|
+
| ISwaggerSecurityScheme.IHttpBearer
|
|
14
|
+
| ISwaggerSecurityScheme.IApiKey
|
|
15
|
+
| ISwaggerSecurityScheme.IOpenId
|
|
16
|
+
| ISwaggerSecurityScheme.IOAuth2;
|
|
17
|
+
export namespace ISwaggerSecurityScheme {
|
|
18
|
+
export interface IHttpBasic {
|
|
19
|
+
type: "http";
|
|
20
|
+
scheme: "basic";
|
|
21
|
+
}
|
|
22
|
+
export interface IHttpBearer {
|
|
23
|
+
type: "http";
|
|
24
|
+
scheme: "bearer";
|
|
25
|
+
bearerFormat?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface IApiKey {
|
|
28
|
+
type: "apiKey";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @default header
|
|
32
|
+
*/
|
|
33
|
+
in?: "header" | "query" | "cookie";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @default Authorization
|
|
37
|
+
*/
|
|
38
|
+
name?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface IOpenId {
|
|
42
|
+
type: "openIdConnect";
|
|
43
|
+
openIdConnectUrl: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface IOAuth2 {
|
|
47
|
+
type: "oauth2";
|
|
48
|
+
flows: IOAuth2.IFlowSet;
|
|
49
|
+
description?: string;
|
|
50
|
+
}
|
|
51
|
+
export namespace IOAuth2 {
|
|
52
|
+
export interface IFlowSet {
|
|
53
|
+
authorizationCode?: IFlow;
|
|
54
|
+
implicit?: Omit<IFlow, "tokenUrl">;
|
|
55
|
+
password?: Omit<IFlow, "authorizationUrl">;
|
|
56
|
+
clientCredentials?: Omit<IFlow, "authorizationUrl">;
|
|
57
|
+
}
|
|
58
|
+
export interface IFlow {
|
|
59
|
+
authorizationUrl: string;
|
|
60
|
+
tokenUrl?: string;
|
|
61
|
+
refreshUrl?: string;
|
|
62
|
+
scopes?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
-
import { MethodTransformer } from "./MethodTransformer";
|
|
5
|
-
import { ParameterTransformer } from "./ParameterTransformer";
|
|
6
|
-
|
|
7
|
-
export namespace NodeTransformer {
|
|
8
|
-
export const transform =
|
|
9
|
-
(project: INestiaTransformProject) =>
|
|
10
|
-
(node: ts.Node): ts.Node =>
|
|
11
|
-
ts.isMethodDeclaration(node)
|
|
12
|
-
? MethodTransformer.transform(project)(node)
|
|
13
|
-
: ts.isParameter(node)
|
|
14
|
-
? ParameterTransformer.transform(project)(node)
|
|
15
|
-
: node;
|
|
16
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
+
import { MethodTransformer } from "./MethodTransformer";
|
|
5
|
+
import { ParameterTransformer } from "./ParameterTransformer";
|
|
6
|
+
|
|
7
|
+
export namespace NodeTransformer {
|
|
8
|
+
export const transform =
|
|
9
|
+
(project: INestiaTransformProject) =>
|
|
10
|
+
(node: ts.Node): ts.Node =>
|
|
11
|
+
ts.isMethodDeclaration(node)
|
|
12
|
+
? MethodTransformer.transform(project)(node)
|
|
13
|
+
: ts.isParameter(node)
|
|
14
|
+
? ParameterTransformer.transform(project)(node)
|
|
15
|
+
: node;
|
|
16
|
+
}
|
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
-
import { PlainBodyProgrammer } from "../programmers/PlainBodyProgrammer";
|
|
6
|
-
import { TypedBodyProgrammer } from "../programmers/TypedBodyProgrammer";
|
|
7
|
-
import { TypedFormDataBodyProgrammer } from "../programmers/TypedFormDataBodyProgrammer";
|
|
8
|
-
import { TypedHeadersProgrammer } from "../programmers/TypedHeadersProgrammer";
|
|
9
|
-
import { TypedParamProgrammer } from "../programmers/TypedParamProgrammer";
|
|
10
|
-
import { TypedQueryBodyProgrammer } from "../programmers/TypedQueryBodyProgrammer";
|
|
11
|
-
import { TypedQueryProgrammer } from "../programmers/TypedQueryProgrammer";
|
|
12
|
-
|
|
13
|
-
export namespace ParameterDecoratorTransformer {
|
|
14
|
-
export const transform =
|
|
15
|
-
(project: INestiaTransformProject) =>
|
|
16
|
-
(type: ts.Type) =>
|
|
17
|
-
(decorator: ts.Decorator): ts.Decorator => {
|
|
18
|
-
//----
|
|
19
|
-
// VALIDATIONS
|
|
20
|
-
//----
|
|
21
|
-
// CHECK DECORATOR
|
|
22
|
-
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
23
|
-
|
|
24
|
-
// SIGNATURE DECLARATION
|
|
25
|
-
const declaration: ts.Declaration | undefined =
|
|
26
|
-
project.checker.getResolvedSignature(decorator.expression)?.declaration;
|
|
27
|
-
if (declaration === undefined) return decorator;
|
|
28
|
-
|
|
29
|
-
// FILE PATH
|
|
30
|
-
const file: string = path.resolve(declaration.getSourceFile().fileName);
|
|
31
|
-
if (file.indexOf(LIB_PATH) === -1 && file.indexOf(SRC_PATH) === -1)
|
|
32
|
-
return decorator;
|
|
33
|
-
|
|
34
|
-
//----
|
|
35
|
-
// TRANSFORMATION
|
|
36
|
-
//----
|
|
37
|
-
// FIND PROGRAMMER
|
|
38
|
-
const programmer: Programmer | undefined =
|
|
39
|
-
FUNCTORS[
|
|
40
|
-
getName(project.checker.getTypeAtLocation(declaration).symbol)
|
|
41
|
-
];
|
|
42
|
-
if (programmer === undefined) return decorator;
|
|
43
|
-
|
|
44
|
-
// GET TYPE INFO
|
|
45
|
-
const typeNode: ts.TypeNode | undefined = project.checker.typeToTypeNode(
|
|
46
|
-
type,
|
|
47
|
-
undefined,
|
|
48
|
-
undefined,
|
|
49
|
-
);
|
|
50
|
-
if (typeNode === undefined) return decorator;
|
|
51
|
-
|
|
52
|
-
// DO TRANSFORM
|
|
53
|
-
return ts.factory.createDecorator(
|
|
54
|
-
ts.factory.updateCallExpression(
|
|
55
|
-
decorator.expression,
|
|
56
|
-
decorator.expression.expression,
|
|
57
|
-
decorator.expression.typeArguments,
|
|
58
|
-
programmer(project)(decorator.expression.expression)(
|
|
59
|
-
decorator.expression.arguments,
|
|
60
|
-
)(type),
|
|
61
|
-
),
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type Programmer = (
|
|
67
|
-
project: INestiaTransformProject,
|
|
68
|
-
) => (
|
|
69
|
-
modulo: ts.LeftHandSideExpression,
|
|
70
|
-
) => (
|
|
71
|
-
parameters: readonly ts.Expression[],
|
|
72
|
-
) => (type: ts.Type) => readonly ts.Expression[];
|
|
73
|
-
|
|
74
|
-
const FUNCTORS: Record<string, Programmer> = {
|
|
75
|
-
EncryptedBody: (project) => (modulo) => (parameters) => (type) =>
|
|
76
|
-
parameters.length
|
|
77
|
-
? parameters
|
|
78
|
-
: [TypedBodyProgrammer.generate(project)(modulo)(type)],
|
|
79
|
-
TypedBody: (project) => (modulo) => (parameters) => (type) =>
|
|
80
|
-
parameters.length
|
|
81
|
-
? parameters
|
|
82
|
-
: [TypedBodyProgrammer.generate(project)(modulo)(type)],
|
|
83
|
-
TypedHeaders: (project) => (modulo) => (parameters) => (type) =>
|
|
84
|
-
parameters.length
|
|
85
|
-
? parameters
|
|
86
|
-
: [TypedHeadersProgrammer.generate(project)(modulo)(type)],
|
|
87
|
-
TypedParam: (project) => TypedParamProgrammer.generate(project),
|
|
88
|
-
TypedQuery: (project) => (modulo) => (parameters) => (type) =>
|
|
89
|
-
parameters.length
|
|
90
|
-
? parameters
|
|
91
|
-
: [TypedQueryProgrammer.generate(project)(modulo)(type)],
|
|
92
|
-
"TypedQuery.Body": (project) => (modulo) => (parameters) => (type) =>
|
|
93
|
-
parameters.length
|
|
94
|
-
? parameters
|
|
95
|
-
: [TypedQueryBodyProgrammer.generate(project)(modulo)(type)],
|
|
96
|
-
"TypedFormData.Body": (project) => (modulo) => (parameters) => (type) =>
|
|
97
|
-
parameters.length
|
|
98
|
-
? parameters
|
|
99
|
-
: [TypedFormDataBodyProgrammer.generate(project)(modulo)(type)],
|
|
100
|
-
PlainBody: (project) => (modulo) => (parameters) => (type) =>
|
|
101
|
-
parameters.length
|
|
102
|
-
? parameters
|
|
103
|
-
: [PlainBodyProgrammer.generate(project)(modulo)(type)],
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const LIB_PATH = path.join("@nestia", "core", "lib", "decorators");
|
|
107
|
-
const SRC_PATH = path.resolve(path.join(__dirname, "..", "decorators"));
|
|
108
|
-
|
|
109
|
-
const getName = (symbol: ts.Symbol): string => {
|
|
110
|
-
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
111
|
-
return parent ? exploreName(parent)(symbol.escapedName.toString()) : "__type";
|
|
112
|
-
};
|
|
113
|
-
const exploreName =
|
|
114
|
-
(decl: ts.Node) =>
|
|
115
|
-
(name: string): string =>
|
|
116
|
-
ts.isModuleBlock(decl)
|
|
117
|
-
? exploreName(decl.parent.parent)(
|
|
118
|
-
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
119
|
-
)
|
|
120
|
-
: name;
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
+
import { PlainBodyProgrammer } from "../programmers/PlainBodyProgrammer";
|
|
6
|
+
import { TypedBodyProgrammer } from "../programmers/TypedBodyProgrammer";
|
|
7
|
+
import { TypedFormDataBodyProgrammer } from "../programmers/TypedFormDataBodyProgrammer";
|
|
8
|
+
import { TypedHeadersProgrammer } from "../programmers/TypedHeadersProgrammer";
|
|
9
|
+
import { TypedParamProgrammer } from "../programmers/TypedParamProgrammer";
|
|
10
|
+
import { TypedQueryBodyProgrammer } from "../programmers/TypedQueryBodyProgrammer";
|
|
11
|
+
import { TypedQueryProgrammer } from "../programmers/TypedQueryProgrammer";
|
|
12
|
+
|
|
13
|
+
export namespace ParameterDecoratorTransformer {
|
|
14
|
+
export const transform =
|
|
15
|
+
(project: INestiaTransformProject) =>
|
|
16
|
+
(type: ts.Type) =>
|
|
17
|
+
(decorator: ts.Decorator): ts.Decorator => {
|
|
18
|
+
//----
|
|
19
|
+
// VALIDATIONS
|
|
20
|
+
//----
|
|
21
|
+
// CHECK DECORATOR
|
|
22
|
+
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
23
|
+
|
|
24
|
+
// SIGNATURE DECLARATION
|
|
25
|
+
const declaration: ts.Declaration | undefined =
|
|
26
|
+
project.checker.getResolvedSignature(decorator.expression)?.declaration;
|
|
27
|
+
if (declaration === undefined) return decorator;
|
|
28
|
+
|
|
29
|
+
// FILE PATH
|
|
30
|
+
const file: string = path.resolve(declaration.getSourceFile().fileName);
|
|
31
|
+
if (file.indexOf(LIB_PATH) === -1 && file.indexOf(SRC_PATH) === -1)
|
|
32
|
+
return decorator;
|
|
33
|
+
|
|
34
|
+
//----
|
|
35
|
+
// TRANSFORMATION
|
|
36
|
+
//----
|
|
37
|
+
// FIND PROGRAMMER
|
|
38
|
+
const programmer: Programmer | undefined =
|
|
39
|
+
FUNCTORS[
|
|
40
|
+
getName(project.checker.getTypeAtLocation(declaration).symbol)
|
|
41
|
+
];
|
|
42
|
+
if (programmer === undefined) return decorator;
|
|
43
|
+
|
|
44
|
+
// GET TYPE INFO
|
|
45
|
+
const typeNode: ts.TypeNode | undefined = project.checker.typeToTypeNode(
|
|
46
|
+
type,
|
|
47
|
+
undefined,
|
|
48
|
+
undefined,
|
|
49
|
+
);
|
|
50
|
+
if (typeNode === undefined) return decorator;
|
|
51
|
+
|
|
52
|
+
// DO TRANSFORM
|
|
53
|
+
return ts.factory.createDecorator(
|
|
54
|
+
ts.factory.updateCallExpression(
|
|
55
|
+
decorator.expression,
|
|
56
|
+
decorator.expression.expression,
|
|
57
|
+
decorator.expression.typeArguments,
|
|
58
|
+
programmer(project)(decorator.expression.expression)(
|
|
59
|
+
decorator.expression.arguments,
|
|
60
|
+
)(type),
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type Programmer = (
|
|
67
|
+
project: INestiaTransformProject,
|
|
68
|
+
) => (
|
|
69
|
+
modulo: ts.LeftHandSideExpression,
|
|
70
|
+
) => (
|
|
71
|
+
parameters: readonly ts.Expression[],
|
|
72
|
+
) => (type: ts.Type) => readonly ts.Expression[];
|
|
73
|
+
|
|
74
|
+
const FUNCTORS: Record<string, Programmer> = {
|
|
75
|
+
EncryptedBody: (project) => (modulo) => (parameters) => (type) =>
|
|
76
|
+
parameters.length
|
|
77
|
+
? parameters
|
|
78
|
+
: [TypedBodyProgrammer.generate(project)(modulo)(type)],
|
|
79
|
+
TypedBody: (project) => (modulo) => (parameters) => (type) =>
|
|
80
|
+
parameters.length
|
|
81
|
+
? parameters
|
|
82
|
+
: [TypedBodyProgrammer.generate(project)(modulo)(type)],
|
|
83
|
+
TypedHeaders: (project) => (modulo) => (parameters) => (type) =>
|
|
84
|
+
parameters.length
|
|
85
|
+
? parameters
|
|
86
|
+
: [TypedHeadersProgrammer.generate(project)(modulo)(type)],
|
|
87
|
+
TypedParam: (project) => TypedParamProgrammer.generate(project),
|
|
88
|
+
TypedQuery: (project) => (modulo) => (parameters) => (type) =>
|
|
89
|
+
parameters.length
|
|
90
|
+
? parameters
|
|
91
|
+
: [TypedQueryProgrammer.generate(project)(modulo)(type)],
|
|
92
|
+
"TypedQuery.Body": (project) => (modulo) => (parameters) => (type) =>
|
|
93
|
+
parameters.length
|
|
94
|
+
? parameters
|
|
95
|
+
: [TypedQueryBodyProgrammer.generate(project)(modulo)(type)],
|
|
96
|
+
"TypedFormData.Body": (project) => (modulo) => (parameters) => (type) =>
|
|
97
|
+
parameters.length
|
|
98
|
+
? parameters
|
|
99
|
+
: [TypedFormDataBodyProgrammer.generate(project)(modulo)(type)],
|
|
100
|
+
PlainBody: (project) => (modulo) => (parameters) => (type) =>
|
|
101
|
+
parameters.length
|
|
102
|
+
? parameters
|
|
103
|
+
: [PlainBodyProgrammer.generate(project)(modulo)(type)],
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const LIB_PATH = path.join("@nestia", "core", "lib", "decorators");
|
|
107
|
+
const SRC_PATH = path.resolve(path.join(__dirname, "..", "decorators"));
|
|
108
|
+
|
|
109
|
+
const getName = (symbol: ts.Symbol): string => {
|
|
110
|
+
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
111
|
+
return parent ? exploreName(parent)(symbol.escapedName.toString()) : "__type";
|
|
112
|
+
};
|
|
113
|
+
const exploreName =
|
|
114
|
+
(decl: ts.Node) =>
|
|
115
|
+
(name: string): string =>
|
|
116
|
+
ts.isModuleBlock(decl)
|
|
117
|
+
? exploreName(decl.parent.parent)(
|
|
118
|
+
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
119
|
+
)
|
|
120
|
+
: name;
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
-
import { TypedExceptionProgrammer } from "../programmers/TypedExceptionProgrammer";
|
|
6
|
-
|
|
7
|
-
export namespace TypedExceptionTransformer {
|
|
8
|
-
export const transform =
|
|
9
|
-
(project: INestiaTransformProject) =>
|
|
10
|
-
(decorator: ts.Decorator): ts.Decorator => {
|
|
11
|
-
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
12
|
-
|
|
13
|
-
// CHECK SIGNATURE
|
|
14
|
-
const signature: ts.Signature | undefined =
|
|
15
|
-
project.checker.getResolvedSignature(decorator.expression);
|
|
16
|
-
if (!signature || !signature.declaration) return decorator;
|
|
17
|
-
|
|
18
|
-
// CHECK TO BE TRANSFORMED
|
|
19
|
-
const done: boolean = (() => {
|
|
20
|
-
// CHECK FILENAME
|
|
21
|
-
const location: string = path.resolve(
|
|
22
|
-
signature.declaration.getSourceFile().fileName,
|
|
23
|
-
);
|
|
24
|
-
if (location.indexOf(LIB_PATH) === -1 && location !== SRC_PATH)
|
|
25
|
-
return false;
|
|
26
|
-
|
|
27
|
-
// CHECK DUPLICATED
|
|
28
|
-
return decorator.expression.arguments.length !== 3;
|
|
29
|
-
})();
|
|
30
|
-
if (done === false) return decorator;
|
|
31
|
-
|
|
32
|
-
// DO TRANSFORM
|
|
33
|
-
return ts.factory.createDecorator(
|
|
34
|
-
TypedExceptionProgrammer.generate(project)(decorator.expression),
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const LIB_PATH = path.join(
|
|
39
|
-
"@nestia",
|
|
40
|
-
"core",
|
|
41
|
-
"lib",
|
|
42
|
-
"decorators",
|
|
43
|
-
`TypedException.d.ts`,
|
|
44
|
-
);
|
|
45
|
-
const SRC_PATH = path.resolve(
|
|
46
|
-
path.join(__dirname, "..", "decorators", `TypedException.ts`),
|
|
47
|
-
);
|
|
48
|
-
}
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
+
import { TypedExceptionProgrammer } from "../programmers/TypedExceptionProgrammer";
|
|
6
|
+
|
|
7
|
+
export namespace TypedExceptionTransformer {
|
|
8
|
+
export const transform =
|
|
9
|
+
(project: INestiaTransformProject) =>
|
|
10
|
+
(decorator: ts.Decorator): ts.Decorator => {
|
|
11
|
+
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
12
|
+
|
|
13
|
+
// CHECK SIGNATURE
|
|
14
|
+
const signature: ts.Signature | undefined =
|
|
15
|
+
project.checker.getResolvedSignature(decorator.expression);
|
|
16
|
+
if (!signature || !signature.declaration) return decorator;
|
|
17
|
+
|
|
18
|
+
// CHECK TO BE TRANSFORMED
|
|
19
|
+
const done: boolean = (() => {
|
|
20
|
+
// CHECK FILENAME
|
|
21
|
+
const location: string = path.resolve(
|
|
22
|
+
signature.declaration.getSourceFile().fileName,
|
|
23
|
+
);
|
|
24
|
+
if (location.indexOf(LIB_PATH) === -1 && location !== SRC_PATH)
|
|
25
|
+
return false;
|
|
26
|
+
|
|
27
|
+
// CHECK DUPLICATED
|
|
28
|
+
return decorator.expression.arguments.length !== 3;
|
|
29
|
+
})();
|
|
30
|
+
if (done === false) return decorator;
|
|
31
|
+
|
|
32
|
+
// DO TRANSFORM
|
|
33
|
+
return ts.factory.createDecorator(
|
|
34
|
+
TypedExceptionProgrammer.generate(project)(decorator.expression),
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const LIB_PATH = path.join(
|
|
39
|
+
"@nestia",
|
|
40
|
+
"core",
|
|
41
|
+
"lib",
|
|
42
|
+
"decorators",
|
|
43
|
+
`TypedException.d.ts`,
|
|
44
|
+
);
|
|
45
|
+
const SRC_PATH = path.resolve(
|
|
46
|
+
path.join(__dirname, "..", "decorators", `TypedException.ts`),
|
|
47
|
+
);
|
|
48
|
+
}
|