@nestia/sdk 2.6.3-dev.20240328 → 2.6.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 (31) hide show
  1. package/package.json +3 -3
  2. package/src/INestiaConfig.ts +248 -248
  3. package/src/NestiaSdkApplication.ts +255 -255
  4. package/src/analyses/ControllerAnalyzer.ts +402 -402
  5. package/src/analyses/ExceptionAnalyzer.ts +148 -148
  6. package/src/analyses/ReflectAnalyzer.ts +463 -463
  7. package/src/analyses/SecurityAnalyzer.ts +24 -24
  8. package/src/generates/CloneGenerator.ts +62 -62
  9. package/src/generates/E2eGenerator.ts +66 -66
  10. package/src/generates/SdkGenerator.ts +84 -84
  11. package/src/generates/SwaggerGenerator.ts +446 -446
  12. package/src/generates/internal/E2eFileProgrammer.ts +182 -182
  13. package/src/generates/internal/FilePrinter.ts +53 -53
  14. package/src/generates/internal/ImportDictionary.ts +147 -147
  15. package/src/generates/internal/SdkAliasCollection.ts +152 -152
  16. package/src/generates/internal/SdkCloneProgrammer.ts +155 -155
  17. package/src/generates/internal/SdkFileProgrammer.ts +115 -115
  18. package/src/generates/internal/SdkFunctionProgrammer.ts +298 -298
  19. package/src/generates/internal/SdkImportWizard.ts +55 -55
  20. package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -510
  21. package/src/generates/internal/SdkRouteProgrammer.ts +83 -83
  22. package/src/generates/internal/SdkSimulationProgrammer.ts +365 -365
  23. package/src/generates/internal/SdkTypeProgrammer.ts +385 -385
  24. package/src/generates/internal/SwaggerSchemaGenerator.ts +438 -438
  25. package/src/structures/IController.ts +94 -94
  26. package/src/structures/IRoute.ts +53 -53
  27. package/src/structures/ISwagger.ts +91 -91
  28. package/src/structures/ISwaggerRoute.ts +54 -54
  29. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  30. package/src/structures/ParamCategory.ts +1 -1
  31. package/src/utils/StringUtil.ts +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/sdk",
3
- "version": "2.6.3-dev.20240328",
3
+ "version": "2.6.3",
4
4
  "description": "Nestia SDK and Swagger generator",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "homepage": "https://nestia.io",
34
34
  "dependencies": {
35
- "@nestia/fetcher": "^2.6.3-dev.20240328",
35
+ "@nestia/fetcher": "^2.6.3",
36
36
  "cli": "^1.0.1",
37
37
  "get-function-location": "^2.0.0",
38
38
  "glob": "^7.2.0",
@@ -45,7 +45,7 @@
45
45
  "typia": "^5.5.7"
46
46
  },
47
47
  "peerDependencies": {
48
- "@nestia/fetcher": ">=2.6.3-dev.20240328",
48
+ "@nestia/fetcher": ">=2.6.3",
49
49
  "@nestjs/common": ">=7.0.1",
50
50
  "@nestjs/core": ">=7.0.1",
51
51
  "reflect-metadata": ">=0.1.12",
@@ -1,248 +1,248 @@
1
- import type { INestApplication } from "@nestjs/common";
2
-
3
- import type { INormalizedInput } from "./structures/INormalizedInput";
4
- import type { ISwagger } from "./structures/ISwagger";
5
- import type { ISwaggerInfo } from "./structures/ISwaggerInfo";
6
- import type { ISwaggerSecurityScheme } from "./structures/ISwaggerSecurityScheme";
7
-
8
- /**
9
- * Definition for the `nestia.config.ts` file.
10
- *
11
- * @author Jeongho Nam - https://github.com/samchon
12
- */
13
- export interface INestiaConfig {
14
- /**
15
- * Accessor of controller classes.
16
- *
17
- * You can specify target controller classes within two ways.
18
- *
19
- * - Asynchronous function returning `INestApplication` instance
20
- * - Specify the path or directory of controller class files
21
- */
22
- input:
23
- | (() => Promise<INestApplication>)
24
- | INestiaConfig.IInput
25
- | string[]
26
- | string;
27
-
28
- /**
29
- * Building `swagger.json` is also possible.
30
- *
31
- * If not specified, you can't build the `swagger.json`.
32
- */
33
- swagger?: INestiaConfig.ISwaggerConfig;
34
-
35
- /**
36
- * Output directory that SDK would be placed in.
37
- *
38
- * If not configured, you can't build the SDK library.
39
- */
40
- output?: string;
41
-
42
- /**
43
- * Target directory that SDK distribution files would be placed in.
44
- *
45
- * If you configure this property and runs `npx nestia sdk` command,
46
- * distribution environments for the SDK library would be generated.
47
- *
48
- * After the SDK library generation, move to the `distribute` directory,
49
- * and runs `npm publish` command, then you can share SDK library with
50
- * other client (frontend) developers.
51
- *
52
- * Recommend to use `"packages/api"` value.
53
- */
54
- distribute?: string;
55
-
56
- /**
57
- * Allow simulation mode.
58
- *
59
- * If you configure this property to be `true`, the SDK library would be contain
60
- * simulation mode. In the simulation mode, the SDK library would not communicate
61
- * with the real backend server, but just returns random mock-up data
62
- * with requestion data validation.
63
- *
64
- * For reference, random mock-up data would be generated by `typia.random<T>()`
65
- * function.
66
- *
67
- * @default false
68
- */
69
- simulate?: boolean;
70
-
71
- /**
72
- * Target directory that e2e test functions would be placed in.
73
- *
74
- * If you configure this property and runs `npx nestia e2e` command,
75
- * `@nestia/sdk` will analyze your NestJS backend server code, and
76
- * generates e2e test functions for every API endpoints.
77
- *
78
- * If not configured, you can't run `npx nestia e2e` command.
79
- */
80
- e2e?: string;
81
-
82
- /**
83
- * Whether to use propagation mode or not.
84
- *
85
- * If being configured, interaction functions of the SDK library would
86
- * perform the propagation mode. The propagation mode means that never
87
- * throwing exception even when status code is not 200 (or 201), but just
88
- * returning the {@link IPropagation} typed instance, which can specify its body
89
- * type through discriminated union determined by status code.
90
- *
91
- * @default false
92
- */
93
- propagate?: boolean;
94
-
95
- /**
96
- * Whether to clone DTO structures or not.
97
- *
98
- * If being configured, all of DTOs used in the backend server would be cloned
99
- * into the `structures` directory, and the SDK library would be refer to the
100
- * cloned DTOs instead of the original.
101
- *
102
- * @default false
103
- */
104
- clone?: boolean;
105
-
106
- /**
107
- * Whether to wrap DTO by primitive type.
108
- *
109
- * If you don't configure this property as `false`, all of DTOs in the
110
- * SDK library would be automatically wrapped by {@link Primitive} type.
111
- *
112
- * For refenrece, if a DTO type be capsuled by the {@link Primitive} type,
113
- * all of methods in the DTO type would be automatically erased. Also, if
114
- * the DTO has a `toJSON()` method, the DTO type would be automatically
115
- * converted to return type of the `toJSON()` method.
116
- *
117
- * @default true
118
- */
119
- primitive?: boolean;
120
-
121
- /**
122
- * Whether to assert parameter types or not.
123
- *
124
- * If you configure this property to be `true`, all of the function
125
- * parameters of SDK library would be checked through
126
- * [`typia.assert<T>()` function](https://typia.io/docs/validators/assert/).
127
- *
128
- * This option would make your SDK library compilation time a little bit slower,
129
- * but would enahcne the type safety even in the runtime level.
130
- *
131
- * @default false
132
- */
133
- assert?: boolean;
134
-
135
- /**
136
- * Whether to optimize JSON string conversion 10x faster or not.
137
- *
138
- * If you configure this property to be `true`, the SDK library would utilize the
139
- * [`typia.assertStringify<T>() function`](https://github.com/samchon/typia#enhanced-json)
140
- * to boost up JSON serialization speed and ensure type safety.
141
- *
142
- * This option would make your SDK library compilation time a little bit slower,
143
- * but would enhance JSON serialization speed 10x faster. Also, it can ensure type
144
- * safety even in the rumtime level.
145
- *
146
- * @default false
147
- */
148
- json?: boolean;
149
-
150
- /**
151
- * @internal
152
- */
153
- normalized?: INormalizedInput;
154
- }
155
- export namespace INestiaConfig {
156
- /**
157
- * List of files or directories to include or exclude to specifying the NestJS
158
- * controllers.
159
- */
160
- export interface IInput {
161
- /**
162
- * List of files or directories containing the NestJS controller classes.
163
- */
164
- include: string[];
165
-
166
- /**
167
- * List of files or directories to be excluded.
168
- */
169
- exclude?: string[];
170
- }
171
-
172
- /**
173
- * Building `swagger.json` is also possible.
174
- */
175
- export interface ISwaggerConfig {
176
- /**
177
- * Output path of the `swagger.json`.
178
- *
179
- * If you've configured only directory, the file name would be the `swagger.json`.
180
- * Otherwise you've configured the full path with file name and extension, the
181
- * `swagger.json` file would be renamed to it.
182
- */
183
- output: string;
184
-
185
- /**
186
- * Whether to beautify JSON content or not.
187
- *
188
- * If you configure this property to be `true`, the `swagger.json` file would
189
- * be beautified with indentation (2 spaces) and line breaks. If you configure
190
- * numeric value instead, the indentation would be specified by the number.
191
- *
192
- * @default false
193
- */
194
- beautify?: boolean | number;
195
-
196
- /**
197
- * Whether to include additional information or not.
198
- *
199
- * If configured to be `true`, those properties would be added into each
200
- * API endpoinnt.
201
- *
202
- * - `x-nestia-method`
203
- * - `x-nestia-namespace`
204
- * ` `x-nestia-jsDocTags`
205
- *
206
- * @default false
207
- */
208
- additional?: boolean;
209
-
210
- /**
211
- * API information.
212
- *
213
- * If omitted, `package.json` content would be used instead.
214
- */
215
- info?: Partial<ISwaggerInfo>;
216
-
217
- /**
218
- * List of server addresses.
219
- */
220
- servers?: ISwagger.IServer[];
221
-
222
- /**
223
- * Security schemes.
224
- *
225
- * When generating `swagger.json` file through `nestia`, if your controllers or
226
- * theirs methods have a security key which is not enrolled in here property,
227
- * it would be an error.
228
- */
229
- security?: Record<string, ISwaggerSecurityScheme>;
230
-
231
- /**
232
- * Decompose query DTO.
233
- *
234
- * If you configure this property to be `true`, the query DTO would be decomposed
235
- * into individual query parameters per each property.
236
- *
237
- * @default false
238
- */
239
- decompose?: boolean;
240
-
241
- operationId?(props: {
242
- class: string;
243
- function: string;
244
- method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
245
- path: string;
246
- }): string;
247
- }
248
- }
1
+ import type { INestApplication } from "@nestjs/common";
2
+
3
+ import type { INormalizedInput } from "./structures/INormalizedInput";
4
+ import type { ISwagger } from "./structures/ISwagger";
5
+ import type { ISwaggerInfo } from "./structures/ISwaggerInfo";
6
+ import type { ISwaggerSecurityScheme } from "./structures/ISwaggerSecurityScheme";
7
+
8
+ /**
9
+ * Definition for the `nestia.config.ts` file.
10
+ *
11
+ * @author Jeongho Nam - https://github.com/samchon
12
+ */
13
+ export interface INestiaConfig {
14
+ /**
15
+ * Accessor of controller classes.
16
+ *
17
+ * You can specify target controller classes within two ways.
18
+ *
19
+ * - Asynchronous function returning `INestApplication` instance
20
+ * - Specify the path or directory of controller class files
21
+ */
22
+ input:
23
+ | (() => Promise<INestApplication>)
24
+ | INestiaConfig.IInput
25
+ | string[]
26
+ | string;
27
+
28
+ /**
29
+ * Building `swagger.json` is also possible.
30
+ *
31
+ * If not specified, you can't build the `swagger.json`.
32
+ */
33
+ swagger?: INestiaConfig.ISwaggerConfig;
34
+
35
+ /**
36
+ * Output directory that SDK would be placed in.
37
+ *
38
+ * If not configured, you can't build the SDK library.
39
+ */
40
+ output?: string;
41
+
42
+ /**
43
+ * Target directory that SDK distribution files would be placed in.
44
+ *
45
+ * If you configure this property and runs `npx nestia sdk` command,
46
+ * distribution environments for the SDK library would be generated.
47
+ *
48
+ * After the SDK library generation, move to the `distribute` directory,
49
+ * and runs `npm publish` command, then you can share SDK library with
50
+ * other client (frontend) developers.
51
+ *
52
+ * Recommend to use `"packages/api"` value.
53
+ */
54
+ distribute?: string;
55
+
56
+ /**
57
+ * Allow simulation mode.
58
+ *
59
+ * If you configure this property to be `true`, the SDK library would be contain
60
+ * simulation mode. In the simulation mode, the SDK library would not communicate
61
+ * with the real backend server, but just returns random mock-up data
62
+ * with requestion data validation.
63
+ *
64
+ * For reference, random mock-up data would be generated by `typia.random<T>()`
65
+ * function.
66
+ *
67
+ * @default false
68
+ */
69
+ simulate?: boolean;
70
+
71
+ /**
72
+ * Target directory that e2e test functions would be placed in.
73
+ *
74
+ * If you configure this property and runs `npx nestia e2e` command,
75
+ * `@nestia/sdk` will analyze your NestJS backend server code, and
76
+ * generates e2e test functions for every API endpoints.
77
+ *
78
+ * If not configured, you can't run `npx nestia e2e` command.
79
+ */
80
+ e2e?: string;
81
+
82
+ /**
83
+ * Whether to use propagation mode or not.
84
+ *
85
+ * If being configured, interaction functions of the SDK library would
86
+ * perform the propagation mode. The propagation mode means that never
87
+ * throwing exception even when status code is not 200 (or 201), but just
88
+ * returning the {@link IPropagation} typed instance, which can specify its body
89
+ * type through discriminated union determined by status code.
90
+ *
91
+ * @default false
92
+ */
93
+ propagate?: boolean;
94
+
95
+ /**
96
+ * Whether to clone DTO structures or not.
97
+ *
98
+ * If being configured, all of DTOs used in the backend server would be cloned
99
+ * into the `structures` directory, and the SDK library would be refer to the
100
+ * cloned DTOs instead of the original.
101
+ *
102
+ * @default false
103
+ */
104
+ clone?: boolean;
105
+
106
+ /**
107
+ * Whether to wrap DTO by primitive type.
108
+ *
109
+ * If you don't configure this property as `false`, all of DTOs in the
110
+ * SDK library would be automatically wrapped by {@link Primitive} type.
111
+ *
112
+ * For refenrece, if a DTO type be capsuled by the {@link Primitive} type,
113
+ * all of methods in the DTO type would be automatically erased. Also, if
114
+ * the DTO has a `toJSON()` method, the DTO type would be automatically
115
+ * converted to return type of the `toJSON()` method.
116
+ *
117
+ * @default true
118
+ */
119
+ primitive?: boolean;
120
+
121
+ /**
122
+ * Whether to assert parameter types or not.
123
+ *
124
+ * If you configure this property to be `true`, all of the function
125
+ * parameters of SDK library would be checked through
126
+ * [`typia.assert<T>()` function](https://typia.io/docs/validators/assert/).
127
+ *
128
+ * This option would make your SDK library compilation time a little bit slower,
129
+ * but would enahcne the type safety even in the runtime level.
130
+ *
131
+ * @default false
132
+ */
133
+ assert?: boolean;
134
+
135
+ /**
136
+ * Whether to optimize JSON string conversion 10x faster or not.
137
+ *
138
+ * If you configure this property to be `true`, the SDK library would utilize the
139
+ * [`typia.assertStringify<T>() function`](https://github.com/samchon/typia#enhanced-json)
140
+ * to boost up JSON serialization speed and ensure type safety.
141
+ *
142
+ * This option would make your SDK library compilation time a little bit slower,
143
+ * but would enhance JSON serialization speed 10x faster. Also, it can ensure type
144
+ * safety even in the rumtime level.
145
+ *
146
+ * @default false
147
+ */
148
+ json?: boolean;
149
+
150
+ /**
151
+ * @internal
152
+ */
153
+ normalized?: INormalizedInput;
154
+ }
155
+ export namespace INestiaConfig {
156
+ /**
157
+ * List of files or directories to include or exclude to specifying the NestJS
158
+ * controllers.
159
+ */
160
+ export interface IInput {
161
+ /**
162
+ * List of files or directories containing the NestJS controller classes.
163
+ */
164
+ include: string[];
165
+
166
+ /**
167
+ * List of files or directories to be excluded.
168
+ */
169
+ exclude?: string[];
170
+ }
171
+
172
+ /**
173
+ * Building `swagger.json` is also possible.
174
+ */
175
+ export interface ISwaggerConfig {
176
+ /**
177
+ * Output path of the `swagger.json`.
178
+ *
179
+ * If you've configured only directory, the file name would be the `swagger.json`.
180
+ * Otherwise you've configured the full path with file name and extension, the
181
+ * `swagger.json` file would be renamed to it.
182
+ */
183
+ output: string;
184
+
185
+ /**
186
+ * Whether to beautify JSON content or not.
187
+ *
188
+ * If you configure this property to be `true`, the `swagger.json` file would
189
+ * be beautified with indentation (2 spaces) and line breaks. If you configure
190
+ * numeric value instead, the indentation would be specified by the number.
191
+ *
192
+ * @default false
193
+ */
194
+ beautify?: boolean | number;
195
+
196
+ /**
197
+ * Whether to include additional information or not.
198
+ *
199
+ * If configured to be `true`, those properties would be added into each
200
+ * API endpoinnt.
201
+ *
202
+ * - `x-nestia-method`
203
+ * - `x-nestia-namespace`
204
+ * ` `x-nestia-jsDocTags`
205
+ *
206
+ * @default false
207
+ */
208
+ additional?: boolean;
209
+
210
+ /**
211
+ * API information.
212
+ *
213
+ * If omitted, `package.json` content would be used instead.
214
+ */
215
+ info?: Partial<ISwaggerInfo>;
216
+
217
+ /**
218
+ * List of server addresses.
219
+ */
220
+ servers?: ISwagger.IServer[];
221
+
222
+ /**
223
+ * Security schemes.
224
+ *
225
+ * When generating `swagger.json` file through `nestia`, if your controllers or
226
+ * theirs methods have a security key which is not enrolled in here property,
227
+ * it would be an error.
228
+ */
229
+ security?: Record<string, ISwaggerSecurityScheme>;
230
+
231
+ /**
232
+ * Decompose query DTO.
233
+ *
234
+ * If you configure this property to be `true`, the query DTO would be decomposed
235
+ * into individual query parameters per each property.
236
+ *
237
+ * @default false
238
+ */
239
+ decompose?: boolean;
240
+
241
+ operationId?(props: {
242
+ class: string;
243
+ function: string;
244
+ method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
245
+ path: string;
246
+ }): string;
247
+ }
248
+ }