@nestia/sdk 12.0.0-dev.20260601.1 → 12.0.0-dev.20260619.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 (259) 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/factories/ExpressionFactory.d.ts +9 -0
  48. package/lib/factories/ExpressionFactory.js +16 -0
  49. package/lib/factories/ExpressionFactory.js.map +1 -0
  50. package/lib/factories/IdentifierFactory.d.ts +22 -0
  51. package/lib/factories/IdentifierFactory.js +50 -0
  52. package/lib/factories/IdentifierFactory.js.map +1 -0
  53. package/lib/factories/LiteralFactory.d.ts +9 -0
  54. package/lib/factories/LiteralFactory.js +48 -0
  55. package/lib/factories/LiteralFactory.js.map +1 -0
  56. package/lib/factories/StatementFactory.d.ts +14 -0
  57. package/lib/factories/StatementFactory.js +20 -0
  58. package/lib/factories/StatementFactory.js.map +1 -0
  59. package/lib/factories/TypeFactory.d.ts +24 -0
  60. package/lib/factories/TypeFactory.js +27 -0
  61. package/lib/factories/TypeFactory.js.map +1 -0
  62. package/lib/generates/CloneGenerator.js +6 -4
  63. package/lib/generates/CloneGenerator.js.map +1 -1
  64. package/lib/generates/SdkGenerator.js +50 -1
  65. package/lib/generates/SdkGenerator.js.map +1 -1
  66. package/lib/generates/SwaggerGenerator.js +18 -2
  67. package/lib/generates/SwaggerGenerator.js.map +1 -1
  68. package/lib/generates/internal/E2eFileProgrammer.js +32 -29
  69. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  70. package/lib/generates/internal/FilePrinter.d.ts +2 -2
  71. package/lib/generates/internal/FilePrinter.js +14 -25
  72. package/lib/generates/internal/FilePrinter.js.map +1 -1
  73. package/lib/generates/internal/ImportDictionary.d.ts +2 -1
  74. package/lib/generates/internal/ImportDictionary.js +16 -10
  75. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  76. package/lib/generates/internal/SdkAliasCollection.d.ts +12 -10
  77. package/lib/generates/internal/SdkAliasCollection.js +29 -22
  78. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  79. package/lib/generates/internal/SdkDistributionComposer.d.ts +1 -0
  80. package/lib/generates/internal/SdkDistributionComposer.js +3 -0
  81. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  82. package/lib/generates/internal/SdkFileProgrammer.js +6 -3
  83. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  84. package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +1 -1
  85. package/lib/generates/internal/SdkHttpCloneProgrammer.js +3 -3
  86. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  87. package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +1 -1
  88. package/lib/generates/internal/SdkHttpCloneReferencer.js +42 -9
  89. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  90. package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +1 -1
  91. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +47 -51
  92. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  93. package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +1 -1
  94. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +63 -61
  95. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  96. package/lib/generates/internal/SdkHttpParameterProgrammer.d.ts +2 -2
  97. package/lib/generates/internal/SdkHttpParameterProgrammer.js +11 -13
  98. package/lib/generates/internal/SdkHttpParameterProgrammer.js.map +1 -1
  99. package/lib/generates/internal/SdkHttpRouteProgrammer.d.ts +1 -1
  100. package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +1 -1
  101. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +52 -47
  102. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  103. package/lib/generates/internal/SdkMcpRouteProgrammer.d.ts +15 -0
  104. package/lib/generates/internal/SdkMcpRouteProgrammer.js +149 -0
  105. package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -0
  106. package/lib/generates/internal/SdkRouteDirectory.d.ts +2 -1
  107. package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
  108. package/lib/generates/internal/SdkTypeProgrammer.d.ts +3 -3
  109. package/lib/generates/internal/SdkTypeProgrammer.js +42 -43
  110. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  111. package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +2 -1
  112. package/lib/generates/internal/SdkTypeTagProgrammer.js +7 -9
  113. package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
  114. package/lib/generates/internal/SdkWebSocketCloneProgrammer.d.ts +6 -0
  115. package/lib/generates/internal/SdkWebSocketCloneProgrammer.js +283 -0
  116. package/lib/generates/internal/SdkWebSocketCloneProgrammer.js.map +1 -0
  117. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +2 -2
  118. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +45 -47
  119. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  120. package/lib/generates/internal/SdkWebSocketParameterProgrammer.d.ts +3 -3
  121. package/lib/generates/internal/SdkWebSocketParameterProgrammer.js +9 -9
  122. package/lib/generates/internal/SdkWebSocketParameterProgrammer.js.map +1 -1
  123. package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +2 -2
  124. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +37 -41
  125. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  126. package/lib/generates/internal/SwaggerOperationParameterComposer.js +10 -2
  127. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  128. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +1 -1
  129. package/lib/generates/internal/SwaggerOperationResponseComposer.js +6 -1
  130. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
  131. package/lib/generates/internal/SwaggerReadonlyArrayEmender.d.ts +9 -0
  132. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js +174 -0
  133. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js.map +1 -0
  134. package/lib/structures/INestiaSdkInput.d.ts +9 -2
  135. package/lib/structures/IReflectController.d.ts +2 -1
  136. package/lib/structures/IReflectHttpOperationSuccess.d.ts +4 -2
  137. package/lib/structures/IReflectMcpOperation.d.ts +35 -0
  138. package/lib/structures/IReflectMcpOperation.js +3 -0
  139. package/lib/structures/IReflectMcpOperation.js.map +1 -0
  140. package/lib/structures/IReflectMcpOperationParameter.d.ts +19 -0
  141. package/lib/structures/IReflectMcpOperationParameter.js +3 -0
  142. package/lib/structures/IReflectMcpOperationParameter.js.map +1 -0
  143. package/lib/structures/ITypedApplication.d.ts +2 -1
  144. package/lib/structures/ITypedHttpRouteSuccess.d.ts +3 -1
  145. package/lib/structures/ITypedMcpRoute.d.ts +31 -0
  146. package/lib/structures/ITypedMcpRoute.js +3 -0
  147. package/lib/structures/ITypedMcpRoute.js.map +1 -0
  148. package/lib/transform.d.ts +5 -9
  149. package/lib/transform.js +8 -31
  150. package/lib/transform.js.map +1 -1
  151. package/lib/utils/HttpResponseContentTypeUtil.d.ts +5 -0
  152. package/lib/utils/HttpResponseContentTypeUtil.js +22 -0
  153. package/lib/utils/HttpResponseContentTypeUtil.js.map +1 -0
  154. package/native/go.mod +52 -52
  155. package/native/go.sum +84 -54
  156. package/native/sdk/register.go +322 -165
  157. package/native/sdk/sdk.go +17 -17
  158. package/native/sdk/sdk_metadata_json.go +327 -327
  159. package/native/sdk/sdk_transform.go +1879 -1549
  160. package/package.json +13 -11
  161. package/src/INestiaConfig.ts +267 -267
  162. package/src/NestiaSdkApplication.ts +39 -8
  163. package/src/NestiaSwaggerComposer.ts +153 -142
  164. package/src/analyses/AccessorAnalyzer.ts +64 -67
  165. package/src/analyses/ConfigAnalyzer.ts +330 -330
  166. package/src/analyses/ImportAnalyzer.ts +92 -92
  167. package/src/analyses/PathAnalyzer.ts +130 -69
  168. package/src/analyses/ReflectControllerAnalyzer.ts +112 -105
  169. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  170. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +90 -90
  171. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  172. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +163 -130
  173. package/src/analyses/ReflectMcpOperationAnalyzer.ts +124 -0
  174. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  175. package/src/analyses/SecurityAnalyzer.ts +25 -25
  176. package/src/analyses/TypedMcpRouteAnalyzer.ts +34 -0
  177. package/src/decorators/OperationMetadata.ts +29 -29
  178. package/src/executable/internal/CommandParser.ts +15 -15
  179. package/src/executable/internal/NestiaConfigLoader.ts +451 -446
  180. package/src/executable/internal/NestiaSdkCommand.ts +124 -106
  181. package/src/executable/internal/NestiaSdkWatcher.ts +342 -0
  182. package/src/executable/sdk.ts +90 -88
  183. package/src/factories/ExpressionFactory.ts +23 -0
  184. package/src/factories/IdentifierFactory.ts +84 -0
  185. package/src/factories/LiteralFactory.ts +54 -0
  186. package/src/factories/StatementFactory.ts +56 -0
  187. package/src/factories/TypeFactory.ts +27 -0
  188. package/src/generates/CloneGenerator.ts +74 -66
  189. package/src/generates/E2eGenerator.ts +32 -32
  190. package/src/generates/SdkGenerator.ts +176 -118
  191. package/src/generates/SwaggerGenerator.ts +342 -310
  192. package/src/generates/internal/E2eFileProgrammer.ts +246 -233
  193. package/src/generates/internal/FilePrinter.ts +57 -65
  194. package/src/generates/internal/ImportDictionary.ts +207 -204
  195. package/src/generates/internal/SdkAliasCollection.ts +280 -261
  196. package/src/generates/internal/SdkDistributionComposer.ts +123 -116
  197. package/src/generates/internal/SdkFileProgrammer.ts +113 -112
  198. package/src/generates/internal/SdkHttpCloneProgrammer.ts +124 -126
  199. package/src/generates/internal/SdkHttpCloneReferencer.ts +131 -77
  200. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +290 -301
  201. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +507 -510
  202. package/src/generates/internal/SdkHttpParameterProgrammer.ts +163 -165
  203. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  204. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +322 -314
  205. package/src/generates/internal/SdkImportWizard.ts +62 -62
  206. package/src/generates/internal/SdkMcpRouteProgrammer.ts +447 -0
  207. package/src/generates/internal/SdkRouteDirectory.ts +21 -18
  208. package/src/generates/internal/SdkTypeProgrammer.ts +389 -382
  209. package/src/generates/internal/SdkTypeTagProgrammer.ts +110 -114
  210. package/src/generates/internal/SdkWebSocketCloneProgrammer.ts +319 -0
  211. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +383 -389
  212. package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +91 -89
  213. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +304 -323
  214. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  215. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  216. package/src/generates/internal/SwaggerOperationParameterComposer.ts +175 -162
  217. package/src/generates/internal/SwaggerOperationResponseComposer.ts +115 -110
  218. package/src/generates/internal/SwaggerReadonlyArrayEmender.ts +262 -0
  219. package/src/index.ts +4 -4
  220. package/src/internal/legacy.ts +492 -492
  221. package/src/module.ts +4 -4
  222. package/src/structures/INestiaProject.ts +10 -10
  223. package/src/structures/INestiaSdkInput.ts +27 -20
  224. package/src/structures/IOperationMetadata.ts +41 -41
  225. package/src/structures/IReflectController.ts +18 -15
  226. package/src/structures/IReflectHttpOperation.ts +26 -26
  227. package/src/structures/IReflectHttpOperationException.ts +18 -18
  228. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  229. package/src/structures/IReflectHttpOperationSuccess.ts +18 -21
  230. package/src/structures/IReflectImport.ts +6 -6
  231. package/src/structures/IReflectMcpOperation.ts +38 -0
  232. package/src/structures/IReflectMcpOperationParameter.ts +27 -0
  233. package/src/structures/IReflectOperationError.ts +26 -26
  234. package/src/structures/IReflectType.ts +4 -4
  235. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  236. package/src/structures/ITypedApplication.ts +12 -11
  237. package/src/structures/ITypedHttpRoute.ts +41 -41
  238. package/src/structures/ITypedHttpRouteException.ts +15 -15
  239. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  240. package/src/structures/ITypedHttpRouteSuccess.ts +18 -22
  241. package/src/structures/ITypedMcpRoute.ts +33 -0
  242. package/src/structures/ITypedWebSocketRoute.ts +24 -24
  243. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  244. package/src/transform.ts +28 -59
  245. package/src/typings/get-function-location.d.ts +7 -7
  246. package/src/utils/ArrayUtil.ts +26 -26
  247. package/src/utils/EmittedJavaScriptPatcher.ts +88 -88
  248. package/src/utils/FileRetriever.ts +22 -22
  249. package/src/utils/HttpResponseContentTypeUtil.ts +30 -0
  250. package/src/utils/MapUtil.ts +14 -14
  251. package/src/utils/PathUtil.ts +10 -10
  252. package/src/utils/SourceFinder.ts +63 -63
  253. package/src/utils/StringUtil.ts +17 -17
  254. package/src/utils/TsConfigReader.ts +108 -108
  255. package/src/utils/TtscExecutor.ts +68 -68
  256. package/src/utils/VersioningStrategy.ts +28 -28
  257. package/src/validators/HttpHeadersValidator.ts +11 -11
  258. package/src/validators/HttpQueryValidator.ts +11 -11
  259. package/src/validators/TextPlainValidator.ts +17 -17
@@ -1,510 +1,507 @@
1
- import { Node, NodeFlags, SyntaxKind, TypeScriptFactory } from "@nestia/factory";
2
- import { ExpressionFactory, IdentifierFactory, LiteralFactory, TypeFactory } from "@nestia/factory";
3
- import { NamingConvention } from "@typia/utils";
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 { SdkHttpSimulationProgrammer } from "./SdkHttpSimulationProgrammer";
12
- import { SdkImportWizard } from "./SdkImportWizard";
13
- import { sizeOf } from "../../internal/legacy";
14
-
15
- export namespace SdkHttpNamespaceProgrammer {
16
- export const write =
17
- (project: INestiaProject) =>
18
- (importer: ImportDictionary) =>
19
- (route: ITypedHttpRoute): Node => {
20
- const types: Node[] =
21
- writeTypes(project)(importer)(route);
22
- return TypeScriptFactory.createModuleDeclaration(
23
- [TypeScriptFactory.createToken(SyntaxKind.ExportKeyword)],
24
- TypeScriptFactory.createIdentifier(route.name),
25
- TypeScriptFactory.createModuleBlock([
26
- ...types,
27
- ...(types.length ? [FilePrinter.enter()] : []),
28
- writeMetadata(project)(importer)(route),
29
- FilePrinter.enter(),
30
- writePath(project)(importer)(route),
31
- ...(project.config.simulate
32
- ? [
33
- SdkHttpSimulationProgrammer.random(project)(importer)(route),
34
- SdkHttpSimulationProgrammer.simulate(project)(importer)(route),
35
- ]
36
- : []),
37
- ...(project.config.json &&
38
- route.body &&
39
- (route.body.contentType === "application/json" ||
40
- route.body.encrypted === true)
41
- ? [writeStringify(project)(importer)]
42
- : []),
43
- ]),
44
- NodeFlags.Namespace,
45
- );
46
- };
47
-
48
- const writeTypes =
49
- (project: INestiaProject) =>
50
- (importer: ImportDictionary) =>
51
- (route: ITypedHttpRoute): Node[] => {
52
- const array: Node[] = [];
53
- const declare = (name: string, type: Node) =>
54
- array.push(
55
- TypeScriptFactory.createTypeAliasDeclaration(
56
- [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
57
- name,
58
- undefined,
59
- type,
60
- ),
61
- );
62
- if (
63
- project.config.keyword === true &&
64
- SdkHttpParameterProgrammer.getSignificant(route, true).length !== 0
65
- )
66
- declare(
67
- "Props",
68
- SdkAliasCollection.httpProps(project)(importer)(route),
69
- );
70
- if (route.headerObject)
71
- declare(
72
- "Headers",
73
- SdkAliasCollection.headers(project)(importer)(route.headerObject),
74
- );
75
- if (route.queryObject)
76
- declare(
77
- "Query",
78
- SdkAliasCollection.query(project)(importer)(route.queryObject),
79
- );
80
- if (route.body)
81
- declare("Body", SdkAliasCollection.body(project)(importer)(route.body));
82
- if (
83
- project.config.propagate === true ||
84
- sizeOf(route.success.metadata) !== 0
85
- )
86
- declare(
87
- "Output",
88
- SdkAliasCollection.response(project)(importer)(route),
89
- );
90
- return array;
91
- };
92
-
93
- const writeMetadata =
94
- (project: INestiaProject) =>
95
- (importer: ImportDictionary) =>
96
- (route: ITypedHttpRoute): Node =>
97
- constant("METADATA")(
98
- TypeScriptFactory.createAsExpression(
99
- TypeScriptFactory.createObjectLiteralExpression(
100
- [
101
- TypeScriptFactory.createPropertyAssignment(
102
- "method",
103
- TypeScriptFactory.createStringLiteral(route.method),
104
- ),
105
- TypeScriptFactory.createPropertyAssignment(
106
- "path",
107
- TypeScriptFactory.createStringLiteral(route.path),
108
- ),
109
- TypeScriptFactory.createPropertyAssignment(
110
- "request",
111
- route.body
112
- ? LiteralFactory.write(
113
- route.body !== undefined
114
- ? {
115
- type: route.body.contentType,
116
- encrypted: !!route.body.encrypted,
117
- }
118
- : {
119
- type: "application/json",
120
- encrypted: false,
121
- },
122
- )
123
- : TypeScriptFactory.createNull(),
124
- ),
125
- TypeScriptFactory.createPropertyAssignment(
126
- "response",
127
- route.method !== "HEAD"
128
- ? LiteralFactory.write({
129
- type: route.success.contentType,
130
- encrypted: !!route.success.encrypted,
131
- })
132
- : TypeScriptFactory.createNull(),
133
- ),
134
- TypeScriptFactory.createPropertyAssignment(
135
- "status",
136
- route.success.status !== null
137
- ? ExpressionFactory.number(route.success.status)
138
- : TypeScriptFactory.createNull(),
139
- ),
140
- ...(route.success.contentType ===
141
- "application/x-www-form-urlencoded"
142
- ? [
143
- TypeScriptFactory.createPropertyAssignment(
144
- "parseQuery",
145
- TypeScriptFactory.createCallExpression(
146
- TypeScriptFactory.createIdentifier(
147
- `${SdkImportWizard.typia(importer)}.http.createAssertQuery`,
148
- ),
149
- [
150
- project.config.clone === true
151
- ? SdkAliasCollection.from(project)(importer)(
152
- route.success.metadata,
153
- )
154
- : SdkAliasCollection.name(route.success),
155
- ],
156
- undefined,
157
- ),
158
- ),
159
- ]
160
- : []),
161
- ],
162
- true,
163
- ),
164
- TypeScriptFactory.createTypeReferenceNode(
165
- TypeScriptFactory.createIdentifier("const"),
166
- ),
167
- ),
168
- );
169
-
170
- const writePath =
171
- (project: INestiaProject) =>
172
- (importer: ImportDictionary) =>
173
- (route: ITypedHttpRoute): Node => {
174
- const out = (body: Node) =>
175
- constant("path")(
176
- TypeScriptFactory.createArrowFunction(
177
- [],
178
- [],
179
- SdkHttpParameterProgrammer.getParameterDeclarations({
180
- project,
181
- importer,
182
- route,
183
- body: false,
184
- prefix: false,
185
- }),
186
- undefined,
187
- undefined,
188
- body,
189
- ),
190
- );
191
- const parameters = SdkHttpParameterProgrammer.getSignificant(
192
- route,
193
- false,
194
- );
195
- if (parameters.length === 0)
196
- return out(TypeScriptFactory.createStringLiteral(route.path));
197
-
198
- const access = (name: string) =>
199
- project.config.keyword === true ? `props.${name}` : name;
200
- const template = () => {
201
- const split: string[] = route.path.split(":");
202
- if (split.length === 1)
203
- return TypeScriptFactory.createStringLiteral(route.path);
204
- return TypeScriptFactory.createTemplateExpression(
205
- TypeScriptFactory.createTemplateHead(split[0]!),
206
- split.slice(1).map((s, i, arr) => {
207
- const name: string = s.split("/")[0]!;
208
- return TypeScriptFactory.createTemplateSpan(
209
- TypeScriptFactory.createCallExpression(
210
- TypeScriptFactory.createIdentifier("encodeURIComponent"),
211
- undefined,
212
- [
213
- TypeScriptFactory.createBinaryExpression(
214
- TypeScriptFactory.createCallChain(
215
- TypeScriptFactory.createPropertyAccessChain(
216
- TypeScriptFactory.createIdentifier(
217
- access(
218
- route.pathParameters.find((p) => p.field === name)!
219
- .name,
220
- ),
221
- ),
222
- TypeScriptFactory.createToken(
223
- SyntaxKind.QuestionDotToken,
224
- ),
225
- "toString",
226
- ),
227
- undefined,
228
- undefined,
229
- [],
230
- ),
231
- TypeScriptFactory.createToken(
232
- SyntaxKind.QuestionQuestionToken,
233
- ),
234
- TypeScriptFactory.createStringLiteral("null"),
235
- ),
236
- ],
237
- ),
238
- (i !== arr.length - 1
239
- ? TypeScriptFactory.createTemplateMiddle
240
- : TypeScriptFactory.createTemplateTail)(
241
- s.substring(name.length),
242
- ),
243
- );
244
- }),
245
- );
246
- };
247
- if (route.queryObject === null && route.queryParameters.length === 0)
248
- return out(template());
249
-
250
- const block = (expr: Node) => {
251
- const computeName = (str: string): string =>
252
- parameters.find((p) => p.name === str) !== undefined
253
- ? computeName("_" + str)
254
- : str;
255
- const variables: string = computeName("variables");
256
- return TypeScriptFactory.createBlock(
257
- [
258
- local(variables)("URLSearchParams")(
259
- TypeScriptFactory.createNewExpression(
260
- TypeScriptFactory.createIdentifier("URLSearchParams"),
261
- [],
262
- [],
263
- ),
264
- ),
265
- TypeScriptFactory.createForOfStatement(
266
- undefined,
267
- TypeScriptFactory.createVariableDeclarationList(
268
- [
269
- TypeScriptFactory.createVariableDeclaration(
270
- TypeScriptFactory.createArrayBindingPattern([
271
- TypeScriptFactory.createBindingElement(
272
- undefined,
273
- undefined,
274
- TypeScriptFactory.createIdentifier("key"),
275
- undefined,
276
- ),
277
- TypeScriptFactory.createBindingElement(
278
- undefined,
279
- undefined,
280
- TypeScriptFactory.createIdentifier("value"),
281
- undefined,
282
- ),
283
- ]),
284
- undefined,
285
- undefined,
286
- undefined,
287
- ),
288
- ],
289
- NodeFlags.Const,
290
- ),
291
- TypeScriptFactory.createCallExpression(
292
- TypeScriptFactory.createIdentifier("Object.entries"),
293
- undefined,
294
- [
295
- TypeScriptFactory.createAsExpression(
296
- expr,
297
- TypeFactory.keyword("any"),
298
- ),
299
- ],
300
- ),
301
- TypeScriptFactory.createIfStatement(
302
- TypeScriptFactory.createStrictEquality(
303
- TypeScriptFactory.createIdentifier("undefined"),
304
- TypeScriptFactory.createIdentifier("value"),
305
- ),
306
- TypeScriptFactory.createContinueStatement(),
307
- TypeScriptFactory.createIfStatement(
308
- TypeScriptFactory.createCallExpression(
309
- TypeScriptFactory.createIdentifier("Array.isArray"),
310
- undefined,
311
- [TypeScriptFactory.createIdentifier("value")],
312
- ),
313
- TypeScriptFactory.createExpressionStatement(
314
- TypeScriptFactory.createCallExpression(
315
- TypeScriptFactory.createPropertyAccessExpression(
316
- TypeScriptFactory.createIdentifier("value"),
317
- TypeScriptFactory.createIdentifier("forEach"),
318
- ),
319
- undefined,
320
- [
321
- TypeScriptFactory.createArrowFunction(
322
- undefined,
323
- undefined,
324
- [IdentifierFactory.parameter("elem")],
325
- undefined,
326
- undefined,
327
- TypeScriptFactory.createCallExpression(
328
- IdentifierFactory.access(
329
- TypeScriptFactory.createIdentifier(variables),
330
- "append",
331
- ),
332
- undefined,
333
- [
334
- TypeScriptFactory.createIdentifier("key"),
335
- TypeScriptFactory.createCallExpression(
336
- TypeScriptFactory.createIdentifier("String"),
337
- undefined,
338
- [TypeScriptFactory.createIdentifier("elem")],
339
- ),
340
- ],
341
- ),
342
- ),
343
- ],
344
- ),
345
- ),
346
- TypeScriptFactory.createExpressionStatement(
347
- TypeScriptFactory.createCallExpression(
348
- IdentifierFactory.access(
349
- TypeScriptFactory.createIdentifier(variables),
350
- "set",
351
- ),
352
- undefined,
353
- [
354
- TypeScriptFactory.createIdentifier("key"),
355
- TypeScriptFactory.createCallExpression(
356
- TypeScriptFactory.createIdentifier("String"),
357
- undefined,
358
- [TypeScriptFactory.createIdentifier("value")],
359
- ),
360
- ],
361
- ),
362
- ),
363
- ),
364
- ),
365
- ),
366
- local("location")("string")(template()),
367
- TypeScriptFactory.createReturnStatement(
368
- TypeScriptFactory.createConditionalExpression(
369
- TypeScriptFactory.createStrictEquality(
370
- ExpressionFactory.number(0),
371
- IdentifierFactory.access(
372
- TypeScriptFactory.createIdentifier(variables),
373
- "size",
374
- ),
375
- ),
376
- undefined,
377
- TypeScriptFactory.createIdentifier("location"),
378
- undefined,
379
- TypeScriptFactory.createTemplateExpression(
380
- TypeScriptFactory.createTemplateHead(""),
381
- [
382
- TypeScriptFactory.createTemplateSpan(
383
- TypeScriptFactory.createIdentifier("location"),
384
- TypeScriptFactory.createTemplateMiddle("?"),
385
- ),
386
- TypeScriptFactory.createTemplateSpan(
387
- TypeScriptFactory.createCallExpression(
388
- IdentifierFactory.access(
389
- TypeScriptFactory.createIdentifier(variables),
390
- "toString",
391
- ),
392
- undefined,
393
- undefined,
394
- ),
395
- TypeScriptFactory.createTemplateTail(""),
396
- ),
397
- ],
398
- ),
399
- ),
400
- ),
401
- ],
402
- true,
403
- );
404
- };
405
- if (route.queryObject !== null && route.queryParameters.length === 0)
406
- return out(
407
- block(
408
- route.queryObject.metadata.required === false
409
- ? TypeScriptFactory.createBinaryExpression(
410
- TypeScriptFactory.createIdentifier(route.queryObject.name),
411
- TypeScriptFactory.createToken(
412
- SyntaxKind.QuestionQuestionToken,
413
- ),
414
- TypeScriptFactory.createObjectLiteralExpression([], false),
415
- )
416
- : TypeScriptFactory.createIdentifier(
417
- access(route.queryObject.name),
418
- ),
419
- ),
420
- );
421
- return out(
422
- block(
423
- TypeScriptFactory.createObjectLiteralExpression(
424
- [
425
- ...(route.queryObject
426
- ? [
427
- TypeScriptFactory.createSpreadAssignment(
428
- TypeScriptFactory.createIdentifier(
429
- access(route.queryObject.name),
430
- ),
431
- ),
432
- ]
433
- : []),
434
- ...route.queryParameters.map((q) =>
435
- TypeScriptFactory.createPropertyAssignment(
436
- NamingConvention.variable(q.field!)
437
- ? q.field!
438
- : TypeScriptFactory.createStringLiteral(q.field!),
439
- TypeScriptFactory.createIdentifier(access(q.name)),
440
- ),
441
- ),
442
- ],
443
- true,
444
- ),
445
- ),
446
- );
447
- };
448
-
449
- const writeStringify =
450
- (project: INestiaProject) =>
451
- (importer: ImportDictionary): Node =>
452
- constant("stringify")(
453
- TypeScriptFactory.createArrowFunction(
454
- [],
455
- undefined,
456
- [
457
- IdentifierFactory.parameter(
458
- "input",
459
- TypeScriptFactory.createTypeReferenceNode("Body"),
460
- ),
461
- ],
462
- undefined,
463
- undefined,
464
- TypeScriptFactory.createCallExpression(
465
- IdentifierFactory.access(
466
- IdentifierFactory.access(
467
- TypeScriptFactory.createIdentifier(
468
- SdkImportWizard.typia(importer),
469
- ),
470
- "json",
471
- ),
472
- project.config.assert ? "stringify" : "assertStringify",
473
- ),
474
- undefined,
475
- [TypeScriptFactory.createIdentifier("input")],
476
- ),
477
- ),
478
- );
479
- }
480
-
481
- const local = (name: string) => (type: string) => (expression: Node) =>
482
- TypeScriptFactory.createVariableStatement(
483
- [],
484
- TypeScriptFactory.createVariableDeclarationList(
485
- [
486
- TypeScriptFactory.createVariableDeclaration(
487
- name,
488
- undefined,
489
- TypeScriptFactory.createTypeReferenceNode(type),
490
- expression,
491
- ),
492
- ],
493
- NodeFlags.Const,
494
- ),
495
- );
496
- const constant = (name: string) => (expression: Node) =>
497
- TypeScriptFactory.createVariableStatement(
498
- [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
499
- TypeScriptFactory.createVariableDeclarationList(
500
- [
501
- TypeScriptFactory.createVariableDeclaration(
502
- name,
503
- undefined,
504
- undefined,
505
- expression,
506
- ),
507
- ],
508
- NodeFlags.Const,
509
- ),
510
- );
1
+ import {
2
+ type Block,
3
+ type Expression,
4
+ type Node,
5
+ NodeFlags,
6
+ type ParameterDeclaration,
7
+ type Statement,
8
+ SyntaxKind,
9
+ type TypeNode,
10
+ factory,
11
+ } from "@ttsc/factory";
12
+ import { NamingConvention } from "@typia/utils";
13
+
14
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
15
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
16
+ import { LiteralFactory } from "../../factories/LiteralFactory";
17
+ import { TypeFactory } from "../../factories/TypeFactory";
18
+ import { sizeOf } from "../../internal/legacy";
19
+ import { INestiaProject } from "../../structures/INestiaProject";
20
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
21
+ import { FilePrinter } from "./FilePrinter";
22
+ import { ImportDictionary } from "./ImportDictionary";
23
+ import { SdkAliasCollection } from "./SdkAliasCollection";
24
+ import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
25
+ import { SdkHttpSimulationProgrammer } from "./SdkHttpSimulationProgrammer";
26
+ import { SdkImportWizard } from "./SdkImportWizard";
27
+
28
+ export namespace SdkHttpNamespaceProgrammer {
29
+ export const write =
30
+ (project: INestiaProject) =>
31
+ (importer: ImportDictionary) =>
32
+ (route: ITypedHttpRoute): Node => {
33
+ const types: Statement[] = writeTypes(project)(importer)(route);
34
+ return factory.createModuleDeclaration(
35
+ [factory.createToken(SyntaxKind.ExportKeyword)],
36
+ factory.createIdentifier(route.name),
37
+ factory.createModuleBlock([
38
+ ...types,
39
+ ...(types.length ? [FilePrinter.enter()] : []),
40
+ writeMetadata(project)(importer)(route),
41
+ FilePrinter.enter(),
42
+ writePath(project)(importer)(route),
43
+ ...(project.config.simulate
44
+ ? [
45
+ SdkHttpSimulationProgrammer.random(project)(importer)(
46
+ route,
47
+ ) as Statement,
48
+ SdkHttpSimulationProgrammer.simulate(project)(importer)(
49
+ route,
50
+ ) as Statement,
51
+ ]
52
+ : []),
53
+ ...(project.config.json &&
54
+ route.body &&
55
+ (route.body.contentType === "application/json" ||
56
+ route.body.encrypted === true)
57
+ ? [writeStringify(project)(importer)]
58
+ : []),
59
+ ]),
60
+ NodeFlags.Namespace,
61
+ );
62
+ };
63
+
64
+ const writeTypes =
65
+ (project: INestiaProject) =>
66
+ (importer: ImportDictionary) =>
67
+ (route: ITypedHttpRoute): Statement[] => {
68
+ const array: Statement[] = [];
69
+ const declare = (name: string, type: Node) =>
70
+ array.push(
71
+ factory.createTypeAliasDeclaration(
72
+ [factory.createModifier(SyntaxKind.ExportKeyword)],
73
+ name,
74
+ undefined,
75
+ type as TypeNode,
76
+ ),
77
+ );
78
+ if (
79
+ project.config.keyword === true &&
80
+ SdkHttpParameterProgrammer.getSignificant(route, true).length !== 0
81
+ )
82
+ declare(
83
+ "Props",
84
+ SdkAliasCollection.httpProps(project)(importer)(route),
85
+ );
86
+ if (route.headerObject)
87
+ declare(
88
+ "Headers",
89
+ SdkAliasCollection.headers(project)(importer)(route.headerObject),
90
+ );
91
+ if (route.queryObject)
92
+ declare(
93
+ "Query",
94
+ SdkAliasCollection.query(project)(importer)(route.queryObject),
95
+ );
96
+ if (route.body)
97
+ declare("Body", SdkAliasCollection.body(project)(importer)(route.body));
98
+ if (
99
+ project.config.propagate === true ||
100
+ route.success.binary === true ||
101
+ sizeOf(route.success.metadata) !== 0
102
+ )
103
+ declare(
104
+ "Output",
105
+ SdkAliasCollection.response(project)(importer)(route),
106
+ );
107
+ return array;
108
+ };
109
+
110
+ const writeMetadata =
111
+ (project: INestiaProject) =>
112
+ (importer: ImportDictionary) =>
113
+ (route: ITypedHttpRoute): Statement =>
114
+ constant("METADATA")(
115
+ factory.createAsExpression(
116
+ factory.createObjectLiteralExpression(
117
+ [
118
+ factory.createPropertyAssignment(
119
+ "method",
120
+ factory.createStringLiteral(route.method),
121
+ ),
122
+ factory.createPropertyAssignment(
123
+ "path",
124
+ factory.createStringLiteral(route.path),
125
+ ),
126
+ factory.createPropertyAssignment(
127
+ "request",
128
+ route.body
129
+ ? LiteralFactory.write(
130
+ route.body !== undefined
131
+ ? {
132
+ type: route.body.contentType,
133
+ encrypted: !!route.body.encrypted,
134
+ }
135
+ : {
136
+ type: "application/json",
137
+ encrypted: false,
138
+ },
139
+ )
140
+ : factory.createNull(),
141
+ ),
142
+ factory.createPropertyAssignment(
143
+ "response",
144
+ route.method !== "HEAD"
145
+ ? LiteralFactory.write({
146
+ type: route.success.contentType,
147
+ encrypted: !!route.success.encrypted,
148
+ })
149
+ : factory.createNull(),
150
+ ),
151
+ factory.createPropertyAssignment(
152
+ "status",
153
+ route.success.status !== null
154
+ ? ExpressionFactory.number(route.success.status)
155
+ : factory.createNull(),
156
+ ),
157
+ ...(route.success.contentType ===
158
+ "application/x-www-form-urlencoded"
159
+ ? [
160
+ factory.createPropertyAssignment(
161
+ "parseQuery",
162
+ factory.createCallExpression(
163
+ factory.createIdentifier(
164
+ `${SdkImportWizard.typia(importer)}.http.createAssertQuery`,
165
+ ),
166
+ [
167
+ (project.config.clone === true
168
+ ? SdkAliasCollection.from(project)(importer)(
169
+ route.success.metadata,
170
+ )
171
+ : SdkAliasCollection.name(
172
+ route.success,
173
+ )) as TypeNode,
174
+ ],
175
+ undefined,
176
+ ),
177
+ ),
178
+ ]
179
+ : []),
180
+ ],
181
+ true,
182
+ ),
183
+ factory.createTypeReferenceNode(factory.createIdentifier("const")),
184
+ ),
185
+ );
186
+
187
+ const writePath =
188
+ (project: INestiaProject) =>
189
+ (importer: ImportDictionary) =>
190
+ (route: ITypedHttpRoute): Statement => {
191
+ const out = (body: Block | Expression) =>
192
+ constant("path")(
193
+ factory.createArrowFunction(
194
+ [],
195
+ [],
196
+ SdkHttpParameterProgrammer.getParameterDeclarations({
197
+ project,
198
+ importer,
199
+ route,
200
+ body: false,
201
+ prefix: false,
202
+ }) as ParameterDeclaration[],
203
+ undefined,
204
+ undefined,
205
+ body,
206
+ ),
207
+ );
208
+ const parameters = SdkHttpParameterProgrammer.getSignificant(
209
+ route,
210
+ false,
211
+ );
212
+ if (parameters.length === 0)
213
+ return out(factory.createStringLiteral(route.path));
214
+
215
+ const access = (name: string) =>
216
+ project.config.keyword === true ? `props.${name}` : name;
217
+ const template = () => {
218
+ const split: string[] = route.path.split(":");
219
+ if (split.length === 1) return factory.createStringLiteral(route.path);
220
+ return factory.createTemplateExpression(
221
+ factory.createTemplateHead(split[0]!),
222
+ split.slice(1).map((s, i, arr) => {
223
+ const name: string = s.split("/")[0]!;
224
+ return factory.createTemplateSpan(
225
+ factory.createCallExpression(
226
+ factory.createIdentifier("encodeURIComponent"),
227
+ undefined,
228
+ [
229
+ factory.createBinaryExpression(
230
+ factory.createCallChain(
231
+ factory.createPropertyAccessChain(
232
+ factory.createIdentifier(
233
+ access(
234
+ route.pathParameters.find((p) => p.field === name)!
235
+ .name,
236
+ ),
237
+ ),
238
+ factory.createToken(SyntaxKind.QuestionDotToken),
239
+ "toString",
240
+ ),
241
+ undefined,
242
+ undefined,
243
+ [],
244
+ ),
245
+ factory.createToken(SyntaxKind.QuestionQuestionToken),
246
+ factory.createStringLiteral("null"),
247
+ ),
248
+ ],
249
+ ),
250
+ (i !== arr.length - 1
251
+ ? factory.createTemplateMiddle
252
+ : factory.createTemplateTail)(s.substring(name.length)),
253
+ );
254
+ }),
255
+ );
256
+ };
257
+ if (route.queryObject === null && route.queryParameters.length === 0)
258
+ return out(template());
259
+
260
+ const block = (expr: Expression) => {
261
+ const computeName = (str: string): string =>
262
+ parameters.find((p) => p.name === str) !== undefined
263
+ ? computeName("_" + str)
264
+ : str;
265
+ const variables: string = computeName("variables");
266
+ return factory.createBlock(
267
+ [
268
+ local(variables)("URLSearchParams")(
269
+ factory.createNewExpression(
270
+ factory.createIdentifier("URLSearchParams"),
271
+ [],
272
+ [],
273
+ ),
274
+ ),
275
+ factory.createForOfStatement(
276
+ undefined,
277
+ factory.createVariableDeclarationList(
278
+ [
279
+ factory.createVariableDeclaration(
280
+ factory.createArrayBindingPattern([
281
+ factory.createBindingElement(
282
+ undefined,
283
+ undefined,
284
+ factory.createIdentifier("key"),
285
+ undefined,
286
+ ),
287
+ factory.createBindingElement(
288
+ undefined,
289
+ undefined,
290
+ factory.createIdentifier("value"),
291
+ undefined,
292
+ ),
293
+ ]),
294
+ undefined,
295
+ undefined,
296
+ undefined,
297
+ ),
298
+ ],
299
+ NodeFlags.Const,
300
+ ),
301
+ factory.createCallExpression(
302
+ factory.createIdentifier("Object.entries"),
303
+ undefined,
304
+ [factory.createAsExpression(expr, TypeFactory.keyword("any"))],
305
+ ),
306
+ factory.createIfStatement(
307
+ factory.createStrictEquality(
308
+ factory.createIdentifier("undefined"),
309
+ factory.createIdentifier("value"),
310
+ ),
311
+ factory.createContinueStatement(),
312
+ factory.createIfStatement(
313
+ factory.createCallExpression(
314
+ factory.createIdentifier("Array.isArray"),
315
+ undefined,
316
+ [factory.createIdentifier("value")],
317
+ ),
318
+ factory.createExpressionStatement(
319
+ factory.createCallExpression(
320
+ factory.createPropertyAccessExpression(
321
+ factory.createIdentifier("value"),
322
+ factory.createIdentifier("forEach"),
323
+ ),
324
+ undefined,
325
+ [
326
+ factory.createArrowFunction(
327
+ undefined,
328
+ undefined,
329
+ [IdentifierFactory.parameter("elem")],
330
+ undefined,
331
+ undefined,
332
+ factory.createCallExpression(
333
+ IdentifierFactory.access(
334
+ factory.createIdentifier(variables),
335
+ "append",
336
+ ),
337
+ undefined,
338
+ [
339
+ factory.createIdentifier("key"),
340
+ factory.createCallExpression(
341
+ factory.createIdentifier("String"),
342
+ undefined,
343
+ [factory.createIdentifier("elem")],
344
+ ),
345
+ ],
346
+ ),
347
+ ),
348
+ ],
349
+ ),
350
+ ),
351
+ factory.createExpressionStatement(
352
+ factory.createCallExpression(
353
+ IdentifierFactory.access(
354
+ factory.createIdentifier(variables),
355
+ "set",
356
+ ),
357
+ undefined,
358
+ [
359
+ factory.createIdentifier("key"),
360
+ factory.createCallExpression(
361
+ factory.createIdentifier("String"),
362
+ undefined,
363
+ [factory.createIdentifier("value")],
364
+ ),
365
+ ],
366
+ ),
367
+ ),
368
+ ),
369
+ ),
370
+ ),
371
+ local("location")("string")(template()),
372
+ factory.createReturnStatement(
373
+ factory.createConditionalExpression(
374
+ factory.createStrictEquality(
375
+ ExpressionFactory.number(0),
376
+ IdentifierFactory.access(
377
+ factory.createIdentifier(variables),
378
+ "size",
379
+ ),
380
+ ),
381
+ undefined,
382
+ factory.createIdentifier("location"),
383
+ undefined,
384
+ factory.createTemplateExpression(
385
+ factory.createTemplateHead(""),
386
+ [
387
+ factory.createTemplateSpan(
388
+ factory.createIdentifier("location"),
389
+ factory.createTemplateMiddle("?"),
390
+ ),
391
+ factory.createTemplateSpan(
392
+ factory.createCallExpression(
393
+ IdentifierFactory.access(
394
+ factory.createIdentifier(variables),
395
+ "toString",
396
+ ),
397
+ undefined,
398
+ undefined,
399
+ ),
400
+ factory.createTemplateTail(""),
401
+ ),
402
+ ],
403
+ ),
404
+ ),
405
+ ),
406
+ ],
407
+ true,
408
+ );
409
+ };
410
+ if (route.queryObject !== null && route.queryParameters.length === 0)
411
+ return out(
412
+ block(
413
+ route.queryObject.metadata.required === false
414
+ ? factory.createBinaryExpression(
415
+ factory.createIdentifier(route.queryObject.name),
416
+ factory.createToken(SyntaxKind.QuestionQuestionToken),
417
+ factory.createObjectLiteralExpression([], false),
418
+ )
419
+ : factory.createIdentifier(access(route.queryObject.name)),
420
+ ),
421
+ );
422
+ return out(
423
+ block(
424
+ factory.createObjectLiteralExpression(
425
+ [
426
+ ...(route.queryObject
427
+ ? [
428
+ factory.createSpreadAssignment(
429
+ factory.createIdentifier(access(route.queryObject.name)),
430
+ ),
431
+ ]
432
+ : []),
433
+ ...route.queryParameters.map((q) =>
434
+ factory.createPropertyAssignment(
435
+ NamingConvention.variable(q.field!)
436
+ ? q.field!
437
+ : factory.createStringLiteral(q.field!),
438
+ factory.createIdentifier(access(q.name)),
439
+ ),
440
+ ),
441
+ ],
442
+ true,
443
+ ),
444
+ ),
445
+ );
446
+ };
447
+
448
+ const writeStringify =
449
+ (project: INestiaProject) =>
450
+ (importer: ImportDictionary): Statement =>
451
+ constant("stringify")(
452
+ factory.createArrowFunction(
453
+ [],
454
+ undefined,
455
+ [
456
+ IdentifierFactory.parameter(
457
+ "input",
458
+ factory.createTypeReferenceNode("Body"),
459
+ ),
460
+ ],
461
+ undefined,
462
+ undefined,
463
+ factory.createCallExpression(
464
+ IdentifierFactory.access(
465
+ IdentifierFactory.access(
466
+ factory.createIdentifier(SdkImportWizard.typia(importer)),
467
+ "json",
468
+ ),
469
+ project.config.assert ? "stringify" : "assertStringify",
470
+ ),
471
+ undefined,
472
+ [factory.createIdentifier("input")],
473
+ ),
474
+ ),
475
+ );
476
+ }
477
+
478
+ const local = (name: string) => (type: string) => (expression: Expression) =>
479
+ factory.createVariableStatement(
480
+ [],
481
+ factory.createVariableDeclarationList(
482
+ [
483
+ factory.createVariableDeclaration(
484
+ name,
485
+ undefined,
486
+ factory.createTypeReferenceNode(type),
487
+ expression,
488
+ ),
489
+ ],
490
+ NodeFlags.Const,
491
+ ),
492
+ );
493
+ const constant = (name: string) => (expression: Expression) =>
494
+ factory.createVariableStatement(
495
+ [factory.createModifier(SyntaxKind.ExportKeyword)],
496
+ factory.createVariableDeclarationList(
497
+ [
498
+ factory.createVariableDeclaration(
499
+ name,
500
+ undefined,
501
+ undefined,
502
+ expression,
503
+ ),
504
+ ],
505
+ NodeFlags.Const,
506
+ ),
507
+ );