@nestia/core 0.1.3 → 0.1.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/lib/decorators/DynamicModule.d.ts +3 -0
- package/lib/decorators/DynamicModule.js +73 -0
- package/lib/decorators/DynamicModule.js.map +1 -0
- package/lib/decorators/EncryptedModule.js +16 -137
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +1 -0
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/headers_to_object.d.ts +3 -1
- package/lib/decorators/internal/headers_to_object.js +0 -3
- package/lib/decorators/internal/headers_to_object.js.map +1 -1
- package/lib/decorators/internal/load_controller.d.ts +2 -0
- package/lib/decorators/internal/load_controller.js +153 -0
- package/lib/decorators/internal/load_controller.js.map +1 -0
- package/lib/decorators/internal/route_error.d.ts +3 -1
- package/lib/decorators/internal/route_error.js +0 -3
- package/lib/decorators/internal/route_error.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +1 -0
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +2 -0
- package/lib/module.js.map +1 -1
- package/lib/transformers/RouteTransformer.js +3 -4
- package/lib/transformers/RouteTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/decorators/DynamicModule.ts +16 -0
- package/src/decorators/EncryptedBody.ts +102 -102
- package/src/decorators/EncryptedController.ts +43 -43
- package/src/decorators/EncryptedModule.ts +77 -127
- package/src/decorators/EncryptedRoute.ts +203 -203
- package/src/decorators/PlainBody.ts +38 -38
- package/src/decorators/TypedBody.ts +49 -49
- package/src/decorators/TypedParam.ts +70 -70
- package/src/decorators/TypedRoute.ts +149 -149
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/get_path_and_stringify.ts +77 -76
- package/src/decorators/internal/headers_to_object.ts +10 -13
- package/src/decorators/internal/load_controller.ts +35 -0
- package/src/decorators/internal/route_error.ts +38 -41
- package/src/decorators/internal/validate_request_body.ts +59 -58
- package/src/index.ts +5 -5
- package/src/module.ts +11 -9
- package/src/options/INestiaTransformOptions.ts +6 -6
- package/src/options/INestiaTransformProject.ts +7 -6
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IResponseBodyStringifier.ts +25 -25
- package/src/transform.ts +20 -20
- package/src/transformers/BodyTransformer.ts +106 -106
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/MethodTransformer.ts +91 -91
- package/src/transformers/NodeTransformer.ts +18 -18
- package/src/transformers/ParameterTransformer.ts +45 -45
- package/src/transformers/RouteTransformer.ts +131 -134
- package/src/typings/Creator.ts +3 -3
- package/src/utils/ExceptionManager.ts +126 -126
- package/src/utils/Singleton.ts +20 -20
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
-
import { NodeTransformer } from "./NodeTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace FileTransformer {
|
|
7
|
-
export function transform(
|
|
8
|
-
project: INestiaTransformProject,
|
|
9
|
-
context: ts.TransformationContext,
|
|
10
|
-
file: ts.SourceFile,
|
|
11
|
-
): ts.SourceFile {
|
|
12
|
-
// ITERATE NODES
|
|
13
|
-
return ts.visitEachChild(
|
|
14
|
-
file,
|
|
15
|
-
(node) => iterate_node(project, context, node),
|
|
16
|
-
context,
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function iterate_node(
|
|
21
|
-
project: INestiaTransformProject,
|
|
22
|
-
context: ts.TransformationContext,
|
|
23
|
-
node: ts.Node,
|
|
24
|
-
): ts.Node {
|
|
25
|
-
return ts.visitEachChild(
|
|
26
|
-
try_transform_node(project, node),
|
|
27
|
-
(child) => iterate_node(project, context, child),
|
|
28
|
-
context,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function try_transform_node(
|
|
33
|
-
project: INestiaTransformProject,
|
|
34
|
-
node: ts.Node,
|
|
35
|
-
): ts.Node {
|
|
36
|
-
try {
|
|
37
|
-
return NodeTransformer.transform(project, node);
|
|
38
|
-
} catch (exp) {
|
|
39
|
-
if (!(exp instanceof Error)) throw exp;
|
|
40
|
-
|
|
41
|
-
const file: ts.SourceFile = node.getSourceFile();
|
|
42
|
-
const { line, character } = file.getLineAndCharacterOfPosition(
|
|
43
|
-
node.pos,
|
|
44
|
-
);
|
|
45
|
-
exp.message += ` - ${file.fileName}.${line + 1}:${character + 1}`;
|
|
46
|
-
throw exp;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
+
import { NodeTransformer } from "./NodeTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace FileTransformer {
|
|
7
|
+
export function transform(
|
|
8
|
+
project: INestiaTransformProject,
|
|
9
|
+
context: ts.TransformationContext,
|
|
10
|
+
file: ts.SourceFile,
|
|
11
|
+
): ts.SourceFile {
|
|
12
|
+
// ITERATE NODES
|
|
13
|
+
return ts.visitEachChild(
|
|
14
|
+
file,
|
|
15
|
+
(node) => iterate_node(project, context, node),
|
|
16
|
+
context,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function iterate_node(
|
|
21
|
+
project: INestiaTransformProject,
|
|
22
|
+
context: ts.TransformationContext,
|
|
23
|
+
node: ts.Node,
|
|
24
|
+
): ts.Node {
|
|
25
|
+
return ts.visitEachChild(
|
|
26
|
+
try_transform_node(project, node),
|
|
27
|
+
(child) => iterate_node(project, context, child),
|
|
28
|
+
context,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function try_transform_node(
|
|
33
|
+
project: INestiaTransformProject,
|
|
34
|
+
node: ts.Node,
|
|
35
|
+
): ts.Node {
|
|
36
|
+
try {
|
|
37
|
+
return NodeTransformer.transform(project, node);
|
|
38
|
+
} catch (exp) {
|
|
39
|
+
if (!(exp instanceof Error)) throw exp;
|
|
40
|
+
|
|
41
|
+
const file: ts.SourceFile = node.getSourceFile();
|
|
42
|
+
const { line, character } = file.getLineAndCharacterOfPosition(
|
|
43
|
+
node.pos,
|
|
44
|
+
);
|
|
45
|
+
exp.message += ` - ${file.fileName}.${line + 1}:${character + 1}`;
|
|
46
|
+
throw exp;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
-
import { RouteTransformer } from "./RouteTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace MethodTransformer {
|
|
7
|
-
export function transform(
|
|
8
|
-
project: INestiaTransformProject,
|
|
9
|
-
method: ts.MethodDeclaration,
|
|
10
|
-
): ts.MethodDeclaration {
|
|
11
|
-
const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
|
|
12
|
-
? ts.getDecorators(method)
|
|
13
|
-
: (method as any).decorators;
|
|
14
|
-
if (!decorators?.length) return method;
|
|
15
|
-
|
|
16
|
-
const signature: ts.Signature | undefined =
|
|
17
|
-
project.checker.getSignatureFromDeclaration(method);
|
|
18
|
-
const original: ts.Type | undefined =
|
|
19
|
-
signature && project.checker.getReturnTypeOfSignature(signature);
|
|
20
|
-
const escaped: ts.Type | undefined =
|
|
21
|
-
original && get_escaped_type(project.checker, original);
|
|
22
|
-
|
|
23
|
-
if (escaped === undefined) return method;
|
|
24
|
-
|
|
25
|
-
if (ts.getDecorators !== undefined)
|
|
26
|
-
return ts.factory.updateMethodDeclaration(
|
|
27
|
-
method,
|
|
28
|
-
(method.modifiers || []).map((mod) =>
|
|
29
|
-
ts.isDecorator(mod)
|
|
30
|
-
? RouteTransformer.transform(project, escaped, mod)
|
|
31
|
-
: mod,
|
|
32
|
-
),
|
|
33
|
-
method.asteriskToken,
|
|
34
|
-
method.name,
|
|
35
|
-
method.questionToken,
|
|
36
|
-
method.typeParameters,
|
|
37
|
-
method.parameters,
|
|
38
|
-
method.type,
|
|
39
|
-
method.body,
|
|
40
|
-
);
|
|
41
|
-
// eslint-disable-next-line
|
|
42
|
-
return ts.factory.updateMethodDeclaration(
|
|
43
|
-
method,
|
|
44
|
-
decorators.map((deco) =>
|
|
45
|
-
RouteTransformer.transform(project, escaped, deco),
|
|
46
|
-
),
|
|
47
|
-
(method as any).modifiers,
|
|
48
|
-
method.asteriskToken,
|
|
49
|
-
method.name,
|
|
50
|
-
method.questionToken,
|
|
51
|
-
method.typeParameters,
|
|
52
|
-
method.parameters,
|
|
53
|
-
method.type,
|
|
54
|
-
method.body,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function get_escaped_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
60
|
-
const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
|
|
61
|
-
return symbol && get_name(symbol) === "Promise"
|
|
62
|
-
? escape_promise(checker, type)
|
|
63
|
-
: type;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
67
|
-
const generic: readonly ts.Type[] = checker.getTypeArguments(
|
|
68
|
-
type as ts.TypeReference,
|
|
69
|
-
);
|
|
70
|
-
if (generic.length !== 1)
|
|
71
|
-
throw new Error(
|
|
72
|
-
"Error on ImportAnalyzer.analyze(): invalid promise type.",
|
|
73
|
-
);
|
|
74
|
-
return generic[0];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function get_name(symbol: ts.Symbol): string {
|
|
78
|
-
return explore_name(
|
|
79
|
-
symbol.escapedName.toString(),
|
|
80
|
-
symbol.getDeclarations()![0].parent,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function explore_name(name: string, decl: ts.Node): string {
|
|
85
|
-
return ts.isModuleBlock(decl)
|
|
86
|
-
? explore_name(
|
|
87
|
-
`${decl.parent.name.getText()}.${name}`,
|
|
88
|
-
decl.parent.parent,
|
|
89
|
-
)
|
|
90
|
-
: name;
|
|
91
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
+
import { RouteTransformer } from "./RouteTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace MethodTransformer {
|
|
7
|
+
export function transform(
|
|
8
|
+
project: INestiaTransformProject,
|
|
9
|
+
method: ts.MethodDeclaration,
|
|
10
|
+
): ts.MethodDeclaration {
|
|
11
|
+
const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
|
|
12
|
+
? ts.getDecorators(method)
|
|
13
|
+
: (method as any).decorators;
|
|
14
|
+
if (!decorators?.length) return method;
|
|
15
|
+
|
|
16
|
+
const signature: ts.Signature | undefined =
|
|
17
|
+
project.checker.getSignatureFromDeclaration(method);
|
|
18
|
+
const original: ts.Type | undefined =
|
|
19
|
+
signature && project.checker.getReturnTypeOfSignature(signature);
|
|
20
|
+
const escaped: ts.Type | undefined =
|
|
21
|
+
original && get_escaped_type(project.checker, original);
|
|
22
|
+
|
|
23
|
+
if (escaped === undefined) return method;
|
|
24
|
+
|
|
25
|
+
if (ts.getDecorators !== undefined)
|
|
26
|
+
return ts.factory.updateMethodDeclaration(
|
|
27
|
+
method,
|
|
28
|
+
(method.modifiers || []).map((mod) =>
|
|
29
|
+
ts.isDecorator(mod)
|
|
30
|
+
? RouteTransformer.transform(project, escaped, mod)
|
|
31
|
+
: mod,
|
|
32
|
+
),
|
|
33
|
+
method.asteriskToken,
|
|
34
|
+
method.name,
|
|
35
|
+
method.questionToken,
|
|
36
|
+
method.typeParameters,
|
|
37
|
+
method.parameters,
|
|
38
|
+
method.type,
|
|
39
|
+
method.body,
|
|
40
|
+
);
|
|
41
|
+
// eslint-disable-next-line
|
|
42
|
+
return ts.factory.updateMethodDeclaration(
|
|
43
|
+
method,
|
|
44
|
+
decorators.map((deco) =>
|
|
45
|
+
RouteTransformer.transform(project, escaped, deco),
|
|
46
|
+
),
|
|
47
|
+
(method as any).modifiers,
|
|
48
|
+
method.asteriskToken,
|
|
49
|
+
method.name,
|
|
50
|
+
method.questionToken,
|
|
51
|
+
method.typeParameters,
|
|
52
|
+
method.parameters,
|
|
53
|
+
method.type,
|
|
54
|
+
method.body,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function get_escaped_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
60
|
+
const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
|
|
61
|
+
return symbol && get_name(symbol) === "Promise"
|
|
62
|
+
? escape_promise(checker, type)
|
|
63
|
+
: type;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
|
|
67
|
+
const generic: readonly ts.Type[] = checker.getTypeArguments(
|
|
68
|
+
type as ts.TypeReference,
|
|
69
|
+
);
|
|
70
|
+
if (generic.length !== 1)
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Error on ImportAnalyzer.analyze(): invalid promise type.",
|
|
73
|
+
);
|
|
74
|
+
return generic[0];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function get_name(symbol: ts.Symbol): string {
|
|
78
|
+
return explore_name(
|
|
79
|
+
symbol.escapedName.toString(),
|
|
80
|
+
symbol.getDeclarations()![0].parent,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function explore_name(name: string, decl: ts.Node): string {
|
|
85
|
+
return ts.isModuleBlock(decl)
|
|
86
|
+
? explore_name(
|
|
87
|
+
`${decl.parent.name.getText()}.${name}`,
|
|
88
|
+
decl.parent.parent,
|
|
89
|
+
)
|
|
90
|
+
: name;
|
|
91
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
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 function transform(
|
|
9
|
-
project: INestiaTransformProject,
|
|
10
|
-
node: ts.Node,
|
|
11
|
-
): ts.Node {
|
|
12
|
-
if (ts.isMethodDeclaration(node))
|
|
13
|
-
return MethodTransformer.transform(project, node);
|
|
14
|
-
else if (ts.isParameter(node))
|
|
15
|
-
return ParameterTransformer.transform(project, node);
|
|
16
|
-
return node;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
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 function transform(
|
|
9
|
+
project: INestiaTransformProject,
|
|
10
|
+
node: ts.Node,
|
|
11
|
+
): ts.Node {
|
|
12
|
+
if (ts.isMethodDeclaration(node))
|
|
13
|
+
return MethodTransformer.transform(project, node);
|
|
14
|
+
else if (ts.isParameter(node))
|
|
15
|
+
return ParameterTransformer.transform(project, node);
|
|
16
|
+
return node;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
-
import { BodyTransformer } from "./BodyTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace ParameterTransformer {
|
|
7
|
-
export function transform(
|
|
8
|
-
project: INestiaTransformProject,
|
|
9
|
-
param: ts.ParameterDeclaration,
|
|
10
|
-
): ts.ParameterDeclaration {
|
|
11
|
-
const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
|
|
12
|
-
? ts.getDecorators(param)
|
|
13
|
-
: (param as any).decorators;
|
|
14
|
-
if (!decorators?.length) return param;
|
|
15
|
-
|
|
16
|
-
const type: ts.Type = project.checker.getTypeAtLocation(param);
|
|
17
|
-
if (ts.getDecorators !== undefined)
|
|
18
|
-
return ts.factory.updateParameterDeclaration(
|
|
19
|
-
param,
|
|
20
|
-
(param.modifiers || []).map((mod) =>
|
|
21
|
-
ts.isDecorator(mod)
|
|
22
|
-
? BodyTransformer.transform(project, type, mod)
|
|
23
|
-
: mod,
|
|
24
|
-
),
|
|
25
|
-
param.dotDotDotToken,
|
|
26
|
-
param.name,
|
|
27
|
-
param.questionToken,
|
|
28
|
-
param.type,
|
|
29
|
-
param.initializer,
|
|
30
|
-
);
|
|
31
|
-
// eslint-disable-next-line
|
|
32
|
-
return ts.factory.updateParameterDeclaration(
|
|
33
|
-
param,
|
|
34
|
-
decorators.map((deco) =>
|
|
35
|
-
BodyTransformer.transform(project, type, deco),
|
|
36
|
-
),
|
|
37
|
-
(param as any).modifiers,
|
|
38
|
-
param.dotDotDotToken,
|
|
39
|
-
param.name,
|
|
40
|
-
param.questionToken,
|
|
41
|
-
param.type,
|
|
42
|
-
param.initializer,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
4
|
+
import { BodyTransformer } from "./BodyTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace ParameterTransformer {
|
|
7
|
+
export function transform(
|
|
8
|
+
project: INestiaTransformProject,
|
|
9
|
+
param: ts.ParameterDeclaration,
|
|
10
|
+
): ts.ParameterDeclaration {
|
|
11
|
+
const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
|
|
12
|
+
? ts.getDecorators(param)
|
|
13
|
+
: (param as any).decorators;
|
|
14
|
+
if (!decorators?.length) return param;
|
|
15
|
+
|
|
16
|
+
const type: ts.Type = project.checker.getTypeAtLocation(param);
|
|
17
|
+
if (ts.getDecorators !== undefined)
|
|
18
|
+
return ts.factory.updateParameterDeclaration(
|
|
19
|
+
param,
|
|
20
|
+
(param.modifiers || []).map((mod) =>
|
|
21
|
+
ts.isDecorator(mod)
|
|
22
|
+
? BodyTransformer.transform(project, type, mod)
|
|
23
|
+
: mod,
|
|
24
|
+
),
|
|
25
|
+
param.dotDotDotToken,
|
|
26
|
+
param.name,
|
|
27
|
+
param.questionToken,
|
|
28
|
+
param.type,
|
|
29
|
+
param.initializer,
|
|
30
|
+
);
|
|
31
|
+
// eslint-disable-next-line
|
|
32
|
+
return ts.factory.updateParameterDeclaration(
|
|
33
|
+
param,
|
|
34
|
+
decorators.map((deco) =>
|
|
35
|
+
BodyTransformer.transform(project, type, deco),
|
|
36
|
+
),
|
|
37
|
+
(param as any).modifiers,
|
|
38
|
+
param.dotDotDotToken,
|
|
39
|
+
param.name,
|
|
40
|
+
param.questionToken,
|
|
41
|
+
param.type,
|
|
42
|
+
param.initializer,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|