@nestia/sdk 3.10.0 → 3.11.0-dev.20240812

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 +33 -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 +17 -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,92 +0,0 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaProject } from "../structures/INestiaProject";
4
- import { IReflectController } from "../structures/IReflectController";
5
- import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
6
- import { IReflectWebSocketOperation } from "../structures/IReflectWebSocketOperation";
7
- import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
8
- import { ITypedWebSocketRoute } from "../structures/ITypedWebSocketRoute";
9
- import { GenericAnalyzer } from "./GenericAnalyzer";
10
- import { TypedHttpOperationAnalyzer } from "./TypedHttpOperationAnalyzer";
11
- import { TypedWebSocketOperationAnalyzer } from "./TypedWebSocketOperationAnalyzer";
12
-
13
- export namespace TypedControllerAnalyzer {
14
- export const analyze =
15
- (project: INestiaProject) =>
16
- async (
17
- sourceFile: ts.SourceFile,
18
- controller: IReflectController,
19
- ): Promise<Array<ITypedHttpRoute | ITypedWebSocketRoute>> => {
20
- // FIND CONTROLLER CLASS
21
- const ret: Array<ITypedHttpRoute | ITypedWebSocketRoute> = [];
22
- ts.forEachChild(sourceFile, (node) => {
23
- if (
24
- ts.isClassDeclaration(node) &&
25
- node.name?.escapedText === controller.name
26
- ) {
27
- // ANALYZE THE CONTROLLER
28
- ret.push(..._Analyze_controller(project)(controller, node));
29
- return;
30
- }
31
- });
32
- return ret;
33
- };
34
-
35
- /* ---------------------------------------------------------
36
- CLASS
37
- --------------------------------------------------------- */
38
- const _Analyze_controller =
39
- (project: INestiaProject) =>
40
- (
41
- controller: IReflectController,
42
- classNode: ts.ClassDeclaration,
43
- ): Array<ITypedHttpRoute | ITypedWebSocketRoute> => {
44
- const classType: ts.InterfaceType = project.checker.getTypeAtLocation(
45
- classNode,
46
- ) as ts.InterfaceType;
47
- const generics: GenericAnalyzer.Dictionary = GenericAnalyzer.analyze(
48
- project.checker,
49
- classNode,
50
- );
51
-
52
- const ret: Array<ITypedHttpRoute | ITypedWebSocketRoute> = [];
53
- for (const symbol of classType.getProperties()) {
54
- // GET METHOD DECLARATION
55
- const declaration: ts.Declaration | undefined = (symbol.declarations ||
56
- [])[0];
57
- if (!declaration || !ts.isMethodDeclaration(declaration)) continue;
58
-
59
- // IDENTIFIER MUST BE
60
- const identifier = declaration.name;
61
- if (!ts.isIdentifier(identifier)) continue;
62
-
63
- // ANALYZED WITH THE REFLECTED-FUNCTION
64
- const operation:
65
- | IReflectHttpOperation
66
- | IReflectWebSocketOperation
67
- | undefined = controller.operations.find(
68
- (f) => f.name === identifier.escapedText,
69
- );
70
- if (operation === undefined) continue;
71
-
72
- const routes: ITypedHttpRoute[] | ITypedWebSocketRoute[] =
73
- operation.protocol === "http"
74
- ? TypedHttpOperationAnalyzer.analyze(project)({
75
- controller,
76
- generics,
77
- operation,
78
- declaration,
79
- symbol,
80
- })
81
- : TypedWebSocketOperationAnalyzer.analyze(project)({
82
- controller,
83
- operation,
84
- declaration,
85
- symbol,
86
- generics,
87
- });
88
- ret.push(...routes);
89
- }
90
- return ret;
91
- };
92
- }
@@ -1,365 +0,0 @@
1
- import { RequestMethod } from "@nestjs/common";
2
- import path from "path";
3
- import { HashMap } from "tstl";
4
- import ts from "typescript";
5
- import { CommentFactory } from "typia/lib/factories/CommentFactory";
6
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
7
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
8
-
9
- import { IErrorReport } from "../structures/IErrorReport";
10
- import { INestiaProject } from "../structures/INestiaProject";
11
- import { IReflectController } from "../structures/IReflectController";
12
- import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
13
- import { ITypeTuple } from "../structures/ITypeTuple";
14
- import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
15
- import { PathUtil } from "../utils/PathUtil";
16
- import { VersioningStrategy } from "../utils/VersioningStrategy";
17
- import { ExceptionAnalyzer } from "./ExceptionAnalyzer";
18
- import { GenericAnalyzer } from "./GenericAnalyzer";
19
- import { ImportAnalyzer } from "./ImportAnalyzer";
20
- import { PathAnalyzer } from "./PathAnalyzer";
21
- import { SecurityAnalyzer } from "./SecurityAnalyzer";
22
-
23
- export namespace TypedHttpOperationAnalyzer {
24
- export const analyze =
25
- (project: INestiaProject) =>
26
- (props: {
27
- controller: IReflectController;
28
- operation: IReflectHttpOperation;
29
- declaration: ts.MethodDeclaration;
30
- symbol: ts.Symbol;
31
- generics: GenericAnalyzer.Dictionary;
32
- }): ITypedHttpRoute[] => {
33
- // CHECK TYPE
34
- const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
35
- props.symbol,
36
- props.symbol.valueDeclaration!,
37
- );
38
- const signature: ts.Signature | undefined =
39
- project.checker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
40
- if (signature === undefined) {
41
- project.errors.push({
42
- file: props.controller.file,
43
- controller: props.controller.name,
44
- function: props.operation.name,
45
- message: "unable to get the type signature.",
46
- });
47
- return [];
48
- }
49
-
50
- // SKIP @IGNORE TAG
51
- const jsDocTags = signature.getJsDocTags();
52
- if (jsDocTags.some((tag) => tag.name === "ignore")) return [];
53
-
54
- // EXPLORE CHILDREN TYPES
55
- const importDict: ImportAnalyzer.Dictionary = new HashMap();
56
- const parameters: Array<ITypedHttpRoute.IParameter | null> =
57
- props.operation.parameters.map(
58
- (param) =>
59
- _Analyze_parameter(project)({
60
- generics: props.generics,
61
- imports: importDict,
62
- controller: props.controller,
63
- function: props.operation.name,
64
- parameter: param,
65
- symbol: signature.getParameters()[param.index],
66
- })!,
67
- );
68
- const outputType: ITypeTuple | null = ImportAnalyzer.analyze(
69
- project.checker,
70
- )({
71
- generics: props.generics,
72
- imports: importDict,
73
- type: signature.getReturnType(),
74
- });
75
- if (outputType === null) {
76
- project.errors.push({
77
- file: props.controller.file,
78
- controller: props.controller.name,
79
- function: props.operation.name,
80
- message: "unknown return type.",
81
- });
82
- return [];
83
- } else if (
84
- props.operation.method === "HEAD" &&
85
- outputType.typeName !== "void" &&
86
- outputType.typeName !== "undefined"
87
- ) {
88
- project.errors.push({
89
- file: props.controller.file,
90
- controller: props.controller.name,
91
- function: props.operation.name,
92
- message: `HEAD method must return void type.`,
93
- });
94
- return [];
95
- }
96
-
97
- const exceptions = ExceptionAnalyzer.analyze(project)({
98
- generics: props.generics,
99
- imports: project.config.propagate === true ? importDict : new HashMap(),
100
- controller: props.controller,
101
- operation: props.operation,
102
- declaration: props.declaration,
103
- });
104
- const imports: [string, string[]][] = importDict
105
- .toJSON()
106
- .map((pair) => [pair.first, pair.second.toJSON()]);
107
-
108
- // CONSIDER SECURITY TAGS
109
- const security: Record<string, string[]>[] = SecurityAnalyzer.merge(
110
- ...props.controller.security,
111
- ...props.operation.security,
112
- ...jsDocTags
113
- .filter((tag) => tag.name === "security")
114
- .map((tag) =>
115
- tag.text === undefined
116
- ? [{}]
117
- : tag.text.map((text) => {
118
- const line: string[] = text.text
119
- .split(" ")
120
- .filter((s) => s.trim())
121
- .filter((s) => !!s.length);
122
- if (line.length === 0) return {};
123
- return {
124
- [line[0]]: line.slice(1),
125
- };
126
- }),
127
- )
128
- .flat(),
129
- );
130
-
131
- // CONSTRUCT COMMON DATA
132
- const common: Omit<ITypedHttpRoute, "path" | "accessors"> = {
133
- ...props.operation,
134
- controller: props.controller,
135
- parameters: parameters.filter(
136
- (p) => p !== null,
137
- ) as ITypedHttpRoute.IParameter[],
138
- output: {
139
- type: outputType.type,
140
- typeName: outputType.typeName,
141
- contentType: props.operation.contentType,
142
- },
143
- imports,
144
- status: props.operation.status,
145
- location: (() => {
146
- const file = props.declaration.getSourceFile();
147
- const { line, character } = file.getLineAndCharacterOfPosition(
148
- props.declaration.pos,
149
- );
150
- return `${path.relative(process.cwd(), file.fileName)}:${line + 1}:${
151
- character + 1
152
- }`;
153
- })(),
154
- description: CommentFactory.description(props.symbol),
155
- operationId: jsDocTags
156
- .find(({ name }) => name === "operationId")
157
- ?.text?.[0].text.split(" ")[0]
158
- .trim(),
159
- jsDocTags: jsDocTags,
160
- setHeaders: jsDocTags
161
- .filter(
162
- (t) =>
163
- t.text?.length &&
164
- t.text[0].text &&
165
- (t.name === "setHeader" || t.name === "assignHeaders"),
166
- )
167
- .map((t) =>
168
- t.name === "setHeader"
169
- ? {
170
- type: "setter",
171
- source: t.text![0].text.split(" ")[0].trim(),
172
- target: t.text![0].text.split(" ")[1]?.trim(),
173
- }
174
- : {
175
- type: "assigner",
176
- source: t.text![0].text,
177
- },
178
- ),
179
- security,
180
- exceptions,
181
- example: props.operation.example,
182
- examples: props.operation.examples,
183
- };
184
-
185
- // CONFIGURE PATHS
186
- const globalPrefix = project.input.globalPrefix ?? {
187
- prefix: "",
188
- };
189
- const pathList: Set<string> = new Set();
190
- const versions: string[] = VersioningStrategy.merge(project)([
191
- ...(props.controller.versions ?? []),
192
- ...(props.operation.versions ?? []),
193
- ]);
194
- for (const v of versions)
195
- for (const prefix of wrapPaths(props.controller.prefixes))
196
- for (const cPath of wrapPaths(props.controller.paths))
197
- for (const filePath of wrapPaths(props.operation.paths))
198
- pathList.add(
199
- PathAnalyzer.join(
200
- globalPrefix.prefix,
201
- v,
202
- prefix,
203
- cPath,
204
- filePath,
205
- ),
206
- );
207
- return [...pathList]
208
- .filter((path) => {
209
- const escaped: string | null = PathAnalyzer.escape(path);
210
- if (escaped === null) {
211
- project.errors.push({
212
- file: props.controller.file,
213
- controller: props.controller.name,
214
- function: props.operation.name,
215
- message: `unable to escape the path "${path}".`,
216
- });
217
- return false;
218
- } else if (Array.isArray(globalPrefix.exclude))
219
- return globalPrefix.exclude.some((e) =>
220
- typeof e === "string"
221
- ? !RegExp(e).test(path)
222
- : RegExp(e.path).test(path) &&
223
- (enumToMethod(e.method) === "all" ||
224
- enumToMethod(e.method) ===
225
- props.operation.method.toLowerCase()) &&
226
- (e.version === undefined ||
227
- versions.some((v) => v === e.version)),
228
- );
229
- return true;
230
- })
231
- .map((path) => ({
232
- ...common,
233
- path: PathAnalyzer.escape(path)!,
234
- accessors: [...PathUtil.accessors(path), props.operation.name],
235
- }));
236
- };
237
-
238
- const _Analyze_parameter =
239
- (project: INestiaProject) =>
240
- (props: {
241
- generics: GenericAnalyzer.Dictionary;
242
- imports: ImportAnalyzer.Dictionary;
243
- controller: IReflectController;
244
- function: string;
245
- parameter: IReflectHttpOperation.IParameter;
246
- symbol: ts.Symbol;
247
- }): ITypedHttpRoute.IParameter | null => {
248
- const type: ts.Type = project.checker.getTypeOfSymbolAtLocation(
249
- props.symbol,
250
- props.symbol.valueDeclaration!,
251
- );
252
- const name: string = props.symbol.getEscapedName().toString();
253
- const optional: boolean = !!project.checker.symbolToParameterDeclaration(
254
- props.symbol,
255
- undefined,
256
- undefined,
257
- )?.questionToken;
258
-
259
- const errors: IErrorReport[] = [];
260
-
261
- // DO NOT SUPPORT BODY PARAMETER
262
- if (
263
- props.parameter.category === "body" &&
264
- props.parameter.field !== undefined
265
- )
266
- errors.push({
267
- file: props.controller.file,
268
- controller: props.controller.name,
269
- function: props.function,
270
- message:
271
- `nestia does not support body field specification. ` +
272
- `Therefore, erase the "${name}" parameter and ` +
273
- `re-define a new body decorator accepting full structured message.`,
274
- });
275
- if (optional === true && props.parameter.category !== "query")
276
- errors.push({
277
- file: props.controller.file,
278
- controller: props.controller.name,
279
- function: props.function,
280
- message:
281
- `nestia does not support optional parameter except query parameter. ` +
282
- `Therefore, erase question mark on the "${name}" parameter, ` +
283
- `or re-define a new method without the "${name}" parameter.`,
284
- });
285
- if (
286
- optional === true &&
287
- props.parameter.category === "query" &&
288
- props.parameter.field === undefined
289
- ) {
290
- const everyPropertiesAreOptional: boolean = (() => {
291
- const res = MetadataFactory.analyze(project.checker)({
292
- escape: false,
293
- constant: true,
294
- absorb: true,
295
- })(new MetadataCollection())(type);
296
- if (res.success === false) return false;
297
- const m = res.data;
298
- return (
299
- m.size() === 1 &&
300
- m.objects.length === 1 &&
301
- m.objects[0]!.properties.every((p) => p.value.optional === true)
302
- );
303
- })();
304
- if (everyPropertiesAreOptional === false)
305
- errors.push({
306
- file: props.controller.file,
307
- controller: props.controller.name,
308
- function: props.function,
309
- message:
310
- `nestia does not support optional query parameter exception field specification or every properties are optional case. ` +
311
- `Therefore, erase question mark on the "${name}" parameter, ` +
312
- `or re-define re-define parameters for each query parameters.`,
313
- });
314
- }
315
-
316
- // GET TYPE NAME
317
- const tuple: ITypeTuple | null = ImportAnalyzer.analyze(project.checker)({
318
- generics: props.generics,
319
- imports: props.imports,
320
- type,
321
- });
322
- if (tuple === null)
323
- errors.push({
324
- file: props.controller.file,
325
- controller: props.controller.name,
326
- function: props.function,
327
- message: `unknown parameter type from ${JSON.stringify(name)}.`,
328
- });
329
- if (errors.length) {
330
- project.errors.push(...errors);
331
- return null;
332
- }
333
- return {
334
- ...props.parameter,
335
- name,
336
- optional,
337
- type: tuple!.type,
338
- typeName: tuple!.typeName,
339
- description: CommentFactory.description(props.symbol),
340
- jsDocTags: props.symbol.getJsDocTags(),
341
- };
342
- };
343
- }
344
-
345
- const enumToMethod = (v: RequestMethod) =>
346
- v === RequestMethod.GET
347
- ? "get"
348
- : v === RequestMethod.POST
349
- ? "post"
350
- : v === RequestMethod.PUT
351
- ? "put"
352
- : v === RequestMethod.DELETE
353
- ? "delete"
354
- : v === RequestMethod.PATCH
355
- ? "patch"
356
- : v === RequestMethod.ALL
357
- ? "all"
358
- : v === RequestMethod.OPTIONS
359
- ? "options"
360
- : v === RequestMethod.HEAD
361
- ? "head"
362
- : "search";
363
-
364
- const wrapPaths = (paths: string[]): string[] =>
365
- paths.length === 0 ? [""] : paths;