@nestia/sdk 11.0.0-dev.20260316 → 11.0.1

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 (65) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/assets/bundle/api/HttpError.ts +1 -1
  4. package/assets/bundle/api/IConnection.ts +1 -1
  5. package/assets/bundle/api/Primitive.ts +1 -1
  6. package/assets/bundle/api/Resolved.ts +1 -1
  7. package/assets/bundle/api/index.ts +4 -4
  8. package/assets/bundle/api/module.ts +6 -6
  9. package/assets/bundle/distribute/README.md +37 -37
  10. package/assets/bundle/distribute/package.json +28 -28
  11. package/assets/bundle/distribute/tsconfig.json +109 -109
  12. package/assets/bundle/e2e/index.ts +42 -42
  13. package/assets/config/nestia.config.ts +97 -97
  14. package/lib/executable/internal/NestiaConfigLoader.js +5 -5
  15. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  16. package/package.json +8 -8
  17. package/src/INestiaConfig.ts +267 -267
  18. package/src/NestiaSdkApplication.ts +307 -307
  19. package/src/NestiaSwaggerComposer.ts +143 -143
  20. package/src/analyses/AccessorAnalyzer.ts +67 -67
  21. package/src/analyses/DtoAnalyzer.ts +260 -260
  22. package/src/analyses/ImportAnalyzer.ts +126 -126
  23. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  24. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +72 -72
  25. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  26. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +126 -126
  27. package/src/analyses/TypedHttpRouteAnalyzer.ts +208 -208
  28. package/src/executable/internal/NestiaConfigLoader.ts +85 -85
  29. package/src/executable/internal/NestiaSdkCommand.ts +107 -107
  30. package/src/generates/SwaggerGenerator.ts +291 -291
  31. package/src/generates/internal/E2eFileProgrammer.ts +196 -196
  32. package/src/generates/internal/FilePrinter.ts +64 -64
  33. package/src/generates/internal/ImportDictionary.ts +192 -192
  34. package/src/generates/internal/SdkAliasCollection.ts +260 -260
  35. package/src/generates/internal/SdkFileProgrammer.ts +110 -110
  36. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
  37. package/src/generates/internal/SdkHttpCloneReferencer.ts +77 -77
  38. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +278 -278
  39. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +502 -502
  40. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  41. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +312 -312
  42. package/src/generates/internal/SdkImportWizard.ts +62 -62
  43. package/src/generates/internal/SdkTypeProgrammer.ts +388 -388
  44. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
  45. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +379 -379
  46. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +302 -302
  47. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  48. package/src/generates/internal/SwaggerOperationParameterComposer.ts +161 -161
  49. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  50. package/src/module.ts +4 -4
  51. package/src/structures/IReflectHttpOperationException.ts +18 -18
  52. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  53. package/src/structures/IReflectHttpOperationSuccess.ts +21 -21
  54. package/src/structures/ITypedApplication.ts +11 -11
  55. package/src/structures/ITypedHttpRouteException.ts +15 -15
  56. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  57. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  58. package/src/transformers/IOperationMetadata.ts +46 -46
  59. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  60. package/src/transformers/SdkOperationProgrammer.ts +240 -240
  61. package/src/transformers/SdkOperationTransformer.ts +248 -248
  62. package/src/transformers/TextPlainValidator.ts +17 -17
  63. package/src/utils/MetadataUtil.ts +26 -26
  64. package/src/validators/HttpHeadersValidator.ts +40 -40
  65. package/src/validators/HttpQueryValidator.ts +40 -40
@@ -1,312 +1,312 @@
1
- import {
2
- ExpressionFactory,
3
- IdentifierFactory,
4
- LiteralFactory,
5
- StatementFactory,
6
- TypeFactory,
7
- } from "@typia/core";
8
- import ts from "typescript";
9
-
10
- import { INestiaProject } from "../../structures/INestiaProject";
11
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
12
- import { ImportDictionary } from "./ImportDictionary";
13
- import { SdkAliasCollection } from "./SdkAliasCollection";
14
- import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
15
- import { SdkImportWizard } from "./SdkImportWizard";
16
-
17
- export namespace SdkHttpSimulationProgrammer {
18
- export const random =
19
- (project: INestiaProject) =>
20
- (importer: ImportDictionary) =>
21
- (route: ITypedHttpRoute): ts.VariableStatement => {
22
- const output = SdkAliasCollection.responseBody(project)(importer)(route);
23
- return constant("random")(
24
- ts.factory.createArrowFunction(
25
- undefined,
26
- undefined,
27
- [],
28
- project.config.primitive === false
29
- ? output
30
- : ts.factory.createTypeReferenceNode(
31
- SdkImportWizard.Resolved(importer),
32
- [output],
33
- ),
34
- undefined,
35
- ts.factory.createCallExpression(
36
- IdentifierFactory.access(
37
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
38
- "random",
39
- ),
40
- [output],
41
- undefined,
42
- ),
43
- ),
44
- );
45
- };
46
-
47
- export const simulate =
48
- (project: INestiaProject) =>
49
- (importer: ImportDictionary) =>
50
- (route: ITypedHttpRoute): ts.VariableStatement => {
51
- const output: boolean =
52
- project.config.propagate === true ||
53
- route.success.metadata.size() !== 0;
54
- const caller = () =>
55
- ts.factory.createCallExpression(
56
- ts.factory.createIdentifier("random"),
57
- undefined,
58
- undefined,
59
- );
60
- return constant("simulate")(
61
- ts.factory.createArrowFunction(
62
- undefined,
63
- undefined,
64
- [
65
- IdentifierFactory.parameter(
66
- SdkHttpParameterProgrammer.getSignificant(route, true).length !==
67
- 0
68
- ? "connection"
69
- : "_connection",
70
- ts.factory.createTypeReferenceNode(
71
- SdkImportWizard.IConnection(importer),
72
- route.headerObject
73
- ? [
74
- ts.factory.createTypeReferenceNode(
75
- `${route.name}.Headers`,
76
- ),
77
- ]
78
- : [],
79
- ),
80
- ),
81
- ...SdkHttpParameterProgrammer.getParameterDeclarations({
82
- project,
83
- importer,
84
- route,
85
- body: true,
86
- prefix: false,
87
- }),
88
- ],
89
- ts.factory.createTypeReferenceNode(output ? "Output" : "void"),
90
- undefined,
91
- ts.factory.createBlock(
92
- [
93
- ...assert(project)(importer)(route),
94
- ts.factory.createReturnStatement(
95
- project.config.propagate
96
- ? ts.factory.createAsExpression(
97
- ts.factory.createObjectLiteralExpression(
98
- [
99
- ts.factory.createPropertyAssignment(
100
- "success",
101
- ts.factory.createTrue(),
102
- ),
103
- ts.factory.createPropertyAssignment(
104
- "status",
105
- ExpressionFactory.number(
106
- route.success.status ??
107
- (route.method === "POST" ? 201 : 200),
108
- ),
109
- ),
110
- ts.factory.createPropertyAssignment(
111
- "headers",
112
- LiteralFactory.write({
113
- "Content-Type": route.success.contentType,
114
- }),
115
- ),
116
- ts.factory.createPropertyAssignment("data", caller()),
117
- ],
118
- true,
119
- ),
120
- ts.factory.createTypeReferenceNode("Output"),
121
- )
122
- : caller(),
123
- ),
124
- ],
125
- true,
126
- ),
127
- ),
128
- );
129
- };
130
-
131
- const assert =
132
- (project: INestiaProject) =>
133
- (importer: ImportDictionary) =>
134
- (route: ITypedHttpRoute): ts.Statement[] => {
135
- const parameters = SdkHttpParameterProgrammer.getSignificant(route, true);
136
- if (parameters.length === 0) return [];
137
-
138
- const typia = SdkImportWizard.typia(importer);
139
- const validator = StatementFactory.constant({
140
- name: "assert",
141
- value: ts.factory.createCallExpression(
142
- IdentifierFactory.access(
143
- ts.factory.createIdentifier(
144
- importer.external({
145
- file: `@nestia/fetcher`,
146
- declaration: false,
147
- type: "element",
148
- name: "NestiaSimulator",
149
- }),
150
- ),
151
- "assert",
152
- ),
153
- undefined,
154
- [
155
- ts.factory.createObjectLiteralExpression(
156
- [
157
- ts.factory.createPropertyAssignment(
158
- "method",
159
- ts.factory.createIdentifier("METADATA.method"),
160
- ),
161
- ts.factory.createPropertyAssignment(
162
- "host",
163
- ts.factory.createIdentifier("connection.host"),
164
- ),
165
- ts.factory.createPropertyAssignment(
166
- "path",
167
- ts.factory.createCallExpression(
168
- ts.factory.createIdentifier("path"),
169
- undefined,
170
- SdkHttpParameterProgrammer.getArguments({
171
- project,
172
- route,
173
- body: false,
174
- }),
175
- ),
176
- ),
177
- ts.factory.createPropertyAssignment(
178
- "contentType",
179
- ts.factory.createIdentifier(
180
- JSON.stringify(route.success.contentType),
181
- ),
182
- ),
183
- ],
184
- true,
185
- ),
186
- ],
187
- ),
188
- });
189
- const individual = parameters
190
- .map((p) =>
191
- ts.factory.createCallExpression(
192
- (() => {
193
- const base = IdentifierFactory.access(
194
- ts.factory.createIdentifier("assert"),
195
- p.category,
196
- );
197
- if (p.category !== "param") return base;
198
- return ts.factory.createCallExpression(base, undefined, [
199
- ts.factory.createStringLiteral(p.name),
200
- ]);
201
- })(),
202
- undefined,
203
- [
204
- ts.factory.createArrowFunction(
205
- undefined,
206
- undefined,
207
- [],
208
- undefined,
209
- undefined,
210
- ts.factory.createCallExpression(
211
- IdentifierFactory.access(
212
- ts.factory.createIdentifier(typia),
213
- "assert",
214
- ),
215
- undefined,
216
- [
217
- project.config.keyword === true
218
- ? ts.factory.createIdentifier(`props.${p.name}`)
219
- : ts.factory.createIdentifier(p.name),
220
- ],
221
- ),
222
- ),
223
- ],
224
- ),
225
- )
226
- .map(ts.factory.createExpressionStatement);
227
- return [
228
- validator,
229
- ...(project.config.propagate !== true
230
- ? individual
231
- : [tryAndCatch(importer)(individual)]),
232
- ];
233
- };
234
-
235
- const tryAndCatch =
236
- (importer: ImportDictionary) => (individual: ts.Statement[]) =>
237
- ts.factory.createTryStatement(
238
- ts.factory.createBlock(individual, true),
239
- ts.factory.createCatchClause(
240
- "exp",
241
- ts.factory.createBlock(
242
- [
243
- ts.factory.createIfStatement(
244
- ts.factory.createLogicalNot(
245
- ts.factory.createCallExpression(
246
- IdentifierFactory.access(
247
- ts.factory.createIdentifier(
248
- SdkImportWizard.typia(importer),
249
- ),
250
- "is",
251
- ),
252
- [
253
- ts.factory.createTypeReferenceNode(
254
- SdkImportWizard.HttpError(importer),
255
- ),
256
- ],
257
- [ts.factory.createIdentifier("exp")],
258
- ),
259
- ),
260
- ts.factory.createThrowStatement(
261
- ts.factory.createIdentifier("exp"),
262
- ),
263
- ),
264
- ts.factory.createReturnStatement(
265
- ts.factory.createAsExpression(
266
- ts.factory.createObjectLiteralExpression(
267
- [
268
- ts.factory.createPropertyAssignment(
269
- "success",
270
- ts.factory.createFalse(),
271
- ),
272
- ts.factory.createPropertyAssignment(
273
- "status",
274
- ts.factory.createIdentifier("exp.status"),
275
- ),
276
- ts.factory.createPropertyAssignment(
277
- "headers",
278
- ts.factory.createIdentifier("exp.headers"),
279
- ),
280
- ts.factory.createPropertyAssignment(
281
- "data",
282
- ts.factory.createIdentifier("exp.toJSON().message"),
283
- ),
284
- ],
285
- true,
286
- ),
287
- TypeFactory.keyword("any"),
288
- ),
289
- ),
290
- ],
291
- true,
292
- ),
293
- ),
294
- undefined,
295
- );
296
- }
297
-
298
- const constant = (name: string) => (expression: ts.Expression) =>
299
- ts.factory.createVariableStatement(
300
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
301
- ts.factory.createVariableDeclarationList(
302
- [
303
- ts.factory.createVariableDeclaration(
304
- ts.factory.createIdentifier(name),
305
- undefined,
306
- undefined,
307
- expression,
308
- ),
309
- ],
310
- ts.NodeFlags.Const,
311
- ),
312
- );
1
+ import {
2
+ ExpressionFactory,
3
+ IdentifierFactory,
4
+ LiteralFactory,
5
+ StatementFactory,
6
+ TypeFactory,
7
+ } from "@typia/core";
8
+ import ts from "typescript";
9
+
10
+ import { INestiaProject } from "../../structures/INestiaProject";
11
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
12
+ import { ImportDictionary } from "./ImportDictionary";
13
+ import { SdkAliasCollection } from "./SdkAliasCollection";
14
+ import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
15
+ import { SdkImportWizard } from "./SdkImportWizard";
16
+
17
+ export namespace SdkHttpSimulationProgrammer {
18
+ export const random =
19
+ (project: INestiaProject) =>
20
+ (importer: ImportDictionary) =>
21
+ (route: ITypedHttpRoute): ts.VariableStatement => {
22
+ const output = SdkAliasCollection.responseBody(project)(importer)(route);
23
+ return constant("random")(
24
+ ts.factory.createArrowFunction(
25
+ undefined,
26
+ undefined,
27
+ [],
28
+ project.config.primitive === false
29
+ ? output
30
+ : ts.factory.createTypeReferenceNode(
31
+ SdkImportWizard.Resolved(importer),
32
+ [output],
33
+ ),
34
+ undefined,
35
+ ts.factory.createCallExpression(
36
+ IdentifierFactory.access(
37
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
38
+ "random",
39
+ ),
40
+ [output],
41
+ undefined,
42
+ ),
43
+ ),
44
+ );
45
+ };
46
+
47
+ export const simulate =
48
+ (project: INestiaProject) =>
49
+ (importer: ImportDictionary) =>
50
+ (route: ITypedHttpRoute): ts.VariableStatement => {
51
+ const output: boolean =
52
+ project.config.propagate === true ||
53
+ route.success.metadata.size() !== 0;
54
+ const caller = () =>
55
+ ts.factory.createCallExpression(
56
+ ts.factory.createIdentifier("random"),
57
+ undefined,
58
+ undefined,
59
+ );
60
+ return constant("simulate")(
61
+ ts.factory.createArrowFunction(
62
+ undefined,
63
+ undefined,
64
+ [
65
+ IdentifierFactory.parameter(
66
+ SdkHttpParameterProgrammer.getSignificant(route, true).length !==
67
+ 0
68
+ ? "connection"
69
+ : "_connection",
70
+ ts.factory.createTypeReferenceNode(
71
+ SdkImportWizard.IConnection(importer),
72
+ route.headerObject
73
+ ? [
74
+ ts.factory.createTypeReferenceNode(
75
+ `${route.name}.Headers`,
76
+ ),
77
+ ]
78
+ : [],
79
+ ),
80
+ ),
81
+ ...SdkHttpParameterProgrammer.getParameterDeclarations({
82
+ project,
83
+ importer,
84
+ route,
85
+ body: true,
86
+ prefix: false,
87
+ }),
88
+ ],
89
+ ts.factory.createTypeReferenceNode(output ? "Output" : "void"),
90
+ undefined,
91
+ ts.factory.createBlock(
92
+ [
93
+ ...assert(project)(importer)(route),
94
+ ts.factory.createReturnStatement(
95
+ project.config.propagate
96
+ ? ts.factory.createAsExpression(
97
+ ts.factory.createObjectLiteralExpression(
98
+ [
99
+ ts.factory.createPropertyAssignment(
100
+ "success",
101
+ ts.factory.createTrue(),
102
+ ),
103
+ ts.factory.createPropertyAssignment(
104
+ "status",
105
+ ExpressionFactory.number(
106
+ route.success.status ??
107
+ (route.method === "POST" ? 201 : 200),
108
+ ),
109
+ ),
110
+ ts.factory.createPropertyAssignment(
111
+ "headers",
112
+ LiteralFactory.write({
113
+ "Content-Type": route.success.contentType,
114
+ }),
115
+ ),
116
+ ts.factory.createPropertyAssignment("data", caller()),
117
+ ],
118
+ true,
119
+ ),
120
+ ts.factory.createTypeReferenceNode("Output"),
121
+ )
122
+ : caller(),
123
+ ),
124
+ ],
125
+ true,
126
+ ),
127
+ ),
128
+ );
129
+ };
130
+
131
+ const assert =
132
+ (project: INestiaProject) =>
133
+ (importer: ImportDictionary) =>
134
+ (route: ITypedHttpRoute): ts.Statement[] => {
135
+ const parameters = SdkHttpParameterProgrammer.getSignificant(route, true);
136
+ if (parameters.length === 0) return [];
137
+
138
+ const typia = SdkImportWizard.typia(importer);
139
+ const validator = StatementFactory.constant({
140
+ name: "assert",
141
+ value: ts.factory.createCallExpression(
142
+ IdentifierFactory.access(
143
+ ts.factory.createIdentifier(
144
+ importer.external({
145
+ file: `@nestia/fetcher`,
146
+ declaration: false,
147
+ type: "element",
148
+ name: "NestiaSimulator",
149
+ }),
150
+ ),
151
+ "assert",
152
+ ),
153
+ undefined,
154
+ [
155
+ ts.factory.createObjectLiteralExpression(
156
+ [
157
+ ts.factory.createPropertyAssignment(
158
+ "method",
159
+ ts.factory.createIdentifier("METADATA.method"),
160
+ ),
161
+ ts.factory.createPropertyAssignment(
162
+ "host",
163
+ ts.factory.createIdentifier("connection.host"),
164
+ ),
165
+ ts.factory.createPropertyAssignment(
166
+ "path",
167
+ ts.factory.createCallExpression(
168
+ ts.factory.createIdentifier("path"),
169
+ undefined,
170
+ SdkHttpParameterProgrammer.getArguments({
171
+ project,
172
+ route,
173
+ body: false,
174
+ }),
175
+ ),
176
+ ),
177
+ ts.factory.createPropertyAssignment(
178
+ "contentType",
179
+ ts.factory.createIdentifier(
180
+ JSON.stringify(route.success.contentType),
181
+ ),
182
+ ),
183
+ ],
184
+ true,
185
+ ),
186
+ ],
187
+ ),
188
+ });
189
+ const individual = parameters
190
+ .map((p) =>
191
+ ts.factory.createCallExpression(
192
+ (() => {
193
+ const base = IdentifierFactory.access(
194
+ ts.factory.createIdentifier("assert"),
195
+ p.category,
196
+ );
197
+ if (p.category !== "param") return base;
198
+ return ts.factory.createCallExpression(base, undefined, [
199
+ ts.factory.createStringLiteral(p.name),
200
+ ]);
201
+ })(),
202
+ undefined,
203
+ [
204
+ ts.factory.createArrowFunction(
205
+ undefined,
206
+ undefined,
207
+ [],
208
+ undefined,
209
+ undefined,
210
+ ts.factory.createCallExpression(
211
+ IdentifierFactory.access(
212
+ ts.factory.createIdentifier(typia),
213
+ "assert",
214
+ ),
215
+ undefined,
216
+ [
217
+ project.config.keyword === true
218
+ ? ts.factory.createIdentifier(`props.${p.name}`)
219
+ : ts.factory.createIdentifier(p.name),
220
+ ],
221
+ ),
222
+ ),
223
+ ],
224
+ ),
225
+ )
226
+ .map(ts.factory.createExpressionStatement);
227
+ return [
228
+ validator,
229
+ ...(project.config.propagate !== true
230
+ ? individual
231
+ : [tryAndCatch(importer)(individual)]),
232
+ ];
233
+ };
234
+
235
+ const tryAndCatch =
236
+ (importer: ImportDictionary) => (individual: ts.Statement[]) =>
237
+ ts.factory.createTryStatement(
238
+ ts.factory.createBlock(individual, true),
239
+ ts.factory.createCatchClause(
240
+ "exp",
241
+ ts.factory.createBlock(
242
+ [
243
+ ts.factory.createIfStatement(
244
+ ts.factory.createLogicalNot(
245
+ ts.factory.createCallExpression(
246
+ IdentifierFactory.access(
247
+ ts.factory.createIdentifier(
248
+ SdkImportWizard.typia(importer),
249
+ ),
250
+ "is",
251
+ ),
252
+ [
253
+ ts.factory.createTypeReferenceNode(
254
+ SdkImportWizard.HttpError(importer),
255
+ ),
256
+ ],
257
+ [ts.factory.createIdentifier("exp")],
258
+ ),
259
+ ),
260
+ ts.factory.createThrowStatement(
261
+ ts.factory.createIdentifier("exp"),
262
+ ),
263
+ ),
264
+ ts.factory.createReturnStatement(
265
+ ts.factory.createAsExpression(
266
+ ts.factory.createObjectLiteralExpression(
267
+ [
268
+ ts.factory.createPropertyAssignment(
269
+ "success",
270
+ ts.factory.createFalse(),
271
+ ),
272
+ ts.factory.createPropertyAssignment(
273
+ "status",
274
+ ts.factory.createIdentifier("exp.status"),
275
+ ),
276
+ ts.factory.createPropertyAssignment(
277
+ "headers",
278
+ ts.factory.createIdentifier("exp.headers"),
279
+ ),
280
+ ts.factory.createPropertyAssignment(
281
+ "data",
282
+ ts.factory.createIdentifier("exp.toJSON().message"),
283
+ ),
284
+ ],
285
+ true,
286
+ ),
287
+ TypeFactory.keyword("any"),
288
+ ),
289
+ ),
290
+ ],
291
+ true,
292
+ ),
293
+ ),
294
+ undefined,
295
+ );
296
+ }
297
+
298
+ const constant = (name: string) => (expression: ts.Expression) =>
299
+ ts.factory.createVariableStatement(
300
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
301
+ ts.factory.createVariableDeclarationList(
302
+ [
303
+ ts.factory.createVariableDeclaration(
304
+ ts.factory.createIdentifier(name),
305
+ undefined,
306
+ undefined,
307
+ expression,
308
+ ),
309
+ ],
310
+ ts.NodeFlags.Const,
311
+ ),
312
+ );