@nestia/core 2.2.0-dev.20231008 → 2.2.0

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.
Files changed (36) hide show
  1. package/lib/decorators/TypedQuery.d.ts +56 -0
  2. package/lib/decorators/TypedQuery.js +164 -0
  3. package/lib/decorators/TypedQuery.js.map +1 -1
  4. package/lib/decorators/internal/get_path_and_querify.d.ts +1 -0
  5. package/lib/decorators/internal/get_path_and_querify.js +164 -0
  6. package/lib/decorators/internal/get_path_and_querify.js.map +1 -0
  7. package/lib/options/IResponseBodyQuerifier.d.ts +20 -0
  8. package/lib/options/IResponseBodyQuerifier.js +3 -0
  9. package/lib/options/IResponseBodyQuerifier.js.map +1 -0
  10. package/lib/programmers/TypedQueryRouteProgrammer.d.ts +5 -0
  11. package/lib/programmers/TypedQueryRouteProgrammer.js +50 -0
  12. package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -0
  13. package/lib/programmers/http/HttpAssertQuerifyProgrammer.d.ts +5 -0
  14. package/lib/programmers/http/HttpAssertQuerifyProgrammer.js +39 -0
  15. package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +1 -0
  16. package/lib/programmers/http/HttpIsQuerifyProgrammer.d.ts +5 -0
  17. package/lib/programmers/http/HttpIsQuerifyProgrammer.js +37 -0
  18. package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +1 -0
  19. package/lib/programmers/http/HttpQuerifyProgrammer.d.ts +5 -0
  20. package/lib/programmers/http/HttpQuerifyProgrammer.js +80 -0
  21. package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -0
  22. package/lib/programmers/http/HttpValidateQuerifyProgrammer.d.ts +5 -0
  23. package/lib/programmers/http/HttpValidateQuerifyProgrammer.js +38 -0
  24. package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +1 -0
  25. package/lib/transformers/TypedRouteTransformer.js +13 -6
  26. package/lib/transformers/TypedRouteTransformer.js.map +1 -1
  27. package/package.json +11 -11
  28. package/src/decorators/TypedQuery.ts +126 -0
  29. package/src/decorators/internal/get_path_and_querify.ts +104 -0
  30. package/src/options/IResponseBodyQuerifier.ts +25 -0
  31. package/src/programmers/TypedQueryRouteProgrammer.ts +55 -0
  32. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +59 -0
  33. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +63 -0
  34. package/src/programmers/http/HttpQuerifyProgrammer.ts +105 -0
  35. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +64 -0
  36. package/src/transformers/TypedRouteTransformer.ts +15 -8
@@ -0,0 +1,59 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+ import { StatementFactory } from "typia/lib/factories/StatementFactory";
5
+ import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
6
+ import { IProject } from "typia/lib/transformers/IProject";
7
+
8
+ import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
9
+
10
+ export namespace HttpAssertQuerifyProgrammer {
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
+ "assert",
24
+ AssertProgrammer.write({
25
+ ...project,
26
+ options: {
27
+ ...project.options,
28
+ functional: false,
29
+ numeric: false,
30
+ },
31
+ })(modulo)(false)(type, name),
32
+ ),
33
+ StatementFactory.constant(
34
+ "stringify",
35
+ HttpQuerifyProgrammer.write({
36
+ ...project,
37
+ options: {
38
+ ...project.options,
39
+ functional: false,
40
+ numeric: false,
41
+ },
42
+ })(modulo)(type),
43
+ ),
44
+ ts.factory.createReturnStatement(
45
+ ts.factory.createCallExpression(
46
+ ts.factory.createIdentifier("stringify"),
47
+ undefined,
48
+ [
49
+ ts.factory.createCallExpression(
50
+ ts.factory.createIdentifier("assert"),
51
+ undefined,
52
+ [ts.factory.createIdentifier("input")],
53
+ ),
54
+ ],
55
+ ),
56
+ ),
57
+ ]),
58
+ );
59
+ }
@@ -0,0 +1,63 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+ import { StatementFactory } from "typia/lib/factories/StatementFactory";
5
+ import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
6
+ import { IProject } from "typia/lib/transformers/IProject";
7
+
8
+ import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
9
+
10
+ export namespace HttpIsQuerifyProgrammer {
11
+ export const write =
12
+ (project: IProject) =>
13
+ (modulo: ts.LeftHandSideExpression) =>
14
+ (type: ts.Type): 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
+ "is",
24
+ IsProgrammer.write({
25
+ ...project,
26
+ options: {
27
+ ...project.options,
28
+ functional: false,
29
+ numeric: false,
30
+ },
31
+ })(modulo)(false)(type),
32
+ ),
33
+ StatementFactory.constant(
34
+ "stringify",
35
+ HttpQuerifyProgrammer.write({
36
+ ...project,
37
+ options: {
38
+ ...project.options,
39
+ functional: false,
40
+ numeric: false,
41
+ },
42
+ })(modulo)(type),
43
+ ),
44
+ ts.factory.createReturnStatement(
45
+ ts.factory.createConditionalExpression(
46
+ ts.factory.createCallExpression(
47
+ ts.factory.createIdentifier("is"),
48
+ undefined,
49
+ [ts.factory.createIdentifier("input")],
50
+ ),
51
+ undefined,
52
+ ts.factory.createCallExpression(
53
+ ts.factory.createIdentifier("stringify"),
54
+ undefined,
55
+ [ts.factory.createIdentifier("input")],
56
+ ),
57
+ undefined,
58
+ ts.factory.createNull(),
59
+ ),
60
+ ),
61
+ ]),
62
+ );
63
+ }
@@ -0,0 +1,105 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
5
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
6
+ import { StatementFactory } from "typia/lib/factories/StatementFactory";
7
+ import { FunctionImporter } from "typia/lib/programmers/helpers/FunctionImporeter";
8
+ import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
9
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
10
+ import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
11
+ import { IProject } from "typia/lib/transformers/IProject";
12
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
13
+
14
+ export namespace HttpQuerifyProgrammer {
15
+ export const write =
16
+ (project: IProject) =>
17
+ (modulo: ts.LeftHandSideExpression) =>
18
+ (type: ts.Type): ts.ArrowFunction => {
19
+ // GET OBJECT TYPE
20
+ const importer: FunctionImporter = new FunctionImporter(
21
+ modulo.getText(),
22
+ );
23
+ const collection: MetadataCollection = new MetadataCollection();
24
+ const result = MetadataFactory.analyze(project.checker)({
25
+ escape: false,
26
+ constant: true,
27
+ absorb: true,
28
+ validate: HttpQueryProgrammer.validate,
29
+ })(collection)(type);
30
+ if (result.success === false)
31
+ throw TransformerError.from(
32
+ `@nestia.core.TypedQuery.${importer.method}`,
33
+ )(result.errors);
34
+
35
+ const object: MetadataObject = result.data.objects[0]!;
36
+ return ts.factory.createArrowFunction(
37
+ undefined,
38
+ undefined,
39
+ [IdentifierFactory.parameter("input")],
40
+ undefined,
41
+ undefined,
42
+ ts.factory.createBlock(
43
+ [
44
+ ...importer.declare(modulo),
45
+ StatementFactory.constant(
46
+ "output",
47
+ ts.factory.createNewExpression(
48
+ ts.factory.createIdentifier("URLSearchParams"),
49
+ undefined,
50
+ [],
51
+ ),
52
+ ),
53
+ ...object.properties.map((p) =>
54
+ ts.factory.createExpressionStatement(
55
+ decode(p.key.constants[0]!.values[0] as string)(
56
+ p.value,
57
+ ),
58
+ ),
59
+ ),
60
+ ts.factory.createReturnStatement(
61
+ ts.factory.createIdentifier("output"),
62
+ ),
63
+ ],
64
+ true,
65
+ ),
66
+ );
67
+ };
68
+
69
+ const decode =
70
+ (key: string) =>
71
+ (value: Metadata): ts.CallExpression =>
72
+ !!value.arrays.length
73
+ ? ts.factory.createCallExpression(
74
+ IdentifierFactory.access(
75
+ IdentifierFactory.access(
76
+ ts.factory.createIdentifier("input"),
77
+ )(key),
78
+ )("forEach"),
79
+ undefined,
80
+ [
81
+ ts.factory.createArrowFunction(
82
+ undefined,
83
+ undefined,
84
+ [IdentifierFactory.parameter("elem")],
85
+ undefined,
86
+ undefined,
87
+ append(key)(ts.factory.createIdentifier("elem")),
88
+ ),
89
+ ],
90
+ )
91
+ : append(key)(
92
+ IdentifierFactory.access(
93
+ ts.factory.createIdentifier("input"),
94
+ )(key),
95
+ );
96
+
97
+ const append = (key: string) => (elem: ts.Expression) =>
98
+ ts.factory.createCallExpression(
99
+ IdentifierFactory.access(ts.factory.createIdentifier("output"))(
100
+ "append",
101
+ ),
102
+ undefined,
103
+ [ts.factory.createStringLiteral(key), elem],
104
+ );
105
+ }
@@ -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
+ }
@@ -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 done: boolean = (() => {
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 false;
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 true;
43
+ return location.split(path.sep).at(-1)?.split(".")[0] ===
44
+ "TypedQuery"
45
+ ? "TypedQuery"
46
+ : "TypedRoute";
43
47
  })();
44
- if (done === false) return decorator;
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
- TypedRouteProgrammer.generate(project)(
60
- decorator.expression.expression,
61
- )(type),
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",