@nestia/sdk 3.10.0 → 3.11.0-dev.20240813

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 (279) hide show
  1. package/lib/NestiaSdkApplication.d.ts +1 -3
  2. package/lib/NestiaSdkApplication.js +138 -136
  3. package/lib/NestiaSdkApplication.js.map +1 -1
  4. package/lib/analyses/ConfigAnalyzer.d.ts +2 -2
  5. package/lib/analyses/ConfigAnalyzer.js +39 -80
  6. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  7. package/lib/analyses/ExceptionAnalyzer.d.ts +0 -16
  8. package/lib/analyses/ExceptionAnalyzer.js +142 -105
  9. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  10. package/lib/analyses/GenericAnalyzer.d.ts +1 -2
  11. package/lib/analyses/GenericAnalyzer.js.map +1 -1
  12. package/lib/analyses/ImportAnalyzer.d.ts +6 -11
  13. package/lib/analyses/ImportAnalyzer.js +70 -42
  14. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  15. package/lib/analyses/ReflectControllerAnalyzer.d.ts +7 -1
  16. package/lib/analyses/ReflectControllerAnalyzer.js +28 -99
  17. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  18. package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +6 -2
  19. package/lib/analyses/ReflectHttpOperationAnalyzer.js +72 -152
  20. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  21. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.d.ts +15 -0
  22. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +215 -0
  23. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -0
  24. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +15 -0
  25. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +81 -0
  26. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -0
  27. package/lib/analyses/ReflectMetadataAnalyzer.d.ts +1 -3
  28. package/lib/analyses/ReflectMetadataAnalyzer.js +0 -4
  29. package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -1
  30. package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +6 -2
  31. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +72 -48
  32. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
  33. package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +15 -0
  34. package/lib/analyses/TypedHttpRouteAnalyzer.js +111 -0
  35. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -0
  36. package/lib/analyses/TypedWebSocketRouteAnalyzer.d.ts +10 -0
  37. package/lib/analyses/TypedWebSocketRouteAnalyzer.js +9 -0
  38. package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -0
  39. package/lib/decorators/OperationMetadata.d.ts +2 -0
  40. package/lib/decorators/OperationMetadata.js +10 -0
  41. package/lib/decorators/OperationMetadata.js.map +1 -0
  42. package/lib/executable/internal/NestiaConfigLoader.d.ts +1 -1
  43. package/lib/executable/internal/NestiaConfigLoader.js +34 -3
  44. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  45. package/lib/executable/internal/NestiaSdkCommand.js +1 -1
  46. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  47. package/lib/generates/CloneGenerator.d.ts +0 -5
  48. package/lib/generates/CloneGenerator.js +60 -60
  49. package/lib/generates/CloneGenerator.js.map +1 -1
  50. package/lib/generates/E2eGenerator.d.ts +2 -3
  51. package/lib/generates/E2eGenerator.js +9 -8
  52. package/lib/generates/E2eGenerator.js.map +1 -1
  53. package/lib/generates/OpenAiGenerator.d.ts +2 -4
  54. package/lib/generates/OpenAiGenerator.js +13 -3
  55. package/lib/generates/OpenAiGenerator.js.map +1 -1
  56. package/lib/generates/SdkGenerator.d.ts +4 -4
  57. package/lib/generates/SdkGenerator.js +63 -73
  58. package/lib/generates/SdkGenerator.js.map +1 -1
  59. package/lib/generates/SwaggerGenerator.d.ts +6 -18
  60. package/lib/generates/SwaggerGenerator.js +60 -235
  61. package/lib/generates/SwaggerGenerator.js.map +1 -1
  62. package/lib/generates/internal/E2eFileProgrammer.js +5 -9
  63. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  64. package/lib/generates/internal/SdkAliasCollection.d.ts +6 -4
  65. package/lib/generates/internal/SdkAliasCollection.js +33 -31
  66. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  67. package/lib/generates/internal/SdkDistributionComposer.d.ts +4 -1
  68. package/lib/generates/internal/SdkDistributionComposer.js +6 -6
  69. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  70. package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -4
  71. package/lib/generates/internal/SdkFileProgrammer.js +6 -6
  72. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  73. package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +0 -12
  74. package/lib/generates/internal/SdkHttpCloneProgrammer.js +142 -97
  75. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  76. package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +4 -3
  77. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +37 -59
  78. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  79. package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +4 -3
  80. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +31 -48
  81. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  82. package/lib/generates/internal/SdkHttpRouteProgrammer.js +7 -3
  83. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  84. package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +4 -3
  85. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +7 -13
  86. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  87. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +1 -2
  88. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +11 -16
  89. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  90. package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +1 -2
  91. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +7 -10
  92. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  93. package/lib/generates/internal/SwaggerDescriptionComposer.d.ts +23 -0
  94. package/lib/generates/internal/SwaggerDescriptionComposer.js +44 -0
  95. package/lib/generates/internal/SwaggerDescriptionComposer.js.map +1 -0
  96. package/lib/generates/internal/SwaggerOperationComposer.d.ts +12 -0
  97. package/lib/generates/internal/SwaggerOperationComposer.js +68 -0
  98. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -0
  99. package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +18 -0
  100. package/lib/generates/internal/SwaggerOperationParameterComposer.js +99 -0
  101. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -0
  102. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +9 -0
  103. package/lib/generates/internal/SwaggerOperationResponseComposer.js +91 -0
  104. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -0
  105. package/lib/structures/INestiaProject.d.ts +5 -5
  106. package/lib/structures/INestiaSdkInput.d.ts +20 -0
  107. package/lib/structures/{ISwaggerError.js → INestiaSdkInput.js} +1 -1
  108. package/lib/structures/INestiaSdkInput.js.map +1 -0
  109. package/lib/structures/IReflectApplication.d.ts +6 -0
  110. package/lib/structures/IReflectApplication.js +3 -0
  111. package/lib/structures/IReflectApplication.js.map +1 -0
  112. package/lib/structures/IReflectController.d.ts +3 -5
  113. package/lib/structures/IReflectHttpOperation.d.ts +13 -65
  114. package/lib/structures/IReflectHttpOperationException.d.ts +14 -0
  115. package/lib/structures/IReflectHttpOperationException.js +3 -0
  116. package/lib/structures/IReflectHttpOperationException.js.map +1 -0
  117. package/lib/structures/IReflectHttpOperationParameter.d.ts +35 -0
  118. package/lib/structures/IReflectHttpOperationParameter.js +3 -0
  119. package/lib/structures/IReflectHttpOperationParameter.js.map +1 -0
  120. package/lib/structures/IReflectHttpOperationSuccess.d.ts +15 -0
  121. package/lib/structures/IReflectHttpOperationSuccess.js +3 -0
  122. package/lib/structures/IReflectHttpOperationSuccess.js.map +1 -0
  123. package/lib/structures/IReflectOperationError.d.ts +16 -0
  124. package/lib/structures/IReflectOperationError.js +23 -0
  125. package/lib/structures/IReflectOperationError.js.map +1 -0
  126. package/lib/structures/IReflectType.d.ts +4 -0
  127. package/lib/structures/{IErrorReport.js → IReflectType.js} +1 -1
  128. package/lib/structures/IReflectType.js.map +1 -0
  129. package/lib/structures/IReflectTypeImport.d.ts +4 -0
  130. package/lib/structures/{ISwaggerLazySchema.js → IReflectTypeImport.js} +1 -1
  131. package/lib/structures/IReflectTypeImport.js.map +1 -0
  132. package/lib/structures/IReflectWebSocketOperation.d.ts +8 -9
  133. package/lib/structures/IReflectWebSocketOperationParameter.d.ts +23 -0
  134. package/lib/structures/IReflectWebSocketOperationParameter.js +3 -0
  135. package/lib/structures/IReflectWebSocketOperationParameter.js.map +1 -0
  136. package/lib/structures/ITypedApplication.d.ts +7 -0
  137. package/lib/structures/{INormalizedInput.js → ITypedApplication.js} +1 -1
  138. package/lib/structures/ITypedApplication.js.map +1 -0
  139. package/lib/structures/ITypedHttpRoute.d.ts +14 -42
  140. package/lib/structures/ITypedHttpRouteException.d.ts +10 -0
  141. package/lib/structures/ITypedHttpRouteException.js +3 -0
  142. package/lib/structures/ITypedHttpRouteException.js.map +1 -0
  143. package/lib/structures/ITypedHttpRouteParameter.d.ts +31 -0
  144. package/lib/structures/ITypedHttpRouteParameter.js +3 -0
  145. package/lib/structures/ITypedHttpRouteParameter.js.map +1 -0
  146. package/lib/structures/ITypedHttpRouteSuccess.d.ts +19 -0
  147. package/lib/structures/{ISwaggerLazyProperty.js → ITypedHttpRouteSuccess.js} +1 -1
  148. package/lib/structures/ITypedHttpRouteSuccess.js.map +1 -0
  149. package/lib/structures/ITypedWebSocketRoute.d.ts +8 -44
  150. package/lib/structures/ITypedWebSocketRouteParameter.d.ts +2 -0
  151. package/lib/structures/ITypedWebSocketRouteParameter.js +3 -0
  152. package/lib/structures/ITypedWebSocketRouteParameter.js.map +1 -0
  153. package/lib/transform.d.ts +3 -0
  154. package/lib/transform.js +8 -0
  155. package/lib/transform.js.map +1 -0
  156. package/lib/transformers/IOperationMetadata.d.ts +36 -0
  157. package/lib/transformers/IOperationMetadata.js +3 -0
  158. package/lib/transformers/IOperationMetadata.js.map +1 -0
  159. package/lib/transformers/ISdkTransformerContext.d.ts +7 -0
  160. package/lib/transformers/ISdkTransformerContext.js +3 -0
  161. package/lib/transformers/ISdkTransformerContext.js.map +1 -0
  162. package/lib/transformers/SdkMetadataProgrammer.d.ts +11 -0
  163. package/lib/transformers/SdkMetadataProgrammer.js +159 -0
  164. package/lib/transformers/SdkMetadataProgrammer.js.map +1 -0
  165. package/lib/transformers/SdkTransformer.d.ts +4 -0
  166. package/lib/transformers/SdkTransformer.js +88 -0
  167. package/lib/transformers/SdkTransformer.js.map +1 -0
  168. package/lib/transformers/TextPlainValidator.d.ts +4 -0
  169. package/lib/transformers/TextPlainValidator.js +19 -0
  170. package/lib/transformers/TextPlainValidator.js.map +1 -0
  171. package/lib/utils/StringUtil.d.ts +1 -0
  172. package/lib/utils/StringUtil.js +1 -0
  173. package/lib/utils/StringUtil.js.map +1 -1
  174. package/package.json +8 -8
  175. package/src/NestiaSdkApplication.ts +173 -160
  176. package/src/analyses/ConfigAnalyzer.ts +50 -98
  177. package/src/analyses/ExceptionAnalyzer.ts +142 -142
  178. package/src/analyses/GenericAnalyzer.ts +3 -5
  179. package/src/analyses/ImportAnalyzer.ts +130 -115
  180. package/src/analyses/ReflectControllerAnalyzer.ts +63 -115
  181. package/src/analyses/ReflectHttpOperationAnalyzer.ts +142 -278
  182. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +319 -0
  183. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +117 -0
  184. package/src/analyses/ReflectMetadataAnalyzer.ts +1 -18
  185. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +143 -78
  186. package/src/analyses/TypedHttpRouteAnalyzer.ts +178 -0
  187. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +18 -0
  188. package/src/decorators/OperationMetadata.ts +15 -0
  189. package/src/executable/internal/NestiaConfigLoader.ts +18 -3
  190. package/src/executable/internal/NestiaSdkCommand.ts +1 -4
  191. package/src/generates/CloneGenerator.ts +60 -59
  192. package/src/generates/E2eGenerator.ts +20 -21
  193. package/src/generates/OpenAiGenerator.ts +44 -45
  194. package/src/generates/SdkGenerator.ts +97 -125
  195. package/src/generates/SwaggerGenerator.ts +114 -416
  196. package/src/generates/internal/E2eFileProgrammer.ts +5 -14
  197. package/src/generates/internal/SdkAliasCollection.ts +33 -41
  198. package/src/generates/internal/SdkDistributionComposer.ts +9 -6
  199. package/src/generates/internal/SdkFileProgrammer.ts +11 -14
  200. package/src/generates/internal/SdkHttpCloneProgrammer.ts +142 -142
  201. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +20 -47
  202. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +245 -275
  203. package/src/generates/internal/SdkHttpRouteProgrammer.ts +7 -7
  204. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +11 -23
  205. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +197 -233
  206. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +5 -15
  207. package/src/generates/internal/{SwaggerDescriptionGenerator.ts → SwaggerDescriptionComposer.ts} +25 -5
  208. package/src/generates/internal/SwaggerOperationComposer.ts +90 -0
  209. package/src/generates/internal/SwaggerOperationParameterComposer.ts +173 -0
  210. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -0
  211. package/src/structures/INestiaProject.ts +5 -5
  212. package/src/structures/INestiaSdkInput.ts +25 -0
  213. package/src/structures/IReflectApplication.ts +8 -0
  214. package/src/structures/IReflectController.ts +3 -5
  215. package/src/structures/IReflectHttpOperation.ts +14 -76
  216. package/src/structures/IReflectHttpOperationException.ts +19 -0
  217. package/src/structures/IReflectHttpOperationParameter.ts +81 -0
  218. package/src/structures/IReflectHttpOperationSuccess.ts +22 -0
  219. package/src/structures/IReflectOperationError.ts +26 -0
  220. package/src/structures/IReflectType.ts +4 -0
  221. package/src/structures/IReflectTypeImport.ts +4 -0
  222. package/src/structures/IReflectWebSocketOperation.ts +9 -9
  223. package/src/structures/IReflectWebSocketOperationParameter.ts +38 -0
  224. package/src/structures/ITypedApplication.ts +8 -0
  225. package/src/structures/ITypedHttpRoute.ts +15 -45
  226. package/src/structures/ITypedHttpRouteException.ts +15 -0
  227. package/src/structures/ITypedHttpRouteParameter.ts +41 -0
  228. package/src/structures/ITypedHttpRouteSuccess.ts +22 -0
  229. package/src/structures/ITypedWebSocketRoute.ts +8 -56
  230. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -0
  231. package/src/transform.ts +9 -0
  232. package/src/transformers/IOperationMetadata.ts +38 -0
  233. package/src/transformers/ISdkTransformerContext.ts +8 -0
  234. package/src/transformers/SdkMetadataProgrammer.ts +227 -0
  235. package/src/transformers/SdkTransformer.ts +168 -0
  236. package/src/transformers/TextPlainValidator.ts +17 -0
  237. package/src/utils/StringUtil.ts +3 -0
  238. package/lib/analyses/TypedControllerAnalyzer.d.ts +0 -8
  239. package/lib/analyses/TypedControllerAnalyzer.js +0 -77
  240. package/lib/analyses/TypedControllerAnalyzer.js.map +0 -1
  241. package/lib/analyses/TypedHttpOperationAnalyzer.d.ts +0 -15
  242. package/lib/analyses/TypedHttpOperationAnalyzer.js +0 -263
  243. package/lib/analyses/TypedHttpOperationAnalyzer.js.map +0 -1
  244. package/lib/analyses/TypedWebSocketOperationAnalyzer.d.ts +0 -15
  245. package/lib/analyses/TypedWebSocketOperationAnalyzer.js +0 -226
  246. package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +0 -1
  247. package/lib/generates/internal/SwaggerDescriptionGenerator.d.ts +0 -14
  248. package/lib/generates/internal/SwaggerDescriptionGenerator.js +0 -33
  249. package/lib/generates/internal/SwaggerDescriptionGenerator.js.map +0 -1
  250. package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +0 -21
  251. package/lib/generates/internal/SwaggerSchemaGenerator.js +0 -289
  252. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +0 -1
  253. package/lib/generates/internal/SwaggerSchemaValidator.d.ts +0 -7
  254. package/lib/generates/internal/SwaggerSchemaValidator.js +0 -191
  255. package/lib/generates/internal/SwaggerSchemaValidator.js.map +0 -1
  256. package/lib/structures/IErrorReport.d.ts +0 -6
  257. package/lib/structures/IErrorReport.js.map +0 -1
  258. package/lib/structures/INormalizedInput.d.ts +0 -19
  259. package/lib/structures/INormalizedInput.js.map +0 -1
  260. package/lib/structures/ISwaggerError.d.ts +0 -6
  261. package/lib/structures/ISwaggerError.js.map +0 -1
  262. package/lib/structures/ISwaggerLazyProperty.d.ts +0 -6
  263. package/lib/structures/ISwaggerLazyProperty.js.map +0 -1
  264. package/lib/structures/ISwaggerLazySchema.d.ts +0 -6
  265. package/lib/structures/ISwaggerLazySchema.js.map +0 -1
  266. package/lib/structures/ITypeTuple.d.ts +0 -5
  267. package/lib/structures/ITypeTuple.js +0 -3
  268. package/lib/structures/ITypeTuple.js.map +0 -1
  269. package/src/analyses/TypedControllerAnalyzer.ts +0 -92
  270. package/src/analyses/TypedHttpOperationAnalyzer.ts +0 -365
  271. package/src/analyses/TypedWebSocketOperationAnalyzer.ts +0 -375
  272. package/src/generates/internal/SwaggerSchemaGenerator.ts +0 -473
  273. package/src/generates/internal/SwaggerSchemaValidator.ts +0 -206
  274. package/src/structures/IErrorReport.ts +0 -6
  275. package/src/structures/INormalizedInput.ts +0 -20
  276. package/src/structures/ISwaggerError.ts +0 -8
  277. package/src/structures/ISwaggerLazyProperty.ts +0 -7
  278. package/src/structures/ISwaggerLazySchema.ts +0 -7
  279. package/src/structures/ITypeTuple.ts +0 -6
@@ -1,154 +1,154 @@
1
- import path from "path";
2
- import ts from "typescript";
3
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
1
+ // import path from "path";
2
+ // import ts from "typescript";
3
+ // import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
+ // import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
+ // import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
6
 
7
- import { INestiaProject } from "../structures/INestiaProject";
8
- import { IReflectController } from "../structures/IReflectController";
9
- import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
10
- import { ITypeTuple } from "../structures/ITypeTuple";
11
- import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
12
- import { GenericAnalyzer } from "./GenericAnalyzer";
13
- import { ImportAnalyzer } from "./ImportAnalyzer";
7
+ // import { INestiaProject } from "../structures/INestiaProject";
8
+ // import { IReflectController } from "../structures/IReflectController";
9
+ // import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
10
+ // import { ITypeTuple } from "../structures/ITypeTuple";
11
+ // import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
12
+ // import { GenericAnalyzer } from "./GenericAnalyzer";
13
+ // import { ImportAnalyzer } from "./ImportAnalyzer";
14
14
 
15
- export namespace ExceptionAnalyzer {
16
- export const analyze =
17
- (project: INestiaProject) =>
18
- (props: {
19
- generics: GenericAnalyzer.Dictionary;
20
- imports: ImportAnalyzer.Dictionary;
21
- controller: IReflectController;
22
- operation: IReflectHttpOperation;
23
- declaration: ts.MethodDeclaration;
24
- }): Record<
25
- number | "2XX" | "3XX" | "4XX" | "5XX",
26
- ITypedHttpRoute.IOutput
27
- > => {
28
- const output: Record<
29
- number | "2XX" | "3XX" | "4XX" | "5XX",
30
- ITypedHttpRoute.IOutput
31
- > = {} as any;
32
- for (const decorator of props.declaration.modifiers ?? [])
33
- if (ts.isDecorator(decorator))
34
- analyzeTyped(project)({
35
- ...props,
36
- output,
37
- decorator,
38
- });
39
- return output;
40
- };
15
+ // export namespace ExceptionAnalyzer {
16
+ // export const analyze =
17
+ // (project: INestiaProject) =>
18
+ // (props: {
19
+ // generics: GenericAnalyzer.Dictionary;
20
+ // imports: ImportAnalyzer.Dictionary;
21
+ // controller: IReflectController;
22
+ // operation: IReflectHttpOperation;
23
+ // declaration: ts.MethodDeclaration;
24
+ // }): Record<
25
+ // number | "2XX" | "3XX" | "4XX" | "5XX",
26
+ // ITypedHttpRoute.IOutput
27
+ // > => {
28
+ // const output: Record<
29
+ // number | "2XX" | "3XX" | "4XX" | "5XX",
30
+ // ITypedHttpRoute.IOutput
31
+ // > = {} as any;
32
+ // for (const decorator of props.declaration.modifiers ?? [])
33
+ // if (ts.isDecorator(decorator))
34
+ // analyzeTyped(project)({
35
+ // ...props,
36
+ // output,
37
+ // decorator,
38
+ // });
39
+ // return output;
40
+ // };
41
41
 
42
- const analyzeTyped =
43
- (project: INestiaProject) =>
44
- (props: {
45
- generics: GenericAnalyzer.Dictionary;
46
- imports: ImportAnalyzer.Dictionary;
47
- controller: IReflectController;
48
- operation: IReflectHttpOperation;
49
- output: Record<
50
- number | "2XX" | "3XX" | "4XX" | "5XX",
51
- ITypedHttpRoute.IOutput
52
- >;
53
- decorator: ts.Decorator;
54
- }): boolean => {
55
- // CHECK DECORATOR
56
- if (!ts.isCallExpression(props.decorator.expression)) return false;
57
- else if ((props.decorator.expression.typeArguments ?? []).length !== 1)
58
- return false;
42
+ // const analyzeTyped =
43
+ // (project: INestiaProject) =>
44
+ // (props: {
45
+ // generics: GenericAnalyzer.Dictionary;
46
+ // imports: ImportAnalyzer.Dictionary;
47
+ // controller: IReflectController;
48
+ // operation: IReflectHttpOperation;
49
+ // output: Record<
50
+ // number | "2XX" | "3XX" | "4XX" | "5XX",
51
+ // ITypedHttpRoute.IOutput
52
+ // >;
53
+ // decorator: ts.Decorator;
54
+ // }): boolean => {
55
+ // // CHECK DECORATOR
56
+ // if (!ts.isCallExpression(props.decorator.expression)) return false;
57
+ // else if ((props.decorator.expression.typeArguments ?? []).length !== 1)
58
+ // return false;
59
59
 
60
- // CHECK SIGNATURE
61
- const signature: ts.Signature | undefined =
62
- project.checker.getResolvedSignature(props.decorator.expression);
63
- if (!signature || !signature.declaration) return false;
64
- else if (
65
- path
66
- .resolve(signature.declaration.getSourceFile().fileName)
67
- .indexOf(TYPED_EXCEPTION_PATH) === -1
68
- )
69
- return false;
60
+ // // CHECK SIGNATURE
61
+ // const signature: ts.Signature | undefined =
62
+ // project.checker.getResolvedSignature(props.decorator.expression);
63
+ // if (!signature || !signature.declaration) return false;
64
+ // else if (
65
+ // path
66
+ // .resolve(signature.declaration.getSourceFile().fileName)
67
+ // .indexOf(TYPED_EXCEPTION_PATH) === -1
68
+ // )
69
+ // return false;
70
70
 
71
- // GET TYPE INFO
72
- const status: string | null = getStatus(project.checker)(
73
- props.decorator.expression.arguments[0] ?? null,
74
- );
75
- if (status === null) return false;
71
+ // // GET TYPE INFO
72
+ // const status: string | null = getStatus(project.checker)(
73
+ // props.decorator.expression.arguments[0] ?? null,
74
+ // );
75
+ // if (status === null) return false;
76
76
 
77
- const node: ts.TypeNode = props.decorator.expression.typeArguments![0];
78
- const type: ts.Type = project.checker.getTypeFromTypeNode(node);
79
- if (type.isTypeParameter()) {
80
- project.errors.push({
81
- file: props.controller.file,
82
- controller: props.controller.name,
83
- function: props.operation.name,
84
- message: "TypedException() without generic argument specification.",
85
- });
86
- return false;
87
- }
77
+ // const node: ts.TypeNode = props.decorator.expression.typeArguments![0];
78
+ // const type: ts.Type = project.checker.getTypeFromTypeNode(node);
79
+ // if (type.isTypeParameter()) {
80
+ // project.errors.push({
81
+ // file: props.controller.file,
82
+ // controller: props.controller.name,
83
+ // function: props.operation.name,
84
+ // message: "TypedException() without generic argument specification.",
85
+ // });
86
+ // return false;
87
+ // }
88
88
 
89
- const tuple: ITypeTuple | null = ImportAnalyzer.analyze(project.checker)({
90
- generics: props.generics,
91
- imports: props.imports,
92
- type,
93
- });
94
- if (tuple === null) {
95
- project.errors.push({
96
- file: props.controller.file,
97
- controller: props.controller.name,
98
- function: props.operation.name,
99
- message: `TypeException() with unknown type on ${status} status.`,
100
- });
101
- return false;
102
- }
89
+ // const tuple: ITypeTuple | null = ImportAnalyzer.analyze(project.checker)({
90
+ // generics: props.generics,
91
+ // imports: props.imports,
92
+ // type,
93
+ // });
94
+ // if (tuple === null) {
95
+ // project.errors.push({
96
+ // file: props.controller.file,
97
+ // controller: props.controller.name,
98
+ // function: props.operation.name,
99
+ // message: `TypeException() with unknown type on ${status} status.`,
100
+ // });
101
+ // return false;
102
+ // }
103
103
 
104
- // DO ASSIGN
105
- const matched: IReflectHttpOperation.IException[] = Object.entries(
106
- props.operation.exceptions,
107
- )
108
- .filter(([key]) => status === key)
109
- .map(([_key, value]) => value);
110
- for (const m of matched)
111
- props.output[m.status] = {
112
- type: tuple.type,
113
- typeName: tuple.typeName,
114
- contentType: "application/json",
115
- description: m.description,
116
- };
117
- return true;
118
- };
104
+ // // DO ASSIGN
105
+ // const matched: IReflectHttpOperation.IException[] = Object.entries(
106
+ // props.operation.exceptions,
107
+ // )
108
+ // .filter(([key]) => status === key)
109
+ // .map(([_key, value]) => value);
110
+ // for (const m of matched)
111
+ // props.output[m.status] = {
112
+ // type: tuple.type,
113
+ // typeName: tuple.typeName,
114
+ // contentType: "application/json",
115
+ // description: m.description,
116
+ // };
117
+ // return true;
118
+ // };
119
119
 
120
- const getStatus =
121
- (checker: ts.TypeChecker) =>
122
- (expression: ts.Expression | null): string | null => {
123
- if (expression === null) return null;
120
+ // const getStatus =
121
+ // (checker: ts.TypeChecker) =>
122
+ // (expression: ts.Expression | null): string | null => {
123
+ // if (expression === null) return null;
124
124
 
125
- const type: ts.Type = checker.getTypeAtLocation(expression);
126
- const result = MetadataFactory.analyze(checker)({
127
- escape: true,
128
- constant: true,
129
- absorb: true,
130
- })(new MetadataCollection())(type);
131
- if (false === result.success) return null;
125
+ // const type: ts.Type = checker.getTypeAtLocation(expression);
126
+ // const result = MetadataFactory.analyze(checker)({
127
+ // escape: true,
128
+ // constant: true,
129
+ // absorb: true,
130
+ // })(new MetadataCollection())(type);
131
+ // if (false === result.success) return null;
132
132
 
133
- const meta: Metadata = result.data;
134
- if (meta.constants.length === 1)
135
- return meta.constants[0].values[0].value.toString();
136
- else if (meta.escaped && meta.escaped.returns.constants.length === 1)
137
- return meta.escaped.returns.constants[0].values[0].value.toString();
138
- else if (ts.isStringLiteral(expression)) return expression.text;
139
- else if (ts.isNumericLiteral(expression)) {
140
- const value: number = Number(expression.text.split("_").join(""));
141
- if (false === isNaN(value)) return value.toString();
142
- }
143
- return null;
144
- };
145
- }
133
+ // const meta: Metadata = result.data;
134
+ // if (meta.constants.length === 1)
135
+ // return meta.constants[0].values[0].value.toString();
136
+ // else if (meta.escaped && meta.escaped.returns.constants.length === 1)
137
+ // return meta.escaped.returns.constants[0].values[0].value.toString();
138
+ // else if (ts.isStringLiteral(expression)) return expression.text;
139
+ // else if (ts.isNumericLiteral(expression)) {
140
+ // const value: number = Number(expression.text.split("_").join(""));
141
+ // if (false === isNaN(value)) return value.toString();
142
+ // }
143
+ // return null;
144
+ // };
145
+ // }
146
146
 
147
- const TYPED_EXCEPTION_PATH = path.join(
148
- "node_modules",
149
- "@nestia",
150
- "core",
151
- "lib",
152
- "decorators",
153
- "TypedException.d.ts",
154
- );
147
+ // const TYPED_EXCEPTION_PATH = path.join(
148
+ // "node_modules",
149
+ // "@nestia",
150
+ // "core",
151
+ // "lib",
152
+ // "decorators",
153
+ // "TypedException.d.ts",
154
+ // );
@@ -1,20 +1,18 @@
1
1
  import ts from "typescript";
2
2
 
3
3
  export namespace GenericAnalyzer {
4
- export type Dictionary = WeakMap<ts.Type, ts.Type>;
5
-
6
4
  export function analyze(
7
5
  checker: ts.TypeChecker,
8
6
  classNode: ts.ClassDeclaration,
9
- ): Dictionary {
10
- const dict: Dictionary = new WeakMap();
7
+ ): WeakMap<ts.Type, ts.Type> {
8
+ const dict: WeakMap<ts.Type, ts.Type> = new WeakMap();
11
9
  explore(checker, dict, classNode);
12
10
  return dict;
13
11
  }
14
12
 
15
13
  function explore(
16
14
  checker: ts.TypeChecker,
17
- dict: Dictionary,
15
+ dict: WeakMap<ts.Type, ts.Type>,
18
16
  classNode: ts.ClassDeclaration,
19
17
  ): void {
20
18
  if (classNode.heritageClauses === undefined) return;
@@ -1,57 +1,61 @@
1
- import { HashMap, HashSet } from "tstl";
2
1
  import ts from "typescript";
3
2
 
4
- import { ITypeTuple } from "../structures/ITypeTuple";
5
- import { GenericAnalyzer } from "./GenericAnalyzer";
3
+ import { IReflectType } from "../structures/IReflectType";
4
+ import { IReflectTypeImport } from "../structures/IReflectTypeImport";
5
+ import { MapUtil } from "../utils/MapUtil";
6
6
 
7
7
  export namespace ImportAnalyzer {
8
8
  export interface IOutput {
9
- features: [string, string[]][];
10
- alias: string;
9
+ imports: IReflectTypeImport[];
10
+ type: IReflectType | null;
11
11
  }
12
-
13
- export type Dictionary = HashMap<string, HashSet<string>>;
14
-
15
- export const analyze =
16
- (checker: ts.TypeChecker) =>
17
- (props: {
18
- generics: GenericAnalyzer.Dictionary;
19
- imports: Dictionary;
20
- type: ts.Type;
21
- }): ITypeTuple | null => {
22
- const type: ts.Type = get_type(checker)(props.type);
23
- explore_escaped_name(checker)({
24
- ...props,
25
- type,
26
- });
27
- try {
28
- return {
12
+ export const analyze = (
13
+ checker: ts.TypeChecker,
14
+ generics: WeakMap<ts.Type, ts.Type>,
15
+ type: ts.Type,
16
+ ): IOutput => {
17
+ const imports: Map<string, Set<string>> = new Map();
18
+ try {
19
+ type = escape(checker, type);
20
+ return {
21
+ type: explore({
22
+ checker,
23
+ generics,
24
+ imports,
29
25
  type,
30
- typeName: explore_escaped_name(checker)({
31
- ...props,
32
- type,
33
- }),
34
- };
35
- } catch {
36
- return null;
37
- }
38
- };
26
+ }),
27
+ imports: [...imports].map(([file, instances]) => ({
28
+ file,
29
+ instances: Array.from(instances),
30
+ })),
31
+ };
32
+ } catch {
33
+ return {
34
+ imports: [],
35
+ type: null,
36
+ };
37
+ }
38
+ };
39
39
 
40
- /* ---------------------------------------------------------
41
- TYPE
42
- --------------------------------------------------------- */
43
- const get_type =
44
- (checker: ts.TypeChecker) =>
45
- (type: ts.Type): ts.Type => {
46
- const symbol: ts.Symbol | undefined = type.getSymbol();
47
- return symbol && get_name(symbol) === "Promise"
48
- ? escape_promise(checker)(type)
49
- : type;
50
- };
40
+ export const unique = (
41
+ imports: IReflectTypeImport[],
42
+ ): IReflectTypeImport[] => {
43
+ const map: Map<string, Set<string>> = new Map();
44
+ imports.forEach(({ file, instances }) => {
45
+ const set: Set<string> = MapUtil.take(map, file, () => new Set());
46
+ instances.forEach((instance) => set.add(instance));
47
+ });
48
+ return [...map].map(([file, instances]) => ({
49
+ file,
50
+ instances: Array.from(instances),
51
+ }));
52
+ };
51
53
 
52
- const escape_promise =
53
- (checker: ts.TypeChecker) =>
54
- (type: ts.Type): ts.Type => {
54
+ /* ---------------------------------------------------------
55
+ TYPE
56
+ --------------------------------------------------------- */
57
+ const escape = (checker: ts.TypeChecker, type: ts.Type): ts.Type => {
58
+ if (type.symbol && getNameOfSymbol(type.symbol) === "Promise") {
55
59
  const generic: readonly ts.Type[] = checker.getTypeArguments(
56
60
  type as ts.TypeReference,
57
61
  );
@@ -59,98 +63,109 @@ export namespace ImportAnalyzer {
59
63
  throw new Error(
60
64
  "Error on ImportAnalyzer.analyze(): invalid promise type.",
61
65
  );
62
- return generic[0];
63
- };
66
+ type = generic[0];
67
+ }
68
+ return type;
69
+ };
64
70
 
65
- const get_name = (symbol: ts.Symbol): string =>
66
- explore_name(
71
+ const getNameOfSymbol = (symbol: ts.Symbol): string =>
72
+ exploreName(
67
73
  symbol.escapedName.toString(),
68
74
  symbol.getDeclarations()?.[0]?.parent,
69
75
  );
70
76
 
71
77
  /* ---------------------------------------------------------
72
- ESCAPED TEXT WITH IMPORT STATEMENTS
73
- --------------------------------------------------------- */
74
- const explore_escaped_name =
75
- (checker: ts.TypeChecker) =>
76
- (props: {
77
- generics: GenericAnalyzer.Dictionary;
78
- imports: Dictionary;
79
- type: ts.Type;
80
- }): string => {
81
- //----
82
- // CONDITIONAL BRANCHES
83
- //----
84
- // DECOMPOSE GENERIC ARGUMENT
85
- let type: ts.Type = props.type;
86
- while (props.generics.has(type) === true)
87
- type = props.generics.get(type)!;
78
+ ESCAPED TEXT WITH IMPORT STATEMENTS
79
+ --------------------------------------------------------- */
80
+ const explore = (props: {
81
+ checker: ts.TypeChecker;
82
+ generics: WeakMap<ts.Type, ts.Type>;
83
+ imports: Map<string, Set<string>>;
84
+ type: ts.Type;
85
+ }): IReflectType => {
86
+ //----
87
+ // CONDITIONAL BRANCHES
88
+ //----
89
+ // DECOMPOSE GENERIC ARGUMENT
90
+ let type: ts.Type = props.type;
91
+ while (props.generics.has(type) === true) type = props.generics.get(type)!;
88
92
 
89
- // PRIMITIVE
90
- const symbol: ts.Symbol | undefined =
91
- type.aliasSymbol ?? type.getSymbol();
93
+ // PRIMITIVE
94
+ const symbol: ts.Symbol | undefined = type.aliasSymbol ?? type.symbol;
92
95
 
93
- // UNION OR INTERSECT
94
- if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
95
- const joiner: string = type.isIntersection() ? " & " : " | ";
96
- return type.types
96
+ // UNION OR INTERSECT
97
+ if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
98
+ const joiner: string = type.isIntersection() ? " & " : " | ";
99
+ return {
100
+ name: type.types
97
101
  .map((child) =>
98
- explore_escaped_name(checker)({
102
+ explore({
99
103
  ...props,
100
104
  type: child,
101
105
  }),
102
106
  )
103
- .join(joiner);
104
- }
105
- // NO SYMBOL
106
- else if (symbol === undefined)
107
- return checker.typeToString(
107
+ .map(getEscapedText)
108
+ .join(joiner),
109
+ };
110
+ }
111
+ // NO SYMBOL
112
+ else if (symbol === undefined)
113
+ return {
114
+ name: props.checker.typeToString(
108
115
  type,
109
116
  undefined,
110
117
  ts.TypeFormatFlags.NoTruncation,
111
- );
118
+ ),
119
+ };
112
120
 
113
- //----
114
- // SPECIALIZATION
115
- //----
116
- const name: string = get_name(symbol);
117
- const sourceFile: ts.SourceFile | undefined =
118
- symbol.declarations?.[0]?.getSourceFile();
119
- if (sourceFile === undefined) return name;
120
- else if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
121
- const set: HashSet<string> = props.imports.take(
122
- sourceFile.fileName,
123
- () => new HashSet(),
124
- );
125
- set.insert(name.split(".")[0]);
126
- }
121
+ //----
122
+ // SPECIALIZATION
123
+ //----
124
+ const name: string = getNameOfSymbol(symbol);
125
+ const sourceFile: ts.SourceFile | undefined =
126
+ symbol.declarations?.[0]?.getSourceFile();
127
+ if (sourceFile === undefined) return { name };
128
+ else if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
129
+ const set: Set<string> = MapUtil.take(
130
+ props.imports,
131
+ sourceFile.fileName,
132
+ () => new Set(),
133
+ );
134
+ set.add(name.split(".")[0]);
135
+ }
127
136
 
128
- // CHECK GENERIC
129
- const generic: readonly ts.Type[] = type.aliasSymbol
130
- ? type.aliasTypeArguments ?? []
131
- : checker.getTypeArguments(type as ts.TypeReference);
132
- return generic.length
133
- ? name === "Promise"
134
- ? explore_escaped_name(checker)({
135
- ...props,
136
- type: generic[0],
137
- })
138
- : `${name}<${generic
139
- .map((child) =>
140
- explore_escaped_name(checker)({
141
- ...props,
142
- type: child,
143
- }),
144
- )
145
- .join(", ")}>`
146
- : name;
147
- };
137
+ // CHECK GENERIC
138
+ const generic: readonly ts.Type[] = type.aliasSymbol
139
+ ? type.aliasTypeArguments ?? []
140
+ : props.checker.getTypeArguments(type as ts.TypeReference);
141
+ return generic.length
142
+ ? name === "Promise"
143
+ ? explore({
144
+ ...props,
145
+ type: generic[0],
146
+ })
147
+ : {
148
+ name,
149
+ typeArguments: generic.map((child) =>
150
+ explore({
151
+ ...props,
152
+ type: child,
153
+ }),
154
+ ),
155
+ }
156
+ : { name };
157
+ };
148
158
 
149
- const explore_name = (name: string, decl?: ts.Node): string =>
159
+ const exploreName = (name: string, decl?: ts.Node): string =>
150
160
  decl && ts.isModuleBlock(decl)
151
- ? explore_name(
161
+ ? exploreName(
152
162
  `${decl.parent.name.getFullText().trim()}.${name}`,
153
163
  decl.parent.parent,
154
164
  )
155
165
  : name;
166
+
167
+ const getEscapedText = (type: IReflectType): string =>
168
+ type.typeArguments
169
+ ? `${type.name}<${type.typeArguments.map(getEscapedText).join(", ")}>`
170
+ : type.name;
156
171
  }