@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,29 +1,31 @@
1
- import transform from "@nestia/core/lib/transform";
2
1
  import fs from "fs";
3
2
  import path from "path";
4
- import ts from "typescript";
3
+ import { HashSet, Pair, TreeMap } from "tstl";
4
+ import { IMetadataDictionary } from "typia/lib/schemas/metadata/IMetadataDictionary";
5
5
 
6
6
  import { INestiaConfig } from "./INestiaConfig";
7
7
  import { AccessorAnalyzer } from "./analyses/AccessorAnalyzer";
8
8
  import { ConfigAnalyzer } from "./analyses/ConfigAnalyzer";
9
+ import { PathAnalyzer } from "./analyses/PathAnalyzer";
9
10
  import { ReflectControllerAnalyzer } from "./analyses/ReflectControllerAnalyzer";
10
- import { TypedControllerAnalyzer } from "./analyses/TypedControllerAnalyzer";
11
+ import { TypedHttpRouteAnalyzer } from "./analyses/TypedHttpRouteAnalyzer";
12
+ import { TypedWebSocketRouteAnalyzer } from "./analyses/TypedWebSocketRouteAnalyzer";
11
13
  import { E2eGenerator } from "./generates/E2eGenerator";
12
14
  import { OpenAiGenerator } from "./generates/OpenAiGenerator";
13
15
  import { SdkGenerator } from "./generates/SdkGenerator";
14
16
  import { SwaggerGenerator } from "./generates/SwaggerGenerator";
15
- import { IErrorReport } from "./structures/IErrorReport";
16
17
  import { INestiaProject } from "./structures/INestiaProject";
17
18
  import { IReflectController } from "./structures/IReflectController";
19
+ import { IReflectOperationError } from "./structures/IReflectOperationError";
20
+ import { ITypedApplication } from "./structures/ITypedApplication";
18
21
  import { ITypedHttpRoute } from "./structures/ITypedHttpRoute";
19
22
  import { ITypedWebSocketRoute } from "./structures/ITypedWebSocketRoute";
20
- import { MapUtil } from "./utils/MapUtil";
23
+ import { IOperationMetadata } from "./transformers/IOperationMetadata";
24
+ import { StringUtil } from "./utils/StringUtil";
25
+ import { VersioningStrategy } from "./utils/VersioningStrategy";
21
26
 
22
27
  export class NestiaSdkApplication {
23
- public constructor(
24
- private readonly config: INestiaConfig,
25
- private readonly compilerOptions: ts.CompilerOptions,
26
- ) {}
28
+ public constructor(private readonly config: INestiaConfig) {}
27
29
 
28
30
  public async e2e(): Promise<void> {
29
31
  if (!this.config.output)
@@ -49,11 +51,11 @@ export class NestiaSdkApplication {
49
51
  await validate("e2e")(this.config.e2e);
50
52
 
51
53
  print_title("Nestia E2E Generator");
52
- await this.generate((project) => async (routes) => {
53
- await SdkGenerator.generate(project)(routes);
54
- await E2eGenerator.generate(project)(
55
- routes.filter((r) => r.protocol === "http") as ITypedHttpRoute[],
56
- );
54
+ await this.generate({
55
+ generate: async (app) => {
56
+ await SdkGenerator.generate(app);
57
+ await E2eGenerator.generate(app);
58
+ },
57
59
  });
58
60
  }
59
61
 
@@ -71,7 +73,10 @@ export class NestiaSdkApplication {
71
73
  );
72
74
 
73
75
  print_title("Nestia SDK Generator");
74
- await this.generate(SdkGenerator.generate);
76
+ await this.generate({
77
+ generate: SdkGenerator.generate,
78
+ validate: SdkGenerator.validate,
79
+ });
75
80
  }
76
81
 
77
82
  public async swagger(): Promise<void> {
@@ -91,7 +96,9 @@ export class NestiaSdkApplication {
91
96
  );
92
97
 
93
98
  print_title("Nestia Swagger Generator");
94
- await this.generate(SwaggerGenerator.generate);
99
+ await this.generate({
100
+ generate: SwaggerGenerator.generate,
101
+ });
95
102
  }
96
103
 
97
104
  public async openai(): Promise<void> {
@@ -111,21 +118,19 @@ export class NestiaSdkApplication {
111
118
  );
112
119
 
113
120
  print_title("Nestia OpenAI Function Calling Schema Generator");
114
- await this.generate(OpenAiGenerator.generate);
121
+ await this.generate({
122
+ generate: OpenAiGenerator.generate,
123
+ });
115
124
  }
116
125
 
117
- private async generate(
118
- archiver: (
119
- project: INestiaProject,
120
- ) => (
121
- routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>,
122
- ) => Promise<void>,
123
- ): Promise<void> {
126
+ private async generate(props: {
127
+ generate: (app: ITypedApplication) => Promise<void>;
128
+ validate?: (app: ITypedApplication) => IReflectOperationError[];
129
+ }): Promise<void> {
124
130
  //----
125
131
  // ANALYZE REFLECTS
126
132
  //----
127
133
  const unique: WeakSet<any> = new WeakSet();
128
- const controllers: IReflectController[] = [];
129
134
  const project: INestiaProject = {
130
135
  config: this.config,
131
136
  input: await ConfigAnalyzer.input(this.config),
@@ -135,28 +140,36 @@ export class NestiaSdkApplication {
135
140
  };
136
141
 
137
142
  console.log("Analyzing reflections");
138
- await turnTransformError(false);
139
- for (const include of (await ConfigAnalyzer.input(this.config)).include)
140
- controllers.push(
141
- ...(await ReflectControllerAnalyzer.analyze(project)(
142
- unique,
143
- include.file,
144
- include.paths,
145
- include.controller,
146
- )),
147
- );
148
- await turnTransformError(true);
143
+ const controllers: IReflectController[] = project.input.controllers
144
+ .map((c) =>
145
+ ReflectControllerAnalyzer.analyze({ project, controller: c, unique }),
146
+ )
147
+ .filter((c): c is IReflectController => c !== null);
148
+
149
+ if (project.warnings.length)
150
+ report({
151
+ type: "warning",
152
+ errors: project.warnings,
153
+ });
154
+ if (project.errors.length)
155
+ return report({
156
+ type: "error",
157
+ errors: project.errors,
158
+ });
149
159
 
150
160
  const agg: number = (() => {
151
- const set: Set<string> = new Set();
152
- for (const c of controllers)
153
- for (const cPath of c.paths)
154
- for (const op of c.operations)
155
- for (const fPath of op.paths)
156
- set.add(
157
- `${op.protocol === "http" ? `${op.method}::` : ""}${cPath}/${fPath}`,
161
+ const set: HashSet<Pair<string, string>> = new HashSet();
162
+ for (const controller of controllers)
163
+ for (const controllerPath of controller.paths)
164
+ for (const operation of controller.operations)
165
+ for (const operationPath of operation.paths)
166
+ set.insert(
167
+ new Pair(
168
+ `${controllerPath}/${operationPath}`,
169
+ operation.protocol === "http" ? operation.method : "",
170
+ ),
158
171
  );
159
- return set.size;
172
+ return set.size();
160
173
  })();
161
174
 
162
175
  console.log(` - controllers: #${controllers.length}`);
@@ -174,82 +187,64 @@ export class NestiaSdkApplication {
174
187
  //----
175
188
  // ANALYZE TYPESCRIPT CODE
176
189
  //----
177
- console.log("Analyzing source codes");
178
-
179
- const program: ts.Program = ts.createProgram(
180
- controllers.map((c) => c.file),
181
- this.compilerOptions,
182
- );
183
- project.checker = program.getTypeChecker();
184
-
185
- const diagnostics: ts.Diagnostic[] = [];
186
- ts.transform(
187
- program
188
- .getSourceFiles()
189
- .filter((file) => false === file.isDeclarationFile),
190
- [
191
- transform(
192
- program,
193
- ((this.compilerOptions.plugins as any) ?? []).find(
194
- (p: any) => p.transform === "@nestia/core/lib/transform",
195
- ) ?? {},
196
- {
197
- addDiagnostic: (diag) => diagnostics.push(diag),
198
- },
199
- ),
200
- ],
201
- program.getCompilerOptions(),
202
- );
203
-
204
- const routeList: Array<ITypedHttpRoute | ITypedWebSocketRoute> = [];
205
- for (const c of controllers) {
206
- const file: ts.SourceFile | undefined = program.getSourceFile(c.file);
207
- if (file === undefined) continue;
208
- routeList.push(
209
- ...(await TypedControllerAnalyzer.analyze(project)(file, c)),
210
- );
211
- }
212
-
213
- // TRACE ERRORS
214
- for (const diag of diagnostics) {
215
- const file: string = diag.file
216
- ? path.relative(diag.file.fileName, process.cwd())
217
- : "(unknown file)";
218
- const category: string =
219
- diag.category === ts.DiagnosticCategory.Warning
220
- ? "warning"
221
- : diag.category === ts.DiagnosticCategory.Error
222
- ? "error"
223
- : diag.category === ts.DiagnosticCategory.Suggestion
224
- ? "suggestion"
225
- : diag.category === ts.DiagnosticCategory.Message
226
- ? "message"
227
- : "unkown";
228
- const [line, pos] = diag.file
229
- ? (() => {
230
- const lines: string[] = diag
231
- .file!.text.substring(0, diag.start)
232
- .split("\n");
233
- if (lines.length === 0) return [0, 0];
234
- return [lines.length, lines.at(-1)!.length + 1];
235
- })()
236
- : [0, 0];
237
- console.error(
238
- `${file}:${line}:${pos} - ${category} TS${diag.code}: ${diag.messageText}`,
239
- );
240
- }
241
- if (diagnostics.length) process.exit(-1);
242
-
243
- // REPORT ERRORS
244
- if (project.errors.length) {
245
- report_errors("error")(project.errors);
246
- process.exit(-1);
247
- }
248
- if (project.warnings.length) report_errors("warning")(project.warnings);
249
-
250
- // DO GENERATE
251
- AccessorAnalyzer.analyze(routeList);
252
- await archiver(project)(routeList);
190
+ console.log("Analyzing soure codes");
191
+
192
+ // METADATA COMPONENTS
193
+ const collection: IMetadataDictionary =
194
+ TypedHttpRouteAnalyzer.dictionary(controllers);
195
+
196
+ // CONVERT TO TYPED OPERATIONS
197
+ const globalPrefix: string = project.input.globalPrefix?.prefix ?? "";
198
+ const routes: Array<ITypedHttpRoute | ITypedWebSocketRoute> = [];
199
+ for (const c of controllers)
200
+ for (const o of c.operations) {
201
+ const pathList: Set<string> = new Set();
202
+ const versions: string[] = VersioningStrategy.merge(project)([
203
+ ...(c.versions ?? []),
204
+ ...(o.versions ?? []),
205
+ ]);
206
+ for (const v of versions)
207
+ for (const prefix of wrapPaths(c.prefixes))
208
+ for (const cPath of wrapPaths(c.paths))
209
+ for (const filePath of wrapPaths(o.paths))
210
+ pathList.add(
211
+ PathAnalyzer.join(globalPrefix, v, prefix, cPath, filePath),
212
+ );
213
+ if (o.protocol === "http")
214
+ routes.push(
215
+ ...TypedHttpRouteAnalyzer.analyze({
216
+ controller: c,
217
+ errors: project.errors,
218
+ dictionary: collection,
219
+ operation: o,
220
+ paths: Array.from(pathList),
221
+ }),
222
+ );
223
+ else if (o.protocol === "websocket")
224
+ routes.push(
225
+ ...TypedWebSocketRouteAnalyzer.analyze({
226
+ controller: c,
227
+ operation: o,
228
+ paths: Array.from(pathList),
229
+ }),
230
+ );
231
+ }
232
+ AccessorAnalyzer.analyze(routes);
233
+
234
+ if (props.validate !== undefined)
235
+ props.validate({
236
+ project,
237
+ routes,
238
+ });
239
+ if (project.errors.length)
240
+ return report({
241
+ type: "error",
242
+ errors: project.errors,
243
+ });
244
+ await props.generate({
245
+ project,
246
+ routes,
247
+ });
253
248
  }
254
249
  }
255
250
 
@@ -275,44 +270,62 @@ const print_title = (str: string): void => {
275
270
  // return true;
276
271
  // };
277
272
 
278
- const report_errors =
279
- (type: "error" | "warning") =>
280
- (errors: IErrorReport[]): void => {
281
- // key: file
282
- // key: controller
283
- // key: function
284
- // value: message
285
- const map: Map<string, Map<string, Map<string, Set<string>>>> = new Map();
286
- for (const e of errors) {
287
- const file = MapUtil.take(map, e.file, () => new Map());
288
- const controller = MapUtil.take(file, e.controller, () => new Map());
289
- const func = MapUtil.take(controller, e.function, () => new Set());
290
- func.add(e.message);
291
- }
292
-
293
- console.log("");
294
- print_title(`Nestia ${type[0].toUpperCase()}${type.slice(1)} Report`);
295
- for (const [file, cMap] of map) {
296
- for (const [controller, fMap] of cMap)
297
- for (const [func, messages] of fMap) {
298
- const location: string = path.relative(process.cwd(), file);
299
- console.log(
300
- `${location} - ${
301
- func !== null ? `${controller}.${func}()` : controller
302
- }`,
303
- );
304
- for (const msg of messages) console.log(` - ${msg}`);
305
- console.log("");
306
- }
307
- }
308
- };
309
-
310
- // const VARIABLE = /[a-zA-Z_$0-9]/;
311
- const turnTransformError = async (flag: boolean): Promise<void> => {
312
- try {
313
- const modulo = await import(
314
- "@nestia/core/lib/decorators/internal/NoTransformConfigureError" as string
315
- );
316
- modulo.NoTransformConfigureError.throws = flag;
317
- } catch {}
273
+ const report = (props: {
274
+ type: "error" | "warning";
275
+ errors: IReflectOperationError[];
276
+ }): void => {
277
+ const map: TreeMap<
278
+ IReflectOperationError.Key,
279
+ Array<string | IOperationMetadata.IError>
280
+ > = new TreeMap();
281
+ for (const e of props.errors)
282
+ map.take(new IReflectOperationError.Key(e), () => []).push(...e.contents);
283
+
284
+ console.log("");
285
+ print_title(`Nestia ${StringUtil.capitalize(props.type)} Report`);
286
+
287
+ for (const {
288
+ first: { error },
289
+ second: contents,
290
+ } of map) {
291
+ if (error.contents.length === 0) continue;
292
+ const location: string = path.relative(process.cwd(), error.file);
293
+ const message: string = [
294
+ `${location} - `,
295
+ error.class,
296
+ ...(error.function !== null ? [`.${error.function}()`] : [""]),
297
+ ...(error.from !== null ? [` from ${error.from}`] : [""]),
298
+ ":\n",
299
+ contents
300
+ .map((c) => {
301
+ if (typeof c === "string") return ` - ${c}`;
302
+ else
303
+ return [
304
+ c.accessor
305
+ ? ` - ${c.name}: `
306
+ : ` - ${c.name} (${c.accessor}): `,
307
+ ...c.messages.map((msg) => ` - ${msg}`),
308
+ ].join("\n");
309
+ })
310
+ .join("\n"),
311
+ ].join("");
312
+ console.log(message);
313
+ }
314
+
315
+ // for (const [file, cMap] of map) {
316
+ // for (const [controller, fMap] of cMap)
317
+ // for (const [func, messages] of fMap) {
318
+ // const location: string = path.relative(process.cwd(), file);
319
+ // console.log(
320
+ // `${location} - ${
321
+ // func !== null ? `${controller}.${func}()` : controller
322
+ // }`,
323
+ // );
324
+ // for (const msg of messages) console.log(` - ${msg}`);
325
+ // console.log("");
326
+ // }
327
+ // }
318
328
  };
329
+
330
+ const wrapPaths = (paths: string[]): string[] =>
331
+ paths.length === 0 ? [""] : paths;
@@ -1,44 +1,43 @@
1
1
  /// <reference path="../typings/get-function-location.d.ts" />
2
+ import { DynamicModule } from "@nestia/core";
2
3
  import { INestApplication, VersioningType } from "@nestjs/common";
3
4
  import { MODULE_PATH } from "@nestjs/common/constants";
4
- import { NestContainer } from "@nestjs/core";
5
+ import { NestContainer, NestFactory } from "@nestjs/core";
5
6
  import { Module } from "@nestjs/core/injector/module";
6
- import fs from "fs";
7
7
  import getFunctionLocation from "get-function-location";
8
- import path from "path";
9
- import { HashMap, Pair, Singleton } from "tstl";
8
+ import { HashMap } from "tstl";
10
9
 
11
10
  import { INestiaConfig } from "../INestiaConfig";
12
- import { SdkGenerator } from "../generates/SdkGenerator";
13
- import { INormalizedInput } from "../structures/INormalizedInput";
14
- import { ArrayUtil } from "../utils/ArrayUtil";
11
+ import { INestiaSdkInput } from "../structures/INestiaSdkInput";
15
12
  import { MapUtil } from "../utils/MapUtil";
16
- import { SourceFinder } from "../utils/SourceFinder";
17
13
 
18
14
  export namespace ConfigAnalyzer {
19
- export const input = (config: INestiaConfig): Promise<INormalizedInput> =>
20
- MapUtil.take(memory, config, async () => {
21
- const input = config.input;
22
- if (Array.isArray(input)) return transform_input(config)(input);
23
- else if (typeof input === "function")
24
- return analyze_application(await input());
25
- else if (typeof input === "object")
26
- if (input === null)
27
- throw new Error("Invalid input config. It can't be null.");
28
- else return transform_input(config)(input.include, input.exclude);
29
- else if (typeof input === "string")
30
- return transform_input(config)([input]);
31
- else throw new Error("Invalid input config.");
15
+ export const input = async (
16
+ config: INestiaConfig,
17
+ ): Promise<INestiaSdkInput> => {
18
+ return MapUtil.take(memory, config, async () => {
19
+ const app: INestApplication =
20
+ typeof config.input === "function"
21
+ ? await config.input()
22
+ : await NestFactory.create(
23
+ await DynamicModule.mount(config.input, {}, true as any),
24
+ {
25
+ logger: false,
26
+ },
27
+ );
28
+ return analyze_application(app);
32
29
  });
30
+ };
33
31
 
34
32
  const analyze_application = async (
35
33
  app: INestApplication,
36
- ): Promise<INormalizedInput> => {
37
- const files: HashMap<Pair<Function, string>, Set<string>> = new HashMap();
34
+ ): Promise<INestiaSdkInput> => {
38
35
  const container: NestContainer = (app as any).container as NestContainer;
39
36
  const modules: Module[] = [...container.getModules().values()].filter(
40
37
  (m) => !!m.controllers.size,
41
38
  );
39
+ const unique: HashMap<Function, Set<string>> = new HashMap();
40
+
42
41
  for (const m of modules) {
43
42
  const path: string =
44
43
  Reflect.getMetadata(
@@ -47,29 +46,28 @@ export namespace ConfigAnalyzer {
47
46
  ) ??
48
47
  Reflect.getMetadata(MODULE_PATH, m.metatype) ??
49
48
  "";
50
- for (const controller of [...m.controllers.keys()]) {
51
- const file: string | null =
52
- (await getFunctionLocation(controller))?.source ?? null;
53
- if (file === null) continue;
54
-
55
- const location: string = normalize_file(file);
56
- if (location.length === 0) continue;
57
-
58
- const key: Pair<Function, string> = new Pair(
59
- controller as Function,
60
- location,
61
- );
62
- files.take(key, () => new Set([])).add(path);
63
- }
49
+ for (const controller of [...m.controllers.keys()])
50
+ if (typeof controller === "function")
51
+ unique.take(controller, () => new Set()).add(path);
52
+ }
53
+ const controllers: INestiaSdkInput.IController[] = [];
54
+ for (const it of unique) {
55
+ const file: string | null =
56
+ (await getFunctionLocation(it.first))?.source ?? null;
57
+ if (file === null) continue;
58
+ const location: string = normalize_file(file);
59
+ if (location.length === 0) continue;
60
+ controllers.push({
61
+ class: it.first,
62
+ prefixes: Array.from(it.second),
63
+ location,
64
+ });
64
65
  }
65
66
 
66
67
  const versioning = (app as any).config?.versioningOptions;
67
68
  return {
68
- include: files.toJSON().map((pair) => ({
69
- controller: pair.first.first,
70
- file: decodeURIComponent(pair.first.second),
71
- paths: [...pair.second.values()],
72
- })),
69
+ application: app,
70
+ controllers,
73
71
  globalPrefix:
74
72
  typeof (app as any).config?.globalPrefix === "string"
75
73
  ? {
@@ -89,61 +87,15 @@ export namespace ConfigAnalyzer {
89
87
  },
90
88
  };
91
89
  };
92
-
93
- const normalize_file = (str: string) =>
94
- str.substring(
95
- str.startsWith("file:///")
96
- ? process.cwd()[0] === "/"
97
- ? 7
98
- : 8
99
- : str.startsWith("file://")
100
- ? 7
101
- : 0,
102
- );
103
-
104
- const transform_input =
105
- (config: INestiaConfig) =>
106
- async (include: string[], exclude?: string[]) => ({
107
- include: (
108
- await SourceFinder.find({
109
- include,
110
- exclude,
111
- filter: filter(config),
112
- })
113
- ).map((file) => ({
114
- paths: [""],
115
- file,
116
- })),
117
- });
118
-
119
- const filter =
120
- (config: INestiaConfig) =>
121
- async (location: string): Promise<boolean> =>
122
- location.endsWith(".ts") &&
123
- !location.endsWith(".d.ts") &&
124
- (config.output === undefined ||
125
- (location.indexOf(path.join(config.output, "functional")) === -1 &&
126
- (await (
127
- await bundler.get(config.output)
128
- )(location))) === false);
129
90
  }
130
-
131
- const memory = new Map<INestiaConfig, Promise<INormalizedInput>>();
132
- const bundler = new Singleton(async (output: string) => {
133
- const assets: string[] = await fs.promises.readdir(SdkGenerator.BUNDLE_PATH);
134
- const tuples: Pair<string, boolean>[] = await ArrayUtil.asyncMap(
135
- assets,
136
- async (file) => {
137
- const relative: string = path.join(output, file);
138
- const location: string = path.join(SdkGenerator.BUNDLE_PATH, file);
139
- const stats: fs.Stats = await fs.promises.stat(location);
140
- return new Pair(relative, stats.isDirectory());
141
- },
91
+ const memory = new Map<INestiaConfig, Promise<INestiaSdkInput>>();
92
+ const normalize_file = (str: string) =>
93
+ str.substring(
94
+ str.startsWith("file:///")
95
+ ? process.cwd()[0] === "/"
96
+ ? 7
97
+ : 8
98
+ : str.startsWith("file://")
99
+ ? 7
100
+ : 0,
142
101
  );
143
- return async (file: string): Promise<boolean> => {
144
- for (const it of tuples)
145
- if (it.second === false && file === it.first) return true;
146
- else if (it.second === true && file.indexOf(it.first) === 0) return true;
147
- return false;
148
- };
149
- });