@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
@@ -5,140 +5,88 @@ import {
5
5
  } from "@nestjs/common/constants";
6
6
 
7
7
  import { INestiaProject } from "../structures/INestiaProject";
8
+ import { INestiaSdkInput } from "../structures/INestiaSdkInput";
8
9
  import { IReflectController } from "../structures/IReflectController";
9
10
  import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
10
11
  import { IReflectWebSocketOperation } from "../structures/IReflectWebSocketOperation";
12
+ import { IOperationMetadata } from "../transformers/IOperationMetadata";
11
13
  import { ArrayUtil } from "../utils/ArrayUtil";
12
14
  import { ReflectHttpOperationAnalyzer } from "./ReflectHttpOperationAnalyzer";
13
15
  import { ReflectMetadataAnalyzer } from "./ReflectMetadataAnalyzer";
14
16
  import { ReflectWebSocketOperationAnalyzer } from "./ReflectWebSocketOperationAnalyzer";
15
17
 
16
- type IModule = {
17
- [key: string]: any;
18
- };
19
-
20
18
  export namespace ReflectControllerAnalyzer {
21
- export const analyze =
22
- (project: INestiaProject) =>
23
- async (
24
- unique: WeakSet<any>,
25
- file: string,
26
- prefixes: string[],
27
- target?: Function,
28
- ): Promise<IReflectController[]> => {
29
- const module: IModule = await (async () => {
30
- try {
31
- return await import(file);
32
- } catch (exp) {
33
- console.log(
34
- ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
35
- );
36
- console.log(`Error on "${file}" file. Check your code.`);
37
- console.log(exp);
38
- console.log(
39
- ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
40
- );
41
- process.exit(-1);
42
- }
43
- })();
44
- const ret: IReflectController[] = [];
45
-
46
- for (const [key, value] of Object.entries(module)) {
47
- if (typeof value !== "function" || unique.has(value)) continue;
48
- else if ((target ?? value) !== value) continue;
49
- else unique.add(value);
50
-
51
- const result: IReflectController | null = _Analyze_controller(project)({
52
- file,
53
- name: key,
54
- creator: value,
55
- prefixes,
56
- });
57
- if (result !== null) ret.push(result);
58
- }
59
- return ret;
60
- };
61
-
19
+ export interface IProps {
20
+ project: INestiaProject;
21
+ controller: INestiaSdkInput.IController;
22
+ unique: WeakSet<Function>;
23
+ }
62
24
  /* ---------------------------------------------------------
63
- CONTROLLER
64
- --------------------------------------------------------- */
65
- const _Analyze_controller =
66
- (project: INestiaProject) =>
67
- (props: {
68
- file: string;
69
- name: string;
70
- creator: any;
71
- prefixes: string[];
72
- }): IReflectController | null => {
73
- //----
74
- // VALIDATIONS
75
- //----
76
- // MUST BE TYPE OF A CREATOR WHO HAS THE CONSTRUCTOR
77
- if (
78
- !(
79
- props.creator instanceof Function &&
80
- props.creator.constructor instanceof Function
81
- )
82
- )
83
- return null;
84
- // MUST HAVE THOSE MATADATA
85
- else if (
86
- ArrayUtil.has(
87
- Reflect.getMetadataKeys(props.creator),
88
- PATH_METADATA,
89
- HOST_METADATA,
90
- SCOPE_OPTIONS_METADATA,
91
- ) === false
92
- )
93
- return null;
25
+ CONTROLLER
26
+ --------------------------------------------------------- */
27
+ export const analyze = (props: IProps): IReflectController | null => {
28
+ // MUST BE TYPE OF A CREATOR WHO HAS THE CONSTRUCTOR
29
+ if (
30
+ ArrayUtil.has(
31
+ Reflect.getMetadataKeys(props.controller.class),
32
+ PATH_METADATA,
33
+ HOST_METADATA,
34
+ SCOPE_OPTIONS_METADATA,
35
+ ) === false
36
+ )
37
+ return null;
94
38
 
95
- //----
96
- // CONSTRUCTION
97
- //----
98
- // BASIC INFO
99
- const meta: IReflectController = {
100
- constructor: props.creator,
101
- prototype: props.creator.prototype,
102
- file: props.file,
103
- name: props.name,
104
- operations: [],
105
- prefixes: props.prefixes,
106
- paths: ReflectMetadataAnalyzer.paths(props.creator).filter((str) => {
39
+ // BASIC INFO
40
+ const controller: IReflectController = {
41
+ class: props.controller.class,
42
+ file: props.controller.location,
43
+ operations: [],
44
+ prefixes: props.controller.prefixes,
45
+ paths: ReflectMetadataAnalyzer.paths(props.controller.class).filter(
46
+ (str) => {
107
47
  if (str.includes("*") === true) {
108
- project.warnings.push({
109
- file: props.file,
110
- controller: props.name,
48
+ props.project.warnings.push({
49
+ file: props.controller.location,
50
+ class: props.controller.class.name,
111
51
  function: null,
112
- message: "@nestia/sdk does not compose wildcard controller.",
52
+ from: null,
53
+ contents: ["@nestia/sdk does not compose wildcard controller."],
113
54
  });
114
55
  return false;
115
56
  }
116
57
  return true;
117
- }),
118
- versions: ReflectMetadataAnalyzer.versions(props.creator),
119
- security: ReflectMetadataAnalyzer.securities(props.creator),
120
- swaggerTgas:
121
- Reflect.getMetadata("swagger/apiUseTags", props.creator) ?? [],
122
- };
123
-
124
- // PARSE CHILDREN DATA
125
- for (const [key, value] of _Get_prototype_entries(props.creator)) {
126
- if (typeof value !== "function") continue;
127
- const next = {
128
- controller: meta,
129
- name: key,
130
- function: value,
131
- };
132
- const child: IReflectHttpOperation | IReflectWebSocketOperation | null =
133
- ReflectWebSocketOperationAnalyzer.analyze(project)(next) ??
134
- ReflectHttpOperationAnalyzer.analyze(project)(next);
135
- if (child !== null) meta.operations.push(child);
136
- }
137
-
138
- // RETURNS
139
- return meta;
58
+ },
59
+ ),
60
+ versions: ReflectMetadataAnalyzer.versions(props.controller.class),
61
+ security: ReflectMetadataAnalyzer.securities(props.controller.class),
62
+ tags:
63
+ Reflect.getMetadata("swagger/apiUseTags", props.controller.class) ?? [],
140
64
  };
141
65
 
66
+ // OPERATORS
67
+ for (const [key, value] of _Get_prototype_entries(props.controller.class)) {
68
+ if (typeof value !== "function") continue;
69
+ const metadata: IOperationMetadata | undefined = Reflect.getMetadata(
70
+ "nestia/OperationMetadata",
71
+ props.controller.class.prototype,
72
+ key,
73
+ );
74
+ if (metadata === undefined) continue;
75
+ const next: ReflectHttpOperationAnalyzer.IProps = {
76
+ project: props.project,
77
+ controller: controller,
78
+ name: key,
79
+ function: value,
80
+ metadata,
81
+ };
82
+ const child: IReflectHttpOperation | IReflectWebSocketOperation | null =
83
+ ReflectWebSocketOperationAnalyzer.analyze(next) ??
84
+ ReflectHttpOperationAnalyzer.analyze(next);
85
+ if (child !== null) controller.operations.push(child);
86
+ }
87
+ return controller;
88
+ };
89
+
142
90
  function _Get_prototype_entries(creator: any): Array<[string, unknown]> {
143
91
  const keyList = Object.getOwnPropertyNames(creator.prototype);
144
92
  const entries: Array<[string, unknown]> = keyList.map((key) => [
@@ -1,300 +1,164 @@
1
- import { SwaggerExample } from "@nestia/core";
2
- import {
3
- HEADERS_METADATA,
4
- HTTP_CODE_METADATA,
5
- INTERCEPTORS_METADATA,
6
- METHOD_METADATA,
7
- PATH_METADATA,
8
- ROUTE_ARGS_METADATA,
9
- } from "@nestjs/common/constants";
10
- import { RouteParamtypes } from "@nestjs/common/enums/route-paramtypes.enum";
1
+ import { METHOD_METADATA, PATH_METADATA } from "@nestjs/common/constants";
11
2
  import { ranges } from "tstl";
12
3
 
13
- import { IErrorReport } from "../structures/IErrorReport";
14
4
  import { INestiaProject } from "../structures/INestiaProject";
15
5
  import { IReflectController } from "../structures/IReflectController";
16
6
  import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
17
- import { ParamCategory } from "../structures/ParamCategory";
7
+ import { IReflectHttpOperationParameter } from "../structures/IReflectHttpOperationParameter";
8
+ import { IReflectHttpOperationSuccess } from "../structures/IReflectHttpOperationSuccess";
9
+ import { IReflectOperationError } from "../structures/IReflectOperationError";
10
+ import { IOperationMetadata } from "../transformers/IOperationMetadata";
18
11
  import { ArrayUtil } from "../utils/ArrayUtil";
12
+ import { ImportAnalyzer } from "./ImportAnalyzer";
19
13
  import { PathAnalyzer } from "./PathAnalyzer";
14
+ import { ReflectHttpOperationParameterAnalyzer } from "./ReflectHttpOperationParameterAnalyzer";
15
+ import { ReflectHttpOperationResponseAnalyzer } from "./ReflectHttpOperationResponseAnalyzer";
20
16
  import { ReflectMetadataAnalyzer } from "./ReflectMetadataAnalyzer";
21
17
 
22
18
  export namespace ReflectHttpOperationAnalyzer {
23
- export const analyze =
24
- (project: INestiaProject) =>
25
- (props: {
26
- controller: IReflectController;
27
- function: Function;
28
- name: string;
29
- }): IReflectHttpOperation | null => {
30
- if (
31
- ArrayUtil.has(
32
- Reflect.getMetadataKeys(props.function),
33
- PATH_METADATA,
34
- METHOD_METADATA,
35
- ) === false
36
- )
19
+ export interface IProps {
20
+ project: INestiaProject;
21
+ controller: IReflectController;
22
+ function: Function;
23
+ name: string;
24
+ metadata: IOperationMetadata;
25
+ }
26
+ export const analyze = (props: IProps): IReflectHttpOperation | null => {
27
+ if (
28
+ ArrayUtil.has(
29
+ Reflect.getMetadataKeys(props.function),
30
+ PATH_METADATA,
31
+ METHOD_METADATA,
32
+ ) === false
33
+ )
34
+ return null;
35
+
36
+ const errors: IReflectOperationError[] = [];
37
+ const method: string =
38
+ METHODS[Reflect.getMetadata(METHOD_METADATA, props.function)];
39
+ if (method === undefined || method === "OPTIONS") return null;
40
+
41
+ const parameters: IReflectHttpOperationParameter[] =
42
+ ReflectHttpOperationParameterAnalyzer.analyze({
43
+ controller: props.controller,
44
+ metadata: props.metadata,
45
+ httpMethod: method,
46
+ function: props.function,
47
+ functionName: props.name,
48
+ errors,
49
+ });
50
+ const success: IReflectHttpOperationSuccess | null = (() => {
51
+ const localErrors: IReflectOperationError[] = [];
52
+ const success = ReflectHttpOperationResponseAnalyzer.analyze({
53
+ controller: props.controller,
54
+ function: props.function,
55
+ functionName: props.name,
56
+ httpMethod: method,
57
+ metadata: props.metadata,
58
+ errors,
59
+ });
60
+ if (localErrors.length) {
61
+ errors.push(...localErrors);
37
62
  return null;
63
+ }
64
+ return success;
65
+ })();
66
+ if (errors.length) {
67
+ props.project.errors.push(...errors);
68
+ return null;
69
+ } else if (success === null) return null;
70
+
71
+ // DO CONSTRUCT
72
+ const operation: IReflectHttpOperation = {
73
+ protocol: "http",
74
+ function: props.function,
75
+ name: props.name,
76
+ method: method === "ALL" ? "POST" : method,
77
+ paths: ReflectMetadataAnalyzer.paths(props.function).filter((str) => {
78
+ if (str.includes("*") === true) {
79
+ props.project.warnings.push({
80
+ file: props.controller.file,
81
+ class: props.controller.class.name,
82
+ function: props.name,
83
+ from: "",
84
+ contents: ["@nestia/sdk does not compose wildcard method."],
85
+ });
86
+ return false;
87
+ }
88
+ return true;
89
+ }),
90
+ versions: ReflectMetadataAnalyzer.versions(props.function),
91
+ parameters,
92
+ success,
93
+ security: ReflectMetadataAnalyzer.securities(props.function),
94
+ exceptions: {} as any,
95
+ tags: Reflect.getMetadata("swagger/apiUseTags", props.function) ?? [],
96
+ imports: ImportAnalyzer.unique(
97
+ [
98
+ ...props.metadata.parameters
99
+ .filter((x) => parameters.some((y) => x.index === y.index))
100
+ .map((x) => x.imports),
101
+ ...props.metadata.success.imports,
102
+ ].flat(),
103
+ ),
104
+ description: props.metadata.description,
105
+ jsDocTags: props.metadata.jsDocTags,
106
+ operationId: props.metadata.jsDocTags
107
+ .find(({ name }) => name === "operationId")
108
+ ?.text?.[0].text.split(" ")[0]
109
+ .trim(),
110
+ };
38
111
 
39
- const errors: IErrorReport[] = [];
40
-
41
- //----
42
- // CONSTRUCTION
43
- //----
44
- // BASIC INFO
45
- const encrypted: boolean = hasInterceptor("EncryptedRouteInterceptor")(
46
- props.function,
47
- );
48
- const query: boolean = hasInterceptor("TypedQueryRouteInterceptor")(
49
- props.function,
50
- );
51
- const method: string =
52
- METHODS[Reflect.getMetadata(METHOD_METADATA, props.function)];
53
- if (method === undefined || method === "OPTIONS") return null;
54
-
55
- const parameters: IReflectHttpOperation.IParameter[] = (() => {
56
- const nestParameters: NestParameters | undefined = Reflect.getMetadata(
57
- ROUTE_ARGS_METADATA,
58
- props.controller.constructor,
59
- props.name,
112
+ // VALIDATE PATH ARGUMENTS
113
+ for (const controllerLocation of props.controller.paths)
114
+ for (const metaLocation of operation.paths) {
115
+ // NORMALIZE LOCATION
116
+ const location: string = PathAnalyzer.join(
117
+ controllerLocation,
118
+ metaLocation,
60
119
  );
61
- if (nestParameters === undefined) return [];
62
-
63
- const output: IReflectHttpOperation.IParameter[] = [];
64
- for (const tuple of Object.entries(nestParameters)) {
65
- const child: IReflectHttpOperation.IParameter | null =
66
- _Analyze_http_parameter(...tuple);
67
- if (child !== null) output.push(child);
120
+ if (location.includes("*")) continue;
121
+
122
+ // LIST UP PARAMETERS
123
+ const binded: string[] | null = PathAnalyzer.parameters(location);
124
+ if (binded === null) {
125
+ props.project.errors.push({
126
+ file: props.controller.file,
127
+ class: props.controller.class.name,
128
+ function: props.name,
129
+ from: "{parameters}",
130
+ contents: [`invalid path (${JSON.stringify(location)})`],
131
+ });
132
+ continue;
68
133
  }
69
- const examples: SwaggerExample.IData<any>[] =
70
- Reflect.getMetadata(
71
- "nestia/SwaggerExample/Parameters",
72
- props.controller.prototype,
73
- props.name,
74
- ) ?? [];
75
- for (const p of output) {
76
- const e = examples.find((elem) => elem.index === p.index);
77
- if (e !== undefined) {
78
- p.example = e.example;
79
- p.examples = e.examples;
80
- }
81
- }
82
- return output.sort((x, y) => x.index - y.index);
83
- })();
84
-
85
- // VALIDATE BODY
86
- const body: IReflectHttpOperation.IParameter | undefined =
87
- parameters.find((param) => param.category === "body");
88
- if (body !== undefined && (method === "GET" || method === "HEAD")) {
89
- project.errors.push({
90
- file: props.controller.file,
91
- controller: props.controller.name,
92
- function: props.name,
93
- message: `"body" parameter cannot be used in the "${method}" method.`,
94
- });
95
- return null;
96
- }
97
-
98
- // DO CONSTRUCT
99
- const example: SwaggerExample.IData<any> | undefined =
100
- Reflect.getMetadata("nestia/SwaggerExample/Response", props.function);
101
- const meta: IReflectHttpOperation = {
102
- protocol: "http",
103
- function: props.function,
104
- name: props.name,
105
- method: method === "ALL" ? "POST" : method,
106
- paths: ReflectMetadataAnalyzer.paths(props.function).filter((str) => {
107
- if (str.includes("*") === true) {
108
- project.warnings.push({
109
- file: props.controller.file,
110
- controller: props.controller.name,
111
- function: props.name,
112
- message: "@nestia/sdk does not compose wildcard method.",
113
- });
114
- return false;
115
- }
116
- return true;
117
- }),
118
- versions: ReflectMetadataAnalyzer.versions(props.function),
119
- parameters,
120
- status: Reflect.getMetadata(HTTP_CODE_METADATA, props.function),
121
- encrypted,
122
- contentType: encrypted
123
- ? "text/plain"
124
- : query
125
- ? "application/x-www-form-urlencoded"
126
- : Reflect.getMetadata(HEADERS_METADATA, props.function)?.find(
127
- (h: Record<string, string>) =>
128
- typeof h?.name === "string" &&
129
- typeof h?.value === "string" &&
130
- h.name.toLowerCase() === "content-type",
131
- )?.value ?? "application/json",
132
- security: ReflectMetadataAnalyzer.securities(props.function),
133
- exceptions: ReflectMetadataAnalyzer.exceptions(props.function),
134
- swaggerTags: [
135
- ...new Set([
136
- ...props.controller.swaggerTgas,
137
- ...(Reflect.getMetadata("swagger/apiUseTags", props.function) ??
138
- []),
139
- ]),
140
- ],
141
- ...(example
142
- ? { example: example.example, examples: example.examples }
143
- : {}),
144
- };
145
-
146
- // VALIDATE PATH ARGUMENTS
147
- for (const controllerLocation of props.controller.paths)
148
- for (const metaLocation of meta.paths) {
149
- // NORMALIZE LOCATION
150
- const location: string = PathAnalyzer.join(
151
- controllerLocation,
152
- metaLocation,
153
- );
154
- if (location.includes("*")) continue;
155
-
156
- // LIST UP PARAMETERS
157
- const binded: string[] | null = PathAnalyzer.parameters(location);
158
- if (binded === null) {
159
- project.errors.push({
160
- file: props.controller.file,
161
- controller: props.controller.name,
162
- function: props.name,
163
- message: `invalid path (${JSON.stringify(location)})`,
164
- });
165
- continue;
166
- }
167
- const parameters: string[] = meta.parameters
168
- .filter((param) => param.category === "param")
169
- .map((param) => param.field!)
170
- .sort();
171
-
172
- // DO VALIDATE
173
- if (ranges.equal(binded.sort(), parameters) === false)
174
- errors.push({
175
- file: props.controller.file,
176
- controller: props.controller.name,
177
- function: props.name,
178
- message: `binded arguments in the "path" between function's decorator and parameters' decorators are different (function: [${binded.join(
134
+ const parameters: string[] = operation.parameters
135
+ .filter((param) => param.category === "param")
136
+ .map((param) => param.field!)
137
+ .sort();
138
+
139
+ // DO VALIDATE
140
+ if (ranges.equal(binded.sort(), parameters) === false)
141
+ errors.push({
142
+ file: props.controller.file,
143
+ class: props.controller.class.name,
144
+ function: props.name,
145
+ from: "{parameters}",
146
+ contents: [
147
+ `binded arguments in the "path" between function's decorator and parameters' decorators are different (function: [${binded.join(
179
148
  ", ",
180
149
  )}], parameters: [${parameters.join(", ")}]).`,
181
- });
182
- }
183
-
184
- // RETURNS
185
- if (errors.length) {
186
- project.errors.push(...errors);
187
- return null;
150
+ ],
151
+ });
188
152
  }
189
- return meta;
190
- };
191
-
192
- function _Analyze_http_parameter(
193
- key: string,
194
- param: INestParam,
195
- ): IReflectHttpOperation.IParameter | null {
196
- const symbol: string = key.split(":")[0];
197
- if (symbol.indexOf("__custom") !== -1)
198
- return _Analyze_http_custom_parameter(param);
199
-
200
- const typeIndex: RouteParamtypes = Number(symbol[0]) as RouteParamtypes;
201
- if (isNaN(typeIndex) === true) return null;
202
-
203
- const type: ParamCategory | undefined = getNestParamType(typeIndex);
204
- if (type === undefined) return null;
205
-
206
- return {
207
- custom: false,
208
- name: key,
209
- category: type,
210
- index: param.index,
211
- field: param.data,
212
- };
213
- }
214
153
 
215
- function _Analyze_http_custom_parameter(
216
- param: INestParam,
217
- ): IReflectHttpOperation.IParameter | null {
218
- if (param.factory === undefined) return null;
219
- else if (
220
- param.factory.name === "EncryptedBody" ||
221
- param.factory.name === "PlainBody" ||
222
- param.factory.name === "TypedQueryBody" ||
223
- param.factory.name === "TypedBody" ||
224
- param.factory.name === "TypedFormDataBody"
225
- )
226
- return {
227
- custom: true,
228
- category: "body",
229
- index: param.index,
230
- name: param.name,
231
- field: param.data,
232
- encrypted: param.factory.name === "EncryptedBody",
233
- contentType:
234
- param.factory.name === "PlainBody" ||
235
- param.factory.name === "EncryptedBody"
236
- ? "text/plain"
237
- : param.factory.name === "TypedQueryBody"
238
- ? "application/x-www-form-urlencoded"
239
- : param.factory.name === "TypedFormDataBody"
240
- ? "multipart/form-data"
241
- : "application/json",
242
- };
243
- else if (param.factory.name === "TypedHeaders")
244
- return {
245
- custom: true,
246
- category: "headers",
247
- name: param.name,
248
- index: param.index,
249
- field: param.data,
250
- };
251
- else if (param.factory.name === "TypedParam")
252
- return {
253
- custom: true,
254
- category: "param",
255
- name: param.name,
256
- index: param.index,
257
- field: param.data,
258
- };
259
- else if (param.factory.name === "TypedQuery")
260
- return {
261
- custom: true,
262
- name: param.name,
263
- category: "query",
264
- index: param.index,
265
- field: undefined,
266
- };
267
- else return null;
268
- }
269
- }
270
-
271
- interface INestParam {
272
- name: string;
273
- index: number;
274
- factory?: (...args: any) => any;
275
- data: string | undefined;
276
- }
277
-
278
- type NestParameters = {
279
- [key: string]: INestParam;
280
- };
281
-
282
- const hasInterceptor =
283
- (name: string) =>
284
- (proto: any): boolean => {
285
- const meta = Reflect.getMetadata(INTERCEPTORS_METADATA, proto);
286
- if (Array.isArray(meta) === false) return false;
287
- return meta.some((elem) => elem?.constructor?.name === name);
154
+ // RETURNS
155
+ if (errors.length) {
156
+ props.project.errors.push(...errors);
157
+ return null;
158
+ }
159
+ return operation;
288
160
  };
289
-
290
- // https://github.com/nestjs/nest/blob/master/packages/common/enums/route-paramtypes.enum.ts
291
- const getNestParamType = (value: RouteParamtypes) => {
292
- if (value === RouteParamtypes.BODY) return "body";
293
- else if (value === RouteParamtypes.HEADERS) return "headers";
294
- else if (value === RouteParamtypes.QUERY) return "query";
295
- else if (value === RouteParamtypes.PARAM) return "param";
296
- return undefined;
297
- };
161
+ }
298
162
 
299
163
  // node_modules/@nestjs/common/lib/enums/request-method.enum.ts
300
164
  const METHODS = [