@nestia/sdk 3.10.0 → 3.11.0-dev.20240813

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/lib/NestiaSdkApplication.d.ts +1 -3
  2. package/lib/NestiaSdkApplication.js +138 -136
  3. package/lib/NestiaSdkApplication.js.map +1 -1
  4. package/lib/analyses/ConfigAnalyzer.d.ts +2 -2
  5. package/lib/analyses/ConfigAnalyzer.js +39 -80
  6. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  7. package/lib/analyses/ExceptionAnalyzer.d.ts +0 -16
  8. package/lib/analyses/ExceptionAnalyzer.js +142 -105
  9. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  10. package/lib/analyses/GenericAnalyzer.d.ts +1 -2
  11. package/lib/analyses/GenericAnalyzer.js.map +1 -1
  12. package/lib/analyses/ImportAnalyzer.d.ts +6 -11
  13. package/lib/analyses/ImportAnalyzer.js +70 -42
  14. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  15. package/lib/analyses/ReflectControllerAnalyzer.d.ts +7 -1
  16. package/lib/analyses/ReflectControllerAnalyzer.js +28 -99
  17. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  18. package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +6 -2
  19. package/lib/analyses/ReflectHttpOperationAnalyzer.js +72 -152
  20. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  21. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.d.ts +15 -0
  22. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +215 -0
  23. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -0
  24. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +15 -0
  25. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +81 -0
  26. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -0
  27. package/lib/analyses/ReflectMetadataAnalyzer.d.ts +1 -3
  28. package/lib/analyses/ReflectMetadataAnalyzer.js +0 -4
  29. package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -1
  30. package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +6 -2
  31. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +72 -48
  32. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
  33. package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +15 -0
  34. package/lib/analyses/TypedHttpRouteAnalyzer.js +111 -0
  35. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -0
  36. package/lib/analyses/TypedWebSocketRouteAnalyzer.d.ts +10 -0
  37. package/lib/analyses/TypedWebSocketRouteAnalyzer.js +9 -0
  38. package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -0
  39. package/lib/decorators/OperationMetadata.d.ts +2 -0
  40. package/lib/decorators/OperationMetadata.js +10 -0
  41. package/lib/decorators/OperationMetadata.js.map +1 -0
  42. package/lib/executable/internal/NestiaConfigLoader.d.ts +1 -1
  43. package/lib/executable/internal/NestiaConfigLoader.js +34 -3
  44. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  45. package/lib/executable/internal/NestiaSdkCommand.js +1 -1
  46. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  47. package/lib/generates/CloneGenerator.d.ts +0 -5
  48. package/lib/generates/CloneGenerator.js +60 -60
  49. package/lib/generates/CloneGenerator.js.map +1 -1
  50. package/lib/generates/E2eGenerator.d.ts +2 -3
  51. package/lib/generates/E2eGenerator.js +9 -8
  52. package/lib/generates/E2eGenerator.js.map +1 -1
  53. package/lib/generates/OpenAiGenerator.d.ts +2 -4
  54. package/lib/generates/OpenAiGenerator.js +13 -3
  55. package/lib/generates/OpenAiGenerator.js.map +1 -1
  56. package/lib/generates/SdkGenerator.d.ts +4 -4
  57. package/lib/generates/SdkGenerator.js +63 -73
  58. package/lib/generates/SdkGenerator.js.map +1 -1
  59. package/lib/generates/SwaggerGenerator.d.ts +6 -18
  60. package/lib/generates/SwaggerGenerator.js +60 -235
  61. package/lib/generates/SwaggerGenerator.js.map +1 -1
  62. package/lib/generates/internal/E2eFileProgrammer.js +5 -9
  63. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  64. package/lib/generates/internal/SdkAliasCollection.d.ts +6 -4
  65. package/lib/generates/internal/SdkAliasCollection.js +33 -31
  66. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  67. package/lib/generates/internal/SdkDistributionComposer.d.ts +4 -1
  68. package/lib/generates/internal/SdkDistributionComposer.js +6 -6
  69. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  70. package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -4
  71. package/lib/generates/internal/SdkFileProgrammer.js +6 -6
  72. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  73. package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +0 -12
  74. package/lib/generates/internal/SdkHttpCloneProgrammer.js +142 -97
  75. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  76. package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +4 -3
  77. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +37 -59
  78. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  79. package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +4 -3
  80. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +31 -48
  81. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  82. package/lib/generates/internal/SdkHttpRouteProgrammer.js +7 -3
  83. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  84. package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +4 -3
  85. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +7 -13
  86. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  87. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +1 -2
  88. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +11 -16
  89. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  90. package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +1 -2
  91. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +7 -10
  92. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  93. package/lib/generates/internal/SwaggerDescriptionComposer.d.ts +23 -0
  94. package/lib/generates/internal/SwaggerDescriptionComposer.js +44 -0
  95. package/lib/generates/internal/SwaggerDescriptionComposer.js.map +1 -0
  96. package/lib/generates/internal/SwaggerOperationComposer.d.ts +12 -0
  97. package/lib/generates/internal/SwaggerOperationComposer.js +68 -0
  98. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -0
  99. package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +18 -0
  100. package/lib/generates/internal/SwaggerOperationParameterComposer.js +99 -0
  101. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -0
  102. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +9 -0
  103. package/lib/generates/internal/SwaggerOperationResponseComposer.js +91 -0
  104. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -0
  105. package/lib/structures/INestiaProject.d.ts +5 -5
  106. package/lib/structures/INestiaSdkInput.d.ts +20 -0
  107. package/lib/structures/{ISwaggerError.js → INestiaSdkInput.js} +1 -1
  108. package/lib/structures/INestiaSdkInput.js.map +1 -0
  109. package/lib/structures/IReflectApplication.d.ts +6 -0
  110. package/lib/structures/IReflectApplication.js +3 -0
  111. package/lib/structures/IReflectApplication.js.map +1 -0
  112. package/lib/structures/IReflectController.d.ts +3 -5
  113. package/lib/structures/IReflectHttpOperation.d.ts +13 -65
  114. package/lib/structures/IReflectHttpOperationException.d.ts +14 -0
  115. package/lib/structures/IReflectHttpOperationException.js +3 -0
  116. package/lib/structures/IReflectHttpOperationException.js.map +1 -0
  117. package/lib/structures/IReflectHttpOperationParameter.d.ts +35 -0
  118. package/lib/structures/IReflectHttpOperationParameter.js +3 -0
  119. package/lib/structures/IReflectHttpOperationParameter.js.map +1 -0
  120. package/lib/structures/IReflectHttpOperationSuccess.d.ts +15 -0
  121. package/lib/structures/IReflectHttpOperationSuccess.js +3 -0
  122. package/lib/structures/IReflectHttpOperationSuccess.js.map +1 -0
  123. package/lib/structures/IReflectOperationError.d.ts +16 -0
  124. package/lib/structures/IReflectOperationError.js +23 -0
  125. package/lib/structures/IReflectOperationError.js.map +1 -0
  126. package/lib/structures/IReflectType.d.ts +4 -0
  127. package/lib/structures/{IErrorReport.js → IReflectType.js} +1 -1
  128. package/lib/structures/IReflectType.js.map +1 -0
  129. package/lib/structures/IReflectTypeImport.d.ts +4 -0
  130. package/lib/structures/{ISwaggerLazySchema.js → IReflectTypeImport.js} +1 -1
  131. package/lib/structures/IReflectTypeImport.js.map +1 -0
  132. package/lib/structures/IReflectWebSocketOperation.d.ts +8 -9
  133. package/lib/structures/IReflectWebSocketOperationParameter.d.ts +23 -0
  134. package/lib/structures/IReflectWebSocketOperationParameter.js +3 -0
  135. package/lib/structures/IReflectWebSocketOperationParameter.js.map +1 -0
  136. package/lib/structures/ITypedApplication.d.ts +7 -0
  137. package/lib/structures/{INormalizedInput.js → ITypedApplication.js} +1 -1
  138. package/lib/structures/ITypedApplication.js.map +1 -0
  139. package/lib/structures/ITypedHttpRoute.d.ts +14 -42
  140. package/lib/structures/ITypedHttpRouteException.d.ts +10 -0
  141. package/lib/structures/ITypedHttpRouteException.js +3 -0
  142. package/lib/structures/ITypedHttpRouteException.js.map +1 -0
  143. package/lib/structures/ITypedHttpRouteParameter.d.ts +31 -0
  144. package/lib/structures/ITypedHttpRouteParameter.js +3 -0
  145. package/lib/structures/ITypedHttpRouteParameter.js.map +1 -0
  146. package/lib/structures/ITypedHttpRouteSuccess.d.ts +19 -0
  147. package/lib/structures/{ISwaggerLazyProperty.js → ITypedHttpRouteSuccess.js} +1 -1
  148. package/lib/structures/ITypedHttpRouteSuccess.js.map +1 -0
  149. package/lib/structures/ITypedWebSocketRoute.d.ts +8 -44
  150. package/lib/structures/ITypedWebSocketRouteParameter.d.ts +2 -0
  151. package/lib/structures/ITypedWebSocketRouteParameter.js +3 -0
  152. package/lib/structures/ITypedWebSocketRouteParameter.js.map +1 -0
  153. package/lib/transform.d.ts +3 -0
  154. package/lib/transform.js +8 -0
  155. package/lib/transform.js.map +1 -0
  156. package/lib/transformers/IOperationMetadata.d.ts +36 -0
  157. package/lib/transformers/IOperationMetadata.js +3 -0
  158. package/lib/transformers/IOperationMetadata.js.map +1 -0
  159. package/lib/transformers/ISdkTransformerContext.d.ts +7 -0
  160. package/lib/transformers/ISdkTransformerContext.js +3 -0
  161. package/lib/transformers/ISdkTransformerContext.js.map +1 -0
  162. package/lib/transformers/SdkMetadataProgrammer.d.ts +11 -0
  163. package/lib/transformers/SdkMetadataProgrammer.js +159 -0
  164. package/lib/transformers/SdkMetadataProgrammer.js.map +1 -0
  165. package/lib/transformers/SdkTransformer.d.ts +4 -0
  166. package/lib/transformers/SdkTransformer.js +88 -0
  167. package/lib/transformers/SdkTransformer.js.map +1 -0
  168. package/lib/transformers/TextPlainValidator.d.ts +4 -0
  169. package/lib/transformers/TextPlainValidator.js +19 -0
  170. package/lib/transformers/TextPlainValidator.js.map +1 -0
  171. package/lib/utils/StringUtil.d.ts +1 -0
  172. package/lib/utils/StringUtil.js +1 -0
  173. package/lib/utils/StringUtil.js.map +1 -1
  174. package/package.json +8 -8
  175. package/src/NestiaSdkApplication.ts +173 -160
  176. package/src/analyses/ConfigAnalyzer.ts +50 -98
  177. package/src/analyses/ExceptionAnalyzer.ts +142 -142
  178. package/src/analyses/GenericAnalyzer.ts +3 -5
  179. package/src/analyses/ImportAnalyzer.ts +130 -115
  180. package/src/analyses/ReflectControllerAnalyzer.ts +63 -115
  181. package/src/analyses/ReflectHttpOperationAnalyzer.ts +142 -278
  182. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +319 -0
  183. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +117 -0
  184. package/src/analyses/ReflectMetadataAnalyzer.ts +1 -18
  185. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +143 -78
  186. package/src/analyses/TypedHttpRouteAnalyzer.ts +178 -0
  187. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +18 -0
  188. package/src/decorators/OperationMetadata.ts +15 -0
  189. package/src/executable/internal/NestiaConfigLoader.ts +18 -3
  190. package/src/executable/internal/NestiaSdkCommand.ts +1 -4
  191. package/src/generates/CloneGenerator.ts +60 -59
  192. package/src/generates/E2eGenerator.ts +20 -21
  193. package/src/generates/OpenAiGenerator.ts +44 -45
  194. package/src/generates/SdkGenerator.ts +97 -125
  195. package/src/generates/SwaggerGenerator.ts +114 -416
  196. package/src/generates/internal/E2eFileProgrammer.ts +5 -14
  197. package/src/generates/internal/SdkAliasCollection.ts +33 -41
  198. package/src/generates/internal/SdkDistributionComposer.ts +9 -6
  199. package/src/generates/internal/SdkFileProgrammer.ts +11 -14
  200. package/src/generates/internal/SdkHttpCloneProgrammer.ts +142 -142
  201. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +20 -47
  202. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +245 -275
  203. package/src/generates/internal/SdkHttpRouteProgrammer.ts +7 -7
  204. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +11 -23
  205. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +197 -233
  206. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +5 -15
  207. package/src/generates/internal/{SwaggerDescriptionGenerator.ts → SwaggerDescriptionComposer.ts} +25 -5
  208. package/src/generates/internal/SwaggerOperationComposer.ts +90 -0
  209. package/src/generates/internal/SwaggerOperationParameterComposer.ts +173 -0
  210. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -0
  211. package/src/structures/INestiaProject.ts +5 -5
  212. package/src/structures/INestiaSdkInput.ts +25 -0
  213. package/src/structures/IReflectApplication.ts +8 -0
  214. package/src/structures/IReflectController.ts +3 -5
  215. package/src/structures/IReflectHttpOperation.ts +14 -76
  216. package/src/structures/IReflectHttpOperationException.ts +19 -0
  217. package/src/structures/IReflectHttpOperationParameter.ts +81 -0
  218. package/src/structures/IReflectHttpOperationSuccess.ts +22 -0
  219. package/src/structures/IReflectOperationError.ts +26 -0
  220. package/src/structures/IReflectType.ts +4 -0
  221. package/src/structures/IReflectTypeImport.ts +4 -0
  222. package/src/structures/IReflectWebSocketOperation.ts +9 -9
  223. package/src/structures/IReflectWebSocketOperationParameter.ts +38 -0
  224. package/src/structures/ITypedApplication.ts +8 -0
  225. package/src/structures/ITypedHttpRoute.ts +15 -45
  226. package/src/structures/ITypedHttpRouteException.ts +15 -0
  227. package/src/structures/ITypedHttpRouteParameter.ts +41 -0
  228. package/src/structures/ITypedHttpRouteSuccess.ts +22 -0
  229. package/src/structures/ITypedWebSocketRoute.ts +8 -56
  230. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -0
  231. package/src/transform.ts +9 -0
  232. package/src/transformers/IOperationMetadata.ts +38 -0
  233. package/src/transformers/ISdkTransformerContext.ts +8 -0
  234. package/src/transformers/SdkMetadataProgrammer.ts +227 -0
  235. package/src/transformers/SdkTransformer.ts +168 -0
  236. package/src/transformers/TextPlainValidator.ts +17 -0
  237. package/src/utils/StringUtil.ts +3 -0
  238. package/lib/analyses/TypedControllerAnalyzer.d.ts +0 -8
  239. package/lib/analyses/TypedControllerAnalyzer.js +0 -77
  240. package/lib/analyses/TypedControllerAnalyzer.js.map +0 -1
  241. package/lib/analyses/TypedHttpOperationAnalyzer.d.ts +0 -15
  242. package/lib/analyses/TypedHttpOperationAnalyzer.js +0 -263
  243. package/lib/analyses/TypedHttpOperationAnalyzer.js.map +0 -1
  244. package/lib/analyses/TypedWebSocketOperationAnalyzer.d.ts +0 -15
  245. package/lib/analyses/TypedWebSocketOperationAnalyzer.js +0 -226
  246. package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +0 -1
  247. package/lib/generates/internal/SwaggerDescriptionGenerator.d.ts +0 -14
  248. package/lib/generates/internal/SwaggerDescriptionGenerator.js +0 -33
  249. package/lib/generates/internal/SwaggerDescriptionGenerator.js.map +0 -1
  250. package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +0 -21
  251. package/lib/generates/internal/SwaggerSchemaGenerator.js +0 -289
  252. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +0 -1
  253. package/lib/generates/internal/SwaggerSchemaValidator.d.ts +0 -7
  254. package/lib/generates/internal/SwaggerSchemaValidator.js +0 -191
  255. package/lib/generates/internal/SwaggerSchemaValidator.js.map +0 -1
  256. package/lib/structures/IErrorReport.d.ts +0 -6
  257. package/lib/structures/IErrorReport.js.map +0 -1
  258. package/lib/structures/INormalizedInput.d.ts +0 -19
  259. package/lib/structures/INormalizedInput.js.map +0 -1
  260. package/lib/structures/ISwaggerError.d.ts +0 -6
  261. package/lib/structures/ISwaggerError.js.map +0 -1
  262. package/lib/structures/ISwaggerLazyProperty.d.ts +0 -6
  263. package/lib/structures/ISwaggerLazyProperty.js.map +0 -1
  264. package/lib/structures/ISwaggerLazySchema.d.ts +0 -6
  265. package/lib/structures/ISwaggerLazySchema.js.map +0 -1
  266. package/lib/structures/ITypeTuple.d.ts +0 -5
  267. package/lib/structures/ITypeTuple.js +0 -3
  268. package/lib/structures/ITypeTuple.js.map +0 -1
  269. package/src/analyses/TypedControllerAnalyzer.ts +0 -92
  270. package/src/analyses/TypedHttpOperationAnalyzer.ts +0 -365
  271. package/src/analyses/TypedWebSocketOperationAnalyzer.ts +0 -375
  272. package/src/generates/internal/SwaggerSchemaGenerator.ts +0 -473
  273. package/src/generates/internal/SwaggerSchemaValidator.ts +0 -206
  274. package/src/structures/IErrorReport.ts +0 -6
  275. package/src/structures/INormalizedInput.ts +0 -20
  276. package/src/structures/ISwaggerError.ts +0 -8
  277. package/src/structures/ISwaggerLazyProperty.ts +0 -7
  278. package/src/structures/ISwaggerLazySchema.ts +0 -7
  279. package/src/structures/ITypeTuple.ts +0 -6
@@ -3,32 +3,31 @@ import path from "path";
3
3
 
4
4
  import { ConfigAnalyzer } from "../analyses/ConfigAnalyzer";
5
5
  import { INestiaProject } from "../structures/INestiaProject";
6
- import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
6
+ import { ITypedApplication } from "../structures/ITypedApplication";
7
7
  import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
8
8
 
9
9
  export namespace E2eGenerator {
10
- export const generate =
11
- (project: INestiaProject) =>
12
- async (routeList: ITypedHttpRoute[]): Promise<void> => {
13
- console.log("Generating E2E Test Functions");
14
-
15
- // PREPARE DIRECTORIES
16
- const output: string = path.resolve(project.config.e2e!);
17
- await mkdir(output);
18
- await mkdir(path.join(output, "features"));
19
- await mkdir(path.join(output, "features", "api"));
20
- await mkdir(path.join(output, "features", "api", "automated"));
21
-
22
- // GENERATE TEST INDEX FILE
23
- await index(project)(path.join(project.config.e2e!, "index.ts"));
24
-
25
- // GENERATE EACH TEST FILES
26
- for (const route of routeList)
27
- await E2eFileProgrammer.generate(project)({
28
- api: path.resolve(project.config.output!),
10
+ export const generate = async (app: ITypedApplication): Promise<void> => {
11
+ console.log("Generating E2E Test Functions");
12
+
13
+ // PREPARE DIRECTORIES
14
+ const output: string = path.resolve(app.project.config.e2e!);
15
+ await mkdir(output);
16
+ await mkdir(path.join(output, "features"));
17
+ await mkdir(path.join(output, "features", "api"));
18
+ await mkdir(path.join(output, "features", "api", "automated"));
19
+
20
+ // GENERATE TEST INDEX FILE
21
+ await index(app.project)(path.join(app.project.config.e2e!, "index.ts"));
22
+
23
+ // GENERATE EACH TEST FILES
24
+ for (const route of app.routes)
25
+ if (route.protocol === "http")
26
+ await E2eFileProgrammer.generate(app.project)({
27
+ api: path.resolve(app.project.config.output!),
29
28
  current: path.join(output, "features", "api", "automated"),
30
29
  })(route);
31
- };
30
+ };
32
31
 
33
32
  const index =
34
33
  (project: INestiaProject) =>
@@ -6,55 +6,54 @@ import {
6
6
  import fs from "fs";
7
7
  import path from "path";
8
8
 
9
- import { INestiaProject } from "../structures/INestiaProject";
10
- import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
11
- import { ITypedWebSocketRoute } from "../structures/ITypedWebSocketRoute";
9
+ import { ITypedApplication } from "../structures/ITypedApplication";
12
10
  import { SwaggerGenerator } from "./SwaggerGenerator";
13
11
 
14
12
  export namespace OpenAiGenerator {
15
- export const generate =
16
- (project: INestiaProject) =>
17
- async (
18
- routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>,
19
- ): Promise<void> => {
20
- console.log("Generating OpenAI Function Calling Document");
13
+ export const generate = async (app: ITypedApplication): Promise<void> => {
14
+ console.log("Generating OpenAI Function Calling Document");
21
15
 
22
- const config = project.config.openai!;
23
- const parsed: path.ParsedPath = path.parse(config.output);
24
- const directory: string = path.dirname(parsed.dir);
25
- if (fs.existsSync(directory) === false)
26
- try {
27
- await fs.promises.mkdir(directory);
28
- } catch {}
29
- if (fs.existsSync(directory) === false)
30
- throw new Error(
31
- `Error on NestiaApplication.openai(): failed to create output directory: ${directory}`,
32
- );
16
+ const config = app.project.config.openai;
17
+ if (config === undefined)
18
+ throw new Error("OpenAI configuration is not defined");
33
19
 
34
- const location: string = !!parsed.ext
35
- ? path.resolve(config.output)
36
- : path.join(path.resolve(config.output), "openai.json");
37
- const swagger: OpenApi.IDocument = await SwaggerGenerator.compose({
38
- ...project,
39
- config: {
40
- ...project.config,
41
- swagger: project.config.swagger ?? { output: "" },
42
- },
43
- })(routes);
44
- const document: IOpenAiDocument = OpenAiComposer.document({
45
- swagger,
46
- options: config,
47
- });
48
- await fs.promises.writeFile(
49
- location,
50
- !config.beautify
51
- ? JSON.stringify(document)
52
- : JSON.stringify(
53
- document,
54
- null,
55
- typeof config.beautify === "number" ? config.beautify : 2,
56
- ),
57
- "utf8",
20
+ const parsed: path.ParsedPath = path.parse(config.output);
21
+ const directory: string = path.dirname(parsed.dir);
22
+ if (fs.existsSync(directory) === false)
23
+ try {
24
+ await fs.promises.mkdir(directory);
25
+ } catch {}
26
+ if (fs.existsSync(directory) === false)
27
+ throw new Error(
28
+ `Error on NestiaApplication.openai(): failed to create output directory: ${directory}`,
58
29
  );
59
- };
30
+
31
+ const location: string = !!parsed.ext
32
+ ? path.resolve(config.output)
33
+ : path.join(path.resolve(config.output), "openai.json");
34
+ const swagger: OpenApi.IDocument = await SwaggerGenerator.compose({
35
+ config: app.project.config.swagger ?? { output: "" },
36
+ routes: app.routes.filter((route) => route.protocol === "http"),
37
+ document: {
38
+ openapi: "3.1.0",
39
+ components: {},
40
+ "x-samchon-emended": true,
41
+ },
42
+ });
43
+ const document: IOpenAiDocument = OpenAiComposer.document({
44
+ swagger,
45
+ options: config,
46
+ });
47
+ await fs.promises.writeFile(
48
+ location,
49
+ !config.beautify
50
+ ? JSON.stringify(document)
51
+ : JSON.stringify(
52
+ document,
53
+ null,
54
+ typeof config.beautify === "number" ? config.beautify : 2,
55
+ ),
56
+ "utf8",
57
+ );
58
+ };
60
59
  }
@@ -1,148 +1,120 @@
1
1
  import fs from "fs";
2
2
  import NodePath from "path";
3
- import path from "path";
4
3
  import { IPointer } from "tstl";
5
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
6
4
 
7
- import { INestiaProject } from "../structures/INestiaProject";
8
- import { ISwaggerError } from "../structures/ISwaggerError";
5
+ import { INestiaConfig } from "../INestiaConfig";
6
+ import { IReflectOperationError } from "../structures/IReflectOperationError";
7
+ import { IReflectType } from "../structures/IReflectType";
8
+ import { ITypedApplication } from "../structures/ITypedApplication";
9
9
  import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
10
- import { ITypedWebSocketRoute } from "../structures/ITypedWebSocketRoute";
11
- import { CloneGenerator } from "./CloneGenerator";
12
- import { SwaggerGenerator } from "./SwaggerGenerator";
10
+ // import { CloneGenerator } from "./CloneGenerator";
13
11
  import { SdkDistributionComposer } from "./internal/SdkDistributionComposer";
14
12
  import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
15
13
 
16
14
  export namespace SdkGenerator {
17
- export const generate =
18
- (project: INestiaProject) =>
19
- async (
20
- routes: Array<ITypedHttpRoute | ITypedWebSocketRoute>,
21
- ): Promise<void> => {
22
- console.log("Generating SDK Library");
15
+ export const generate = async (app: ITypedApplication): Promise<void> => {
16
+ if (app.project.config.output === undefined)
17
+ throw new Error("Output directory is not defined.");
23
18
 
24
- // VALIDATE THROUGH SWAGGER GENERATOR
25
- const errors: ISwaggerError[] = [];
26
- const validate = SwaggerGenerator.generate_route({
27
- config: { output: "" },
28
- checker: project.checker,
29
- collection: new MetadataCollection({
30
- replace: MetadataCollection.replace,
31
- }),
32
- lazyProperties: [],
33
- lazySchemas: [],
34
- errors,
35
- swagger: await SwaggerGenerator.initialize(
36
- project.config.swagger ?? { output: "" },
37
- ),
38
- });
39
- for (const r of routes)
40
- if (r.protocol === "http") {
41
- validate(r);
42
- if (project.config.clone !== true) validateImplicity(project)(r);
43
- }
44
- if (errors.length) {
45
- for (const e of errors)
46
- console.error(
47
- `${path.relative(process.cwd(), e.route.location)}:${
48
- e.route.controller.name
49
- }.${e.route.name}:${
50
- e.from
51
- } - error TS(@nestia/sdk): invalid type detected.\n\n` +
52
- e.messages.map((m) => ` - ${m}`).join("\n"),
53
- "\n\n",
54
- );
55
- throw new TypeError("Invalid type detected");
56
- } else if (project.errors.length) {
57
- for (const e of project.errors)
58
- console.error(
59
- `${path.relative(process.cwd(), e.file)}:${
60
- e.controller
61
- }.${e.function}: error TS(@nestia/sdk): ${e.message}`,
62
- );
63
- throw new TypeError("Invalid type detected");
64
- }
19
+ // PREPARE NEW DIRECTORIES
20
+ console.log("Generating SDK Library");
21
+ try {
22
+ await fs.promises.mkdir(app.project.config.output);
23
+ } catch {}
65
24
 
66
- // PREPARE NEW DIRECTORIES
67
- try {
68
- await fs.promises.mkdir(project.config.output!);
69
- } catch {}
25
+ // BUNDLING
26
+ const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
27
+ for (const file of bundle) {
28
+ const current: string = `${BUNDLE_PATH}/${file}`;
29
+ const target: string = `${app.project.config.output}/${file}`;
30
+ const stats: fs.Stats = await fs.promises.stat(current);
70
31
 
71
- // BUNDLING
72
- const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
73
- for (const file of bundle) {
74
- const current: string = `${BUNDLE_PATH}/${file}`;
75
- const target: string = `${project.config.output}/${file}`;
76
- const stats: fs.Stats = await fs.promises.stat(current);
77
-
78
- if (stats.isFile() === true) {
79
- const content: string = await fs.promises.readFile(current, "utf8");
80
- if (fs.existsSync(target) === false)
81
- await fs.promises.writeFile(target, content, "utf8");
82
- else if (BUNDLE_CHANGES[file] !== undefined) {
83
- const r: IPointer<string> = {
84
- value: await fs.promises.readFile(target, "utf8"),
85
- };
86
- for (const [before, after] of BUNDLE_CHANGES[file])
87
- r.value = r.value.replace(before, after);
88
- await fs.promises.writeFile(target, r.value, "utf8");
89
- }
32
+ if (stats.isFile() === true) {
33
+ const content: string = await fs.promises.readFile(current, "utf8");
34
+ if (fs.existsSync(target) === false)
35
+ await fs.promises.writeFile(target, content, "utf8");
36
+ else if (BUNDLE_CHANGES[file] !== undefined) {
37
+ const r: IPointer<string> = {
38
+ value: await fs.promises.readFile(target, "utf8"),
39
+ };
40
+ for (const [before, after] of BUNDLE_CHANGES[file])
41
+ r.value = r.value.replace(before, after);
42
+ await fs.promises.writeFile(target, r.value, "utf8");
90
43
  }
91
44
  }
45
+ }
92
46
 
93
- // STRUCTURES
94
- if (project.config.clone)
95
- await CloneGenerator.write(project)(
96
- routes.filter((r) => r.protocol === "http") as ITypedHttpRoute[],
97
- );
47
+ // // STRUCTURES
48
+ // if (app.project.config.clone === true) await CloneGenerator.write(app);
98
49
 
99
- // FUNCTIONAL
100
- await SdkFileProgrammer.generate(project)(routes);
50
+ // FUNCTIONAL
51
+ await SdkFileProgrammer.generate(app);
101
52
 
102
- // DISTRIBUTION
103
- if (project.config.distribute !== undefined)
104
- await SdkDistributionComposer.compose(
105
- project.config,
106
- routes.some((r) => r.protocol === "websocket"),
107
- );
108
- };
53
+ // DISTRIBUTION
54
+ if (app.project.config.distribute !== undefined)
55
+ await SdkDistributionComposer.compose({
56
+ config: app.project.config,
57
+ websocket: app.routes.some((r) => r.protocol === "websocket"),
58
+ });
59
+ };
109
60
 
110
- const validateImplicity =
111
- (project: INestiaProject) =>
112
- (route: ITypedHttpRoute): void => {
113
- for (const p of route.parameters) {
114
- if (isImplicitType(p.typeName))
115
- project.errors.push({
116
- file: route.location,
117
- controller: route.controller.name,
118
- function: route.name,
119
- message: `implicit (unnamed) parameter type from "${route.name}@${p.name}".`,
120
- });
121
- }
122
- if (project.config.propagate !== true)
123
- for (const [key, value] of Object.entries(route.exceptions))
124
- if (isImplicitType(value.typeName))
125
- project.errors.push({
126
- file: route.location,
127
- controller: route.controller.name,
128
- function: route.name,
129
- message: `implicit (unnamed) exception type of ${key} status from "${route.name}".`,
130
- });
131
- if (isImplicitType(route.output.typeName))
132
- project.errors.push({
133
- file: route.location,
134
- controller: route.controller.name,
135
- function: route.name,
136
- message: `implicit (unnamed) return type from "${route.name}".`,
61
+ export const validate = (
62
+ app: ITypedApplication,
63
+ ): IReflectOperationError[] => {
64
+ const errors: IReflectOperationError[] = [];
65
+ if (app.project.config.clone === true) return errors;
66
+ for (const route of app.routes)
67
+ if (route.protocol === "http")
68
+ validateImplicity({
69
+ config: app.project.config,
70
+ errors,
71
+ route,
72
+ });
73
+ return errors;
74
+ };
75
+
76
+ const validateImplicity = (props: {
77
+ config: INestiaConfig;
78
+ errors: IReflectOperationError[];
79
+ route: ITypedHttpRoute;
80
+ }): void => {
81
+ for (const p of props.route.parameters) {
82
+ if (isImplicitType(p.type))
83
+ props.errors.push({
84
+ file: props.route.controller.file,
85
+ class: props.route.controller.class.name,
86
+ function: props.route.name,
87
+ from: `parameter ${JSON.stringify(p.name)}`,
88
+ contents: [`implicit (unnamed) parameter type.`],
137
89
  });
138
- };
90
+ }
91
+ if (props.config.propagate === true)
92
+ for (const [key, value] of Object.entries(props.route.exceptions))
93
+ if (isImplicitType(value.type))
94
+ props.errors.push({
95
+ file: props.route.controller.file,
96
+ class: props.route.controller.class.name,
97
+ function: props.route.name,
98
+ from: `exception ${JSON.stringify(key)}`,
99
+ contents: [`implicit (unnamed) exception type.`],
100
+ });
101
+ if (isImplicitType(props.route.success.type))
102
+ props.errors.push({
103
+ file: props.route.controller.file,
104
+ class: props.route.controller.class.name,
105
+ function: props.route.name,
106
+ from: "success",
107
+ contents: [`implicit (unnamed) return type.`],
108
+ });
109
+ };
139
110
 
140
- const isImplicitType = (typeName: string): boolean =>
141
- typeName === "__type" ||
142
- typeName === "__object" ||
143
- typeName.startsWith("__type.") ||
144
- typeName.startsWith("__object.") ||
145
- typeName.includes("readonly [");
111
+ const isImplicitType = (type: IReflectType): boolean =>
112
+ type.name === "__type" ||
113
+ type.name === "__object" ||
114
+ type.name.startsWith("__type.") ||
115
+ type.name.startsWith("__object.") ||
116
+ type.name.includes("readonly [") ||
117
+ (!!type.typeArguments?.length && type.typeArguments.some(isImplicitType));
146
118
 
147
119
  export const BUNDLE_PATH = NodePath.join(
148
120
  __dirname,