@nestia/sdk 12.0.0-dev.20260601.1 → 12.0.0-dev.20260612.2

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 (209) 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/NestiaSdkApplication.js +29 -7
  15. package/lib/NestiaSdkApplication.js.map +1 -1
  16. package/lib/NestiaSwaggerComposer.js +21 -13
  17. package/lib/NestiaSwaggerComposer.js.map +1 -1
  18. package/lib/analyses/AccessorAnalyzer.d.ts +4 -1
  19. package/lib/analyses/AccessorAnalyzer.js.map +1 -1
  20. package/lib/analyses/ConfigAnalyzer.js +1 -1
  21. package/lib/analyses/PathAnalyzer.d.ts +18 -3
  22. package/lib/analyses/PathAnalyzer.js +32 -0
  23. package/lib/analyses/PathAnalyzer.js.map +1 -1
  24. package/lib/analyses/ReflectControllerAnalyzer.js +3 -2
  25. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  26. package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +1 -1
  27. package/lib/analyses/ReflectHttpOperationAnalyzer.js +1 -1
  28. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  29. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +1 -1
  30. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +53 -20
  31. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
  32. package/lib/analyses/ReflectMcpOperationAnalyzer.d.ts +14 -0
  33. package/lib/analyses/ReflectMcpOperationAnalyzer.js +79 -0
  34. package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -0
  35. package/lib/analyses/TypedMcpRouteAnalyzer.d.ts +9 -0
  36. package/lib/analyses/TypedMcpRouteAnalyzer.js +31 -0
  37. package/lib/analyses/TypedMcpRouteAnalyzer.js.map +1 -0
  38. package/lib/executable/internal/NestiaConfigLoader.js +5 -1
  39. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  40. package/lib/executable/internal/NestiaSdkCommand.js +30 -14
  41. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  42. package/lib/executable/internal/NestiaSdkWatcher.d.ts +10 -0
  43. package/lib/executable/internal/NestiaSdkWatcher.js +322 -0
  44. package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -0
  45. package/lib/executable/sdk.js +12 -12
  46. package/lib/executable/sdk.js.map +1 -1
  47. package/lib/generates/CloneGenerator.js +4 -2
  48. package/lib/generates/CloneGenerator.js.map +1 -1
  49. package/lib/generates/SdkGenerator.js +50 -1
  50. package/lib/generates/SdkGenerator.js.map +1 -1
  51. package/lib/generates/SwaggerGenerator.js +18 -2
  52. package/lib/generates/SwaggerGenerator.js.map +1 -1
  53. package/lib/generates/internal/E2eFileProgrammer.js +3 -1
  54. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  55. package/lib/generates/internal/ImportDictionary.d.ts +1 -0
  56. package/lib/generates/internal/ImportDictionary.js +9 -4
  57. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  58. package/lib/generates/internal/SdkAliasCollection.d.ts +2 -0
  59. package/lib/generates/internal/SdkAliasCollection.js +11 -2
  60. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  61. package/lib/generates/internal/SdkDistributionComposer.d.ts +1 -0
  62. package/lib/generates/internal/SdkDistributionComposer.js +3 -0
  63. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  64. package/lib/generates/internal/SdkFileProgrammer.js +4 -1
  65. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  66. package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +1 -1
  67. package/lib/generates/internal/SdkHttpCloneReferencer.js +42 -9
  68. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  69. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +3 -4
  70. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  71. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +2 -1
  72. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  73. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +6 -3
  74. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  75. package/lib/generates/internal/SdkMcpRouteProgrammer.d.ts +15 -0
  76. package/lib/generates/internal/SdkMcpRouteProgrammer.js +148 -0
  77. package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -0
  78. package/lib/generates/internal/SdkRouteDirectory.d.ts +2 -1
  79. package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
  80. package/lib/generates/internal/SdkWebSocketCloneProgrammer.d.ts +6 -0
  81. package/lib/generates/internal/SdkWebSocketCloneProgrammer.js +283 -0
  82. package/lib/generates/internal/SdkWebSocketCloneProgrammer.js.map +1 -0
  83. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +11 -9
  84. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  85. package/lib/generates/internal/SwaggerOperationParameterComposer.js +10 -2
  86. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  87. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +1 -1
  88. package/lib/generates/internal/SwaggerOperationResponseComposer.js +6 -1
  89. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
  90. package/lib/generates/internal/SwaggerReadonlyArrayEmender.d.ts +9 -0
  91. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js +174 -0
  92. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js.map +1 -0
  93. package/lib/structures/INestiaSdkInput.d.ts +9 -2
  94. package/lib/structures/IReflectController.d.ts +2 -1
  95. package/lib/structures/IReflectHttpOperationSuccess.d.ts +4 -2
  96. package/lib/structures/IReflectMcpOperation.d.ts +35 -0
  97. package/lib/structures/IReflectMcpOperation.js +3 -0
  98. package/lib/structures/IReflectMcpOperation.js.map +1 -0
  99. package/lib/structures/IReflectMcpOperationParameter.d.ts +19 -0
  100. package/lib/structures/IReflectMcpOperationParameter.js +3 -0
  101. package/lib/structures/IReflectMcpOperationParameter.js.map +1 -0
  102. package/lib/structures/ITypedApplication.d.ts +2 -1
  103. package/lib/structures/ITypedHttpRouteSuccess.d.ts +3 -1
  104. package/lib/structures/ITypedMcpRoute.d.ts +31 -0
  105. package/lib/structures/ITypedMcpRoute.js +3 -0
  106. package/lib/structures/ITypedMcpRoute.js.map +1 -0
  107. package/lib/utils/HttpResponseContentTypeUtil.d.ts +5 -0
  108. package/lib/utils/HttpResponseContentTypeUtil.js +22 -0
  109. package/lib/utils/HttpResponseContentTypeUtil.js.map +1 -0
  110. package/native/go.mod +52 -52
  111. package/native/go.sum +84 -54
  112. package/native/sdk/register.go +322 -165
  113. package/native/sdk/sdk.go +17 -17
  114. package/native/sdk/sdk_metadata_json.go +327 -327
  115. package/native/sdk/sdk_transform.go +1879 -1549
  116. package/package.json +11 -9
  117. package/src/INestiaConfig.ts +267 -267
  118. package/src/NestiaSdkApplication.ts +39 -8
  119. package/src/NestiaSwaggerComposer.ts +153 -142
  120. package/src/analyses/AccessorAnalyzer.ts +64 -67
  121. package/src/analyses/ConfigAnalyzer.ts +330 -330
  122. package/src/analyses/ImportAnalyzer.ts +92 -92
  123. package/src/analyses/PathAnalyzer.ts +130 -69
  124. package/src/analyses/ReflectControllerAnalyzer.ts +112 -105
  125. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  126. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +90 -90
  127. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  128. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +163 -130
  129. package/src/analyses/ReflectMcpOperationAnalyzer.ts +124 -0
  130. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  131. package/src/analyses/SecurityAnalyzer.ts +25 -25
  132. package/src/analyses/TypedMcpRouteAnalyzer.ts +34 -0
  133. package/src/decorators/OperationMetadata.ts +29 -29
  134. package/src/executable/internal/CommandParser.ts +15 -15
  135. package/src/executable/internal/NestiaConfigLoader.ts +451 -446
  136. package/src/executable/internal/NestiaSdkCommand.ts +124 -106
  137. package/src/executable/internal/NestiaSdkWatcher.ts +342 -0
  138. package/src/executable/sdk.ts +90 -88
  139. package/src/generates/CloneGenerator.ts +73 -66
  140. package/src/generates/E2eGenerator.ts +32 -32
  141. package/src/generates/SdkGenerator.ts +176 -118
  142. package/src/generates/SwaggerGenerator.ts +342 -310
  143. package/src/generates/internal/E2eFileProgrammer.ts +240 -233
  144. package/src/generates/internal/FilePrinter.ts +65 -65
  145. package/src/generates/internal/ImportDictionary.ts +209 -204
  146. package/src/generates/internal/SdkAliasCollection.ts +274 -261
  147. package/src/generates/internal/SdkDistributionComposer.ts +123 -116
  148. package/src/generates/internal/SdkFileProgrammer.ts +116 -112
  149. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
  150. package/src/generates/internal/SdkHttpCloneReferencer.ts +131 -77
  151. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +301 -301
  152. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +520 -510
  153. package/src/generates/internal/SdkHttpParameterProgrammer.ts +165 -165
  154. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  155. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +331 -314
  156. package/src/generates/internal/SdkImportWizard.ts +62 -62
  157. package/src/generates/internal/SdkMcpRouteProgrammer.ts +452 -0
  158. package/src/generates/internal/SdkRouteDirectory.ts +21 -18
  159. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
  160. package/src/generates/internal/SdkWebSocketCloneProgrammer.ts +319 -0
  161. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +389 -389
  162. package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +89 -89
  163. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +331 -323
  164. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  165. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  166. package/src/generates/internal/SwaggerOperationParameterComposer.ts +175 -162
  167. package/src/generates/internal/SwaggerOperationResponseComposer.ts +115 -110
  168. package/src/generates/internal/SwaggerReadonlyArrayEmender.ts +262 -0
  169. package/src/index.ts +4 -4
  170. package/src/internal/legacy.ts +492 -492
  171. package/src/module.ts +4 -4
  172. package/src/structures/INestiaProject.ts +10 -10
  173. package/src/structures/INestiaSdkInput.ts +27 -20
  174. package/src/structures/IOperationMetadata.ts +41 -41
  175. package/src/structures/IReflectController.ts +18 -15
  176. package/src/structures/IReflectHttpOperation.ts +26 -26
  177. package/src/structures/IReflectHttpOperationException.ts +18 -18
  178. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  179. package/src/structures/IReflectHttpOperationSuccess.ts +18 -21
  180. package/src/structures/IReflectImport.ts +6 -6
  181. package/src/structures/IReflectMcpOperation.ts +38 -0
  182. package/src/structures/IReflectMcpOperationParameter.ts +27 -0
  183. package/src/structures/IReflectOperationError.ts +26 -26
  184. package/src/structures/IReflectType.ts +4 -4
  185. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  186. package/src/structures/ITypedApplication.ts +12 -11
  187. package/src/structures/ITypedHttpRoute.ts +41 -41
  188. package/src/structures/ITypedHttpRouteException.ts +15 -15
  189. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  190. package/src/structures/ITypedHttpRouteSuccess.ts +18 -22
  191. package/src/structures/ITypedMcpRoute.ts +33 -0
  192. package/src/structures/ITypedWebSocketRoute.ts +24 -24
  193. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  194. package/src/transform.ts +59 -59
  195. package/src/typings/get-function-location.d.ts +7 -7
  196. package/src/utils/ArrayUtil.ts +26 -26
  197. package/src/utils/EmittedJavaScriptPatcher.ts +88 -88
  198. package/src/utils/FileRetriever.ts +22 -22
  199. package/src/utils/HttpResponseContentTypeUtil.ts +30 -0
  200. package/src/utils/MapUtil.ts +14 -14
  201. package/src/utils/PathUtil.ts +10 -10
  202. package/src/utils/SourceFinder.ts +63 -63
  203. package/src/utils/StringUtil.ts +17 -17
  204. package/src/utils/TsConfigReader.ts +108 -108
  205. package/src/utils/TtscExecutor.ts +68 -68
  206. package/src/utils/VersioningStrategy.ts +28 -28
  207. package/src/validators/HttpHeadersValidator.ts +11 -11
  208. package/src/validators/HttpQueryValidator.ts +11 -11
  209. package/src/validators/TextPlainValidator.ts +17 -17
@@ -1,233 +1,240 @@
1
- import { Node, NodeFlags, SyntaxKind, TypeScriptFactory } from "@nestia/factory";
2
- import { IdentifierFactory, LiteralFactory } from "@nestia/factory";
3
-
4
- import { INestiaProject } from "../../structures/INestiaProject";
5
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
6
- import { FilePrinter } from "./FilePrinter";
7
- import { ImportDictionary } from "./ImportDictionary";
8
- import { SdkAliasCollection } from "./SdkAliasCollection";
9
- import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
10
- import { SdkImportWizard } from "./SdkImportWizard";
11
-
12
- export namespace E2eFileProgrammer {
13
- export const generate =
14
- (project: INestiaProject) =>
15
- (props: { api: string; current: string }) =>
16
- async (route: ITypedHttpRoute): Promise<void> => {
17
- const importer: ImportDictionary = new ImportDictionary(
18
- `${props.current}/${getFunctionName(route)}.ts`,
19
- );
20
- if (project.config.clone !== true) importer.declarations(route.imports);
21
- importer.internal({
22
- file: props.api,
23
- declaration: false,
24
- type: "default",
25
- name: "api",
26
- });
27
- const functor: Node = generateFunctor(project)(importer)(route);
28
- await FilePrinter.write({
29
- location: importer.file,
30
- statements: [
31
- ...importer.toStatements(props.current),
32
- FilePrinter.enter(),
33
- functor,
34
- ],
35
- });
36
- };
37
-
38
- const generateFunctor =
39
- (project: INestiaProject) =>
40
- (importer: ImportDictionary) =>
41
- (route: ITypedHttpRoute): Node =>
42
- TypeScriptFactory.createVariableStatement(
43
- [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
44
- TypeScriptFactory.createVariableDeclarationList(
45
- [
46
- TypeScriptFactory.createVariableDeclaration(
47
- TypeScriptFactory.createIdentifier(getFunctionName(route)),
48
- undefined,
49
- undefined,
50
- generateArrow(project)(importer)(route),
51
- ),
52
- ],
53
- NodeFlags.Const,
54
- ),
55
- );
56
-
57
- const generateArrow =
58
- (project: INestiaProject) =>
59
- (importer: ImportDictionary) =>
60
- (route: ITypedHttpRoute) => {
61
- const random = IdentifierFactory.access(
62
- TypeScriptFactory.createIdentifier(SdkImportWizard.typia(importer)),
63
- "random",
64
- );
65
- const connection = route.headerObject
66
- ? TypeScriptFactory.createObjectLiteralExpression(
67
- [
68
- TypeScriptFactory.createSpreadAssignment(
69
- TypeScriptFactory.createIdentifier("connection"),
70
- ),
71
- TypeScriptFactory.createPropertyAssignment(
72
- "headers",
73
- TypeScriptFactory.createObjectLiteralExpression(
74
- [
75
- TypeScriptFactory.createSpreadAssignment(
76
- IdentifierFactory.access(
77
- TypeScriptFactory.createIdentifier("connection"),
78
- "headers",
79
- ),
80
- ),
81
- TypeScriptFactory.createSpreadAssignment(
82
- TypeScriptFactory.createCallExpression(
83
- random,
84
- [
85
- project.config.clone === true
86
- ? SdkAliasCollection.from(project)(importer)(
87
- route.headerObject.metadata,
88
- )
89
- : SdkAliasCollection.name(route.headerObject),
90
- ],
91
- undefined,
92
- ),
93
- ),
94
- ],
95
- true,
96
- ),
97
- ),
98
- ],
99
- true,
100
- )
101
- : TypeScriptFactory.createIdentifier("connection");
102
- const entries = SdkHttpParameterProgrammer.getEntries({
103
- project,
104
- importer,
105
- route,
106
- body: true,
107
- e2e: true,
108
- prefix: ["api", "functional", ...route.accessor].join(".") + ".",
109
- });
110
- const fetch = TypeScriptFactory.createCallExpression(
111
- TypeScriptFactory.createIdentifier(
112
- ["api", "functional", ...route.accessor].join("."),
113
- ),
114
- undefined,
115
- [
116
- connection,
117
- ...(project.config.keyword === true && entries.length !== 0
118
- ? [
119
- LiteralFactory.write(
120
- Object.fromEntries(
121
- entries.map((e) => [
122
- e.key,
123
- TypeScriptFactory.createCallExpression(
124
- IdentifierFactory.access(
125
- TypeScriptFactory.createIdentifier(
126
- SdkImportWizard.typia(importer),
127
- ),
128
- "random",
129
- ),
130
- [getRandomType(importer)(e)],
131
- undefined,
132
- ),
133
- ]),
134
- ),
135
- ),
136
- ]
137
- : entries.map((e) =>
138
- TypeScriptFactory.createCallExpression(
139
- IdentifierFactory.access(
140
- TypeScriptFactory.createIdentifier(
141
- SdkImportWizard.typia(importer),
142
- ),
143
- "random",
144
- ),
145
- [getRandomType(importer)(e)],
146
- undefined,
147
- ),
148
- )),
149
- ],
150
- );
151
- const assert = TypeScriptFactory.createCallExpression(
152
- IdentifierFactory.access(
153
- TypeScriptFactory.createIdentifier(SdkImportWizard.typia(importer)),
154
- "assert",
155
- ),
156
- undefined,
157
- [TypeScriptFactory.createIdentifier("output")],
158
- );
159
-
160
- return TypeScriptFactory.createArrowFunction(
161
- [TypeScriptFactory.createModifier(SyntaxKind.AsyncKeyword)],
162
- undefined,
163
- [
164
- IdentifierFactory.parameter(
165
- "connection",
166
- TypeScriptFactory.createTypeReferenceNode("api.IConnection"),
167
- ),
168
- ],
169
- undefined,
170
- undefined,
171
- TypeScriptFactory.createBlock([
172
- TypeScriptFactory.createVariableStatement(
173
- [],
174
- TypeScriptFactory.createVariableDeclarationList(
175
- [
176
- TypeScriptFactory.createVariableDeclaration(
177
- "output",
178
- undefined,
179
- project.config.propagate !== true &&
180
- route.success.type!.name === "void"
181
- ? undefined
182
- : SdkAliasCollection.response(project)(importer)(route),
183
- TypeScriptFactory.createAwaitExpression(fetch),
184
- ),
185
- ],
186
- NodeFlags.Const,
187
- ),
188
- ),
189
- TypeScriptFactory.createExpressionStatement(assert),
190
- ]),
191
- );
192
- };
193
- }
194
-
195
- const getRandomType =
196
- (importer: ImportDictionary) =>
197
- (entry: SdkHttpParameterProgrammer.IEntry): Node => {
198
- if (isPlainStringPathParameter(entry) === false) return entry.type;
199
- return TypeScriptFactory.createIntersectionTypeNode([
200
- entry.type,
201
- TypeScriptFactory.createTypeReferenceNode(
202
- TypeScriptFactory.createQualifiedName(
203
- TypeScriptFactory.createIdentifier(
204
- importer.external({
205
- declaration: true,
206
- file: "typia",
207
- type: "element",
208
- name: "tags",
209
- }),
210
- ),
211
- TypeScriptFactory.createIdentifier("MinLength"),
212
- ),
213
- [
214
- TypeScriptFactory.createLiteralTypeNode(
215
- LiteralFactory.write(1) as Node,
216
- ),
217
- ],
218
- ),
219
- ]);
220
- };
221
-
222
- const isPlainStringPathParameter = (
223
- entry: SdkHttpParameterProgrammer.IEntry,
224
- ): boolean =>
225
- entry.parameter.category === "param" &&
226
- entry.parameter.metadata.atomics.length === 1 &&
227
- entry.parameter.metadata.atomics[0]!.type === "string" &&
228
- entry.parameter.metadata.atomics[0]!.tags.every((row) =>
229
- row.every((tag) => tag.kind !== "minLength"),
230
- );
231
-
232
- const getFunctionName = (route: ITypedHttpRoute): string =>
233
- ["test", "api", ...route.accessor].join("_");
1
+ import {
2
+ Node,
3
+ NodeFlags,
4
+ SyntaxKind,
5
+ TypeScriptFactory,
6
+ } from "@nestia/factory";
7
+ import { IdentifierFactory, LiteralFactory } from "@nestia/factory";
8
+
9
+ import { INestiaProject } from "../../structures/INestiaProject";
10
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
11
+ import { FilePrinter } from "./FilePrinter";
12
+ import { ImportDictionary } from "./ImportDictionary";
13
+ import { SdkAliasCollection } from "./SdkAliasCollection";
14
+ import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
15
+ import { SdkImportWizard } from "./SdkImportWizard";
16
+
17
+ export namespace E2eFileProgrammer {
18
+ export const generate =
19
+ (project: INestiaProject) =>
20
+ (props: { api: string; current: string }) =>
21
+ async (route: ITypedHttpRoute): Promise<void> => {
22
+ const importer: ImportDictionary = new ImportDictionary(
23
+ `${props.current}/${getFunctionName(route)}.ts`,
24
+ );
25
+ if (project.config.clone !== true) importer.declarations(route.imports);
26
+ importer.internal({
27
+ file: props.api,
28
+ declaration: false,
29
+ type: "default",
30
+ name: "api",
31
+ });
32
+ const functor: Node = generateFunctor(project)(importer)(route);
33
+ await FilePrinter.write({
34
+ location: importer.file,
35
+ statements: [
36
+ ...importer.toStatements(props.current),
37
+ FilePrinter.enter(),
38
+ functor,
39
+ ],
40
+ });
41
+ };
42
+
43
+ const generateFunctor =
44
+ (project: INestiaProject) =>
45
+ (importer: ImportDictionary) =>
46
+ (route: ITypedHttpRoute): Node =>
47
+ TypeScriptFactory.createVariableStatement(
48
+ [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
49
+ TypeScriptFactory.createVariableDeclarationList(
50
+ [
51
+ TypeScriptFactory.createVariableDeclaration(
52
+ TypeScriptFactory.createIdentifier(getFunctionName(route)),
53
+ undefined,
54
+ undefined,
55
+ generateArrow(project)(importer)(route),
56
+ ),
57
+ ],
58
+ NodeFlags.Const,
59
+ ),
60
+ );
61
+
62
+ const generateArrow =
63
+ (project: INestiaProject) =>
64
+ (importer: ImportDictionary) =>
65
+ (route: ITypedHttpRoute) => {
66
+ const random = IdentifierFactory.access(
67
+ TypeScriptFactory.createIdentifier(SdkImportWizard.typia(importer)),
68
+ "random",
69
+ );
70
+ const connection = route.headerObject
71
+ ? TypeScriptFactory.createObjectLiteralExpression(
72
+ [
73
+ TypeScriptFactory.createSpreadAssignment(
74
+ TypeScriptFactory.createIdentifier("connection"),
75
+ ),
76
+ TypeScriptFactory.createPropertyAssignment(
77
+ "headers",
78
+ TypeScriptFactory.createObjectLiteralExpression(
79
+ [
80
+ TypeScriptFactory.createSpreadAssignment(
81
+ IdentifierFactory.access(
82
+ TypeScriptFactory.createIdentifier("connection"),
83
+ "headers",
84
+ ),
85
+ ),
86
+ TypeScriptFactory.createSpreadAssignment(
87
+ TypeScriptFactory.createCallExpression(
88
+ random,
89
+ [
90
+ project.config.clone === true
91
+ ? SdkAliasCollection.from(project)(importer)(
92
+ route.headerObject.metadata,
93
+ )
94
+ : SdkAliasCollection.name(route.headerObject),
95
+ ],
96
+ undefined,
97
+ ),
98
+ ),
99
+ ],
100
+ true,
101
+ ),
102
+ ),
103
+ ],
104
+ true,
105
+ )
106
+ : TypeScriptFactory.createIdentifier("connection");
107
+ const entries = SdkHttpParameterProgrammer.getEntries({
108
+ project,
109
+ importer,
110
+ route,
111
+ body: true,
112
+ e2e: true,
113
+ prefix: ["api", "functional", ...route.accessor].join(".") + ".",
114
+ });
115
+ const fetch = TypeScriptFactory.createCallExpression(
116
+ TypeScriptFactory.createIdentifier(
117
+ ["api", "functional", ...route.accessor].join("."),
118
+ ),
119
+ undefined,
120
+ [
121
+ connection,
122
+ ...(project.config.keyword === true && entries.length !== 0
123
+ ? [
124
+ LiteralFactory.write(
125
+ Object.fromEntries(
126
+ entries.map((e) => [
127
+ e.key,
128
+ TypeScriptFactory.createCallExpression(
129
+ IdentifierFactory.access(
130
+ TypeScriptFactory.createIdentifier(
131
+ SdkImportWizard.typia(importer),
132
+ ),
133
+ "random",
134
+ ),
135
+ [getRandomType(importer)(e)],
136
+ undefined,
137
+ ),
138
+ ]),
139
+ ),
140
+ ),
141
+ ]
142
+ : entries.map((e) =>
143
+ TypeScriptFactory.createCallExpression(
144
+ IdentifierFactory.access(
145
+ TypeScriptFactory.createIdentifier(
146
+ SdkImportWizard.typia(importer),
147
+ ),
148
+ "random",
149
+ ),
150
+ [getRandomType(importer)(e)],
151
+ undefined,
152
+ ),
153
+ )),
154
+ ],
155
+ );
156
+ const assert = TypeScriptFactory.createCallExpression(
157
+ IdentifierFactory.access(
158
+ TypeScriptFactory.createIdentifier(SdkImportWizard.typia(importer)),
159
+ "assert",
160
+ ),
161
+ undefined,
162
+ [TypeScriptFactory.createIdentifier("output")],
163
+ );
164
+
165
+ return TypeScriptFactory.createArrowFunction(
166
+ [TypeScriptFactory.createModifier(SyntaxKind.AsyncKeyword)],
167
+ undefined,
168
+ [
169
+ IdentifierFactory.parameter(
170
+ "connection",
171
+ TypeScriptFactory.createTypeReferenceNode("api.IConnection"),
172
+ ),
173
+ ],
174
+ undefined,
175
+ undefined,
176
+ TypeScriptFactory.createBlock([
177
+ TypeScriptFactory.createVariableStatement(
178
+ [],
179
+ TypeScriptFactory.createVariableDeclarationList(
180
+ [
181
+ TypeScriptFactory.createVariableDeclaration(
182
+ "output",
183
+ undefined,
184
+ project.config.propagate !== true &&
185
+ route.success.type!.name === "void"
186
+ ? undefined
187
+ : SdkAliasCollection.response(project)(importer)(route),
188
+ TypeScriptFactory.createAwaitExpression(fetch),
189
+ ),
190
+ ],
191
+ NodeFlags.Const,
192
+ ),
193
+ ),
194
+ ...(route.success.binary === true
195
+ ? []
196
+ : [TypeScriptFactory.createExpressionStatement(assert)]),
197
+ ]),
198
+ );
199
+ };
200
+ }
201
+
202
+ const getRandomType =
203
+ (importer: ImportDictionary) =>
204
+ (entry: SdkHttpParameterProgrammer.IEntry): Node => {
205
+ if (isPlainStringPathParameter(entry) === false) return entry.type;
206
+ return TypeScriptFactory.createIntersectionTypeNode([
207
+ entry.type,
208
+ TypeScriptFactory.createTypeReferenceNode(
209
+ TypeScriptFactory.createQualifiedName(
210
+ TypeScriptFactory.createIdentifier(
211
+ importer.external({
212
+ declaration: true,
213
+ file: "typia",
214
+ type: "element",
215
+ name: "tags",
216
+ }),
217
+ ),
218
+ TypeScriptFactory.createIdentifier("MinLength"),
219
+ ),
220
+ [
221
+ TypeScriptFactory.createLiteralTypeNode(
222
+ LiteralFactory.write(1) as Node,
223
+ ),
224
+ ],
225
+ ),
226
+ ]);
227
+ };
228
+
229
+ const isPlainStringPathParameter = (
230
+ entry: SdkHttpParameterProgrammer.IEntry,
231
+ ): boolean =>
232
+ entry.parameter.category === "param" &&
233
+ entry.parameter.metadata.atomics.length === 1 &&
234
+ entry.parameter.metadata.atomics[0]!.type === "string" &&
235
+ entry.parameter.metadata.atomics[0]!.tags.every((row) =>
236
+ row.every((tag) => tag.kind !== "minLength"),
237
+ );
238
+
239
+ const getFunctionName = (route: ITypedHttpRoute): string =>
240
+ ["test", "api", ...route.accessor].join("_");
@@ -1,65 +1,65 @@
1
- import {
2
- Node,
3
- SyntaxKind,
4
- TypeScriptFactory,
5
- TypeScriptPrinter,
6
- } from "@nestia/factory";
7
- import fs from "fs";
8
- import { format } from "prettier";
9
-
10
- export namespace FilePrinter {
11
- export const description = <T extends Node>(
12
- node: T,
13
- comment: string,
14
- ): T => {
15
- if (comment.length === 0) return node;
16
- node.emitNode ??= {};
17
- node.emitNode.leadingComments = [
18
- ...(node.emitNode.leadingComments ?? []),
19
- {
20
- kind: SyntaxKind.MultiLineCommentTrivia,
21
- text: [
22
- "*",
23
- ...comment
24
- .split("\r\n")
25
- .join("\n")
26
- .split("\n")
27
- .map(
28
- (str) =>
29
- ` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
30
- ),
31
- "",
32
- ].join("\n"),
33
- hasTrailingNewLine: true,
34
- },
35
- ];
36
- return node;
37
- };
38
-
39
- export const enter = () =>
40
- TypeScriptFactory.createExpressionStatement(
41
- TypeScriptFactory.createIdentifier("\n"),
42
- );
43
-
44
- export const write = async (props: {
45
- location: string;
46
- statements: Node[];
47
- top?: string;
48
- }): Promise<void> => {
49
- const script: string = TypeScriptPrinter.write({
50
- statements: props.statements,
51
- top: props.top,
52
- });
53
- await fs.promises.writeFile(props.location, await beautify(script), "utf8");
54
- };
55
-
56
- const beautify = async (script: string): Promise<string> => {
57
- try {
58
- return await format(script, {
59
- parser: "typescript",
60
- });
61
- } catch {
62
- return script;
63
- }
64
- };
65
- }
1
+ import {
2
+ Node,
3
+ SyntaxKind,
4
+ TypeScriptFactory,
5
+ TypeScriptPrinter,
6
+ } from "@nestia/factory";
7
+ import fs from "fs";
8
+ import { format } from "prettier";
9
+
10
+ export namespace FilePrinter {
11
+ export const description = <T extends Node>(
12
+ node: T,
13
+ comment: string,
14
+ ): T => {
15
+ if (comment.length === 0) return node;
16
+ node.emitNode ??= {};
17
+ node.emitNode.leadingComments = [
18
+ ...(node.emitNode.leadingComments ?? []),
19
+ {
20
+ kind: SyntaxKind.MultiLineCommentTrivia,
21
+ text: [
22
+ "*",
23
+ ...comment
24
+ .split("\r\n")
25
+ .join("\n")
26
+ .split("\n")
27
+ .map(
28
+ (str) =>
29
+ ` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
30
+ ),
31
+ "",
32
+ ].join("\n"),
33
+ hasTrailingNewLine: true,
34
+ },
35
+ ];
36
+ return node;
37
+ };
38
+
39
+ export const enter = () =>
40
+ TypeScriptFactory.createExpressionStatement(
41
+ TypeScriptFactory.createIdentifier("\n"),
42
+ );
43
+
44
+ export const write = async (props: {
45
+ location: string;
46
+ statements: Node[];
47
+ top?: string;
48
+ }): Promise<void> => {
49
+ const script: string = TypeScriptPrinter.write({
50
+ statements: props.statements,
51
+ top: props.top,
52
+ });
53
+ await fs.promises.writeFile(props.location, await beautify(script), "utf8");
54
+ };
55
+
56
+ const beautify = async (script: string): Promise<string> => {
57
+ try {
58
+ return await format(script, {
59
+ parser: "typescript",
60
+ });
61
+ } catch {
62
+ return script;
63
+ }
64
+ };
65
+ }