@nestia/sdk 11.2.1 → 12.0.0-dev.20260521.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 (277) hide show
  1. package/assets/bundle/distribute/package.json +1 -1
  2. package/lib/NestiaSdkApplication.js +5 -4
  3. package/lib/NestiaSdkApplication.js.map +1 -1
  4. package/lib/NestiaSwaggerComposer.js +2 -2
  5. package/lib/NestiaSwaggerComposer.js.map +1 -1
  6. package/lib/analyses/AccessorAnalyzer.js.map +1 -1
  7. package/lib/analyses/ConfigAnalyzer.js +133 -7
  8. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  9. package/lib/analyses/ImportAnalyzer.d.ts +9 -2
  10. package/lib/analyses/ImportAnalyzer.js +13 -50
  11. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  12. package/lib/analyses/PathAnalyzer.js.map +1 -1
  13. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  14. package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +1 -1
  15. package/lib/analyses/ReflectHttpOperationAnalyzer.js +5 -4
  16. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  17. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.d.ts +1 -1
  18. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js +22 -5
  19. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js.map +1 -1
  20. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.d.ts +1 -1
  21. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +8 -8
  22. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
  23. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +1 -1
  24. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +15 -15
  25. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
  26. package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -1
  27. package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +1 -1
  28. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +1 -1
  29. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
  30. package/lib/analyses/SecurityAnalyzer.js.map +1 -1
  31. package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +2 -1
  32. package/lib/analyses/TypedHttpRouteAnalyzer.js +296 -39
  33. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
  34. package/lib/analyses/TypedWebSocketRouteAnalyzer.js +1 -4
  35. package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -1
  36. package/lib/decorators/OperationMetadata.d.ts +12 -2
  37. package/lib/decorators/OperationMetadata.js +14 -1
  38. package/lib/decorators/OperationMetadata.js.map +1 -1
  39. package/lib/executable/internal/CommandParser.js.map +1 -1
  40. package/lib/executable/internal/NestiaConfigLoader.d.ts +6 -2
  41. package/lib/executable/internal/NestiaConfigLoader.js +285 -793
  42. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  43. package/lib/executable/internal/NestiaSdkCommand.js +6 -4
  44. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  45. package/lib/executable/sdk.js +17 -5
  46. package/lib/executable/sdk.js.map +1 -1
  47. package/lib/generates/CloneGenerator.js +2 -2
  48. package/lib/generates/CloneGenerator.js.map +1 -1
  49. package/lib/generates/E2eGenerator.js.map +1 -1
  50. package/lib/generates/SdkGenerator.js +6 -9
  51. package/lib/generates/SdkGenerator.js.map +1 -1
  52. package/lib/generates/SwaggerGenerator.js +20 -107
  53. package/lib/generates/SwaggerGenerator.js.map +1 -1
  54. package/lib/generates/internal/E2eFileProgrammer.js +44 -28
  55. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  56. package/lib/generates/internal/FilePrinter.d.ts +4 -4
  57. package/lib/generates/internal/FilePrinter.js +25 -16
  58. package/lib/generates/internal/FilePrinter.js.map +1 -1
  59. package/lib/generates/internal/ImportDictionary.d.ts +2 -2
  60. package/lib/generates/internal/ImportDictionary.js +7 -5
  61. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  62. package/lib/generates/internal/SdkAliasCollection.d.ts +11 -11
  63. package/lib/generates/internal/SdkAliasCollection.js +27 -31
  64. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  65. package/lib/generates/internal/SdkDistributionComposer.js +15 -70
  66. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  67. package/lib/generates/internal/SdkFileProgrammer.js +2 -2
  68. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  69. package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +2 -2
  70. package/lib/generates/internal/SdkHttpCloneProgrammer.js +6 -12
  71. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  72. package/lib/generates/internal/SdkHttpCloneReferencer.js +2 -1
  73. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  74. package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +2 -2
  75. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +73 -77
  76. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  77. package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +2 -2
  78. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +64 -66
  79. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  80. package/lib/generates/internal/SdkHttpParameterProgrammer.d.ts +4 -10
  81. package/lib/generates/internal/SdkHttpParameterProgrammer.js +15 -22
  82. package/lib/generates/internal/SdkHttpParameterProgrammer.js.map +1 -1
  83. package/lib/generates/internal/SdkHttpRouteProgrammer.d.ts +2 -2
  84. package/lib/generates/internal/SdkHttpRouteProgrammer.js +18 -20
  85. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  86. package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +3 -3
  87. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +47 -49
  88. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  89. package/lib/generates/internal/SdkImportWizard.js.map +1 -1
  90. package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
  91. package/lib/generates/internal/SdkTypeProgrammer.d.ts +4 -4
  92. package/lib/generates/internal/SdkTypeProgrammer.js +66 -67
  93. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  94. package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +1 -2
  95. package/lib/generates/internal/SdkTypeTagProgrammer.js +29 -11
  96. package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
  97. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +2 -2
  98. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +55 -55
  99. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  100. package/lib/generates/internal/SdkWebSocketParameterProgrammer.d.ts +3 -3
  101. package/lib/generates/internal/SdkWebSocketParameterProgrammer.js +9 -12
  102. package/lib/generates/internal/SdkWebSocketParameterProgrammer.js.map +1 -1
  103. package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +2 -2
  104. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +43 -45
  105. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  106. package/lib/generates/internal/SwaggerDescriptionComposer.js.map +1 -1
  107. package/lib/generates/internal/SwaggerOperationComposer.d.ts +1 -1
  108. package/lib/generates/internal/SwaggerOperationComposer.js +5 -4
  109. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
  110. package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +0 -3
  111. package/lib/generates/internal/SwaggerOperationParameterComposer.js +19 -20
  112. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  113. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +1 -1
  114. package/lib/generates/internal/SwaggerOperationResponseComposer.js +4 -3
  115. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
  116. package/lib/index.js.map +1 -1
  117. package/lib/internal/legacy.d.ts +180 -0
  118. package/lib/internal/legacy.js +361 -0
  119. package/lib/internal/legacy.js.map +1 -0
  120. package/lib/structures/INestiaProject.d.ts +0 -2
  121. package/lib/{transformers → structures}/IOperationMetadata.d.ts +2 -7
  122. package/lib/structures/IOperationMetadata.js.map +1 -0
  123. package/lib/structures/IReflectHttpOperationException.d.ts +1 -1
  124. package/lib/structures/IReflectHttpOperationParameter.d.ts +1 -1
  125. package/lib/structures/IReflectHttpOperationSuccess.d.ts +1 -1
  126. package/lib/structures/IReflectOperationError.d.ts +1 -1
  127. package/lib/structures/IReflectOperationError.js.map +1 -1
  128. package/lib/structures/IReflectWebSocketOperation.d.ts +2 -2
  129. package/lib/structures/ITypedApplication.d.ts +1 -1
  130. package/lib/structures/ITypedHttpRouteException.d.ts +1 -1
  131. package/lib/structures/ITypedHttpRouteParameter.d.ts +1 -1
  132. package/lib/structures/ITypedHttpRouteSuccess.d.ts +1 -1
  133. package/lib/structures/ITypedWebSocketRoute.d.ts +2 -2
  134. package/lib/transform.d.ts +16 -3
  135. package/lib/transform.js +47 -5
  136. package/lib/transform.js.map +1 -1
  137. package/lib/utils/ArrayUtil.js.map +1 -1
  138. package/lib/utils/FileRetriever.js.map +1 -1
  139. package/lib/utils/MapUtil.js.map +1 -1
  140. package/lib/utils/PathUtil.js.map +1 -1
  141. package/lib/utils/SourceFinder.js.map +1 -1
  142. package/lib/utils/StringUtil.js.map +1 -1
  143. package/lib/utils/TsConfigReader.d.ts +7 -0
  144. package/lib/utils/TsConfigReader.js +102 -0
  145. package/lib/utils/TsConfigReader.js.map +1 -0
  146. package/lib/utils/TtscExecutor.d.ts +8 -0
  147. package/lib/utils/TtscExecutor.js +58 -0
  148. package/lib/utils/TtscExecutor.js.map +1 -0
  149. package/lib/utils/VersioningStrategy.js.map +1 -1
  150. package/lib/validators/HttpHeadersValidator.d.ts +8 -5
  151. package/lib/validators/HttpHeadersValidator.js +7 -26
  152. package/lib/validators/HttpHeadersValidator.js.map +1 -1
  153. package/lib/validators/HttpQueryValidator.d.ts +8 -5
  154. package/lib/validators/HttpQueryValidator.js +7 -26
  155. package/lib/validators/HttpQueryValidator.js.map +1 -1
  156. package/lib/{transformers → validators}/TextPlainValidator.d.ts +1 -1
  157. package/lib/{transformers → validators}/TextPlainValidator.js +2 -1
  158. package/lib/validators/TextPlainValidator.js.map +1 -0
  159. package/native/go.mod +52 -0
  160. package/native/go.sum +54 -0
  161. package/native/sdk/register.go +130 -0
  162. package/native/sdk/sdk.go +17 -0
  163. package/native/sdk/sdk_metadata_json.go +327 -0
  164. package/native/sdk/sdk_transform.go +1542 -0
  165. package/package.json +19 -19
  166. package/src/NestiaSdkApplication.ts +9 -5
  167. package/src/NestiaSwaggerComposer.ts +2 -3
  168. package/src/analyses/ConfigAnalyzer.ts +175 -1
  169. package/src/analyses/ImportAnalyzer.ts +15 -49
  170. package/src/analyses/ReflectControllerAnalyzer.ts +1 -1
  171. package/src/analyses/ReflectHttpOperationAnalyzer.ts +1 -1
  172. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +24 -6
  173. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +3 -3
  174. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +14 -10
  175. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +2 -2
  176. package/src/analyses/TypedHttpRouteAnalyzer.ts +354 -22
  177. package/src/decorators/OperationMetadata.ts +17 -3
  178. package/src/executable/internal/NestiaConfigLoader.ts +419 -53
  179. package/src/executable/internal/NestiaSdkCommand.ts +9 -10
  180. package/src/executable/sdk.ts +15 -4
  181. package/src/generates/CloneGenerator.ts +10 -10
  182. package/src/generates/SwaggerGenerator.ts +28 -9
  183. package/src/generates/internal/E2eFileProgrammer.ts +80 -43
  184. package/src/generates/internal/FilePrinter.ts +38 -37
  185. package/src/generates/internal/ImportDictionary.ts +18 -16
  186. package/src/generates/internal/SdkAliasCollection.ts +41 -40
  187. package/src/generates/internal/SdkDistributionComposer.ts +21 -8
  188. package/src/generates/internal/SdkFileProgrammer.ts +7 -5
  189. package/src/generates/internal/SdkHttpCloneProgrammer.ts +10 -10
  190. package/src/generates/internal/SdkHttpCloneReferencer.ts +6 -6
  191. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +101 -78
  192. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +153 -145
  193. package/src/generates/internal/SdkHttpParameterProgrammer.ts +20 -33
  194. package/src/generates/internal/SdkHttpRouteProgrammer.ts +2 -2
  195. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +88 -86
  196. package/src/generates/internal/SdkTypeProgrammer.ts +93 -99
  197. package/src/generates/internal/SdkTypeTagProgrammer.ts +12 -12
  198. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +128 -118
  199. package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +15 -13
  200. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +133 -112
  201. package/src/generates/internal/SwaggerOperationComposer.ts +1 -1
  202. package/src/generates/internal/SwaggerOperationParameterComposer.ts +10 -9
  203. package/src/generates/internal/SwaggerOperationResponseComposer.ts +1 -1
  204. package/src/internal/legacy.ts +492 -0
  205. package/src/structures/INestiaProject.ts +0 -3
  206. package/src/{transformers → structures}/IOperationMetadata.ts +2 -7
  207. package/src/structures/IReflectHttpOperationException.ts +1 -1
  208. package/src/structures/IReflectHttpOperationParameter.ts +1 -1
  209. package/src/structures/IReflectHttpOperationSuccess.ts +1 -1
  210. package/src/structures/IReflectOperationError.ts +1 -1
  211. package/src/structures/IReflectWebSocketOperation.ts +2 -2
  212. package/src/structures/ITypedApplication.ts +1 -1
  213. package/src/structures/ITypedHttpRouteException.ts +1 -1
  214. package/src/structures/ITypedHttpRouteParameter.ts +1 -1
  215. package/src/structures/ITypedHttpRouteSuccess.ts +1 -1
  216. package/src/structures/ITypedWebSocketRoute.ts +2 -2
  217. package/src/transform.ts +57 -7
  218. package/src/utils/TsConfigReader.ts +108 -0
  219. package/src/utils/TtscExecutor.ts +63 -0
  220. package/src/validators/HttpHeadersValidator.ts +8 -37
  221. package/src/validators/HttpQueryValidator.ts +8 -37
  222. package/src/{transformers → validators}/TextPlainValidator.ts +2 -2
  223. package/lib/analyses/DtoAnalyzer.d.ts +0 -21
  224. package/lib/analyses/DtoAnalyzer.js +0 -219
  225. package/lib/analyses/DtoAnalyzer.js.map +0 -1
  226. package/lib/analyses/ExceptionAnalyzer.d.ts +0 -0
  227. package/lib/analyses/ExceptionAnalyzer.js +0 -2
  228. package/lib/analyses/ExceptionAnalyzer.js.map +0 -1
  229. package/lib/analyses/GenericAnalyzer.d.ts +0 -4
  230. package/lib/analyses/GenericAnalyzer.js +0 -42
  231. package/lib/analyses/GenericAnalyzer.js.map +0 -1
  232. package/lib/structures/IReflectApplication.d.ts +0 -6
  233. package/lib/structures/IReflectApplication.js +0 -3
  234. package/lib/structures/IReflectApplication.js.map +0 -1
  235. package/lib/structures/MethodType.d.ts +0 -4
  236. package/lib/structures/MethodType.js +0 -8
  237. package/lib/structures/MethodType.js.map +0 -1
  238. package/lib/structures/ParamCategory.d.ts +0 -1
  239. package/lib/structures/ParamCategory.js +0 -3
  240. package/lib/structures/ParamCategory.js.map +0 -1
  241. package/lib/structures/TypeEntry.d.ts +0 -9
  242. package/lib/structures/TypeEntry.js +0 -21
  243. package/lib/structures/TypeEntry.js.map +0 -1
  244. package/lib/transformers/IOperationMetadata.js.map +0 -1
  245. package/lib/transformers/ISdkOperationTransformerContext.d.ts +0 -7
  246. package/lib/transformers/ISdkOperationTransformerContext.js +0 -3
  247. package/lib/transformers/ISdkOperationTransformerContext.js.map +0 -1
  248. package/lib/transformers/SdkOperationProgrammer.d.ts +0 -15
  249. package/lib/transformers/SdkOperationProgrammer.js +0 -186
  250. package/lib/transformers/SdkOperationProgrammer.js.map +0 -1
  251. package/lib/transformers/SdkOperationTransformer.d.ts +0 -4
  252. package/lib/transformers/SdkOperationTransformer.js +0 -128
  253. package/lib/transformers/SdkOperationTransformer.js.map +0 -1
  254. package/lib/transformers/TextPlainValidator.js.map +0 -1
  255. package/lib/utils/MetadataUtil.d.ts +0 -4
  256. package/lib/utils/MetadataUtil.js +0 -34
  257. package/lib/utils/MetadataUtil.js.map +0 -1
  258. package/lib/utils/StripEnums.d.ts +0 -3
  259. package/lib/utils/StripEnums.js +0 -3
  260. package/lib/utils/StripEnums.js.map +0 -1
  261. package/lib/utils/TypeLiteralExpression.d.ts +0 -0
  262. package/lib/utils/TypeLiteralExpression.js +0 -2
  263. package/lib/utils/TypeLiteralExpression.js.map +0 -1
  264. package/src/analyses/DtoAnalyzer.ts +0 -260
  265. package/src/analyses/ExceptionAnalyzer.ts +0 -154
  266. package/src/analyses/GenericAnalyzer.ts +0 -49
  267. package/src/structures/IReflectApplication.ts +0 -8
  268. package/src/structures/MethodType.ts +0 -5
  269. package/src/structures/ParamCategory.ts +0 -1
  270. package/src/structures/TypeEntry.ts +0 -22
  271. package/src/transformers/ISdkOperationTransformerContext.ts +0 -8
  272. package/src/transformers/SdkOperationProgrammer.ts +0 -240
  273. package/src/transformers/SdkOperationTransformer.ts +0 -248
  274. package/src/utils/MetadataUtil.ts +0 -26
  275. package/src/utils/StripEnums.ts +0 -5
  276. package/src/utils/TypeLiteralExpression.ts +0 -0
  277. /package/lib/{transformers → structures}/IOperationMetadata.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import { SwaggerCustomizer } from "@nestia/core";
2
- import { JsonSchemasProgrammer, MetadataSchema } from "@typia/core";
2
+ import { JsonSchemasProgrammer, MetadataSchema, sizeOf } from "../internal/legacy";
3
3
  import {
4
4
  OpenApi,
5
5
  OpenApiV3,
@@ -11,7 +11,7 @@ import { OpenApiConverter } from "@typia/utils";
11
11
  import fs from "fs";
12
12
  import path from "path";
13
13
  import { Singleton } from "tstl";
14
- import typia, { IJsonSchemaCollection } from "typia";
14
+ import type { IJsonSchemaCollection } from "typia";
15
15
 
16
16
  import { INestiaConfig } from "../INestiaConfig";
17
17
  import { ITypedApplication } from "../structures/ITypedApplication";
@@ -89,7 +89,7 @@ export namespace SwaggerGenerator {
89
89
  ...Object.values(r.exceptions).map((e) => e.metadata),
90
90
  ])
91
91
  .flat()
92
- .filter((m) => m.size() !== 0);
92
+ .filter((m) => sizeOf(m) !== 0);
93
93
 
94
94
  // COMPOSE JSON SCHEMAS
95
95
  const json: IJsonSchemaCollection = JsonSchemasProgrammer.writeSchemas({
@@ -127,7 +127,7 @@ export namespace SwaggerGenerator {
127
127
 
128
128
  try {
129
129
  const content: string = await fs.promises.readFile(location, "utf8");
130
- const data = typia.json.assertParse<{
130
+ const data = JSON.parse(content) as {
131
131
  name?: string;
132
132
  version?: string;
133
133
  description?: string;
@@ -138,12 +138,16 @@ export namespace SwaggerGenerator {
138
138
  /** @format uri */
139
139
  url: string;
140
140
  };
141
- }>(content);
141
+ };
142
142
  return {
143
- title: data.name,
144
- version: data.version,
145
- description: data.description,
146
- license: data.license
143
+ title: typeof data.name === "string" ? data.name : undefined,
144
+ version:
145
+ typeof data.version === "string" ? data.version : undefined,
146
+ description:
147
+ typeof data.description === "string"
148
+ ? data.description
149
+ : undefined,
150
+ license: isLicense(data.license)
147
151
  ? typeof data.license === "string"
148
152
  ? { name: data.license }
149
153
  : typeof data.license === "object"
@@ -191,6 +195,21 @@ export namespace SwaggerGenerator {
191
195
  };
192
196
  };
193
197
 
198
+ const isLicense = (
199
+ input: unknown,
200
+ ): input is
201
+ | string
202
+ | {
203
+ type: string;
204
+ url: string;
205
+ } =>
206
+ typeof input === "string" ||
207
+ (typeof input === "object" &&
208
+ input !== null &&
209
+ Array.isArray(input) === false &&
210
+ typeof (input as { type?: unknown }).type === "string" &&
211
+ typeof (input as { url?: unknown }).url === "string");
212
+
194
213
  const fillPaths = (props: {
195
214
  config: Omit<INestiaConfig.ISwaggerConfig, "output">;
196
215
  document: OpenApi.IDocument;
@@ -1,5 +1,5 @@
1
- import { IdentifierFactory, LiteralFactory } from "@typia/core";
2
- import ts from "typescript";
1
+ import { Node, NodeFlags, SyntaxKind, TypeScriptFactory } from "@nestia/factory";
2
+ import { IdentifierFactory, LiteralFactory } from "@nestia/factory";
3
3
 
4
4
  import { INestiaProject } from "../../structures/INestiaProject";
5
5
  import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
@@ -24,7 +24,7 @@ export namespace E2eFileProgrammer {
24
24
  type: "default",
25
25
  name: "api",
26
26
  });
27
- const functor: ts.Statement = generateFunctor(project)(importer)(route);
27
+ const functor: Node = generateFunctor(project)(importer)(route);
28
28
  await FilePrinter.write({
29
29
  location: importer.file,
30
30
  statements: [
@@ -38,19 +38,19 @@ export namespace E2eFileProgrammer {
38
38
  const generateFunctor =
39
39
  (project: INestiaProject) =>
40
40
  (importer: ImportDictionary) =>
41
- (route: ITypedHttpRoute): ts.Statement =>
42
- ts.factory.createVariableStatement(
43
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
44
- ts.factory.createVariableDeclarationList(
41
+ (route: ITypedHttpRoute): Node =>
42
+ TypeScriptFactory.createVariableStatement(
43
+ [TypeScriptFactory.createModifier(SyntaxKind.ExportKeyword)],
44
+ TypeScriptFactory.createVariableDeclarationList(
45
45
  [
46
- ts.factory.createVariableDeclaration(
47
- ts.factory.createIdentifier(getFunctionName(route)),
46
+ TypeScriptFactory.createVariableDeclaration(
47
+ TypeScriptFactory.createIdentifier(getFunctionName(route)),
48
48
  undefined,
49
49
  undefined,
50
50
  generateArrow(project)(importer)(route),
51
51
  ),
52
52
  ],
53
- ts.NodeFlags.Const,
53
+ NodeFlags.Const,
54
54
  ),
55
55
  );
56
56
 
@@ -59,27 +59,27 @@ export namespace E2eFileProgrammer {
59
59
  (importer: ImportDictionary) =>
60
60
  (route: ITypedHttpRoute) => {
61
61
  const random = IdentifierFactory.access(
62
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
62
+ TypeScriptFactory.createIdentifier(SdkImportWizard.typia(importer)),
63
63
  "random",
64
64
  );
65
65
  const connection = route.headerObject
66
- ? ts.factory.createObjectLiteralExpression(
66
+ ? TypeScriptFactory.createObjectLiteralExpression(
67
67
  [
68
- ts.factory.createSpreadAssignment(
69
- ts.factory.createIdentifier("connection"),
68
+ TypeScriptFactory.createSpreadAssignment(
69
+ TypeScriptFactory.createIdentifier("connection"),
70
70
  ),
71
- ts.factory.createPropertyAssignment(
71
+ TypeScriptFactory.createPropertyAssignment(
72
72
  "headers",
73
- ts.factory.createObjectLiteralExpression(
73
+ TypeScriptFactory.createObjectLiteralExpression(
74
74
  [
75
- ts.factory.createSpreadAssignment(
75
+ TypeScriptFactory.createSpreadAssignment(
76
76
  IdentifierFactory.access(
77
- ts.factory.createIdentifier("connection"),
77
+ TypeScriptFactory.createIdentifier("connection"),
78
78
  "headers",
79
79
  ),
80
80
  ),
81
- ts.factory.createSpreadAssignment(
82
- ts.factory.createCallExpression(
81
+ TypeScriptFactory.createSpreadAssignment(
82
+ TypeScriptFactory.createCallExpression(
83
83
  random,
84
84
  [
85
85
  project.config.clone === true
@@ -98,7 +98,7 @@ export namespace E2eFileProgrammer {
98
98
  ],
99
99
  true,
100
100
  )
101
- : ts.factory.createIdentifier("connection");
101
+ : TypeScriptFactory.createIdentifier("connection");
102
102
  const entries = SdkHttpParameterProgrammer.getEntries({
103
103
  project,
104
104
  importer,
@@ -107,8 +107,8 @@ export namespace E2eFileProgrammer {
107
107
  e2e: true,
108
108
  prefix: ["api", "functional", ...route.accessor].join(".") + ".",
109
109
  });
110
- const fetch = ts.factory.createCallExpression(
111
- ts.factory.createIdentifier(
110
+ const fetch = TypeScriptFactory.createCallExpression(
111
+ TypeScriptFactory.createIdentifier(
112
112
  ["api", "functional", ...route.accessor].join("."),
113
113
  ),
114
114
  undefined,
@@ -120,14 +120,14 @@ export namespace E2eFileProgrammer {
120
120
  Object.fromEntries(
121
121
  entries.map((e) => [
122
122
  e.key,
123
- ts.factory.createCallExpression(
123
+ TypeScriptFactory.createCallExpression(
124
124
  IdentifierFactory.access(
125
- ts.factory.createIdentifier(
125
+ TypeScriptFactory.createIdentifier(
126
126
  SdkImportWizard.typia(importer),
127
127
  ),
128
128
  "random",
129
129
  ),
130
- [e.type],
130
+ [getRandomType(importer)(e)],
131
131
  undefined,
132
132
  ),
133
133
  ]),
@@ -135,62 +135,99 @@ export namespace E2eFileProgrammer {
135
135
  ),
136
136
  ]
137
137
  : entries.map((e) =>
138
- ts.factory.createCallExpression(
138
+ TypeScriptFactory.createCallExpression(
139
139
  IdentifierFactory.access(
140
- ts.factory.createIdentifier(
140
+ TypeScriptFactory.createIdentifier(
141
141
  SdkImportWizard.typia(importer),
142
142
  ),
143
143
  "random",
144
144
  ),
145
- [e.type],
145
+ [getRandomType(importer)(e)],
146
146
  undefined,
147
147
  ),
148
148
  )),
149
149
  ],
150
150
  );
151
- const assert = ts.factory.createCallExpression(
151
+ const assert = TypeScriptFactory.createCallExpression(
152
152
  IdentifierFactory.access(
153
- ts.factory.createIdentifier(SdkImportWizard.typia(importer)),
153
+ TypeScriptFactory.createIdentifier(SdkImportWizard.typia(importer)),
154
154
  "assert",
155
155
  ),
156
156
  undefined,
157
- [ts.factory.createIdentifier("output")],
157
+ [TypeScriptFactory.createIdentifier("output")],
158
158
  );
159
159
 
160
- return ts.factory.createArrowFunction(
161
- [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)],
160
+ return TypeScriptFactory.createArrowFunction(
161
+ [TypeScriptFactory.createModifier(SyntaxKind.AsyncKeyword)],
162
162
  undefined,
163
163
  [
164
164
  IdentifierFactory.parameter(
165
165
  "connection",
166
- ts.factory.createTypeReferenceNode("api.IConnection"),
166
+ TypeScriptFactory.createTypeReferenceNode("api.IConnection"),
167
167
  ),
168
168
  ],
169
169
  undefined,
170
170
  undefined,
171
- ts.factory.createBlock([
172
- ts.factory.createVariableStatement(
171
+ TypeScriptFactory.createBlock([
172
+ TypeScriptFactory.createVariableStatement(
173
173
  [],
174
- ts.factory.createVariableDeclarationList(
174
+ TypeScriptFactory.createVariableDeclarationList(
175
175
  [
176
- ts.factory.createVariableDeclaration(
176
+ TypeScriptFactory.createVariableDeclaration(
177
177
  "output",
178
178
  undefined,
179
179
  project.config.propagate !== true &&
180
- route.success.type.name === "void"
180
+ route.success.type!.name === "void"
181
181
  ? undefined
182
182
  : SdkAliasCollection.response(project)(importer)(route),
183
- ts.factory.createAwaitExpression(fetch),
183
+ TypeScriptFactory.createAwaitExpression(fetch),
184
184
  ),
185
185
  ],
186
- ts.NodeFlags.Const,
186
+ NodeFlags.Const,
187
187
  ),
188
188
  ),
189
- ts.factory.createExpressionStatement(assert),
189
+ TypeScriptFactory.createExpressionStatement(assert),
190
190
  ]),
191
191
  );
192
192
  };
193
193
  }
194
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
+
195
232
  const getFunctionName = (route: ITypedHttpRoute): string =>
196
233
  ["test", "api", ...route.accessor].join("_");
@@ -1,55 +1,56 @@
1
+ import {
2
+ Node,
3
+ SyntaxKind,
4
+ TypeScriptFactory,
5
+ TypeScriptPrinter,
6
+ } from "@nestia/factory";
1
7
  import fs from "fs";
2
8
  import { format } from "prettier";
3
- import ts from "typescript";
4
9
 
5
10
  export namespace FilePrinter {
6
- export const description = <Node extends ts.Node>(
7
- node: Node,
11
+ export const description = <T extends Node>(
12
+ node: T,
8
13
  comment: string,
9
- ): Node => {
14
+ ): T => {
10
15
  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
- );
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
+ ];
28
36
  return node;
29
37
  };
30
38
 
31
39
  export const enter = () =>
32
- ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
40
+ TypeScriptFactory.createExpressionStatement(
41
+ TypeScriptFactory.createIdentifier("\n"),
42
+ );
33
43
 
34
44
  export const write = async (props: {
35
45
  location: string;
36
- statements: ts.Statement[];
46
+ statements: Node[];
37
47
  top?: string;
38
48
  }): 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
- );
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");
53
54
  };
54
55
 
55
56
  const beautify = async (script: string): Promise<string> => {
@@ -1,6 +1,6 @@
1
+ import { Node, TypeScriptFactory } from "@nestia/factory";
1
2
  import path from "path";
2
3
  import { HashMap, TreeSet, hash } from "tstl";
3
- import ts from "typescript";
4
4
 
5
5
  import { ImportAnalyzer } from "../../analyses/ImportAnalyzer";
6
6
  import { IReflectImport } from "../../structures/IReflectImport";
@@ -84,11 +84,11 @@ export class ImportDictionary {
84
84
  return props.name;
85
85
  }
86
86
 
87
- public toStatements(outDir: string): ts.Statement[] {
87
+ public toStatements(outDir: string): Node[] {
88
88
  outDir = path.resolve(outDir);
89
89
 
90
- const external: ts.ImportDeclaration[] = [];
91
- const internal: ts.ImportDeclaration[] = [];
90
+ const external: Node[] = [];
91
+ const internal: Node[] = [];
92
92
  const locator = (str: string) => {
93
93
  const location: string = path
94
94
  .relative(outDir, str)
@@ -103,7 +103,7 @@ export class ImportDictionary {
103
103
  };
104
104
  const enroll =
105
105
  (filter: (str: string) => boolean) =>
106
- (container: ts.ImportDeclaration[]) => {
106
+ (container: Node[]) => {
107
107
  const compositions: ICompositeValue[] = this.components_
108
108
  .toJSON()
109
109
  .filter((c) => filter(c.second.file))
@@ -117,10 +117,10 @@ export class ImportDictionary {
117
117
  .sort((a, b) => a.file.localeCompare(b.file));
118
118
  for (const c of compositions)
119
119
  container.push(
120
- ts.factory.createImportDeclaration(
120
+ TypeScriptFactory.createImportDeclaration(
121
121
  undefined,
122
122
  this.toImportClaude(c),
123
- ts.factory.createStringLiteral(c.file),
123
+ TypeScriptFactory.createStringLiteral(c.file),
124
124
  undefined,
125
125
  ),
126
126
  );
@@ -135,25 +135,27 @@ export class ImportDictionary {
135
135
  ];
136
136
  }
137
137
 
138
- private toImportClaude(c: ICompositeValue): ts.ImportClause {
138
+ private toImportClaude(c: ICompositeValue): Node {
139
139
  if (c.asterisk !== null)
140
- return ts.factory.createImportClause(
140
+ return TypeScriptFactory.createImportClause(
141
141
  c.declaration,
142
142
  undefined,
143
- ts.factory.createNamespaceImport(
144
- ts.factory.createIdentifier(c.asterisk),
143
+ TypeScriptFactory.createNamespaceImport(
144
+ TypeScriptFactory.createIdentifier(c.asterisk),
145
145
  ),
146
146
  );
147
- return ts.factory.createImportClause(
147
+ return TypeScriptFactory.createImportClause(
148
148
  c.declaration,
149
- c.default !== null ? ts.factory.createIdentifier(c.default) : undefined,
149
+ c.default !== null
150
+ ? TypeScriptFactory.createIdentifier(c.default)
151
+ : undefined,
150
152
  c.elements.size() !== 0
151
- ? ts.factory.createNamedImports(
153
+ ? TypeScriptFactory.createNamedImports(
152
154
  Array.from(c.elements).map((elem) =>
153
- ts.factory.createImportSpecifier(
155
+ TypeScriptFactory.createImportSpecifier(
154
156
  false,
155
157
  undefined,
156
- ts.factory.createIdentifier(elem),
158
+ TypeScriptFactory.createIdentifier(elem),
157
159
  ),
158
160
  ),
159
161
  )