@nestia/sdk 10.0.2 → 11.0.0-dev.20260305

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 (198) 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/INestiaConfig.d.ts +1 -1
  15. package/lib/NestiaSdkApplication.js.map +1 -1
  16. package/lib/NestiaSwaggerComposer.d.ts +2 -1
  17. package/lib/NestiaSwaggerComposer.js +3 -3
  18. package/lib/NestiaSwaggerComposer.js.map +1 -1
  19. package/lib/analyses/AccessorAnalyzer.js +2 -2
  20. package/lib/analyses/AccessorAnalyzer.js.map +1 -1
  21. package/lib/analyses/DtoAnalyzer.js.map +1 -1
  22. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  23. package/lib/analyses/ReflectHttpOperationAnalyzer.js +3 -3
  24. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  25. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js +2 -2
  26. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js.map +1 -1
  27. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +7 -11
  28. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
  29. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +6 -6
  30. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
  31. package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +1 -1
  32. package/lib/analyses/TypedHttpRouteAnalyzer.js +6 -8
  33. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
  34. package/lib/executable/internal/NestiaConfigLoader.js +47 -43
  35. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  36. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  37. package/lib/executable/sdk.js +12 -12
  38. package/lib/generates/SwaggerGenerator.d.ts +1 -1
  39. package/lib/generates/SwaggerGenerator.js +6 -6
  40. package/lib/generates/SwaggerGenerator.js.map +1 -1
  41. package/lib/generates/internal/E2eFileProgrammer.js +8 -9
  42. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  43. package/lib/generates/internal/SdkAliasCollection.d.ts +2 -2
  44. package/lib/generates/internal/SdkAliasCollection.js +2 -2
  45. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  46. package/lib/generates/internal/SdkDistributionComposer.js +1 -1
  47. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  48. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  49. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +11 -12
  50. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  51. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +13 -16
  52. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  53. package/lib/generates/internal/SdkHttpRouteProgrammer.js +4 -4
  54. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  55. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +12 -16
  56. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  57. package/lib/generates/internal/SdkImportWizard.js +2 -2
  58. package/lib/generates/internal/SdkImportWizard.js.map +1 -1
  59. package/lib/generates/internal/SdkTypeProgrammer.d.ts +2 -3
  60. package/lib/generates/internal/SdkTypeProgrammer.js +6 -7
  61. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  62. package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +1 -1
  63. package/lib/generates/internal/SdkTypeTagProgrammer.js +11 -11
  64. package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
  65. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +6 -8
  66. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  67. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +2 -2
  68. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  69. package/lib/generates/internal/SwaggerOperationComposer.d.ts +3 -3
  70. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
  71. package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +1 -1
  72. package/lib/generates/internal/SwaggerOperationParameterComposer.js +10 -8
  73. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  74. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +3 -3
  75. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
  76. package/lib/module.d.ts +1 -0
  77. package/lib/module.js +1 -0
  78. package/lib/module.js.map +1 -1
  79. package/lib/structures/IReflectHttpOperationException.d.ts +3 -4
  80. package/lib/structures/IReflectHttpOperationParameter.d.ts +3 -5
  81. package/lib/structures/IReflectHttpOperationSuccess.d.ts +3 -4
  82. package/lib/structures/ITypedApplication.d.ts +1 -1
  83. package/lib/structures/ITypedHttpRouteException.d.ts +2 -2
  84. package/lib/structures/ITypedHttpRouteParameter.d.ts +2 -2
  85. package/lib/structures/ITypedHttpRouteSuccess.d.ts +2 -2
  86. package/lib/transformers/IOperationMetadata.d.ts +2 -4
  87. package/lib/transformers/ISdkOperationTransformerContext.d.ts +1 -1
  88. package/lib/transformers/SdkOperationProgrammer.js +8 -10
  89. package/lib/transformers/SdkOperationProgrammer.js.map +1 -1
  90. package/lib/transformers/SdkOperationTransformer.js +5 -7
  91. package/lib/transformers/SdkOperationTransformer.js.map +1 -1
  92. package/lib/transformers/TextPlainValidator.d.ts +2 -2
  93. package/lib/transformers/TextPlainValidator.js.map +1 -1
  94. package/lib/utils/MetadataUtil.d.ts +2 -2
  95. package/lib/utils/MetadataUtil.js.map +1 -1
  96. package/lib/validators/HttpHeadersValidator.d.ts +2 -3
  97. package/lib/validators/HttpHeadersValidator.js +2 -2
  98. package/lib/validators/HttpHeadersValidator.js.map +1 -1
  99. package/lib/validators/HttpQueryValidator.d.ts +2 -3
  100. package/lib/validators/HttpQueryValidator.js +2 -2
  101. package/lib/validators/HttpQueryValidator.js.map +1 -1
  102. package/package.json +44 -30
  103. package/src/INestiaConfig.ts +267 -267
  104. package/src/NestiaSdkApplication.ts +307 -307
  105. package/src/NestiaSwaggerComposer.ts +140 -138
  106. package/src/analyses/AccessorAnalyzer.ts +67 -67
  107. package/src/analyses/ConfigAnalyzer.ts +155 -155
  108. package/src/analyses/DtoAnalyzer.ts +260 -260
  109. package/src/analyses/ExceptionAnalyzer.ts +154 -154
  110. package/src/analyses/GenericAnalyzer.ts +49 -49
  111. package/src/analyses/ImportAnalyzer.ts +126 -126
  112. package/src/analyses/PathAnalyzer.ts +69 -69
  113. package/src/analyses/ReflectControllerAnalyzer.ts +105 -105
  114. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  115. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +72 -71
  116. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -348
  117. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +126 -127
  118. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  119. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +172 -172
  120. package/src/analyses/SecurityAnalyzer.ts +25 -25
  121. package/src/analyses/TypedHttpRouteAnalyzer.ts +208 -204
  122. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +33 -33
  123. package/src/decorators/OperationMetadata.ts +15 -15
  124. package/src/executable/internal/CommandParser.ts +15 -15
  125. package/src/executable/internal/NestiaConfigLoader.ts +85 -78
  126. package/src/executable/internal/NestiaSdkCommand.ts +107 -103
  127. package/src/executable/sdk.ts +75 -75
  128. package/src/generates/CloneGenerator.ts +66 -66
  129. package/src/generates/E2eGenerator.ts +32 -32
  130. package/src/generates/SdkGenerator.ts +160 -160
  131. package/src/generates/SwaggerGenerator.ts +285 -284
  132. package/src/generates/internal/E2eFileProgrammer.ts +196 -197
  133. package/src/generates/internal/FilePrinter.ts +64 -64
  134. package/src/generates/internal/ImportDictionary.ts +192 -192
  135. package/src/generates/internal/SdkAliasCollection.ts +260 -261
  136. package/src/generates/internal/SdkDistributionComposer.ts +103 -103
  137. package/src/generates/internal/SdkFileProgrammer.ts +110 -110
  138. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -124
  139. package/src/generates/internal/SdkHttpCloneReferencer.ts +77 -77
  140. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +278 -279
  141. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +502 -500
  142. package/src/generates/internal/SdkHttpParameterProgrammer.ts +178 -178
  143. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -108
  144. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +312 -310
  145. package/src/generates/internal/SdkImportWizard.ts +62 -62
  146. package/src/generates/internal/SdkRouteDirectory.ts +18 -18
  147. package/src/generates/internal/SdkTypeProgrammer.ts +388 -385
  148. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -104
  149. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +379 -381
  150. package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +87 -87
  151. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +302 -302
  152. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  153. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  154. package/src/generates/internal/SwaggerOperationParameterComposer.ts +161 -162
  155. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  156. package/src/index.ts +4 -4
  157. package/src/module.ts +4 -3
  158. package/src/structures/INestiaProject.ts +13 -13
  159. package/src/structures/INestiaSdkInput.ts +20 -20
  160. package/src/structures/IReflectApplication.ts +8 -8
  161. package/src/structures/IReflectController.ts +15 -15
  162. package/src/structures/IReflectHttpOperation.ts +26 -26
  163. package/src/structures/IReflectHttpOperationException.ts +18 -19
  164. package/src/structures/IReflectHttpOperationParameter.ts +79 -77
  165. package/src/structures/IReflectHttpOperationSuccess.ts +21 -22
  166. package/src/structures/IReflectImport.ts +6 -6
  167. package/src/structures/IReflectOperationError.ts +26 -26
  168. package/src/structures/IReflectType.ts +4 -4
  169. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  170. package/src/structures/IReflectWebSocketOperationParameter.ts +36 -36
  171. package/src/structures/ITypedApplication.ts +11 -11
  172. package/src/structures/ITypedHttpRoute.ts +41 -41
  173. package/src/structures/ITypedHttpRouteException.ts +15 -15
  174. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  175. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  176. package/src/structures/ITypedWebSocketRoute.ts +24 -24
  177. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  178. package/src/structures/MethodType.ts +5 -5
  179. package/src/structures/ParamCategory.ts +1 -1
  180. package/src/structures/TypeEntry.ts +22 -22
  181. package/src/transform.ts +9 -9
  182. package/src/transformers/IOperationMetadata.ts +46 -44
  183. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  184. package/src/transformers/SdkOperationProgrammer.ts +240 -238
  185. package/src/transformers/SdkOperationTransformer.ts +248 -252
  186. package/src/transformers/TextPlainValidator.ts +17 -17
  187. package/src/typings/get-function-location.d.ts +7 -7
  188. package/src/utils/ArrayUtil.ts +26 -26
  189. package/src/utils/FileRetriever.ts +22 -22
  190. package/src/utils/MapUtil.ts +14 -14
  191. package/src/utils/MetadataUtil.ts +26 -26
  192. package/src/utils/PathUtil.ts +10 -10
  193. package/src/utils/SourceFinder.ts +63 -63
  194. package/src/utils/StringUtil.ts +17 -17
  195. package/src/utils/StripEnums.ts +5 -5
  196. package/src/utils/VersioningStrategy.ts +28 -28
  197. package/src/validators/HttpHeadersValidator.ts +36 -34
  198. package/src/validators/HttpQueryValidator.ts +36 -34
@@ -1,197 +1,196 @@
1
- import ts from "typescript";
2
- import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
- import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
4
-
5
- import { INestiaProject } from "../../structures/INestiaProject";
6
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
7
- import { FilePrinter } from "./FilePrinter";
8
- import { ImportDictionary } from "./ImportDictionary";
9
- import { SdkAliasCollection } from "./SdkAliasCollection";
10
- import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
11
- import { SdkImportWizard } from "./SdkImportWizard";
12
-
13
- export namespace E2eFileProgrammer {
14
- export const generate =
15
- (project: INestiaProject) =>
16
- (props: { api: string; current: string }) =>
17
- async (route: ITypedHttpRoute): Promise<void> => {
18
- const importer: ImportDictionary = new ImportDictionary(
19
- `${props.current}/${getFunctionName(route)}.ts`,
20
- );
21
- if (project.config.clone !== true) importer.declarations(route.imports);
22
- importer.internal({
23
- file: props.api,
24
- declaration: false,
25
- type: "default",
26
- name: "api",
27
- });
28
- const functor: ts.Statement = generateFunctor(project)(importer)(route);
29
- await FilePrinter.write({
30
- location: importer.file,
31
- statements: [
32
- ...importer.toStatements(props.current),
33
- FilePrinter.enter(),
34
- functor,
35
- ],
36
- });
37
- };
38
-
39
- const generateFunctor =
40
- (project: INestiaProject) =>
41
- (importer: ImportDictionary) =>
42
- (route: ITypedHttpRoute): ts.Statement =>
43
- ts.factory.createVariableStatement(
44
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
45
- ts.factory.createVariableDeclarationList(
46
- [
47
- ts.factory.createVariableDeclaration(
48
- ts.factory.createIdentifier(getFunctionName(route)),
49
- undefined,
50
- undefined,
51
- generateArrow(project)(importer)(route),
52
- ),
53
- ],
54
- ts.NodeFlags.Const,
55
- ),
56
- );
57
-
58
- const generateArrow =
59
- (project: INestiaProject) =>
60
- (importer: ImportDictionary) =>
61
- (route: ITypedHttpRoute) => {
62
- const random = IdentifierFactory.access(
63
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
64
- "random",
65
- );
66
- const connection = route.headerObject
67
- ? ts.factory.createObjectLiteralExpression(
68
- [
69
- ts.factory.createSpreadAssignment(
70
- ts.factory.createIdentifier("connection"),
71
- ),
72
- ts.factory.createPropertyAssignment(
73
- "headers",
74
- ts.factory.createObjectLiteralExpression(
75
- [
76
- ts.factory.createSpreadAssignment(
77
- IdentifierFactory.access(
78
- ts.factory.createIdentifier("connection"),
79
- "headers",
80
- ),
81
- ),
82
- ts.factory.createSpreadAssignment(
83
- ts.factory.createCallExpression(
84
- random,
85
- [
86
- project.config.clone === true
87
- ? SdkAliasCollection.from(project)(importer)(
88
- route.headerObject.metadata,
89
- )
90
- : SdkAliasCollection.name(route.headerObject),
91
- ],
92
- undefined,
93
- ),
94
- ),
95
- ],
96
- true,
97
- ),
98
- ),
99
- ],
100
- true,
101
- )
102
- : ts.factory.createIdentifier("connection");
103
- const entries = SdkHttpParameterProgrammer.getEntries({
104
- project,
105
- importer,
106
- route,
107
- body: true,
108
- e2e: true,
109
- prefix: ["api", "functional", ...route.accessor].join(".") + ".",
110
- });
111
- const fetch = ts.factory.createCallExpression(
112
- ts.factory.createIdentifier(
113
- ["api", "functional", ...route.accessor].join("."),
114
- ),
115
- undefined,
116
- [
117
- connection,
118
- ...(project.config.keyword === true && entries.length !== 0
119
- ? [
120
- LiteralFactory.write(
121
- Object.fromEntries(
122
- entries.map((e) => [
123
- e.key,
124
- ts.factory.createCallExpression(
125
- IdentifierFactory.access(
126
- ts.factory.createIdentifier(
127
- SdkImportWizard.typia(importer),
128
- ),
129
- "random",
130
- ),
131
- [e.type],
132
- undefined,
133
- ),
134
- ]),
135
- ),
136
- ),
137
- ]
138
- : entries.map((e) =>
139
- ts.factory.createCallExpression(
140
- IdentifierFactory.access(
141
- ts.factory.createIdentifier(
142
- SdkImportWizard.typia(importer),
143
- ),
144
- "random",
145
- ),
146
- [e.type],
147
- undefined,
148
- ),
149
- )),
150
- ],
151
- );
152
- const assert = ts.factory.createCallExpression(
153
- IdentifierFactory.access(
154
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
155
- "assert",
156
- ),
157
- undefined,
158
- [ts.factory.createIdentifier("output")],
159
- );
160
-
161
- return ts.factory.createArrowFunction(
162
- [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
163
- undefined,
164
- [
165
- IdentifierFactory.parameter(
166
- "connection",
167
- ts.factory.createTypeReferenceNode("api.IConnection"),
168
- ),
169
- ],
170
- undefined,
171
- undefined,
172
- ts.factory.createBlock([
173
- ts.factory.createVariableStatement(
174
- [],
175
- ts.factory.createVariableDeclarationList(
176
- [
177
- ts.factory.createVariableDeclaration(
178
- "output",
179
- undefined,
180
- project.config.propagate !== true &&
181
- route.success.type.name === "void"
182
- ? undefined
183
- : SdkAliasCollection.response(project)(importer)(route),
184
- ts.factory.createAwaitExpression(fetch),
185
- ),
186
- ],
187
- ts.NodeFlags.Const,
188
- ),
189
- ),
190
- ts.factory.createExpressionStatement(assert),
191
- ]),
192
- );
193
- };
194
- }
195
-
196
- const getFunctionName = (route: ITypedHttpRoute): string =>
197
- ["test", "api", ...route.accessor].join("_");
1
+ import { IdentifierFactory, LiteralFactory } from "@typia/core";
2
+ import ts from "typescript";
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: ts.Statement = 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): ts.Statement =>
42
+ ts.factory.createVariableStatement(
43
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
44
+ ts.factory.createVariableDeclarationList(
45
+ [
46
+ ts.factory.createVariableDeclaration(
47
+ ts.factory.createIdentifier(getFunctionName(route)),
48
+ undefined,
49
+ undefined,
50
+ generateArrow(project)(importer)(route),
51
+ ),
52
+ ],
53
+ ts.NodeFlags.Const,
54
+ ),
55
+ );
56
+
57
+ const generateArrow =
58
+ (project: INestiaProject) =>
59
+ (importer: ImportDictionary) =>
60
+ (route: ITypedHttpRoute) => {
61
+ const random = IdentifierFactory.access(
62
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
63
+ "random",
64
+ );
65
+ const connection = route.headerObject
66
+ ? ts.factory.createObjectLiteralExpression(
67
+ [
68
+ ts.factory.createSpreadAssignment(
69
+ ts.factory.createIdentifier("connection"),
70
+ ),
71
+ ts.factory.createPropertyAssignment(
72
+ "headers",
73
+ ts.factory.createObjectLiteralExpression(
74
+ [
75
+ ts.factory.createSpreadAssignment(
76
+ IdentifierFactory.access(
77
+ ts.factory.createIdentifier("connection"),
78
+ "headers",
79
+ ),
80
+ ),
81
+ ts.factory.createSpreadAssignment(
82
+ ts.factory.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
+ : ts.factory.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 = ts.factory.createCallExpression(
111
+ ts.factory.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
+ ts.factory.createCallExpression(
124
+ IdentifierFactory.access(
125
+ ts.factory.createIdentifier(
126
+ SdkImportWizard.typia(importer),
127
+ ),
128
+ "random",
129
+ ),
130
+ [e.type],
131
+ undefined,
132
+ ),
133
+ ]),
134
+ ),
135
+ ),
136
+ ]
137
+ : entries.map((e) =>
138
+ ts.factory.createCallExpression(
139
+ IdentifierFactory.access(
140
+ ts.factory.createIdentifier(
141
+ SdkImportWizard.typia(importer),
142
+ ),
143
+ "random",
144
+ ),
145
+ [e.type],
146
+ undefined,
147
+ ),
148
+ )),
149
+ ],
150
+ );
151
+ const assert = ts.factory.createCallExpression(
152
+ IdentifierFactory.access(
153
+ ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
154
+ "assert",
155
+ ),
156
+ undefined,
157
+ [ts.factory.createIdentifier("output")],
158
+ );
159
+
160
+ return ts.factory.createArrowFunction(
161
+ [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
162
+ undefined,
163
+ [
164
+ IdentifierFactory.parameter(
165
+ "connection",
166
+ ts.factory.createTypeReferenceNode("api.IConnection"),
167
+ ),
168
+ ],
169
+ undefined,
170
+ undefined,
171
+ ts.factory.createBlock([
172
+ ts.factory.createVariableStatement(
173
+ [],
174
+ ts.factory.createVariableDeclarationList(
175
+ [
176
+ ts.factory.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
+ ts.factory.createAwaitExpression(fetch),
184
+ ),
185
+ ],
186
+ ts.NodeFlags.Const,
187
+ ),
188
+ ),
189
+ ts.factory.createExpressionStatement(assert),
190
+ ]),
191
+ );
192
+ };
193
+ }
194
+
195
+ const getFunctionName = (route: ITypedHttpRoute): string =>
196
+ ["test", "api", ...route.accessor].join("_");
@@ -1,64 +1,64 @@
1
- import fs from "fs";
2
- import { format } from "prettier";
3
- import ts from "typescript";
4
-
5
- export namespace FilePrinter {
6
- export const description = <Node extends ts.Node>(
7
- node: Node,
8
- comment: string,
9
- ): Node => {
10
- if (comment.length === 0) return node;
11
- ts.addSyntheticLeadingComment(
12
- node,
13
- ts.SyntaxKind.MultiLineCommentTrivia,
14
- [
15
- "*",
16
- ...comment
17
- .split("\r\n")
18
- .join("\n")
19
- .split("\n")
20
- .map(
21
- (str) =>
22
- ` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
23
- ),
24
- "",
25
- ].join("\n"),
26
- true,
27
- );
28
- return node;
29
- };
30
-
31
- export const enter = () =>
32
- ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
33
-
34
- export const write = async (props: {
35
- location: string;
36
- statements: ts.Statement[];
37
- top?: string;
38
- }): Promise<void> => {
39
- const script: string = ts
40
- .createPrinter()
41
- .printFile(
42
- ts.factory.createSourceFile(
43
- props.statements,
44
- ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
45
- ts.NodeFlags.None,
46
- ),
47
- );
48
- await fs.promises.writeFile(
49
- props.location,
50
- await beautify((props.top ?? "") + script),
51
- "utf8",
52
- );
53
- };
54
-
55
- const beautify = async (script: string): Promise<string> => {
56
- try {
57
- return await format(script, {
58
- parser: "typescript",
59
- });
60
- } catch {
61
- return script;
62
- }
63
- };
64
- }
1
+ import fs from "fs";
2
+ import { format } from "prettier";
3
+ import ts from "typescript";
4
+
5
+ export namespace FilePrinter {
6
+ export const description = <Node extends ts.Node>(
7
+ node: Node,
8
+ comment: string,
9
+ ): Node => {
10
+ if (comment.length === 0) return node;
11
+ ts.addSyntheticLeadingComment(
12
+ node,
13
+ ts.SyntaxKind.MultiLineCommentTrivia,
14
+ [
15
+ "*",
16
+ ...comment
17
+ .split("\r\n")
18
+ .join("\n")
19
+ .split("\n")
20
+ .map(
21
+ (str) =>
22
+ ` * ${str.split("*/").join("*\\\\/").split("*\\/").join("*\\\\/")}`,
23
+ ),
24
+ "",
25
+ ].join("\n"),
26
+ true,
27
+ );
28
+ return node;
29
+ };
30
+
31
+ export const enter = () =>
32
+ ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
33
+
34
+ export const write = async (props: {
35
+ location: string;
36
+ statements: ts.Statement[];
37
+ top?: string;
38
+ }): Promise<void> => {
39
+ const script: string = ts
40
+ .createPrinter()
41
+ .printFile(
42
+ ts.factory.createSourceFile(
43
+ props.statements,
44
+ ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
45
+ ts.NodeFlags.None,
46
+ ),
47
+ );
48
+ await fs.promises.writeFile(
49
+ props.location,
50
+ await beautify((props.top ?? "") + script),
51
+ "utf8",
52
+ );
53
+ };
54
+
55
+ const beautify = async (script: string): Promise<string> => {
56
+ try {
57
+ return await format(script, {
58
+ parser: "typescript",
59
+ });
60
+ } catch {
61
+ return script;
62
+ }
63
+ };
64
+ }