@nestia/core 2.1.8 → 2.2.0-dev.20231010
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/TypedQuery.d.ts +59 -0
- package/lib/decorators/TypedQuery.js +220 -0
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/internal/get_path_and_querify.d.ts +1 -0
- package/lib/decorators/internal/get_path_and_querify.js +164 -0
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -0
- package/lib/options/IResponseBodyQuerifier.d.ts +20 -0
- package/lib/options/IResponseBodyQuerifier.js +3 -0
- package/lib/options/IResponseBodyQuerifier.js.map +1 -0
- package/lib/programmers/TypedQueryBodyProgrammer.d.ts +5 -0
- package/lib/programmers/TypedQueryBodyProgrammer.js +51 -0
- package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -0
- package/lib/programmers/TypedQueryRouteProgrammer.d.ts +5 -0
- package/lib/programmers/TypedQueryRouteProgrammer.js +50 -0
- package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js +39 -0
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpIsQuerifyProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js +37 -0
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpQuerifyProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpQuerifyProgrammer.js +80 -0
- package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js +38 -0
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +1 -0
- package/lib/transformers/ParameterDecoratorTransformer.js +21 -1
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/lib/transformers/TypedRouteTransformer.js +13 -6
- package/lib/transformers/TypedRouteTransformer.js.map +1 -1
- package/package.json +13 -13
- package/src/decorators/TypedQuery.ts +197 -1
- package/src/decorators/internal/get_path_and_querify.ts +104 -0
- package/src/options/IResponseBodyQuerifier.ts +25 -0
- package/src/programmers/TypedQueryBodyProgrammer.ts +52 -0
- package/src/programmers/TypedQueryRouteProgrammer.ts +55 -0
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +59 -0
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +63 -0
- package/src/programmers/http/HttpQuerifyProgrammer.ts +105 -0
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +64 -0
- package/src/transformers/ParameterDecoratorTransformer.ts +23 -1
- package/src/transformers/TypedRouteTransformer.ts +15 -8
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "typia/lib/factories/StatementFactory";
|
|
5
|
+
import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
|
|
6
|
+
import { IProject } from "typia/lib/transformers/IProject";
|
|
7
|
+
|
|
8
|
+
import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
|
|
9
|
+
|
|
10
|
+
export namespace HttpValidateQuerifyProgrammer {
|
|
11
|
+
export const write =
|
|
12
|
+
(project: IProject) =>
|
|
13
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
14
|
+
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
15
|
+
ts.factory.createArrowFunction(
|
|
16
|
+
undefined,
|
|
17
|
+
undefined,
|
|
18
|
+
[IdentifierFactory.parameter("input")],
|
|
19
|
+
undefined,
|
|
20
|
+
undefined,
|
|
21
|
+
ts.factory.createBlock([
|
|
22
|
+
StatementFactory.constant(
|
|
23
|
+
"validate",
|
|
24
|
+
ValidateProgrammer.write({
|
|
25
|
+
...project,
|
|
26
|
+
options: {
|
|
27
|
+
...project.options,
|
|
28
|
+
functional: false,
|
|
29
|
+
numeric: true,
|
|
30
|
+
},
|
|
31
|
+
})(modulo)(false)(type, name),
|
|
32
|
+
),
|
|
33
|
+
StatementFactory.constant(
|
|
34
|
+
"query",
|
|
35
|
+
HttpQuerifyProgrammer.write({
|
|
36
|
+
...project,
|
|
37
|
+
options: {
|
|
38
|
+
...project.options,
|
|
39
|
+
functional: false,
|
|
40
|
+
numeric: false,
|
|
41
|
+
},
|
|
42
|
+
})(modulo)(type),
|
|
43
|
+
),
|
|
44
|
+
StatementFactory.constant(
|
|
45
|
+
"output",
|
|
46
|
+
ts.factory.createCallExpression(
|
|
47
|
+
ts.factory.createIdentifier("query"),
|
|
48
|
+
undefined,
|
|
49
|
+
[ts.factory.createIdentifier("input")],
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
ts.factory.createReturnStatement(
|
|
53
|
+
ts.factory.createAsExpression(
|
|
54
|
+
ts.factory.createCallExpression(
|
|
55
|
+
ts.factory.createIdentifier("validate"),
|
|
56
|
+
undefined,
|
|
57
|
+
[ts.factory.createIdentifier("output")],
|
|
58
|
+
),
|
|
59
|
+
ts.factory.createTypeReferenceNode("any"),
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
]),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -6,6 +6,7 @@ import { PlainBodyProgrammer } from "../programmers/PlainBodyProgrammer";
|
|
|
6
6
|
import { TypedBodyProgrammer } from "../programmers/TypedBodyProgrammer";
|
|
7
7
|
import { TypedHeadersProgrammer } from "../programmers/TypedHeadersProgrammer";
|
|
8
8
|
import { TypedParamProgrammer } from "../programmers/TypedParamProgrammer";
|
|
9
|
+
import { TypedQueryBodyProgrammer } from "../programmers/TypedQueryBodyProgrammer";
|
|
9
10
|
import { TypedQueryProgrammer } from "../programmers/TypedQueryProgrammer";
|
|
10
11
|
|
|
11
12
|
export namespace ParameterDecoratorTransformer {
|
|
@@ -39,7 +40,9 @@ export namespace ParameterDecoratorTransformer {
|
|
|
39
40
|
// FIND PROGRAMMER
|
|
40
41
|
const programmer: Programmer | undefined =
|
|
41
42
|
FUNCTORS[
|
|
42
|
-
|
|
43
|
+
getName(
|
|
44
|
+
project.checker.getTypeAtLocation(declaration).symbol,
|
|
45
|
+
)
|
|
43
46
|
];
|
|
44
47
|
if (programmer === undefined) return decorator;
|
|
45
48
|
|
|
@@ -88,6 +91,10 @@ const FUNCTORS: Record<string, Programmer> = {
|
|
|
88
91
|
parameters.length
|
|
89
92
|
? parameters
|
|
90
93
|
: [TypedQueryProgrammer.generate(project)(modulo)(type)],
|
|
94
|
+
"TypedQuery.Body": (project) => (modulo) => (parameters) => (type) =>
|
|
95
|
+
parameters.length
|
|
96
|
+
? parameters
|
|
97
|
+
: [TypedQueryBodyProgrammer.generate(project)(modulo)(type)],
|
|
91
98
|
PlainBody: (project) => (modulo) => (parameters) => (type) =>
|
|
92
99
|
parameters.length
|
|
93
100
|
? parameters
|
|
@@ -102,3 +109,18 @@ const LIB_PATH = path.join(
|
|
|
102
109
|
"decorators",
|
|
103
110
|
);
|
|
104
111
|
const SRC_PATH = path.resolve(path.join(__dirname, "..", "decorators"));
|
|
112
|
+
|
|
113
|
+
const getName = (symbol: ts.Symbol): string => {
|
|
114
|
+
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
115
|
+
return parent
|
|
116
|
+
? exploreName(parent)(symbol.escapedName.toString())
|
|
117
|
+
: "__type";
|
|
118
|
+
};
|
|
119
|
+
const exploreName =
|
|
120
|
+
(decl: ts.Node) =>
|
|
121
|
+
(name: string): string =>
|
|
122
|
+
ts.isModuleBlock(decl)
|
|
123
|
+
? exploreName(decl.parent.parent)(
|
|
124
|
+
`${decl.parent.name.getFullText().trim()}.${name}`,
|
|
125
|
+
)
|
|
126
|
+
: name;
|
|
@@ -2,6 +2,7 @@ import path from "path";
|
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
|
|
4
4
|
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
+
import { TypedQueryRouteProgrammer } from "../programmers/TypedQueryRouteProgrammer";
|
|
5
6
|
import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
|
|
6
7
|
|
|
7
8
|
export namespace TypedRouteTransformer {
|
|
@@ -17,7 +18,7 @@ export namespace TypedRouteTransformer {
|
|
|
17
18
|
if (!signature || !signature.declaration) return decorator;
|
|
18
19
|
|
|
19
20
|
// CHECK TO BE TRANSFORMED
|
|
20
|
-
const
|
|
21
|
+
const modulo = (() => {
|
|
21
22
|
// CHECK FILENAME
|
|
22
23
|
const location: string = path.resolve(
|
|
23
24
|
signature.declaration.getSourceFile().fileName,
|
|
@@ -26,7 +27,7 @@ export namespace TypedRouteTransformer {
|
|
|
26
27
|
LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
|
|
27
28
|
SRC_PATHS.every((str) => location !== str)
|
|
28
29
|
)
|
|
29
|
-
return
|
|
30
|
+
return null;
|
|
30
31
|
|
|
31
32
|
// CHECK DUPLICATE BOOSTER
|
|
32
33
|
if (decorator.expression.arguments.length >= 2) return false;
|
|
@@ -39,9 +40,12 @@ export namespace TypedRouteTransformer {
|
|
|
39
40
|
project.checker.getTypeAtLocation(last);
|
|
40
41
|
if (isObject(project.checker)(type)) return false;
|
|
41
42
|
}
|
|
42
|
-
return
|
|
43
|
+
return location.split(path.sep).at(-1)?.split(".")[0] ===
|
|
44
|
+
"TypedQuery"
|
|
45
|
+
? "TypedQuery"
|
|
46
|
+
: "TypedRoute";
|
|
43
47
|
})();
|
|
44
|
-
if (
|
|
48
|
+
if (modulo === null) return decorator;
|
|
45
49
|
|
|
46
50
|
// CHECK TYPE NODE
|
|
47
51
|
const typeNode: ts.TypeNode | undefined =
|
|
@@ -56,9 +60,12 @@ export namespace TypedRouteTransformer {
|
|
|
56
60
|
decorator.expression.typeArguments,
|
|
57
61
|
[
|
|
58
62
|
...decorator.expression.arguments,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
(modulo === "TypedQuery"
|
|
64
|
+
? TypedQueryRouteProgrammer
|
|
65
|
+
: TypedRouteProgrammer
|
|
66
|
+
).generate(project)(decorator.expression.expression)(
|
|
67
|
+
type,
|
|
68
|
+
),
|
|
62
69
|
],
|
|
63
70
|
),
|
|
64
71
|
);
|
|
@@ -72,7 +79,7 @@ export namespace TypedRouteTransformer {
|
|
|
72
79
|
!(checker as any).isArrayType(type) &&
|
|
73
80
|
!(checker as any).isArrayLikeType(type);
|
|
74
81
|
|
|
75
|
-
const CLASSES = ["EncryptedRoute", "TypedRoute"];
|
|
82
|
+
const CLASSES = ["EncryptedRoute", "TypedRoute", "TypedQuery"];
|
|
76
83
|
const LIB_PATHS = CLASSES.map((cla) =>
|
|
77
84
|
path.join(
|
|
78
85
|
"node_modules",
|