@nestia/sdk 2.5.0-dev.20240129 → 2.5.0-dev.20240130

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 (69) hide show
  1. package/lib/INestiaConfig.d.ts +6 -0
  2. package/lib/NestiaSdkApplication.js +1 -1
  3. package/lib/NestiaSdkApplication.js.map +1 -1
  4. package/lib/executable/internal/NestiaConfigLoader.js +6 -2
  5. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  6. package/lib/generates/CloneGenerator.d.ts +6 -0
  7. package/lib/generates/CloneGenerator.js +60 -0
  8. package/lib/generates/CloneGenerator.js.map +1 -0
  9. package/lib/generates/E2eGenerator.d.ts +2 -1
  10. package/lib/generates/E2eGenerator.js +2 -2
  11. package/lib/generates/E2eGenerator.js.map +1 -1
  12. package/lib/generates/SdkGenerator.js +3 -3
  13. package/lib/generates/SdkGenerator.js.map +1 -1
  14. package/lib/generates/SwaggerGenerator.js +11 -8
  15. package/lib/generates/SwaggerGenerator.js.map +1 -1
  16. package/lib/generates/internal/E2eFileProgrammer.d.ts +2 -1
  17. package/lib/generates/internal/E2eFileProgrammer.js +12 -16
  18. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  19. package/lib/generates/internal/SdkAliasCollection.d.ts +12 -0
  20. package/lib/generates/internal/SdkAliasCollection.js +89 -0
  21. package/lib/generates/internal/SdkAliasCollection.js.map +1 -0
  22. package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -1
  23. package/lib/generates/internal/SdkFileProgrammer.js +5 -5
  24. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  25. package/lib/generates/internal/SdkFunctionProgrammer.js +6 -6
  26. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  27. package/lib/generates/internal/SdkInterfaceProgrammer.d.ts +12 -0
  28. package/lib/generates/internal/SdkInterfaceProgrammer.js +112 -0
  29. package/lib/generates/internal/SdkInterfaceProgrammer.js.map +1 -0
  30. package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +1 -1
  31. package/lib/generates/internal/SdkNamespaceProgrammer.js +19 -18
  32. package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -1
  33. package/lib/generates/internal/SdkRouteProgrammer.d.ts +1 -1
  34. package/lib/generates/internal/SdkRouteProgrammer.js +2 -2
  35. package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -1
  36. package/lib/generates/internal/SdkSimulationProgrammer.d.ts +1 -1
  37. package/lib/generates/internal/SdkSimulationProgrammer.js +11 -12
  38. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  39. package/lib/generates/internal/{SdkDtoGenerator.d.ts → SdkTypeProgrammer.d.ts} +2 -4
  40. package/lib/generates/internal/SdkTypeProgrammer.js +160 -0
  41. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -0
  42. package/lib/structures/ISwagger.d.ts +1 -1
  43. package/lib/utils/FormatUtil.js +3 -1
  44. package/lib/utils/FormatUtil.js.map +1 -1
  45. package/package.json +3 -3
  46. package/src/INestiaConfig.ts +7 -0
  47. package/src/NestiaSdkApplication.ts +1 -1
  48. package/src/generates/CloneGenerator.ts +75 -0
  49. package/src/generates/E2eGenerator.ts +3 -1
  50. package/src/generates/SdkGenerator.ts +3 -3
  51. package/src/generates/SwaggerGenerator.ts +4 -2
  52. package/src/generates/internal/E2eFileProgrammer.ts +12 -19
  53. package/src/generates/internal/SdkAliasCollection.ts +145 -0
  54. package/src/generates/internal/SdkFileProgrammer.ts +5 -3
  55. package/src/generates/internal/SdkFunctionProgrammer.ts +9 -9
  56. package/src/generates/internal/SdkInterfaceProgrammer.ts +211 -0
  57. package/src/generates/internal/SdkNamespaceProgrammer.ts +31 -19
  58. package/src/generates/internal/SdkRouteProgrammer.ts +5 -1
  59. package/src/generates/internal/SdkSimulationProgrammer.ts +14 -16
  60. package/src/generates/internal/SdkTypeProgrammer.ts +252 -0
  61. package/src/structures/ISwagger.ts +1 -1
  62. package/src/utils/FormatUtil.ts +2 -1
  63. package/lib/generates/internal/SdkDtoGenerator.js +0 -295
  64. package/lib/generates/internal/SdkDtoGenerator.js.map +0 -1
  65. package/lib/generates/internal/SdkTypeDefiner.d.ts +0 -11
  66. package/lib/generates/internal/SdkTypeDefiner.js +0 -82
  67. package/lib/generates/internal/SdkTypeDefiner.js.map +0 -1
  68. package/src/generates/internal/SdkDtoGenerator.ts +0 -429
  69. package/src/generates/internal/SdkTypeDefiner.ts +0 -119
@@ -0,0 +1,145 @@
1
+ import ts from "typescript";
2
+
3
+ import { INestiaConfig } from "../../INestiaConfig";
4
+ import { IRoute } from "../../structures/IRoute";
5
+ import { ImportDictionary } from "../../utils/ImportDictionary";
6
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
7
+
8
+ export namespace SdkAliasCollection {
9
+ export const name =
10
+ (config: INestiaConfig) =>
11
+ (importer: ImportDictionary) =>
12
+ (p: IRoute.IParameter | IRoute.IOutput): ts.TypeNode =>
13
+ p.metadata
14
+ ? SdkTypeProgrammer.decode(config)(importer)(p.metadata)
15
+ : ts.factory.createTypeReferenceNode(p.typeName);
16
+
17
+ export const headers =
18
+ (config: INestiaConfig) =>
19
+ (importer: ImportDictionary) =>
20
+ (param: IRoute.IParameter): ts.TypeNode => {
21
+ const type: ts.TypeNode = name(config)(importer)(param);
22
+ if (config.primitive === false) return type;
23
+ return ts.factory.createTypeReferenceNode(
24
+ importer.external({
25
+ type: true,
26
+ library: "@nestia/fetcher",
27
+ instance: "Resolved",
28
+ }),
29
+ [type],
30
+ );
31
+ };
32
+
33
+ export const query =
34
+ (config: INestiaConfig) =>
35
+ (importer: ImportDictionary) =>
36
+ (param: IRoute.IParameter): ts.TypeNode => {
37
+ const type: ts.TypeNode = name(config)(importer)(param);
38
+ if (config.primitive === false) return type;
39
+ return ts.factory.createTypeReferenceNode(
40
+ importer.external({
41
+ type: true,
42
+ library: "@nestia/fetcher",
43
+ instance: "Resolved",
44
+ }),
45
+ [type],
46
+ );
47
+ };
48
+
49
+ export const input =
50
+ (config: INestiaConfig) =>
51
+ (importer: ImportDictionary) =>
52
+ (param: IRoute.IParameter): ts.TypeNode => {
53
+ const type: ts.TypeNode = name(config)(importer)(param);
54
+ if (config.primitive === false) return type;
55
+ return ts.factory.createTypeReferenceNode(
56
+ importer.external({
57
+ type: true,
58
+ library: "@nestia/fetcher",
59
+ instance: "Primitive",
60
+ }),
61
+ [type],
62
+ );
63
+ };
64
+
65
+ export const output =
66
+ (checker: ts.TypeChecker) =>
67
+ (config: INestiaConfig) =>
68
+ (importer: ImportDictionary) =>
69
+ (route: IRoute): ts.TypeNode => {
70
+ if (config.propagate !== true) {
71
+ const node: ts.TypeNode = name(config)(importer)(route.output);
72
+ const type = checker.getTypeAtLocation(node);
73
+ const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
74
+
75
+ if (
76
+ filter(ts.TypeFlags.Undefined) ||
77
+ filter(ts.TypeFlags.Never) ||
78
+ filter(ts.TypeFlags.Void) ||
79
+ filter(ts.TypeFlags.VoidLike) ||
80
+ config.primitive === false
81
+ )
82
+ return node;
83
+ return ts.factory.createTypeReferenceNode(
84
+ importer.external({
85
+ type: true,
86
+ library: "@nestia/fetcher",
87
+ instance:
88
+ route.output.contentType === "application/x-www-form-urlencoded"
89
+ ? "Resolved"
90
+ : "Primitive",
91
+ }),
92
+ [node],
93
+ );
94
+ }
95
+
96
+ const branches: IBranch[] = [
97
+ {
98
+ status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
99
+ type: name(config)(importer)(route.output),
100
+ },
101
+ ...Object.entries(route.exceptions).map(([status, value]) => ({
102
+ status,
103
+ type: name(config)(importer)(value),
104
+ })),
105
+ ];
106
+ return ts.factory.createTypeReferenceNode(
107
+ importer.external({
108
+ type: true,
109
+ library: "@nestia/fetcher",
110
+ instance: "IPropagation",
111
+ }),
112
+ [
113
+ ts.factory.createTypeLiteralNode(
114
+ branches.map((b) =>
115
+ ts.factory.createPropertySignature(
116
+ undefined,
117
+ ts.factory.createNumericLiteral(b.status),
118
+ undefined,
119
+ b.type,
120
+ ),
121
+ ),
122
+ ),
123
+ ...(route.status
124
+ ? [
125
+ ts.factory.createLiteralTypeNode(
126
+ ts.factory.createNumericLiteral(route.status),
127
+ ),
128
+ ]
129
+ : []),
130
+ ],
131
+ );
132
+ };
133
+
134
+ export const responseBody =
135
+ (checker: ts.TypeChecker) =>
136
+ (config: INestiaConfig) =>
137
+ (importer: ImportDictionary) =>
138
+ (route: IRoute): ts.TypeNode =>
139
+ output(checker)({ ...config, propagate: false })(importer)(route);
140
+ }
141
+
142
+ interface IBranch {
143
+ status: string;
144
+ type: ts.TypeNode;
145
+ }
@@ -14,6 +14,7 @@ export namespace SdkFileProgrammer {
14
14
  CONSTRUCTOR
15
15
  --------------------------------------------------------- */
16
16
  export const generate =
17
+ (checker: ts.TypeChecker) =>
17
18
  (config: INestiaConfig) =>
18
19
  async (routeList: IRoute[]): Promise<void> => {
19
20
  // CONSTRUCT FOLDER TREE
@@ -21,7 +22,7 @@ export namespace SdkFileProgrammer {
21
22
  for (const route of routeList) emplace(root)(route);
22
23
 
23
24
  // ITERATE FILES
24
- await iterate(config)(root)(config.output + "/functional");
25
+ await iterate(checker)(config)(root)(config.output + "/functional");
25
26
  };
26
27
 
27
28
  const emplace =
@@ -44,6 +45,7 @@ export namespace SdkFileProgrammer {
44
45
  FILE ITERATOR
45
46
  --------------------------------------------------------- */
46
47
  const iterate =
48
+ (checker: ts.TypeChecker) =>
47
49
  (config: INestiaConfig) =>
48
50
  (directory: SdkRouteDirectory) =>
49
51
  async (outDir: string): Promise<void> => {
@@ -55,7 +57,7 @@ export namespace SdkFileProgrammer {
55
57
  // ITERATE CHILDREN
56
58
  const statements: ts.Statement[] = [];
57
59
  for (const [key, value] of directory.children) {
58
- await iterate(config)(value)(`${outDir}/${key}`);
60
+ await iterate(checker)(config)(value)(`${outDir}/${key}`);
59
61
  statements.push(
60
62
  ts.factory.createExportDeclaration(
61
63
  undefined,
@@ -92,7 +94,7 @@ export namespace SdkFileProgrammer {
92
94
  type: true,
93
95
  });
94
96
  statements.push(
95
- ...SdkRouteProgrammer.generate(config)(importer)(route),
97
+ ...SdkRouteProgrammer.generate(checker)(config)(importer)(route),
96
98
  );
97
99
  if (i !== directory.routes.length - 1)
98
100
  statements.push(FormatUtil.enter());
@@ -6,8 +6,8 @@ import { INestiaConfig } from "../../INestiaConfig";
6
6
  import { IController } from "../../structures/IController";
7
7
  import { IRoute } from "../../structures/IRoute";
8
8
  import { ImportDictionary } from "../../utils/ImportDictionary";
9
- import { SdkDtoGenerator } from "./SdkDtoGenerator";
10
9
  import { SdkImportWizard } from "./SdkImportWizard";
10
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
11
11
 
12
12
  export namespace SdkFunctionProgrammer {
13
13
  export const generate =
@@ -49,12 +49,12 @@ export namespace SdkFunctionProgrammer {
49
49
  p.optional
50
50
  ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
51
51
  : undefined,
52
- ts.factory.createTypeReferenceNode(
53
- config.primitive !== false &&
54
- (p === props.query || p === props.input)
55
- ? `${route.name}.${p === props.query ? "Query" : "Input"}`
56
- : getTypeName(config)(importer)(p),
57
- ),
52
+ config.primitive !== false &&
53
+ (p === props.query || p === props.input)
54
+ ? ts.factory.createTypeReferenceNode(
55
+ `${route.name}.${p === props.query ? "Query" : "Input"}`,
56
+ )
57
+ : getTypeName(config)(importer)(p),
58
58
  ),
59
59
  ),
60
60
  ],
@@ -215,5 +215,5 @@ const getTypeName =
215
215
  (importer: ImportDictionary) =>
216
216
  (p: IRoute.IParameter | IRoute.IOutput) =>
217
217
  p.metadata
218
- ? SdkDtoGenerator.decode(config)(importer)(p.metadata)
219
- : p.typeName;
218
+ ? SdkTypeProgrammer.decode(config)(importer)(p.metadata)
219
+ : ts.factory.createTypeReferenceNode(p.typeName);
@@ -0,0 +1,211 @@
1
+ import { IPointer } from "tstl";
2
+ import ts from "typescript";
3
+ import { IJsDocTagInfo } from "typia";
4
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
5
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
6
+ import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
7
+ import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
8
+ import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
9
+ import { MetadataProperty } from "typia/lib/schemas/metadata/MetadataProperty";
10
+ import { Escaper } from "typia/lib/utils/Escaper";
11
+
12
+ import { INestiaConfig } from "../../INestiaConfig";
13
+ import { IRoute } from "../../structures/IRoute";
14
+ import { FormatUtil } from "../../utils/FormatUtil";
15
+ import { ImportDictionary } from "../../utils/ImportDictionary";
16
+ import { MapUtil } from "../../utils/MapUtil";
17
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
18
+
19
+ export namespace SdkInterfaceProgrammer {
20
+ export interface IModule {
21
+ name: string;
22
+ children: Map<string, IModule>;
23
+ programmer:
24
+ | null
25
+ | ((importer: ImportDictionary) => ts.TypeAliasDeclaration);
26
+ }
27
+
28
+ export const generate =
29
+ (checker: ts.TypeChecker) =>
30
+ (config: INestiaConfig) =>
31
+ (routes: IRoute[]): Map<string, IModule> => {
32
+ const collection = new MetadataCollection({
33
+ replace: MetadataCollection.replace,
34
+ });
35
+ for (const r of routes) {
36
+ for (const p of r.parameters) {
37
+ const res = MetadataFactory.analyze(checker)({
38
+ escape: false,
39
+ constant: true,
40
+ absorb: false,
41
+ })(collection)(p.type);
42
+ if (res.success) p.metadata = res.data;
43
+ }
44
+ for (const e of Object.values(r.exceptions)) {
45
+ const res = MetadataFactory.analyze(checker)({
46
+ escape: true,
47
+ constant: true,
48
+ absorb: false,
49
+ })(collection)(e.type);
50
+ if (res.success) e.metadata = res.data;
51
+ }
52
+ const res = MetadataFactory.analyze(checker)({
53
+ escape: true,
54
+ constant: true,
55
+ absorb: false,
56
+ })(collection)(r.output.type);
57
+ if (res.success) r.output.metadata = res.data;
58
+ }
59
+
60
+ const dict: Map<string, IModule> = new Map();
61
+ for (const alias of collection.aliases())
62
+ prepare(dict)(alias.name)((importer) =>
63
+ define_alias(config)(importer)(alias),
64
+ );
65
+ for (const object of collection.objects())
66
+ prepare(dict)(object.name)((importer) =>
67
+ define_object(config)(importer)(object),
68
+ );
69
+ return dict;
70
+ };
71
+
72
+ const prepare =
73
+ (dict: Map<string, IModule>) =>
74
+ (name: string) =>
75
+ (programmer: (importer: ImportDictionary) => ts.TypeAliasDeclaration) => {
76
+ const accessors: string[] = name.split(".");
77
+ const modulo: IPointer<IModule> = { value: null! };
78
+
79
+ accessors.forEach((acc, i) => {
80
+ modulo.value = MapUtil.take(dict, acc, () => ({
81
+ name: acc,
82
+ children: new Map(),
83
+ programmer: null,
84
+ }));
85
+ if (i === accessors.length - 1) modulo.value.programmer = programmer;
86
+ dict = modulo.value.children;
87
+ });
88
+ return modulo!;
89
+ };
90
+
91
+ const define_alias =
92
+ (config: INestiaConfig) =>
93
+ (importer: ImportDictionary) =>
94
+ (alias: MetadataAlias): ts.TypeAliasDeclaration =>
95
+ FormatUtil.description(
96
+ ts.factory.createTypeAliasDeclaration(
97
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
98
+ alias.name.split(".").at(-1)!,
99
+ [],
100
+ SdkTypeProgrammer.decode(config)(importer)(alias.value),
101
+ ),
102
+ writeComment([])(alias.description, alias.jsDocTags),
103
+ );
104
+
105
+ const define_object =
106
+ (config: INestiaConfig) =>
107
+ (importer: ImportDictionary) =>
108
+ (object: MetadataObject): ts.TypeAliasDeclaration => {
109
+ const regular = object.properties.filter((p) => p.key.isSoleLiteral());
110
+ const dynamic = object.properties.filter((p) => !p.key.isSoleLiteral());
111
+ return FormatUtil.description(
112
+ ts.factory.createTypeAliasDeclaration(
113
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
114
+ object.name.split(".").at(-1)!,
115
+ [],
116
+ regular.length && dynamic.length
117
+ ? ts.factory.createIntersectionTypeNode([
118
+ define_regular(config)(importer)(regular),
119
+ ...dynamic.map(define_dynamic(config)(importer)),
120
+ ])
121
+ : dynamic.length
122
+ ? ts.factory.createIntersectionTypeNode(
123
+ dynamic.map(define_dynamic(config)(importer)),
124
+ )
125
+ : define_regular(config)(importer)(regular),
126
+ ),
127
+ writeComment([])(object.description ?? null, object.jsDocTags),
128
+ );
129
+ };
130
+
131
+ const define_regular =
132
+ (config: INestiaConfig) =>
133
+ (importer: ImportDictionary) =>
134
+ (properties: MetadataProperty[]): ts.TypeLiteralNode =>
135
+ ts.factory.createTypeLiteralNode(
136
+ properties.map((p) =>
137
+ FormatUtil.description(
138
+ ts.factory.createPropertySignature(
139
+ undefined,
140
+ Escaper.variable(String(p.key.constants[0].values[0]))
141
+ ? ts.factory.createIdentifier(
142
+ String(p.key.constants[0].values[0]),
143
+ )
144
+ : ts.factory.createStringLiteral(
145
+ String(p.key.constants[0].values[0]),
146
+ ),
147
+ p.value.isRequired() === false
148
+ ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
149
+ : undefined,
150
+ SdkTypeProgrammer.decode(config)(importer)(p.value),
151
+ ),
152
+ writeComment(p.value.atomics)(p.description, p.jsDocTags),
153
+ ),
154
+ ),
155
+ );
156
+
157
+ const define_dynamic =
158
+ (config: INestiaConfig) =>
159
+ (importer: ImportDictionary) =>
160
+ (property: MetadataProperty): ts.TypeLiteralNode =>
161
+ ts.factory.createTypeLiteralNode([
162
+ FormatUtil.description(
163
+ ts.factory.createIndexSignature(
164
+ undefined,
165
+ [
166
+ ts.factory.createParameterDeclaration(
167
+ undefined,
168
+ undefined,
169
+ ts.factory.createIdentifier("key"),
170
+ undefined,
171
+ SdkTypeProgrammer.decode(config)(importer)(property.key),
172
+ ),
173
+ ],
174
+ SdkTypeProgrammer.decode(config)(importer)(property.value),
175
+ ),
176
+ writeComment(property.value.atomics)(
177
+ property.description,
178
+ property.jsDocTags,
179
+ ),
180
+ ),
181
+ ]);
182
+ }
183
+
184
+ const writeComment =
185
+ (atomics: MetadataAtomic[]) =>
186
+ (description: string | null, jsDocTags: IJsDocTagInfo[]): string => {
187
+ const lines: string[] = [];
188
+ if (description?.length)
189
+ lines.push(...description.split("\n").map((s) => `${s}`));
190
+
191
+ const filtered: IJsDocTagInfo[] =
192
+ !!atomics.length && !!jsDocTags?.length
193
+ ? jsDocTags.filter(
194
+ (tag) =>
195
+ !atomics.some((a) =>
196
+ a.tags.some((r) => r.some((t) => t.kind === tag.name)),
197
+ ),
198
+ )
199
+ : jsDocTags ?? [];
200
+
201
+ if (description?.length && filtered.length) lines.push("");
202
+ if (filtered.length)
203
+ lines.push(
204
+ ...filtered.map((t) =>
205
+ t.text?.length
206
+ ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
207
+ : `@${t.name}`,
208
+ ),
209
+ );
210
+ return lines.join("\n");
211
+ };
@@ -1,5 +1,6 @@
1
1
  import ts from "typescript";
2
2
  import typia from "typia";
3
+ import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
3
4
  import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
4
5
  import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
5
6
  import { TypeFactory } from "typia/lib/factories/TypeFactory";
@@ -10,13 +11,14 @@ import { IController } from "../../structures/IController";
10
11
  import { IRoute } from "../../structures/IRoute";
11
12
  import { FormatUtil } from "../../utils/FormatUtil";
12
13
  import { ImportDictionary } from "../../utils/ImportDictionary";
13
- import { SdkDtoGenerator } from "./SdkDtoGenerator";
14
+ import { SdkAliasCollection } from "./SdkAliasCollection";
14
15
  import { SdkImportWizard } from "./SdkImportWizard";
15
16
  import { SdkSimulationProgrammer } from "./SdkSimulationProgrammer";
16
- import { SdkTypeDefiner } from "./SdkTypeDefiner";
17
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
17
18
 
18
19
  export namespace SdkNamespaceProgrammer {
19
20
  export const generate =
21
+ (checker: ts.TypeChecker) =>
20
22
  (config: INestiaConfig) =>
21
23
  (importer: ImportDictionary) =>
22
24
  (
@@ -27,7 +29,7 @@ export namespace SdkNamespaceProgrammer {
27
29
  input: IRoute.IParameter | undefined;
28
30
  },
29
31
  ): ts.ModuleDeclaration => {
30
- const types = generate_types(config)(importer)(route, props);
32
+ const types = generate_types(checker)(config)(importer)(route, props);
31
33
  return ts.factory.createModuleDeclaration(
32
34
  [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
33
35
  ts.factory.createIdentifier(route.name),
@@ -39,7 +41,9 @@ export namespace SdkNamespaceProgrammer {
39
41
  generate_path(config)(importer)(route, props),
40
42
  ...(config.simulate
41
43
  ? [
42
- SdkSimulationProgrammer.random(config)(importer)(route),
44
+ SdkSimulationProgrammer.random(checker)(config)(importer)(
45
+ route,
46
+ ),
43
47
  SdkSimulationProgrammer.simulate(config)(importer)(
44
48
  route,
45
49
  props,
@@ -55,6 +59,7 @@ export namespace SdkNamespaceProgrammer {
55
59
  };
56
60
 
57
61
  const generate_types =
62
+ (checker: ts.TypeChecker) =>
58
63
  (config: INestiaConfig) =>
59
64
  (importer: ImportDictionary) =>
60
65
  (
@@ -66,26 +71,35 @@ export namespace SdkNamespaceProgrammer {
66
71
  },
67
72
  ): ts.TypeAliasDeclaration[] => {
68
73
  const array: ts.TypeAliasDeclaration[] = [];
69
- const declare = (name: string, type: string) =>
74
+ const declare = (name: string, type: ts.TypeNode) =>
70
75
  array.push(
71
76
  ts.factory.createTypeAliasDeclaration(
72
77
  [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
73
78
  name,
74
79
  undefined,
75
- ts.factory.createTypeReferenceNode(type),
80
+ type,
76
81
  ),
77
82
  );
78
83
  if (props.headers !== undefined)
79
84
  declare(
80
85
  "Headers",
81
- SdkTypeDefiner.headers(config)(importer)(props.headers),
86
+ SdkAliasCollection.headers(config)(importer)(props.headers),
82
87
  );
83
88
  if (props.query !== undefined)
84
- declare("Query", SdkTypeDefiner.query(config)(importer)(props.query));
89
+ declare(
90
+ "Query",
91
+ SdkAliasCollection.query(config)(importer)(props.query),
92
+ );
85
93
  if (props.input !== undefined)
86
- declare("Input", SdkTypeDefiner.input(config)(importer)(props.input));
94
+ declare(
95
+ "Input",
96
+ SdkAliasCollection.input(config)(importer)(props.input),
97
+ );
87
98
  if (config.propagate === true || route.output.typeName !== "void")
88
- declare("Output", SdkTypeDefiner.output(config)(importer)(route));
99
+ declare(
100
+ "Output",
101
+ SdkAliasCollection.output(checker)(config)(importer)(route),
102
+ );
89
103
  return array;
90
104
  };
91
105
 
@@ -139,7 +153,7 @@ export namespace SdkNamespaceProgrammer {
139
153
  ts.factory.createPropertyAssignment(
140
154
  "status",
141
155
  route.status !== undefined
142
- ? ts.factory.createNumericLiteral(route.status)
156
+ ? ExpressionFactory.number(route.status)
143
157
  : ts.factory.createNull(),
144
158
  ),
145
159
  ...(route.output.contentType ===
@@ -198,11 +212,9 @@ export namespace SdkNamespaceProgrammer {
198
212
  g.total.map((p) =>
199
213
  IdentifierFactory.parameter(
200
214
  p.name,
201
- ts.factory.createTypeReferenceNode(
202
- p === props.query
203
- ? `${route.name}.Query`
204
- : getType(config)(importer)(p),
205
- ),
215
+ p === props.query
216
+ ? ts.factory.createTypeReferenceNode(`${route.name}.Query`)
217
+ : getType(config)(importer)(p),
206
218
  ),
207
219
  ),
208
220
  undefined,
@@ -365,7 +377,7 @@ export namespace SdkNamespaceProgrammer {
365
377
  ts.factory.createReturnStatement(
366
378
  ts.factory.createConditionalExpression(
367
379
  ts.factory.createStrictEquality(
368
- ts.factory.createNumericLiteral(0),
380
+ ExpressionFactory.number(0),
369
381
  IdentifierFactory.access(
370
382
  ts.factory.createIdentifier(variables),
371
383
  )("size"),
@@ -491,5 +503,5 @@ const getType =
491
503
  (importer: ImportDictionary) =>
492
504
  (p: IRoute.IParameter | IRoute.IOutput) =>
493
505
  p.metadata
494
- ? SdkDtoGenerator.decode(config)(importer)(p.metadata)
495
- : p.typeName;
506
+ ? SdkTypeProgrammer.decode(config)(importer)(p.metadata)
507
+ : ts.factory.createTypeReferenceNode(p.typeName);
@@ -10,6 +10,7 @@ import { SdkNamespaceProgrammer } from "./SdkNamespaceProgrammer";
10
10
 
11
11
  export namespace SdkRouteProgrammer {
12
12
  export const generate =
13
+ (checker: ts.TypeChecker) =>
13
14
  (config: INestiaConfig) =>
14
15
  (importer: ImportDictionary) =>
15
16
  (route: IRoute): ts.Statement[] => {
@@ -27,7 +28,10 @@ export namespace SdkRouteProgrammer {
27
28
  SdkFunctionProgrammer.generate(config)(importer)(route, props),
28
29
  describe(route),
29
30
  ),
30
- SdkNamespaceProgrammer.generate(config)(importer)(route, props),
31
+ SdkNamespaceProgrammer.generate(checker)(config)(importer)(
32
+ route,
33
+ props,
34
+ ),
31
35
  ];
32
36
  };
33
37
 
@@ -1,4 +1,5 @@
1
1
  import ts from "typescript";
2
+ import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
2
3
  import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
4
  import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
4
5
  import { StatementFactory } from "typia/lib/factories/StatementFactory";
@@ -7,12 +8,13 @@ import { TypeFactory } from "typia/lib/factories/TypeFactory";
7
8
  import { INestiaConfig } from "../../INestiaConfig";
8
9
  import { IRoute } from "../../structures/IRoute";
9
10
  import { ImportDictionary } from "../../utils/ImportDictionary";
10
- import { SdkDtoGenerator } from "./SdkDtoGenerator";
11
+ import { SdkAliasCollection } from "./SdkAliasCollection";
11
12
  import { SdkImportWizard } from "./SdkImportWizard";
12
- import { SdkTypeDefiner } from "./SdkTypeDefiner";
13
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
13
14
 
14
15
  export namespace SdkSimulationProgrammer {
15
16
  export const random =
17
+ (checker: ts.TypeChecker) =>
16
18
  (config: INestiaConfig) =>
17
19
  (importer: ImportDictionary) =>
18
20
  (route: IRoute): ts.VariableStatement =>
@@ -42,11 +44,7 @@ export namespace SdkSimulationProgrammer {
42
44
  IdentifierFactory.access(
43
45
  ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
44
46
  )("random"),
45
- [
46
- ts.factory.createTypeReferenceNode(
47
- SdkTypeDefiner.responseBody(config)(importer)(route),
48
- ),
49
- ],
47
+ [SdkAliasCollection.responseBody(checker)(config)(importer)(route)],
50
48
  [ts.factory.createIdentifier("g")],
51
49
  ),
52
50
  ),
@@ -121,12 +119,12 @@ export namespace SdkSimulationProgrammer {
121
119
  p.optional
122
120
  ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
123
121
  : undefined,
124
- ts.factory.createTypeReferenceNode(
125
- config.primitive !== false &&
126
- (p === props.query || p === props.input)
127
- ? `${route.name}.${p === props.query ? "Query" : "Input"}`
128
- : getTypeName(config)(importer)(p),
129
- ),
122
+ config.primitive !== false &&
123
+ (p === props.query || p === props.input)
124
+ ? ts.factory.createTypeReferenceNode(
125
+ `${route.name}.${p === props.query ? "Query" : "Input"}`,
126
+ )
127
+ : getTypeName(config)(importer)(p),
130
128
  ),
131
129
  ),
132
130
  ],
@@ -145,7 +143,7 @@ export namespace SdkSimulationProgrammer {
145
143
  ),
146
144
  ts.factory.createPropertyAssignment(
147
145
  "status",
148
- ts.factory.createNumericLiteral(
146
+ ExpressionFactory.number(
149
147
  route.status ??
150
148
  (route.method === "POST" ? 201 : 200),
151
149
  ),
@@ -355,5 +353,5 @@ const getTypeName =
355
353
  (importer: ImportDictionary) =>
356
354
  (p: IRoute.IParameter | IRoute.IOutput) =>
357
355
  p.metadata
358
- ? SdkDtoGenerator.decode(config)(importer)(p.metadata)
359
- : p.typeName;
356
+ ? SdkTypeProgrammer.decode(config)(importer)(p.metadata)
357
+ : ts.factory.createTypeReferenceNode(p.typeName);