@nestia/sdk 2.6.4 → 3.0.0-dev.20240412

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