@nestia/sdk 2.0.0-dev.20230991 → 2.0.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 (93) hide show
  1. package/assets/bundle/api/utils/NestiaSimulator.ts +5 -14
  2. package/lib/INestiaConfig.d.ts +60 -47
  3. package/lib/NestiaSdkApplication.d.ts +6 -5
  4. package/lib/NestiaSdkApplication.js +30 -87
  5. package/lib/NestiaSdkApplication.js.map +1 -1
  6. package/lib/analyses/ControllerAnalyzer.js +8 -5
  7. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  8. package/lib/analyses/ReflectAnalyzer.js +9 -1
  9. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  10. package/lib/executable/internal/NestiaConfigLoader.d.ts +7 -0
  11. package/lib/executable/internal/NestiaConfigLoader.js +582 -0
  12. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -0
  13. package/lib/executable/internal/NestiaProjectGetter.d.ts +3 -0
  14. package/lib/executable/internal/NestiaProjectGetter.js +28 -0
  15. package/lib/executable/internal/NestiaProjectGetter.js.map +1 -0
  16. package/lib/executable/internal/NestiaSdkCommand.d.ts +3 -3
  17. package/lib/executable/internal/NestiaSdkCommand.js +13 -104
  18. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  19. package/lib/executable/internal/{nestia.config.getter.js → nestia.project.getter.js} +3 -3
  20. package/lib/executable/internal/nestia.project.getter.js.map +1 -0
  21. package/lib/executable/sdk.js +3 -3
  22. package/lib/executable/sdk.js.map +1 -1
  23. package/lib/generates/SdkGenerator.d.ts +2 -1
  24. package/lib/generates/SdkGenerator.js +7 -3
  25. package/lib/generates/SdkGenerator.js.map +1 -1
  26. package/lib/generates/SwaggerGenerator.js +26 -9
  27. package/lib/generates/SwaggerGenerator.js.map +1 -1
  28. package/lib/generates/internal/E2eFileProgrammer.js +21 -15
  29. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  30. package/lib/generates/internal/{DistributionComposer.d.ts → SdkDistributionComposer.d.ts} +1 -1
  31. package/lib/generates/internal/{DistributionComposer.js → SdkDistributionComposer.js} +8 -12
  32. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -0
  33. package/lib/generates/internal/SdkDtoGenerator.d.ts +9 -0
  34. package/lib/generates/internal/SdkDtoGenerator.js +264 -0
  35. package/lib/generates/internal/SdkDtoGenerator.js.map +1 -0
  36. package/lib/generates/internal/SdkFileProgrammer.js +8 -7
  37. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  38. package/lib/generates/internal/SdkFunctionProgrammer.js +32 -22
  39. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  40. package/lib/generates/internal/SdkImportWizard.d.ts +2 -0
  41. package/lib/generates/internal/SdkImportWizard.js +10 -0
  42. package/lib/generates/internal/SdkImportWizard.js.map +1 -1
  43. package/lib/generates/internal/SdkSimulationProgrammer.js +61 -25
  44. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  45. package/lib/generates/internal/SdkTypeDefiner.d.ts +11 -0
  46. package/lib/generates/internal/SdkTypeDefiner.js +82 -0
  47. package/lib/generates/internal/SdkTypeDefiner.js.map +1 -0
  48. package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +1 -1
  49. package/lib/generates/internal/SwaggerSchemaGenerator.js +67 -75
  50. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  51. package/lib/generates/internal/SwaggerSchemaValidator.js +0 -8
  52. package/lib/generates/internal/SwaggerSchemaValidator.js.map +1 -1
  53. package/lib/structures/IController.d.ts +2 -0
  54. package/lib/structures/IRoute.d.ts +9 -2
  55. package/lib/utils/ImportDictionary.d.ts +1 -2
  56. package/lib/utils/ImportDictionary.js +28 -24
  57. package/lib/utils/ImportDictionary.js.map +1 -1
  58. package/package.json +8 -8
  59. package/src/INestiaConfig.ts +65 -50
  60. package/src/NestiaSdkApplication.ts +39 -84
  61. package/src/analyses/ControllerAnalyzer.ts +10 -8
  62. package/src/analyses/ReflectAnalyzer.ts +8 -0
  63. package/src/executable/internal/NestiaConfigLoader.ts +82 -0
  64. package/src/executable/internal/NestiaProjectGetter.ts +11 -0
  65. package/src/executable/internal/NestiaSdkCommand.ts +23 -146
  66. package/src/executable/internal/{nestia.config.getter.ts → nestia.project.getter.ts} +2 -2
  67. package/src/executable/sdk.ts +3 -3
  68. package/src/generates/SdkGenerator.ts +9 -2
  69. package/src/generates/SwaggerGenerator.ts +37 -9
  70. package/src/generates/internal/E2eFileProgrammer.ts +33 -20
  71. package/src/generates/internal/{DistributionComposer.ts → SdkDistributionComposer.ts} +3 -6
  72. package/src/generates/internal/SdkDtoGenerator.ts +384 -0
  73. package/src/generates/internal/SdkFileProgrammer.ts +8 -7
  74. package/src/generates/internal/SdkFunctionProgrammer.ts +71 -37
  75. package/src/generates/internal/SdkImportWizard.ts +14 -0
  76. package/src/generates/internal/SdkSimulationProgrammer.ts +71 -37
  77. package/src/generates/internal/SdkTypeDefiner.ts +120 -0
  78. package/src/generates/internal/SwaggerSchemaGenerator.ts +94 -92
  79. package/src/generates/internal/SwaggerSchemaValidator.ts +0 -12
  80. package/src/structures/IController.ts +2 -0
  81. package/src/structures/IRoute.ts +10 -2
  82. package/src/utils/ImportDictionary.ts +29 -26
  83. package/lib/executable/internal/NestiaConfigCompilerOptions.d.ts +0 -12
  84. package/lib/executable/internal/NestiaConfigCompilerOptions.js +0 -18
  85. package/lib/executable/internal/NestiaConfigCompilerOptions.js.map +0 -1
  86. package/lib/executable/internal/NestiaSdkConfig.d.ts +0 -4
  87. package/lib/executable/internal/NestiaSdkConfig.js +0 -1019
  88. package/lib/executable/internal/NestiaSdkConfig.js.map +0 -1
  89. package/lib/executable/internal/nestia.config.getter.js.map +0 -1
  90. package/lib/generates/internal/DistributionComposer.js.map +0 -1
  91. package/src/executable/internal/NestiaConfigCompilerOptions.ts +0 -19
  92. package/src/executable/internal/NestiaSdkConfig.ts +0 -36
  93. /package/lib/executable/internal/{nestia.config.getter.d.ts → nestia.project.getter.d.ts} +0 -0
@@ -0,0 +1,384 @@
1
+ import fs from "fs";
2
+ import ts from "typescript";
3
+
4
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
5
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
6
+ import { IJsDocTagInfo } from "typia/lib/schemas/metadata/IJsDocTagInfo";
7
+ import { IMetadataTypeTag } from "typia/lib/schemas/metadata/IMetadataTypeTag";
8
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
9
+ import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
10
+ import { MetadataArray } from "typia/lib/schemas/metadata/MetadataArray";
11
+ import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
12
+ import { MetadataConstant } from "typia/lib/schemas/metadata/MetadataConstant";
13
+ import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
14
+ import { MetadataProperty } from "typia/lib/schemas/metadata/MetadataProperty";
15
+ import { MetadataTuple } from "typia/lib/schemas/metadata/MetadataTuple";
16
+ import { Escaper } from "typia/lib/utils/Escaper";
17
+
18
+ import { INestiaConfig } from "../../INestiaConfig";
19
+ import { IRoute } from "../../structures/IRoute";
20
+ import { ImportDictionary } from "../../utils/ImportDictionary";
21
+ import { MapUtil } from "../../utils/MapUtil";
22
+
23
+ export namespace SdkDtoGenerator {
24
+ export const generate =
25
+ (checker: ts.TypeChecker) =>
26
+ (config: INestiaConfig) =>
27
+ async (routes: IRoute[]): Promise<void> => {
28
+ try {
29
+ await fs.promises.mkdir(`${config.output}/structures`);
30
+ } catch {}
31
+
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
+ const res = MetadataFactory.analyze(checker)({
45
+ escape: true,
46
+ constant: true,
47
+ absorb: false,
48
+ })(collection)(r.output.type);
49
+ if (res.success) r.output.metadata = res.data;
50
+ }
51
+
52
+ const modules: Map<string, IModule> = new Map();
53
+ for (const alias of collection.aliases())
54
+ prepare(modules)(alias.name)((importer) =>
55
+ defineAlias(config)(importer)(alias),
56
+ );
57
+ for (const object of collection.objects())
58
+ prepare(modules)(object.name)((importer) =>
59
+ defineObject(config)(importer)(object),
60
+ );
61
+
62
+ for (const module of modules.values())
63
+ await generateFile(config)(module);
64
+ };
65
+
66
+ const prepare =
67
+ (dict: Map<string, IModule>) =>
68
+ (name: string) =>
69
+ (programmer: (importer: ImportDictionary) => string) => {
70
+ const accessors: string[] = name.split(".");
71
+ let module: IModule;
72
+
73
+ accessors.forEach((acc, i) => {
74
+ module = MapUtil.take(dict, acc, () => ({
75
+ name: accessors.slice(0, i + 1).join("."),
76
+ children: new Map(),
77
+ }));
78
+ module.programmer = programmer;
79
+ dict = module.children;
80
+ });
81
+ return module!;
82
+ };
83
+
84
+ const generateFile =
85
+ (config: INestiaConfig) =>
86
+ async (module: IModule): Promise<void> => {
87
+ const importer: ImportDictionary = new ImportDictionary();
88
+
89
+ const body: string = writeModule(importer)(module);
90
+ const content: string[] = [];
91
+ if (!importer.empty())
92
+ content.push(
93
+ importer.toScript(`${config.output}/structures`),
94
+ "",
95
+ );
96
+ content.push(body);
97
+
98
+ const location: string = `${config.output}/structures/${module.name}.ts`;
99
+ await fs.promises.writeFile(location, content.join("\n"), "utf8");
100
+ };
101
+
102
+ const writeModule =
103
+ (importer: ImportDictionary) =>
104
+ (module: IModule): string => {
105
+ const content: string[] = [];
106
+ if (module.programmer) content.push(module.programmer(importer));
107
+ if (module.children.size) {
108
+ content.push(
109
+ `export namespace ${module.name.split(".").at(-1)} {`,
110
+ );
111
+ for (const child of module.children.values())
112
+ content.push(
113
+ writeModule(importer)(child)
114
+ .split("\n")
115
+ .map((l) => ` ${l}`)
116
+ .join("\n"),
117
+ );
118
+ content.push("}");
119
+ }
120
+ return content.join("\n");
121
+ };
122
+
123
+ const defineAlias =
124
+ (config: INestiaConfig) =>
125
+ (importer: ImportDictionary) =>
126
+ (alias: MetadataAlias) =>
127
+ [
128
+ ...writeComment(alias.description, alias.jsDocTags),
129
+ `export type ${alias.name.split(".").pop()!} = ${decode(config)(
130
+ importer,
131
+ )(alias.value)};`,
132
+ ].join("\n");
133
+
134
+ const defineObject =
135
+ (config: INestiaConfig) =>
136
+ (importer: ImportDictionary) =>
137
+ (object: MetadataObject) => {
138
+ const top: string = [
139
+ ...writeComment(object.description ?? null, object.jsDocTags),
140
+ `export type ${object.name.split(".").pop()!} = `,
141
+ ].join("\n");
142
+ if (object.properties.length === 0) return top + "{};";
143
+
144
+ const regular: MetadataProperty[] = object.properties.filter((p) =>
145
+ p.key.isSoleLiteral(),
146
+ );
147
+ const dynamic: MetadataProperty[] = object.properties.filter(
148
+ (p) => !p.key.isSoleLiteral(),
149
+ );
150
+
151
+ const brackets: string[][] = [];
152
+ if (regular.length) {
153
+ const row: string[] = ["{"];
154
+ for (const p of regular) {
155
+ const key: string = p.key.constants[0].values[0] as string;
156
+ const identifier: string = Escaper.variable(key)
157
+ ? key
158
+ : JSON.stringify(key);
159
+ row.push(
160
+ ...writeComment(p.description, p.jsDocTags).map(
161
+ (l) => ` ${l}`,
162
+ ),
163
+ ` ${identifier}: ${decode(config)(importer)(
164
+ p.value,
165
+ )};`,
166
+ );
167
+ }
168
+ row.push("}");
169
+ brackets.push(row);
170
+ }
171
+ for (const p of dynamic) {
172
+ const row: string[] = ["{"];
173
+ row.push(
174
+ ...writeComment(p.description, p.jsDocTags).map(
175
+ (l) => ` ${l}`,
176
+ ),
177
+ ` [key: ${decode(config)(importer)(p.key)}]: ${decode(
178
+ config,
179
+ )(importer)(p.value)};`,
180
+ );
181
+ row.push("}");
182
+ brackets.push(row);
183
+ }
184
+ return top + brackets.map((row) => row.join("\n")).join(" & ");
185
+ };
186
+
187
+ const writeComment = (
188
+ description: string | null,
189
+ jsDocTags: IJsDocTagInfo[],
190
+ ): string[] => {
191
+ const lines: string[] = [];
192
+ if (description?.length)
193
+ lines.push(...description.split("\n").map((s) => `${s}`));
194
+ if (description?.length && jsDocTags?.length) lines.push("");
195
+ if (jsDocTags?.length)
196
+ lines.push(
197
+ ...jsDocTags.map((t) =>
198
+ t.text?.length
199
+ ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
200
+ : `@${t.name}`,
201
+ ),
202
+ );
203
+ if (lines.length === 0) return [];
204
+ return ["/**", ...lines.map((s) => ` * ${s}`), " */"];
205
+ };
206
+
207
+ export const decode =
208
+ (config: INestiaConfig) =>
209
+ (importer: ImportDictionary) =>
210
+ (meta: Metadata): string => {
211
+ const union: string[] = [];
212
+
213
+ // COALESCES
214
+ if (meta.nullable) union.push("null");
215
+ if (meta.required === false) union.push("undefined");
216
+
217
+ // ATOMICS
218
+ for (const atomic of meta.atomics)
219
+ union.push(decodeAtomic(importer)(atomic));
220
+ for (const constant of meta.constants)
221
+ union.push(decodeConstant(constant));
222
+ for (const tpl of meta.templates)
223
+ union.push(decodeTemplate(config)(importer)(tpl));
224
+
225
+ // ARRAYS
226
+ for (const array of meta.arrays)
227
+ union.push(decodeArray(config)(importer)(array));
228
+ for (const tuple of meta.tuples)
229
+ union.push(decodeTuple(config)(importer)(tuple));
230
+
231
+ // OBJECTS
232
+ for (const obj of meta.objects)
233
+ union.push(decodeObject(config)(importer)(obj));
234
+ for (const alias of meta.aliases)
235
+ union.push(decodeAlias(config)(importer)(alias));
236
+
237
+ return union.join(" | ");
238
+ };
239
+
240
+ const decodeTypeTag =
241
+ (importer: ImportDictionary) =>
242
+ (tag: IMetadataTypeTag): string => {
243
+ const front: string = tag.name.split("<")[0];
244
+ if (NATIVE_TYPE_TAGS.has(front)) {
245
+ importer.external({
246
+ type: true,
247
+ library: `typia/lib/tags/${front}`,
248
+ instance: front,
249
+ });
250
+ return tag.name;
251
+ }
252
+ importer.external({
253
+ type: true,
254
+ library: `typia/lib/tags/TagBase`,
255
+ instance: "TagBase",
256
+ });
257
+ return `TagBase<${JSON.stringify(tag)}>`;
258
+ };
259
+
260
+ const decodeTypeTagMatrix =
261
+ (importer: ImportDictionary) =>
262
+ (base: string, tags: IMetadataTypeTag[][]): string => {
263
+ if (tags.length === 0) return base;
264
+ else if (tags.length === 1)
265
+ return `(${base} & ${tags[0]
266
+ .map((t) => decodeTypeTag(importer)(t))
267
+ .join(" & ")})`;
268
+ return (
269
+ "(" +
270
+ [
271
+ base,
272
+ ...tags.map(
273
+ (row) =>
274
+ `(${row
275
+ .map((t) => decodeTypeTag(importer)(t))
276
+ .join(" & ")})`,
277
+ ),
278
+ ] +
279
+ ")"
280
+ );
281
+ };
282
+
283
+ const decodeAtomic =
284
+ (importer: ImportDictionary) =>
285
+ (atomic: MetadataAtomic): string =>
286
+ decodeTypeTagMatrix(importer)(atomic.type, atomic.tags);
287
+
288
+ const decodeTemplate =
289
+ (config: INestiaConfig) =>
290
+ (importer: ImportDictionary) =>
291
+ (template: Metadata[]): string =>
292
+ "`" +
293
+ template
294
+ .map((meta) =>
295
+ meta.size() === 1 &&
296
+ meta.isRequired() &&
297
+ meta.nullable === false &&
298
+ meta.constants.length === 1
299
+ ? String(meta.constants[0].values[0])
300
+ .split("`")
301
+ .join("\\`")
302
+ : `\${${decode(config)(importer)(meta)}}`,
303
+ )
304
+ .join("") +
305
+ "`";
306
+
307
+ const decodeConstant = (constant: MetadataConstant): string => {
308
+ if (constant.values.length === 0)
309
+ return JSON.stringify(constant.values[0]);
310
+ return `(${constant.values
311
+ .map((val) => JSON.stringify(val))
312
+ .join(" | ")})`;
313
+ };
314
+
315
+ const decodeArray =
316
+ (config: INestiaConfig) =>
317
+ (importer: ImportDictionary) =>
318
+ (array: MetadataArray): string =>
319
+ decodeTypeTagMatrix(importer)(
320
+ `Array<${decode(config)(importer)(array.type.value)}>`,
321
+ array.tags,
322
+ );
323
+
324
+ const decodeTuple =
325
+ (config: INestiaConfig) =>
326
+ (importer: ImportDictionary) =>
327
+ (tuple: MetadataTuple): string =>
328
+ "[" +
329
+ tuple.type.elements.map((e) =>
330
+ e.rest
331
+ ? `...${decode(config)(importer)(e.rest)}`
332
+ : decode(config)(importer)(e),
333
+ ) +
334
+ "]";
335
+
336
+ const decodeAlias =
337
+ (config: INestiaConfig) =>
338
+ (importer: ImportDictionary) =>
339
+ (alias: MetadataAlias) => {
340
+ importInternalFile(config)(importer)(alias.name);
341
+ return alias.name;
342
+ };
343
+
344
+ const decodeObject =
345
+ (config: INestiaConfig) =>
346
+ (importer: ImportDictionary) =>
347
+ (object: MetadataObject) => {
348
+ importInternalFile(config)(importer)(object.name);
349
+ return object.name;
350
+ };
351
+
352
+ const importInternalFile =
353
+ (config: INestiaConfig) =>
354
+ (importer: ImportDictionary) =>
355
+ (name: string) => {
356
+ const top = name.split(".")[0];
357
+ importer.internal({
358
+ type: true,
359
+ file: `${config.output}/structures/${name.split(".")[0]}`,
360
+ instance: top,
361
+ });
362
+ };
363
+ }
364
+
365
+ const NATIVE_TYPE_TAGS = new Set([
366
+ "ExclusiveMinimum",
367
+ "ExclusiveMaximum",
368
+ "Format",
369
+ "Maximum",
370
+ "MaxItems",
371
+ "MaxLength",
372
+ "Minimum",
373
+ "MinItems",
374
+ "MinLength",
375
+ "MultipleOf",
376
+ "Pattern",
377
+ "Type",
378
+ ]);
379
+
380
+ interface IModule {
381
+ name: string;
382
+ children: Map<string, IModule>;
383
+ programmer?: (importer: ImportDictionary) => string;
384
+ }
@@ -73,13 +73,14 @@ export namespace SdkFileProgrammer {
73
73
  type: false,
74
74
  });
75
75
  directory.routes.forEach((route, i) => {
76
- for (const tuple of route.imports)
77
- for (const instance of tuple[1])
78
- importer.internal({
79
- file: tuple[0],
80
- instance,
81
- type: true,
82
- });
76
+ if (config.clone !== true)
77
+ for (const tuple of route.imports)
78
+ for (const instance of tuple[1])
79
+ importer.internal({
80
+ file: tuple[0],
81
+ instance,
82
+ type: true,
83
+ });
83
84
 
84
85
  content.push(
85
86
  SdkFunctionProgrammer.generate(config)(importer)(route),
@@ -7,8 +7,10 @@ import { INestiaConfig } from "../../INestiaConfig";
7
7
  import { IController } from "../../structures/IController";
8
8
  import { IRoute } from "../../structures/IRoute";
9
9
  import { ImportDictionary } from "../../utils/ImportDictionary";
10
+ import { SdkDtoGenerator } from "./SdkDtoGenerator";
10
11
  import { SdkImportWizard } from "./SdkImportWizard";
11
12
  import { SdkSimulationProgrammer } from "./SdkSimulationProgrammer";
13
+ import { SdkTypeDefiner } from "./SdkTypeDefiner";
12
14
 
13
15
  export namespace SdkFunctionProgrammer {
14
16
  export const generate =
@@ -132,7 +134,9 @@ export namespace SdkFunctionProgrammer {
132
134
  [
133
135
  `${awa ? "await " : ""}${SdkImportWizard.Fetcher(
134
136
  encrypted,
135
- )(importer)}.fetch(`,
137
+ )(importer)}.${
138
+ config.propagate === true ? "propagate" : "fetch"
139
+ }(`,
136
140
  fetchArguments
137
141
  .map((param) =>
138
142
  typeof param === "string"
@@ -163,23 +167,28 @@ export namespace SdkFunctionProgrammer {
163
167
  ` // configure header(s)\n`,
164
168
  ` connection.headers ??= {};\n`,
165
169
  ];
166
-
167
- for (const header of route.setHeaders) {
168
- if (header.type === "assigner")
169
- content.push(
170
- " ",
171
- `Object.assign(connection.headers, ${access("output")(
172
- header.source,
173
- )});\n`,
174
- );
175
- else
176
- content.push(
177
- " ",
178
- `${access("connection.headers")(
179
- header.target ?? header.source,
180
- )} = ${access("output")(header.source)};\n`,
181
- );
182
- }
170
+ const headerContents = (variable: string) =>
171
+ route.setHeaders.map((header) =>
172
+ header.type === "assigner"
173
+ ? `Object.assign(connection.headers, ${access(variable)(
174
+ header.source,
175
+ )});`
176
+ : `${access("connection.headers")(
177
+ header.target ?? header.source,
178
+ )} = ${access(variable)(header.source)};`,
179
+ );
180
+ if (config.propagate === true) {
181
+ content.push(` if (output.success) {\n`);
182
+ content.push(
183
+ ...headerContents("output.data").map(
184
+ (line) => ` ${line}\n`,
185
+ ),
186
+ );
187
+ content.push(` }\n`);
188
+ } else
189
+ content.push(
190
+ ...headerContents("output").map((line) => ` ${line}\n`),
191
+ );
183
192
  content.push("\n", " return output;\n", "}");
184
193
  return content.join("");
185
194
  };
@@ -221,7 +230,7 @@ export namespace SdkFunctionProgrammer {
221
230
  : [];
222
231
 
223
232
  // COMMENT TAGS
224
- const tags: IJsDocTagInfo[] = route.tags.filter(
233
+ const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
225
234
  (tag) =>
226
235
  tag.name !== "param" ||
227
236
  route.parameters
@@ -283,7 +292,7 @@ export namespace SdkFunctionProgrammer {
283
292
  ? `${route.name}.${
284
293
  param === props.query ? "Query" : "Input"
285
294
  }`
286
- : param.typeName;
295
+ : getTypeName(config)(importer)(param);
287
296
  return `${param.name}${
288
297
  param.optional ? "?" : ""
289
298
  }: ${type}`;
@@ -292,7 +301,7 @@ export namespace SdkFunctionProgrammer {
292
301
 
293
302
  // OUTPUT TYPE
294
303
  const output: string =
295
- route.output.typeName === "void"
304
+ config.propagate !== true && route.output.typeName === "void"
296
305
  ? "void"
297
306
  : `${route.name}.Output`;
298
307
 
@@ -321,13 +330,33 @@ export namespace SdkFunctionProgrammer {
321
330
  // LIST UP TYPES
322
331
  const types: Pair<string, string>[] = [];
323
332
  if (props.headers !== undefined)
324
- types.push(new Pair("Headers", props.headers.typeName));
333
+ types.push(
334
+ new Pair(
335
+ "Headers",
336
+ SdkTypeDefiner.headers(config)(importer)(props.headers),
337
+ ),
338
+ );
325
339
  if (props.query !== undefined)
326
- types.push(new Pair("Query", props.query.typeName));
340
+ types.push(
341
+ new Pair(
342
+ "Query",
343
+ SdkTypeDefiner.query(config)(importer)(props.query),
344
+ ),
345
+ );
327
346
  if (props.input !== undefined)
328
- types.push(new Pair("Input", props.input.typeName));
329
- if (route.output.typeName !== "void")
330
- types.push(new Pair("Output", route.output.typeName));
347
+ types.push(
348
+ new Pair(
349
+ "Input",
350
+ SdkTypeDefiner.input(config)(importer)(props.input),
351
+ ),
352
+ );
353
+ if (config.propagate === true || route.output.typeName !== "void")
354
+ types.push(
355
+ new Pair(
356
+ "Output",
357
+ SdkTypeDefiner.output(config)(importer)(route),
358
+ ),
359
+ );
331
360
 
332
361
  // PATH WITH PARAMETERS
333
362
  const parameters: IRoute.IParameter[] = filter_path_parameters(
@@ -344,13 +373,7 @@ export namespace SdkFunctionProgrammer {
344
373
  ? types
345
374
  .map(
346
375
  (tuple) =>
347
- ` export type ${tuple.first} = ${
348
- config.primitive !== false
349
- ? `${SdkImportWizard.Primitive(
350
- importer,
351
- )}<${tuple.second}>`
352
- : tuple.second
353
- };`,
376
+ ` export type ${tuple.first} = ${tuple.second};`,
354
377
  )
355
378
  .join("\n") + "\n"
356
379
  : "") +
@@ -401,7 +424,7 @@ export namespace SdkFunctionProgrammer {
401
424
  param.category === "query" &&
402
425
  param.typeName === props.query?.typeName
403
426
  ? `${route.name}.Query`
404
- : param.typeName
427
+ : getTypeName(config)(importer)(param)
405
428
  }`,
406
429
  )
407
430
  .join(", ")}): string => {\n` +
@@ -410,10 +433,14 @@ export namespace SdkFunctionProgrammer {
410
433
  (config.simulate === true && route.output.typeName !== "void"
411
434
  ? ` export const random = (g?: Partial<${SdkImportWizard.typia(
412
435
  importer,
413
- )}.IRandomGenerator>): Output =>\n` +
436
+ )}.IRandomGenerator>): ${SdkTypeDefiner.responseBody(
437
+ config,
438
+ )(importer)(route)} =>\n` +
414
439
  ` ${SdkImportWizard.typia(
415
440
  importer,
416
- )}.random<Output>(g);\n`
441
+ )}.random<${SdkTypeDefiner.responseBody(config)(importer)(
442
+ route,
443
+ )}>(g);\n`
417
444
  : "") +
418
445
  (config.simulate === true
419
446
  ? SdkSimulationProgrammer.generate(config)(importer)(
@@ -425,7 +452,7 @@ export namespace SdkFunctionProgrammer {
425
452
  undefined
426
453
  ? ` export const stringify = (input: Input) => ${SdkImportWizard.typia(
427
454
  importer,
428
- )}.assertStringify(input);\n`
455
+ )}.json.assertStringify(input);\n`
429
456
  : "") +
430
457
  "}"
431
458
  );
@@ -507,3 +534,10 @@ export namespace SdkFunctionProgrammer {
507
534
  }
508
535
 
509
536
  const space = (count: number) => " ".repeat(count);
537
+ const getTypeName =
538
+ (config: INestiaConfig) =>
539
+ (importer: ImportDictionary) =>
540
+ (p: IRoute.IParameter | IRoute.IOutput) =>
541
+ p.metadata
542
+ ? SdkDtoGenerator.decode(config)(importer)(p.metadata)
543
+ : p.typeName;
@@ -4,6 +4,13 @@ export namespace SdkImportWizard {
4
4
  export const Fetcher = (encrypted: boolean) =>
5
5
  encrypted ? EncryptedFetcher : PlainFetcher;
6
6
 
7
+ export const HttpError = (importer: ImportDictionary) =>
8
+ importer.external({
9
+ type: true,
10
+ library: "@nestia/fetcher",
11
+ instance: "HttpError",
12
+ });
13
+
7
14
  export const IConnection = (importer: ImportDictionary) =>
8
15
  importer.external({
9
16
  type: true,
@@ -18,6 +25,13 @@ export namespace SdkImportWizard {
18
25
  instance: "Primitive",
19
26
  });
20
27
 
28
+ export const Resolved = (importer: ImportDictionary) =>
29
+ importer.external({
30
+ type: true,
31
+ library: "@nestia/fetcher",
32
+ instance: "Resolved",
33
+ });
34
+
21
35
  export const typia = (importer: ImportDictionary) =>
22
36
  importer.external({
23
37
  type: false,