@nestia/sdk 2.4.2 → 2.4.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 (111) hide show
  1. package/lib/NestiaSdkApplication.js +2 -6
  2. package/lib/NestiaSdkApplication.js.map +1 -1
  3. package/lib/analyses/AccessorAnalyzer.js.map +1 -1
  4. package/lib/analyses/ConfigAnalyzer.js +4 -8
  5. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  6. package/lib/analyses/ControllerAnalyzer.js +6 -8
  7. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  8. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  9. package/lib/analyses/GenericAnalyzer.js +1 -2
  10. package/lib/analyses/GenericAnalyzer.js.map +1 -1
  11. package/lib/analyses/ImportAnalyzer.js +4 -4
  12. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  13. package/lib/analyses/PathAnalyzer.js.map +1 -1
  14. package/lib/analyses/ReflectAnalyzer.js +7 -8
  15. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  16. package/lib/analyses/SecurityAnalyzer.js.map +1 -1
  17. package/lib/executable/internal/CommandParser.js.map +1 -1
  18. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  19. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  20. package/lib/executable/sdk.js +11 -11
  21. package/lib/executable/sdk.js.map +1 -1
  22. package/lib/generates/E2eGenerator.js.map +1 -1
  23. package/lib/generates/SdkGenerator.js.map +1 -1
  24. package/lib/generates/SwaggerGenerator.js +5 -11
  25. package/lib/generates/SwaggerGenerator.js.map +1 -1
  26. package/lib/generates/internal/E2eFileProgrammer.js +2 -8
  27. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  28. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  29. package/lib/generates/internal/SdkDtoGenerator.js +3 -9
  30. package/lib/generates/internal/SdkDtoGenerator.js.map +1 -1
  31. package/lib/generates/internal/SdkFileProgrammer.js +4 -4
  32. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  33. package/lib/generates/internal/SdkFunctionProgrammer.js +12 -20
  34. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  35. package/lib/generates/internal/SdkImportWizard.js.map +1 -1
  36. package/lib/generates/internal/SdkRouteDirectory.js +1 -3
  37. package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
  38. package/lib/generates/internal/SdkSimulationProgrammer.js +5 -7
  39. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  40. package/lib/generates/internal/SdkTypeDefiner.js +2 -5
  41. package/lib/generates/internal/SdkTypeDefiner.js.map +1 -1
  42. package/lib/generates/internal/SwaggerSchemaGenerator.js +29 -44
  43. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  44. package/lib/generates/internal/SwaggerSchemaValidator.js +3 -9
  45. package/lib/generates/internal/SwaggerSchemaValidator.js.map +1 -1
  46. package/lib/structures/MethodType.js +1 -7
  47. package/lib/structures/MethodType.js.map +1 -1
  48. package/lib/structures/TypeEntry.js.map +1 -1
  49. package/lib/utils/ArrayUtil.js.map +1 -1
  50. package/lib/utils/FileRetriever.js.map +1 -1
  51. package/lib/utils/ImportDictionary.js +1 -4
  52. package/lib/utils/ImportDictionary.js.map +1 -1
  53. package/lib/utils/MapUtil.js.map +1 -1
  54. package/lib/utils/PathUtil.js.map +1 -1
  55. package/lib/utils/SourceFinder.js.map +1 -1
  56. package/package.json +4 -7
  57. package/src/INestiaConfig.ts +234 -234
  58. package/src/NestiaSdkApplication.ts +253 -268
  59. package/src/analyses/AccessorAnalyzer.ts +60 -60
  60. package/src/analyses/ConfigAnalyzer.ts +147 -164
  61. package/src/analyses/ControllerAnalyzer.ts +379 -399
  62. package/src/analyses/ExceptionAnalyzer.ts +115 -124
  63. package/src/analyses/GenericAnalyzer.ts +51 -57
  64. package/src/analyses/ImportAnalyzer.ts +138 -159
  65. package/src/analyses/PathAnalyzer.ts +98 -100
  66. package/src/analyses/ReflectAnalyzer.ts +425 -433
  67. package/src/analyses/SecurityAnalyzer.ts +20 -20
  68. package/src/executable/internal/CommandParser.ts +15 -15
  69. package/src/executable/internal/NestiaConfigLoader.ts +67 -68
  70. package/src/executable/internal/NestiaSdkCommand.ts +60 -64
  71. package/src/executable/sdk.ts +73 -73
  72. package/src/generates/E2eGenerator.ts +64 -67
  73. package/src/generates/SdkGenerator.ts +96 -100
  74. package/src/generates/SwaggerGenerator.ts +372 -410
  75. package/src/generates/internal/E2eFileProgrammer.ts +123 -129
  76. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  77. package/src/generates/internal/SdkDtoGenerator.ts +424 -450
  78. package/src/generates/internal/SdkFileProgrammer.ts +106 -111
  79. package/src/generates/internal/SdkFunctionProgrammer.ts +466 -501
  80. package/src/generates/internal/SdkImportWizard.ts +55 -55
  81. package/src/generates/internal/SdkRouteDirectory.ts +17 -19
  82. package/src/generates/internal/SdkSimulationProgrammer.ts +133 -142
  83. package/src/generates/internal/SdkTypeDefiner.ts +119 -124
  84. package/src/generates/internal/SwaggerSchemaGenerator.ts +382 -401
  85. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -210
  86. package/src/index.ts +4 -4
  87. package/src/module.ts +2 -2
  88. package/src/structures/IController.ts +79 -81
  89. package/src/structures/IErrorReport.ts +6 -6
  90. package/src/structures/INestiaProject.ts +13 -13
  91. package/src/structures/INormalizedInput.ts +20 -20
  92. package/src/structures/IRoute.ts +40 -41
  93. package/src/structures/ISwagger.ts +91 -91
  94. package/src/structures/ISwaggerComponents.ts +29 -29
  95. package/src/structures/ISwaggerError.ts +8 -8
  96. package/src/structures/ISwaggerInfo.ts +80 -80
  97. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  98. package/src/structures/ISwaggerLazySchema.ts +7 -7
  99. package/src/structures/ISwaggerRoute.ts +51 -51
  100. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  101. package/src/structures/ITypeTuple.ts +6 -6
  102. package/src/structures/MethodType.ts +5 -11
  103. package/src/structures/ParamCategory.ts +1 -1
  104. package/src/structures/TypeEntry.ts +22 -22
  105. package/src/utils/ArrayUtil.ts +26 -26
  106. package/src/utils/FileRetriever.ts +22 -22
  107. package/src/utils/ImportDictionary.ts +125 -128
  108. package/src/utils/MapUtil.ts +14 -14
  109. package/src/utils/PathUtil.ts +10 -10
  110. package/src/utils/SourceFinder.ts +66 -70
  111. package/src/utils/StripEnums.ts +5 -10
@@ -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,19 +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
16
- ? `${this.parent.module}.${name}`
17
- : `api.${name}`;
18
- }
19
- }
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,142 +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")
16
- .length !== 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")
25
- .length === 0 && route.output.typeName === "void"
26
- ? "_connection"
27
- : "connection"
28
- }: ${
29
- route.parameters.some(
30
- (p) =>
31
- p.category === "headers" && p.field === undefined,
32
- )
33
- ? `${SdkImportWizard.IConnection(importer)}<${
34
- route.name
35
- }.Headers>`
36
- : SdkImportWizard.IConnection(importer)
37
- },`,
38
- ...route.parameters
39
- .filter((p) => p.category !== "headers")
40
- .map(
41
- (p) =>
42
- ` ${p.name}: ${
43
- p.category === "query" || p.category === "body"
44
- ? `${route.name}.${
45
- p.category === "query"
46
- ? "Query"
47
- : "Input"
48
- }`
49
- : SdkTypeDefiner.name(config)(importer)(p)
50
- },`,
51
- ),
52
- `): Promise<${output ? "Output" : "void"}> => {`,
53
- ...body.map((l) => ` ${l}`),
54
- `}`,
55
- ]
56
- .map((line) => ` ${line}`)
57
- .join("\n");
58
- };
59
-
60
- const assert =
61
- (config: INestiaConfig) =>
62
- (importer: ImportDictionary) =>
63
- (route: IRoute): string[] => {
64
- const typia = SdkImportWizard.typia(importer);
65
- const func: string[] = [
66
- `const assert = ${importer.internal({
67
- file: `${config.output}/utils/NestiaSimulator.ts`,
68
- instance: "NestiaSimulator",
69
- type: false,
70
- })}.assert({`,
71
- ` method: METADATA.method,`,
72
- ` host: connection.host,`,
73
- ` path: path(${route.parameters
74
- .filter(
75
- (p) => p.category === "param" || p.category === "query",
76
- )
77
- .map((p) => p.name)
78
- .join(", ")}),`,
79
- ` contentType: ${JSON.stringify(route.output.contentType)},`,
80
- `});`,
81
- ];
82
- const individual: string[] = route.parameters
83
- .filter((p) => p.category !== "headers")
84
- .map((p) =>
85
- p.category === "body"
86
- ? `assert.body(() => ${typia}.assert(${p.name}));`
87
- : p.category === "query"
88
- ? `assert.query(() => ${typia}.assert(${p.name}));`
89
- : p.category === "headers"
90
- ? `assert.headers(() => ${typia}.assert(connection.headers);`
91
- : `assert.param("${p.field}")(() => ${typia}.assert(${p.name}));`,
92
- );
93
- if (config.propagate !== true) return [...func, ...individual];
94
-
95
- return [
96
- ...func,
97
- `try {`,
98
- ...individual.map((l) => ` ${l}`),
99
- `} catch (exp) {`,
100
- ` if (!${typia}.is<${SdkImportWizard.HttpError(
101
- importer,
102
- )}>(exp)) throw exp;`,
103
- ` return {`,
104
- ` success: false,`,
105
- ` status: exp.status,`,
106
- ` headers: exp.headers,`,
107
- ` data: exp.toJSON().message,`,
108
- ` } as any;`,
109
- `}`,
110
- ];
111
- };
112
-
113
- const returns =
114
- (config: INestiaConfig) =>
115
- (route: IRoute): string[] => {
116
- const random = (prefix: string, postfix: string) =>
117
- route.output.typeName === "void"
118
- ? [`${prefix} undefined${postfix}`]
119
- : [
120
- `${prefix} random(`,
121
- ` typeof connection.simulate === 'object' &&`,
122
- ` connection.simulate !== null`,
123
- ` ? connection.simulate`,
124
- ` : undefined`,
125
- `)${postfix}`,
126
- ];
127
- if (config.propagate !== true) return random("return", ";");
128
-
129
- return [
130
- `return {`,
131
- ` success: true,`,
132
- ` status: ${
133
- route.status ?? (route.method === "POST" ? 201 : 200)
134
- },`,
135
- ` headers: {`,
136
- ` "Content-Type": "${route.output.contentType}",`,
137
- ` },`,
138
- ...random("data:", ",").map((r) => ` ${r}`),
139
- `}`,
140
- ];
141
- };
142
- }
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
+ }