@nestia/sdk 2.4.3-dev.20231207 → 2.4.4-dev.20240109-3

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 (67) hide show
  1. package/lib/INestiaConfig.d.ts +13 -0
  2. package/lib/analyses/ControllerAnalyzer.js +12 -1
  3. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  4. package/lib/analyses/PathAnalyzer.d.ts +2 -2
  5. package/lib/analyses/PathAnalyzer.js +27 -11
  6. package/lib/analyses/PathAnalyzer.js.map +1 -1
  7. package/lib/analyses/ReflectAnalyzer.js +11 -2
  8. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  9. package/lib/executable/internal/NestiaConfigLoader.js +5 -1
  10. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  11. package/lib/executable/sdk.js +11 -11
  12. package/lib/generates/SwaggerGenerator.js +16 -22
  13. package/lib/generates/SwaggerGenerator.js.map +1 -1
  14. package/lib/structures/ISwaggerComponents.d.ts +1 -1
  15. package/lib/structures/ISwaggerRoute.d.ts +2 -2
  16. package/package.json +5 -5
  17. package/src/INestiaConfig.ts +248 -234
  18. package/src/NestiaSdkApplication.ts +253 -253
  19. package/src/analyses/AccessorAnalyzer.ts +60 -60
  20. package/src/analyses/ConfigAnalyzer.ts +147 -147
  21. package/src/analyses/ControllerAnalyzer.ts +390 -379
  22. package/src/analyses/ExceptionAnalyzer.ts +115 -115
  23. package/src/analyses/GenericAnalyzer.ts +51 -51
  24. package/src/analyses/ImportAnalyzer.ts +138 -138
  25. package/src/analyses/PathAnalyzer.ts +110 -98
  26. package/src/analyses/ReflectAnalyzer.ts +11 -6
  27. package/src/analyses/SecurityAnalyzer.ts +20 -20
  28. package/src/executable/internal/CommandParser.ts +15 -15
  29. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  30. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  31. package/src/executable/sdk.ts +73 -73
  32. package/src/generates/E2eGenerator.ts +64 -64
  33. package/src/generates/SdkGenerator.ts +96 -96
  34. package/src/generates/SwaggerGenerator.ts +376 -372
  35. package/src/generates/internal/E2eFileProgrammer.ts +123 -123
  36. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  37. package/src/generates/internal/SdkDtoGenerator.ts +424 -424
  38. package/src/generates/internal/SdkFileProgrammer.ts +106 -106
  39. package/src/generates/internal/SdkImportWizard.ts +55 -55
  40. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  41. package/src/generates/internal/SdkSimulationProgrammer.ts +133 -133
  42. package/src/generates/internal/SdkTypeDefiner.ts +119 -119
  43. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  44. package/src/index.ts +4 -4
  45. package/src/module.ts +2 -2
  46. package/src/structures/IErrorReport.ts +6 -6
  47. package/src/structures/INestiaProject.ts +13 -13
  48. package/src/structures/INormalizedInput.ts +20 -20
  49. package/src/structures/ISwagger.ts +91 -91
  50. package/src/structures/ISwaggerComponents.ts +29 -29
  51. package/src/structures/ISwaggerError.ts +8 -8
  52. package/src/structures/ISwaggerInfo.ts +80 -80
  53. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  54. package/src/structures/ISwaggerLazySchema.ts +7 -7
  55. package/src/structures/ISwaggerRoute.ts +51 -51
  56. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  57. package/src/structures/ITypeTuple.ts +6 -6
  58. package/src/structures/MethodType.ts +5 -5
  59. package/src/structures/ParamCategory.ts +1 -1
  60. package/src/structures/TypeEntry.ts +22 -22
  61. package/src/utils/ArrayUtil.ts +26 -26
  62. package/src/utils/FileRetriever.ts +22 -22
  63. package/src/utils/ImportDictionary.ts +125 -125
  64. package/src/utils/MapUtil.ts +14 -14
  65. package/src/utils/PathUtil.ts +10 -10
  66. package/src/utils/SourceFinder.ts +66 -66
  67. package/src/utils/StripEnums.ts +5 -5
@@ -1,106 +1,106 @@
1
- import fs from "fs";
2
-
3
- import { INestiaConfig } from "../../INestiaConfig";
4
- import { IRoute } from "../../structures/IRoute";
5
- import { ImportDictionary } from "../../utils/ImportDictionary";
6
- import { MapUtil } from "../../utils/MapUtil";
7
- import { SdkFunctionProgrammer } from "./SdkFunctionProgrammer";
8
- import { SdkRouteDirectory } from "./SdkRouteDirectory";
9
-
10
- export namespace SdkFileProgrammer {
11
- /* ---------------------------------------------------------
12
- CONSTRUCTOR
13
- --------------------------------------------------------- */
14
- export const generate =
15
- (config: INestiaConfig) =>
16
- async (routeList: IRoute[]): Promise<void> => {
17
- // CONSTRUCT FOLDER TREE
18
- const root: SdkRouteDirectory = new SdkRouteDirectory(null, "functional");
19
- for (const route of routeList) emplace(root)(route);
20
-
21
- // ITERATE FILES
22
- await iterate(config)(root)(config.output + "/functional");
23
- };
24
-
25
- const emplace =
26
- (directory: SdkRouteDirectory) =>
27
- (route: IRoute): void => {
28
- // OPEN DIRECTORIES
29
- for (const key of route.accessors.slice(0, -1)) {
30
- directory = MapUtil.take(
31
- directory.children,
32
- key,
33
- () => new SdkRouteDirectory(directory, key),
34
- );
35
- }
36
-
37
- // ADD ROUTE
38
- directory.routes.push(route);
39
- };
40
-
41
- /* ---------------------------------------------------------
42
- FILE ITERATOR
43
- --------------------------------------------------------- */
44
- const iterate =
45
- (config: INestiaConfig) =>
46
- (directory: SdkRouteDirectory) =>
47
- async (outDir: string): Promise<void> => {
48
- // CREATE A NEW DIRECTORY
49
- try {
50
- await fs.promises.mkdir(outDir);
51
- } catch {}
52
-
53
- // ITERATE CHILDREN
54
- const content: string[] = [];
55
- for (const [key, value] of directory.children) {
56
- await iterate(config)(value)(`${outDir}/${key}`);
57
- content.push(`export * as ${key} from "./${key}";`);
58
- }
59
- if (content.length && directory.routes.length) content.push("");
60
-
61
- // ITERATE ROUTES
62
- const importer: ImportDictionary = new ImportDictionary(
63
- `${outDir}/index.ts`,
64
- );
65
- if (
66
- config.simulate === true &&
67
- directory.routes.some((r) => !!r.parameters.length)
68
- )
69
- importer.internal({
70
- file: `${config.output}/utils/NestiaSimulator.ts`,
71
- instance: "NestiaSimulator",
72
- type: false,
73
- });
74
- directory.routes.forEach((route, i) => {
75
- if (config.clone !== true)
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
- });
83
-
84
- content.push(SdkFunctionProgrammer.generate(config)(importer)(route));
85
- if (i !== directory.routes.length - 1) content.push("");
86
- });
87
-
88
- // FINALIZE THE CONTENT
89
- if (directory.routes.length !== 0)
90
- content.push(
91
- importer.toScript(outDir),
92
- "",
93
- ...content.splice(0, content.length),
94
- );
95
-
96
- const script: string =
97
- "/**\n" +
98
- " * @packageDocumentation\n" +
99
- ` * @module ${directory.module}\n` +
100
- " * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
101
- " */\n" +
102
- "//================================================================\n" +
103
- content.join("\n");
104
- await fs.promises.writeFile(importer.file, script, "utf8");
105
- };
106
- }
1
+ import fs from "fs";
2
+
3
+ import { INestiaConfig } from "../../INestiaConfig";
4
+ import { IRoute } from "../../structures/IRoute";
5
+ import { ImportDictionary } from "../../utils/ImportDictionary";
6
+ import { MapUtil } from "../../utils/MapUtil";
7
+ import { SdkFunctionProgrammer } from "./SdkFunctionProgrammer";
8
+ import { SdkRouteDirectory } from "./SdkRouteDirectory";
9
+
10
+ export namespace SdkFileProgrammer {
11
+ /* ---------------------------------------------------------
12
+ CONSTRUCTOR
13
+ --------------------------------------------------------- */
14
+ export const generate =
15
+ (config: INestiaConfig) =>
16
+ async (routeList: IRoute[]): Promise<void> => {
17
+ // CONSTRUCT FOLDER TREE
18
+ const root: SdkRouteDirectory = new SdkRouteDirectory(null, "functional");
19
+ for (const route of routeList) emplace(root)(route);
20
+
21
+ // ITERATE FILES
22
+ await iterate(config)(root)(config.output + "/functional");
23
+ };
24
+
25
+ const emplace =
26
+ (directory: SdkRouteDirectory) =>
27
+ (route: IRoute): void => {
28
+ // OPEN DIRECTORIES
29
+ for (const key of route.accessors.slice(0, -1)) {
30
+ directory = MapUtil.take(
31
+ directory.children,
32
+ key,
33
+ () => new SdkRouteDirectory(directory, key),
34
+ );
35
+ }
36
+
37
+ // ADD ROUTE
38
+ directory.routes.push(route);
39
+ };
40
+
41
+ /* ---------------------------------------------------------
42
+ FILE ITERATOR
43
+ --------------------------------------------------------- */
44
+ const iterate =
45
+ (config: INestiaConfig) =>
46
+ (directory: SdkRouteDirectory) =>
47
+ async (outDir: string): Promise<void> => {
48
+ // CREATE A NEW DIRECTORY
49
+ try {
50
+ await fs.promises.mkdir(outDir);
51
+ } catch {}
52
+
53
+ // ITERATE CHILDREN
54
+ const content: string[] = [];
55
+ for (const [key, value] of directory.children) {
56
+ await iterate(config)(value)(`${outDir}/${key}`);
57
+ content.push(`export * as ${key} from "./${key}";`);
58
+ }
59
+ if (content.length && directory.routes.length) content.push("");
60
+
61
+ // ITERATE ROUTES
62
+ const importer: ImportDictionary = new ImportDictionary(
63
+ `${outDir}/index.ts`,
64
+ );
65
+ if (
66
+ config.simulate === true &&
67
+ directory.routes.some((r) => !!r.parameters.length)
68
+ )
69
+ importer.internal({
70
+ file: `${config.output}/utils/NestiaSimulator.ts`,
71
+ instance: "NestiaSimulator",
72
+ type: false,
73
+ });
74
+ directory.routes.forEach((route, i) => {
75
+ if (config.clone !== true)
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
+ });
83
+
84
+ content.push(SdkFunctionProgrammer.generate(config)(importer)(route));
85
+ if (i !== directory.routes.length - 1) content.push("");
86
+ });
87
+
88
+ // FINALIZE THE CONTENT
89
+ if (directory.routes.length !== 0)
90
+ content.push(
91
+ importer.toScript(outDir),
92
+ "",
93
+ ...content.splice(0, content.length),
94
+ );
95
+
96
+ const script: string =
97
+ "/**\n" +
98
+ " * @packageDocumentation\n" +
99
+ ` * @module ${directory.module}\n` +
100
+ " * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
101
+ " */\n" +
102
+ "//================================================================\n" +
103
+ content.join("\n");
104
+ await fs.promises.writeFile(importer.file, script, "utf8");
105
+ };
106
+ }
@@ -1,55 +1,55 @@
1
- import { ImportDictionary } from "../../utils/ImportDictionary";
2
-
3
- export namespace SdkImportWizard {
4
- export const Fetcher = (encrypted: boolean) =>
5
- encrypted ? EncryptedFetcher : PlainFetcher;
6
-
7
- export const HttpError = (importer: ImportDictionary) =>
8
- importer.external({
9
- type: true,
10
- library: "@nestia/fetcher",
11
- instance: "HttpError",
12
- });
13
-
14
- export const IConnection = (importer: ImportDictionary) =>
15
- importer.external({
16
- type: true,
17
- library: "@nestia/fetcher",
18
- instance: "IConnection",
19
- });
20
-
21
- export const Primitive = (importer: ImportDictionary) =>
22
- importer.external({
23
- type: true,
24
- library: "@nestia/fetcher",
25
- instance: "Primitive",
26
- });
27
-
28
- export const Resolved = (importer: ImportDictionary) =>
29
- importer.external({
30
- type: true,
31
- library: "@nestia/fetcher",
32
- instance: "Resolved",
33
- });
34
-
35
- export const typia = (importer: ImportDictionary) =>
36
- importer.external({
37
- type: false,
38
- library: "typia",
39
- instance: null,
40
- });
41
- }
42
-
43
- const PlainFetcher = (importer: ImportDictionary) =>
44
- importer.external({
45
- type: false,
46
- library: "@nestia/fetcher/lib/PlainFetcher",
47
- instance: "PlainFetcher",
48
- });
49
-
50
- const EncryptedFetcher = (importer: ImportDictionary) =>
51
- importer.external({
52
- type: false,
53
- library: "@nestia/fetcher/lib/EncryptedFetcher",
54
- instance: "EncryptedFetcher",
55
- });
1
+ import { ImportDictionary } from "../../utils/ImportDictionary";
2
+
3
+ export namespace SdkImportWizard {
4
+ export const Fetcher = (encrypted: boolean) =>
5
+ encrypted ? EncryptedFetcher : PlainFetcher;
6
+
7
+ export const HttpError = (importer: ImportDictionary) =>
8
+ importer.external({
9
+ type: true,
10
+ library: "@nestia/fetcher",
11
+ instance: "HttpError",
12
+ });
13
+
14
+ export const IConnection = (importer: ImportDictionary) =>
15
+ importer.external({
16
+ type: true,
17
+ library: "@nestia/fetcher",
18
+ instance: "IConnection",
19
+ });
20
+
21
+ export const Primitive = (importer: ImportDictionary) =>
22
+ importer.external({
23
+ type: true,
24
+ library: "@nestia/fetcher",
25
+ instance: "Primitive",
26
+ });
27
+
28
+ export const Resolved = (importer: ImportDictionary) =>
29
+ importer.external({
30
+ type: true,
31
+ library: "@nestia/fetcher",
32
+ instance: "Resolved",
33
+ });
34
+
35
+ export const typia = (importer: ImportDictionary) =>
36
+ importer.external({
37
+ type: false,
38
+ library: "typia",
39
+ instance: null,
40
+ });
41
+ }
42
+
43
+ const PlainFetcher = (importer: ImportDictionary) =>
44
+ importer.external({
45
+ type: false,
46
+ library: "@nestia/fetcher/lib/PlainFetcher",
47
+ instance: "PlainFetcher",
48
+ });
49
+
50
+ const EncryptedFetcher = (importer: ImportDictionary) =>
51
+ importer.external({
52
+ type: false,
53
+ library: "@nestia/fetcher/lib/EncryptedFetcher",
54
+ instance: "EncryptedFetcher",
55
+ });
@@ -1,17 +1,17 @@
1
- import { IRoute } from "../../structures/IRoute";
2
-
3
- export class SdkRouteDirectory {
4
- public readonly module: string;
5
- public readonly children: Map<string, SdkRouteDirectory>;
6
- public readonly routes: IRoute[];
7
-
8
- public constructor(
9
- readonly parent: SdkRouteDirectory | null,
10
- readonly name: string,
11
- ) {
12
- this.children = new Map();
13
- this.routes = [];
14
- this.module =
15
- this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
16
- }
17
- }
1
+ import { IRoute } from "../../structures/IRoute";
2
+
3
+ export class SdkRouteDirectory {
4
+ public readonly module: string;
5
+ public readonly children: Map<string, SdkRouteDirectory>;
6
+ public readonly routes: IRoute[];
7
+
8
+ public constructor(
9
+ readonly parent: SdkRouteDirectory | null,
10
+ readonly name: string,
11
+ ) {
12
+ this.children = new Map();
13
+ this.routes = [];
14
+ this.module =
15
+ this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
16
+ }
17
+ }
@@ -1,133 +1,133 @@
1
- import { INestiaConfig } from "../../INestiaConfig";
2
- import { IRoute } from "../../structures/IRoute";
3
- import { ImportDictionary } from "../../utils/ImportDictionary";
4
- import { SdkImportWizard } from "./SdkImportWizard";
5
- import { SdkTypeDefiner } from "./SdkTypeDefiner";
6
-
7
- export namespace SdkSimulationProgrammer {
8
- export const generate =
9
- (config: INestiaConfig) =>
10
- (importer: ImportDictionary) =>
11
- (route: IRoute): string => {
12
- const output: boolean =
13
- config.propagate === true || route.output.typeName !== "void";
14
- const body: string[] = [
15
- ...(route.parameters.filter((p) => p.category !== "headers").length !==
16
- 0
17
- ? assert(config)(importer)(route)
18
- : []),
19
- ...(output ? returns(config)(route) : []),
20
- ];
21
- return [
22
- `export const simulate = async (`,
23
- ` ${
24
- route.parameters.filter((p) => p.category !== "headers").length ===
25
- 0 && route.output.typeName === "void"
26
- ? "_connection"
27
- : "connection"
28
- }: ${
29
- route.parameters.some(
30
- (p) => p.category === "headers" && p.field === undefined,
31
- )
32
- ? `${SdkImportWizard.IConnection(importer)}<${route.name}.Headers>`
33
- : SdkImportWizard.IConnection(importer)
34
- },`,
35
- ...route.parameters
36
- .filter((p) => p.category !== "headers")
37
- .map(
38
- (p) =>
39
- ` ${p.name}: ${
40
- p.category === "query" || p.category === "body"
41
- ? `${route.name}.${
42
- p.category === "query" ? "Query" : "Input"
43
- }`
44
- : SdkTypeDefiner.name(config)(importer)(p)
45
- },`,
46
- ),
47
- `): Promise<${output ? "Output" : "void"}> => {`,
48
- ...body.map((l) => ` ${l}`),
49
- `}`,
50
- ]
51
- .map((line) => ` ${line}`)
52
- .join("\n");
53
- };
54
-
55
- const assert =
56
- (config: INestiaConfig) =>
57
- (importer: ImportDictionary) =>
58
- (route: IRoute): string[] => {
59
- const typia = SdkImportWizard.typia(importer);
60
- const func: string[] = [
61
- `const assert = ${importer.internal({
62
- file: `${config.output}/utils/NestiaSimulator.ts`,
63
- instance: "NestiaSimulator",
64
- type: false,
65
- })}.assert({`,
66
- ` method: METADATA.method,`,
67
- ` host: connection.host,`,
68
- ` path: path(${route.parameters
69
- .filter((p) => p.category === "param" || p.category === "query")
70
- .map((p) => p.name)
71
- .join(", ")}),`,
72
- ` contentType: ${JSON.stringify(route.output.contentType)},`,
73
- `});`,
74
- ];
75
- const individual: string[] = route.parameters
76
- .filter((p) => p.category !== "headers")
77
- .map((p) =>
78
- p.category === "body"
79
- ? `assert.body(() => ${typia}.assert(${p.name}));`
80
- : p.category === "query"
81
- ? `assert.query(() => ${typia}.assert(${p.name}));`
82
- : p.category === "headers"
83
- ? `assert.headers(() => ${typia}.assert(connection.headers);`
84
- : `assert.param("${p.field}")(() => ${typia}.assert(${p.name}));`,
85
- );
86
- if (config.propagate !== true) return [...func, ...individual];
87
-
88
- return [
89
- ...func,
90
- `try {`,
91
- ...individual.map((l) => ` ${l}`),
92
- `} catch (exp) {`,
93
- ` if (!${typia}.is<${SdkImportWizard.HttpError(
94
- importer,
95
- )}>(exp)) throw exp;`,
96
- ` return {`,
97
- ` success: false,`,
98
- ` status: exp.status,`,
99
- ` headers: exp.headers,`,
100
- ` data: exp.toJSON().message,`,
101
- ` } as any;`,
102
- `}`,
103
- ];
104
- };
105
-
106
- const returns =
107
- (config: INestiaConfig) =>
108
- (route: IRoute): string[] => {
109
- const random = (prefix: string, postfix: string) =>
110
- route.output.typeName === "void"
111
- ? [`${prefix} undefined${postfix}`]
112
- : [
113
- `${prefix} random(`,
114
- ` typeof connection.simulate === 'object' &&`,
115
- ` connection.simulate !== null`,
116
- ` ? connection.simulate`,
117
- ` : undefined`,
118
- `)${postfix}`,
119
- ];
120
- if (config.propagate !== true) return random("return", ";");
121
-
122
- return [
123
- `return {`,
124
- ` success: true,`,
125
- ` status: ${route.status ?? (route.method === "POST" ? 201 : 200)},`,
126
- ` headers: {`,
127
- ` "Content-Type": "${route.output.contentType}",`,
128
- ` },`,
129
- ...random("data:", ",").map((r) => ` ${r}`),
130
- `}`,
131
- ];
132
- };
133
- }
1
+ import { INestiaConfig } from "../../INestiaConfig";
2
+ import { IRoute } from "../../structures/IRoute";
3
+ import { ImportDictionary } from "../../utils/ImportDictionary";
4
+ import { SdkImportWizard } from "./SdkImportWizard";
5
+ import { SdkTypeDefiner } from "./SdkTypeDefiner";
6
+
7
+ export namespace SdkSimulationProgrammer {
8
+ export const generate =
9
+ (config: INestiaConfig) =>
10
+ (importer: ImportDictionary) =>
11
+ (route: IRoute): string => {
12
+ const output: boolean =
13
+ config.propagate === true || route.output.typeName !== "void";
14
+ const body: string[] = [
15
+ ...(route.parameters.filter((p) => p.category !== "headers").length !==
16
+ 0
17
+ ? assert(config)(importer)(route)
18
+ : []),
19
+ ...(output ? returns(config)(route) : []),
20
+ ];
21
+ return [
22
+ `export const simulate = async (`,
23
+ ` ${
24
+ route.parameters.filter((p) => p.category !== "headers").length ===
25
+ 0 && route.output.typeName === "void"
26
+ ? "_connection"
27
+ : "connection"
28
+ }: ${
29
+ route.parameters.some(
30
+ (p) => p.category === "headers" && p.field === undefined,
31
+ )
32
+ ? `${SdkImportWizard.IConnection(importer)}<${route.name}.Headers>`
33
+ : SdkImportWizard.IConnection(importer)
34
+ },`,
35
+ ...route.parameters
36
+ .filter((p) => p.category !== "headers")
37
+ .map(
38
+ (p) =>
39
+ ` ${p.name}: ${
40
+ p.category === "query" || p.category === "body"
41
+ ? `${route.name}.${
42
+ p.category === "query" ? "Query" : "Input"
43
+ }`
44
+ : SdkTypeDefiner.name(config)(importer)(p)
45
+ },`,
46
+ ),
47
+ `): Promise<${output ? "Output" : "void"}> => {`,
48
+ ...body.map((l) => ` ${l}`),
49
+ `}`,
50
+ ]
51
+ .map((line) => ` ${line}`)
52
+ .join("\n");
53
+ };
54
+
55
+ const assert =
56
+ (config: INestiaConfig) =>
57
+ (importer: ImportDictionary) =>
58
+ (route: IRoute): string[] => {
59
+ const typia = SdkImportWizard.typia(importer);
60
+ const func: string[] = [
61
+ `const assert = ${importer.internal({
62
+ file: `${config.output}/utils/NestiaSimulator.ts`,
63
+ instance: "NestiaSimulator",
64
+ type: false,
65
+ })}.assert({`,
66
+ ` method: METADATA.method,`,
67
+ ` host: connection.host,`,
68
+ ` path: path(${route.parameters
69
+ .filter((p) => p.category === "param" || p.category === "query")
70
+ .map((p) => p.name)
71
+ .join(", ")}),`,
72
+ ` contentType: ${JSON.stringify(route.output.contentType)},`,
73
+ `});`,
74
+ ];
75
+ const individual: string[] = route.parameters
76
+ .filter((p) => p.category !== "headers")
77
+ .map((p) =>
78
+ p.category === "body"
79
+ ? `assert.body(() => ${typia}.assert(${p.name}));`
80
+ : p.category === "query"
81
+ ? `assert.query(() => ${typia}.assert(${p.name}));`
82
+ : p.category === "headers"
83
+ ? `assert.headers(() => ${typia}.assert(connection.headers);`
84
+ : `assert.param("${p.field}")(() => ${typia}.assert(${p.name}));`,
85
+ );
86
+ if (config.propagate !== true) return [...func, ...individual];
87
+
88
+ return [
89
+ ...func,
90
+ `try {`,
91
+ ...individual.map((l) => ` ${l}`),
92
+ `} catch (exp) {`,
93
+ ` if (!${typia}.is<${SdkImportWizard.HttpError(
94
+ importer,
95
+ )}>(exp)) throw exp;`,
96
+ ` return {`,
97
+ ` success: false,`,
98
+ ` status: exp.status,`,
99
+ ` headers: exp.headers,`,
100
+ ` data: exp.toJSON().message,`,
101
+ ` } as any;`,
102
+ `}`,
103
+ ];
104
+ };
105
+
106
+ const returns =
107
+ (config: INestiaConfig) =>
108
+ (route: IRoute): string[] => {
109
+ const random = (prefix: string, postfix: string) =>
110
+ route.output.typeName === "void"
111
+ ? [`${prefix} undefined${postfix}`]
112
+ : [
113
+ `${prefix} random(`,
114
+ ` typeof connection.simulate === 'object' &&`,
115
+ ` connection.simulate !== null`,
116
+ ` ? connection.simulate`,
117
+ ` : undefined`,
118
+ `)${postfix}`,
119
+ ];
120
+ if (config.propagate !== true) return random("return", ";");
121
+
122
+ return [
123
+ `return {`,
124
+ ` success: true,`,
125
+ ` status: ${route.status ?? (route.method === "POST" ? 201 : 200)},`,
126
+ ` headers: {`,
127
+ ` "Content-Type": "${route.output.contentType}",`,
128
+ ` },`,
129
+ ...random("data:", ",").map((r) => ` ${r}`),
130
+ `}`,
131
+ ];
132
+ };
133
+ }