@nestia/sdk 3.10.0 → 3.11.0-dev.20240813

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/lib/NestiaSdkApplication.d.ts +1 -3
  2. package/lib/NestiaSdkApplication.js +138 -136
  3. package/lib/NestiaSdkApplication.js.map +1 -1
  4. package/lib/analyses/ConfigAnalyzer.d.ts +2 -2
  5. package/lib/analyses/ConfigAnalyzer.js +39 -80
  6. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  7. package/lib/analyses/ExceptionAnalyzer.d.ts +0 -16
  8. package/lib/analyses/ExceptionAnalyzer.js +142 -105
  9. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  10. package/lib/analyses/GenericAnalyzer.d.ts +1 -2
  11. package/lib/analyses/GenericAnalyzer.js.map +1 -1
  12. package/lib/analyses/ImportAnalyzer.d.ts +6 -11
  13. package/lib/analyses/ImportAnalyzer.js +70 -42
  14. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  15. package/lib/analyses/ReflectControllerAnalyzer.d.ts +7 -1
  16. package/lib/analyses/ReflectControllerAnalyzer.js +28 -99
  17. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  18. package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +6 -2
  19. package/lib/analyses/ReflectHttpOperationAnalyzer.js +72 -152
  20. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  21. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.d.ts +15 -0
  22. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +215 -0
  23. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -0
  24. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +15 -0
  25. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +81 -0
  26. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -0
  27. package/lib/analyses/ReflectMetadataAnalyzer.d.ts +1 -3
  28. package/lib/analyses/ReflectMetadataAnalyzer.js +0 -4
  29. package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -1
  30. package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +6 -2
  31. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +72 -48
  32. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
  33. package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +15 -0
  34. package/lib/analyses/TypedHttpRouteAnalyzer.js +111 -0
  35. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -0
  36. package/lib/analyses/TypedWebSocketRouteAnalyzer.d.ts +10 -0
  37. package/lib/analyses/TypedWebSocketRouteAnalyzer.js +9 -0
  38. package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -0
  39. package/lib/decorators/OperationMetadata.d.ts +2 -0
  40. package/lib/decorators/OperationMetadata.js +10 -0
  41. package/lib/decorators/OperationMetadata.js.map +1 -0
  42. package/lib/executable/internal/NestiaConfigLoader.d.ts +1 -1
  43. package/lib/executable/internal/NestiaConfigLoader.js +34 -3
  44. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  45. package/lib/executable/internal/NestiaSdkCommand.js +1 -1
  46. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  47. package/lib/generates/CloneGenerator.d.ts +0 -5
  48. package/lib/generates/CloneGenerator.js +60 -60
  49. package/lib/generates/CloneGenerator.js.map +1 -1
  50. package/lib/generates/E2eGenerator.d.ts +2 -3
  51. package/lib/generates/E2eGenerator.js +9 -8
  52. package/lib/generates/E2eGenerator.js.map +1 -1
  53. package/lib/generates/OpenAiGenerator.d.ts +2 -4
  54. package/lib/generates/OpenAiGenerator.js +13 -3
  55. package/lib/generates/OpenAiGenerator.js.map +1 -1
  56. package/lib/generates/SdkGenerator.d.ts +4 -4
  57. package/lib/generates/SdkGenerator.js +63 -73
  58. package/lib/generates/SdkGenerator.js.map +1 -1
  59. package/lib/generates/SwaggerGenerator.d.ts +6 -18
  60. package/lib/generates/SwaggerGenerator.js +60 -235
  61. package/lib/generates/SwaggerGenerator.js.map +1 -1
  62. package/lib/generates/internal/E2eFileProgrammer.js +5 -9
  63. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  64. package/lib/generates/internal/SdkAliasCollection.d.ts +6 -4
  65. package/lib/generates/internal/SdkAliasCollection.js +33 -31
  66. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  67. package/lib/generates/internal/SdkDistributionComposer.d.ts +4 -1
  68. package/lib/generates/internal/SdkDistributionComposer.js +6 -6
  69. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  70. package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -4
  71. package/lib/generates/internal/SdkFileProgrammer.js +6 -6
  72. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  73. package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +0 -12
  74. package/lib/generates/internal/SdkHttpCloneProgrammer.js +142 -97
  75. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  76. package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +4 -3
  77. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +37 -59
  78. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  79. package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +4 -3
  80. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +31 -48
  81. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  82. package/lib/generates/internal/SdkHttpRouteProgrammer.js +7 -3
  83. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  84. package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +4 -3
  85. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +7 -13
  86. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  87. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +1 -2
  88. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +11 -16
  89. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  90. package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +1 -2
  91. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +7 -10
  92. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  93. package/lib/generates/internal/SwaggerDescriptionComposer.d.ts +23 -0
  94. package/lib/generates/internal/SwaggerDescriptionComposer.js +44 -0
  95. package/lib/generates/internal/SwaggerDescriptionComposer.js.map +1 -0
  96. package/lib/generates/internal/SwaggerOperationComposer.d.ts +12 -0
  97. package/lib/generates/internal/SwaggerOperationComposer.js +68 -0
  98. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -0
  99. package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +18 -0
  100. package/lib/generates/internal/SwaggerOperationParameterComposer.js +99 -0
  101. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -0
  102. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +9 -0
  103. package/lib/generates/internal/SwaggerOperationResponseComposer.js +91 -0
  104. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -0
  105. package/lib/structures/INestiaProject.d.ts +5 -5
  106. package/lib/structures/INestiaSdkInput.d.ts +20 -0
  107. package/lib/structures/{ISwaggerError.js → INestiaSdkInput.js} +1 -1
  108. package/lib/structures/INestiaSdkInput.js.map +1 -0
  109. package/lib/structures/IReflectApplication.d.ts +6 -0
  110. package/lib/structures/IReflectApplication.js +3 -0
  111. package/lib/structures/IReflectApplication.js.map +1 -0
  112. package/lib/structures/IReflectController.d.ts +3 -5
  113. package/lib/structures/IReflectHttpOperation.d.ts +13 -65
  114. package/lib/structures/IReflectHttpOperationException.d.ts +14 -0
  115. package/lib/structures/IReflectHttpOperationException.js +3 -0
  116. package/lib/structures/IReflectHttpOperationException.js.map +1 -0
  117. package/lib/structures/IReflectHttpOperationParameter.d.ts +35 -0
  118. package/lib/structures/IReflectHttpOperationParameter.js +3 -0
  119. package/lib/structures/IReflectHttpOperationParameter.js.map +1 -0
  120. package/lib/structures/IReflectHttpOperationSuccess.d.ts +15 -0
  121. package/lib/structures/IReflectHttpOperationSuccess.js +3 -0
  122. package/lib/structures/IReflectHttpOperationSuccess.js.map +1 -0
  123. package/lib/structures/IReflectOperationError.d.ts +16 -0
  124. package/lib/structures/IReflectOperationError.js +23 -0
  125. package/lib/structures/IReflectOperationError.js.map +1 -0
  126. package/lib/structures/IReflectType.d.ts +4 -0
  127. package/lib/structures/{IErrorReport.js → IReflectType.js} +1 -1
  128. package/lib/structures/IReflectType.js.map +1 -0
  129. package/lib/structures/IReflectTypeImport.d.ts +4 -0
  130. package/lib/structures/{ISwaggerLazySchema.js → IReflectTypeImport.js} +1 -1
  131. package/lib/structures/IReflectTypeImport.js.map +1 -0
  132. package/lib/structures/IReflectWebSocketOperation.d.ts +8 -9
  133. package/lib/structures/IReflectWebSocketOperationParameter.d.ts +23 -0
  134. package/lib/structures/IReflectWebSocketOperationParameter.js +3 -0
  135. package/lib/structures/IReflectWebSocketOperationParameter.js.map +1 -0
  136. package/lib/structures/ITypedApplication.d.ts +7 -0
  137. package/lib/structures/{INormalizedInput.js → ITypedApplication.js} +1 -1
  138. package/lib/structures/ITypedApplication.js.map +1 -0
  139. package/lib/structures/ITypedHttpRoute.d.ts +14 -42
  140. package/lib/structures/ITypedHttpRouteException.d.ts +10 -0
  141. package/lib/structures/ITypedHttpRouteException.js +3 -0
  142. package/lib/structures/ITypedHttpRouteException.js.map +1 -0
  143. package/lib/structures/ITypedHttpRouteParameter.d.ts +31 -0
  144. package/lib/structures/ITypedHttpRouteParameter.js +3 -0
  145. package/lib/structures/ITypedHttpRouteParameter.js.map +1 -0
  146. package/lib/structures/ITypedHttpRouteSuccess.d.ts +19 -0
  147. package/lib/structures/{ISwaggerLazyProperty.js → ITypedHttpRouteSuccess.js} +1 -1
  148. package/lib/structures/ITypedHttpRouteSuccess.js.map +1 -0
  149. package/lib/structures/ITypedWebSocketRoute.d.ts +8 -44
  150. package/lib/structures/ITypedWebSocketRouteParameter.d.ts +2 -0
  151. package/lib/structures/ITypedWebSocketRouteParameter.js +3 -0
  152. package/lib/structures/ITypedWebSocketRouteParameter.js.map +1 -0
  153. package/lib/transform.d.ts +3 -0
  154. package/lib/transform.js +8 -0
  155. package/lib/transform.js.map +1 -0
  156. package/lib/transformers/IOperationMetadata.d.ts +36 -0
  157. package/lib/transformers/IOperationMetadata.js +3 -0
  158. package/lib/transformers/IOperationMetadata.js.map +1 -0
  159. package/lib/transformers/ISdkTransformerContext.d.ts +7 -0
  160. package/lib/transformers/ISdkTransformerContext.js +3 -0
  161. package/lib/transformers/ISdkTransformerContext.js.map +1 -0
  162. package/lib/transformers/SdkMetadataProgrammer.d.ts +11 -0
  163. package/lib/transformers/SdkMetadataProgrammer.js +159 -0
  164. package/lib/transformers/SdkMetadataProgrammer.js.map +1 -0
  165. package/lib/transformers/SdkTransformer.d.ts +4 -0
  166. package/lib/transformers/SdkTransformer.js +88 -0
  167. package/lib/transformers/SdkTransformer.js.map +1 -0
  168. package/lib/transformers/TextPlainValidator.d.ts +4 -0
  169. package/lib/transformers/TextPlainValidator.js +19 -0
  170. package/lib/transformers/TextPlainValidator.js.map +1 -0
  171. package/lib/utils/StringUtil.d.ts +1 -0
  172. package/lib/utils/StringUtil.js +1 -0
  173. package/lib/utils/StringUtil.js.map +1 -1
  174. package/package.json +8 -8
  175. package/src/NestiaSdkApplication.ts +173 -160
  176. package/src/analyses/ConfigAnalyzer.ts +50 -98
  177. package/src/analyses/ExceptionAnalyzer.ts +142 -142
  178. package/src/analyses/GenericAnalyzer.ts +3 -5
  179. package/src/analyses/ImportAnalyzer.ts +130 -115
  180. package/src/analyses/ReflectControllerAnalyzer.ts +63 -115
  181. package/src/analyses/ReflectHttpOperationAnalyzer.ts +142 -278
  182. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +319 -0
  183. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +117 -0
  184. package/src/analyses/ReflectMetadataAnalyzer.ts +1 -18
  185. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +143 -78
  186. package/src/analyses/TypedHttpRouteAnalyzer.ts +178 -0
  187. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +18 -0
  188. package/src/decorators/OperationMetadata.ts +15 -0
  189. package/src/executable/internal/NestiaConfigLoader.ts +18 -3
  190. package/src/executable/internal/NestiaSdkCommand.ts +1 -4
  191. package/src/generates/CloneGenerator.ts +60 -59
  192. package/src/generates/E2eGenerator.ts +20 -21
  193. package/src/generates/OpenAiGenerator.ts +44 -45
  194. package/src/generates/SdkGenerator.ts +97 -125
  195. package/src/generates/SwaggerGenerator.ts +114 -416
  196. package/src/generates/internal/E2eFileProgrammer.ts +5 -14
  197. package/src/generates/internal/SdkAliasCollection.ts +33 -41
  198. package/src/generates/internal/SdkDistributionComposer.ts +9 -6
  199. package/src/generates/internal/SdkFileProgrammer.ts +11 -14
  200. package/src/generates/internal/SdkHttpCloneProgrammer.ts +142 -142
  201. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +20 -47
  202. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +245 -275
  203. package/src/generates/internal/SdkHttpRouteProgrammer.ts +7 -7
  204. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +11 -23
  205. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +197 -233
  206. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +5 -15
  207. package/src/generates/internal/{SwaggerDescriptionGenerator.ts → SwaggerDescriptionComposer.ts} +25 -5
  208. package/src/generates/internal/SwaggerOperationComposer.ts +90 -0
  209. package/src/generates/internal/SwaggerOperationParameterComposer.ts +173 -0
  210. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -0
  211. package/src/structures/INestiaProject.ts +5 -5
  212. package/src/structures/INestiaSdkInput.ts +25 -0
  213. package/src/structures/IReflectApplication.ts +8 -0
  214. package/src/structures/IReflectController.ts +3 -5
  215. package/src/structures/IReflectHttpOperation.ts +14 -76
  216. package/src/structures/IReflectHttpOperationException.ts +19 -0
  217. package/src/structures/IReflectHttpOperationParameter.ts +81 -0
  218. package/src/structures/IReflectHttpOperationSuccess.ts +22 -0
  219. package/src/structures/IReflectOperationError.ts +26 -0
  220. package/src/structures/IReflectType.ts +4 -0
  221. package/src/structures/IReflectTypeImport.ts +4 -0
  222. package/src/structures/IReflectWebSocketOperation.ts +9 -9
  223. package/src/structures/IReflectWebSocketOperationParameter.ts +38 -0
  224. package/src/structures/ITypedApplication.ts +8 -0
  225. package/src/structures/ITypedHttpRoute.ts +15 -45
  226. package/src/structures/ITypedHttpRouteException.ts +15 -0
  227. package/src/structures/ITypedHttpRouteParameter.ts +41 -0
  228. package/src/structures/ITypedHttpRouteSuccess.ts +22 -0
  229. package/src/structures/ITypedWebSocketRoute.ts +8 -56
  230. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -0
  231. package/src/transform.ts +9 -0
  232. package/src/transformers/IOperationMetadata.ts +38 -0
  233. package/src/transformers/ISdkTransformerContext.ts +8 -0
  234. package/src/transformers/SdkMetadataProgrammer.ts +227 -0
  235. package/src/transformers/SdkTransformer.ts +168 -0
  236. package/src/transformers/TextPlainValidator.ts +17 -0
  237. package/src/utils/StringUtil.ts +3 -0
  238. package/lib/analyses/TypedControllerAnalyzer.d.ts +0 -8
  239. package/lib/analyses/TypedControllerAnalyzer.js +0 -77
  240. package/lib/analyses/TypedControllerAnalyzer.js.map +0 -1
  241. package/lib/analyses/TypedHttpOperationAnalyzer.d.ts +0 -15
  242. package/lib/analyses/TypedHttpOperationAnalyzer.js +0 -263
  243. package/lib/analyses/TypedHttpOperationAnalyzer.js.map +0 -1
  244. package/lib/analyses/TypedWebSocketOperationAnalyzer.d.ts +0 -15
  245. package/lib/analyses/TypedWebSocketOperationAnalyzer.js +0 -226
  246. package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +0 -1
  247. package/lib/generates/internal/SwaggerDescriptionGenerator.d.ts +0 -14
  248. package/lib/generates/internal/SwaggerDescriptionGenerator.js +0 -33
  249. package/lib/generates/internal/SwaggerDescriptionGenerator.js.map +0 -1
  250. package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +0 -21
  251. package/lib/generates/internal/SwaggerSchemaGenerator.js +0 -289
  252. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +0 -1
  253. package/lib/generates/internal/SwaggerSchemaValidator.d.ts +0 -7
  254. package/lib/generates/internal/SwaggerSchemaValidator.js +0 -191
  255. package/lib/generates/internal/SwaggerSchemaValidator.js.map +0 -1
  256. package/lib/structures/IErrorReport.d.ts +0 -6
  257. package/lib/structures/IErrorReport.js.map +0 -1
  258. package/lib/structures/INormalizedInput.d.ts +0 -19
  259. package/lib/structures/INormalizedInput.js.map +0 -1
  260. package/lib/structures/ISwaggerError.d.ts +0 -6
  261. package/lib/structures/ISwaggerError.js.map +0 -1
  262. package/lib/structures/ISwaggerLazyProperty.d.ts +0 -6
  263. package/lib/structures/ISwaggerLazyProperty.js.map +0 -1
  264. package/lib/structures/ISwaggerLazySchema.d.ts +0 -6
  265. package/lib/structures/ISwaggerLazySchema.js.map +0 -1
  266. package/lib/structures/ITypeTuple.d.ts +0 -5
  267. package/lib/structures/ITypeTuple.js +0 -3
  268. package/lib/structures/ITypeTuple.js.map +0 -1
  269. package/src/analyses/TypedControllerAnalyzer.ts +0 -92
  270. package/src/analyses/TypedHttpOperationAnalyzer.ts +0 -365
  271. package/src/analyses/TypedWebSocketOperationAnalyzer.ts +0 -375
  272. package/src/generates/internal/SwaggerSchemaGenerator.ts +0 -473
  273. package/src/generates/internal/SwaggerSchemaValidator.ts +0 -206
  274. package/src/structures/IErrorReport.ts +0 -6
  275. package/src/structures/INormalizedInput.ts +0 -20
  276. package/src/structures/ISwaggerError.ts +0 -8
  277. package/src/structures/ISwaggerLazyProperty.ts +0 -7
  278. package/src/structures/ISwaggerLazySchema.ts +0 -7
  279. package/src/structures/ITypeTuple.ts +0 -6
@@ -1,96 +1,161 @@
1
1
  import { ranges } from "tstl";
2
2
 
3
- import { IErrorReport } from "../structures/IErrorReport";
4
3
  import { INestiaProject } from "../structures/INestiaProject";
5
4
  import { IReflectController } from "../structures/IReflectController";
5
+ import { IReflectTypeImport } from "../structures/IReflectTypeImport";
6
6
  import { IReflectWebSocketOperation } from "../structures/IReflectWebSocketOperation";
7
+ import { IReflectWebSocketOperationParameter } from "../structures/IReflectWebSocketOperationParameter";
8
+ import { IOperationMetadata } from "../transformers/IOperationMetadata";
9
+ import { StringUtil } from "../utils/StringUtil";
10
+ import { ImportAnalyzer } from "./ImportAnalyzer";
7
11
  import { PathAnalyzer } from "./PathAnalyzer";
8
12
  import { ReflectMetadataAnalyzer } from "./ReflectMetadataAnalyzer";
9
13
 
10
14
  export namespace ReflectWebSocketOperationAnalyzer {
11
- export const analyze =
12
- (project: INestiaProject) =>
13
- (props: {
14
- controller: IReflectController;
15
- function: Function;
16
- name: string;
17
- }): IReflectWebSocketOperation | null => {
18
- const route: { paths: string[] } | undefined = Reflect.getMetadata(
19
- "nestia/WebSocketRoute",
20
- props.function,
21
- );
22
- if (route === undefined) return null;
15
+ export interface IProps {
16
+ project: INestiaProject;
17
+ controller: IReflectController;
18
+ function: Function;
19
+ name: string;
20
+ metadata: IOperationMetadata;
21
+ }
22
+ export const analyze = (ctx: IProps): IReflectWebSocketOperation | null => {
23
+ const route: { paths: string[] } | undefined = Reflect.getMetadata(
24
+ "nestia/WebSocketRoute",
25
+ ctx.function,
26
+ );
27
+ if (route === undefined) return null;
23
28
 
24
- const errors: IErrorReport[] = [];
25
- const parameters: IReflectWebSocketOperation.IParameter[] = (
29
+ // @todo -> detailing is required
30
+ const errors: string[] = [];
31
+ const preconfigured: IReflectWebSocketOperationParameter.IPreconfigured[] =
32
+ (
26
33
  (Reflect.getMetadata(
27
34
  "nestia/WebSocketRoute/Parameters",
28
- props.controller.prototype,
29
- props.name,
30
- ) ?? []) as IReflectWebSocketOperation.IParameter[]
35
+ ctx.controller.class.prototype,
36
+ ctx.name,
37
+ ) ?? []) as IReflectWebSocketOperationParameter[]
31
38
  ).sort((a, b) => a.index - b.index);
32
- if (parameters.find((p) => (p.category === "acceptor") === undefined))
33
- errors.push({
34
- file: props.controller.file,
35
- controller: props.controller.name,
36
- function: props.name,
37
- message: "@WebSocketRoute.Acceptor() is essentially required",
38
- });
39
- if (parameters.length !== props.function.length)
40
- errors.push({
41
- file: props.controller.file,
42
- controller: props.controller.name,
43
- function: props.name,
44
- message: [
45
- "Every parameters must be one of below:",
46
- " - @WebSocketRoute.Acceptor()",
47
- " - @WebSocketRoute.Driver()",
48
- " - @WebSocketRoute.Header()",
49
- " - @WebSocketRoute.Param()",
50
- " - @WebSocketRoute.Query()",
51
- ].join("\n"),
52
- });
39
+ if (preconfigured.find((p) => (p.category === "acceptor") === undefined))
40
+ errors.push("@WebSocketRoute.Acceptor() is essentially required");
41
+ if (preconfigured.length !== ctx.function.length)
42
+ errors.push(
43
+ [
44
+ "Every parameters must be one of below:",
45
+ " - @WebSocketRoute.Acceptor()",
46
+ " - @WebSocketRoute.Driver()",
47
+ " - @WebSocketRoute.Header()",
48
+ " - @WebSocketRoute.Param()",
49
+ " - @WebSocketRoute.Query()",
50
+ ].join("\n"),
51
+ );
52
+
53
+ const imports: IReflectTypeImport[] = [];
54
+ const parameters: IReflectWebSocketOperationParameter[] = preconfigured
55
+ .map((p) => {
56
+ // METADATA INFO
57
+ const matched: IOperationMetadata.IParameter | undefined =
58
+ ctx.metadata.parameters.find((m) => p.index === m.index);
59
+
60
+ // VALIDATE PARAMETER
61
+ if (matched === undefined)
62
+ return errors.push(
63
+ `Unable to find parameter type of the ${p.index} (th).`,
64
+ );
65
+ else if (matched.type === null)
66
+ return errors.push(
67
+ `Failed to analyze the parameter type of the ${JSON.stringify(matched.name)}.`,
68
+ );
69
+ else if (
70
+ p.category === "param" &&
71
+ !(p as IReflectWebSocketOperationParameter.IParam).field?.length
72
+ )
73
+ return errors.push(`@WebSocketRoute.Param() must have a field name.`);
74
+ else if (
75
+ p.category === "acceptor" &&
76
+ matched.type?.typeArguments?.length !== 3
77
+ )
78
+ return `@WebSocketRoute.Acceptor() must have three type arguments.`;
79
+ else if (
80
+ p.category === "driver" &&
81
+ matched.type?.typeArguments?.length !== 1
82
+ )
83
+ return errors.push(
84
+ `@WebSocketRoute.Driver() must have one type argument.`,
85
+ );
86
+
87
+ // COMPLETE COMPOSITION
88
+ imports.push(...matched.imports);
89
+ if (
90
+ p.category === "acceptor" ||
91
+ p.category === "driver" ||
92
+ p.category === "query"
93
+ )
94
+ return {
95
+ ...p,
96
+ name: matched.name,
97
+ type: matched.type,
98
+ };
99
+ else if (p.category === "param")
100
+ return {
101
+ ...p,
102
+ category: "param",
103
+ field: p.field!,
104
+ name: matched.name,
105
+ type: matched.type,
106
+ imports: matched.imports,
107
+ description: matched.description,
108
+ jsDocTags: matched.jsDocTags,
109
+ } satisfies IReflectWebSocketOperationParameter.IParam;
110
+
111
+ // UNKNOWN TYPE, MAYBE NEW FEATURE
112
+ console.log(p);
113
+ return errors.push(
114
+ `@WebSocketRoute.${StringUtil.capitalize(p.category)}() has not been supported yet. How about upgrading the nestia packages?`,
115
+ );
116
+ })
117
+ .filter((p): p is IReflectWebSocketOperationParameter => !!p);
53
118
 
54
- const fields: string[] = parameters
55
- .filter((p) => p.category === "param")
56
- .map((p) => p.field)
57
- .sort();
58
- for (const cLoc of props.controller.paths)
59
- for (const mLoc of route.paths) {
60
- const location: string = PathAnalyzer.join(cLoc, mLoc);
61
- if (location.includes("*")) continue;
119
+ const fields: string[] = preconfigured
120
+ .filter((p) => p.category === "param")
121
+ .map((p) => p.field ?? "")
122
+ .filter((field): field is string => !!field?.length)
123
+ .sort();
124
+ for (const cLoc of ctx.controller.paths)
125
+ for (const mLoc of route.paths) {
126
+ const location: string = PathAnalyzer.join(cLoc, mLoc);
127
+ if (location.includes("*")) continue;
62
128
 
63
- const binded: string[] | null = PathAnalyzer.parameters(location);
64
- if (binded === null) {
65
- errors.push({
66
- file: props.controller.file,
67
- controller: props.controller.name,
68
- function: props.name,
69
- message: `invalid path (${JSON.stringify(location)})`,
70
- });
71
- continue;
72
- }
73
- if (ranges.equal(binded.sort(), fields) === false)
74
- errors.push({
75
- file: props.controller.file,
76
- controller: props.controller.name,
77
- function: props.name,
78
- message: `binded arguments in the "path" between function's decorator and parameters' decorators are different (function: [${binded.join(
79
- ", ",
80
- )}], parameters: [${fields.join(", ")}]).`,
81
- });
82
- }
83
- if (errors.length) {
84
- project.errors.push(...errors);
85
- return null;
129
+ const binded: string[] | null = PathAnalyzer.parameters(location);
130
+ if (binded === null)
131
+ errors.push(`invalid path (${JSON.stringify(location)})`);
132
+ else if (ranges.equal(binded.sort(), fields) === false)
133
+ errors.push(
134
+ `binded arguments in the "path" between function's decorator and parameters' decorators are different (function: [${binded.join(
135
+ ", ",
136
+ )}], parameters: [${fields.join(", ")}]).`,
137
+ );
86
138
  }
87
- return {
88
- protocol: "websocket",
89
- target: props.function,
90
- name: props.name,
91
- paths: route.paths,
92
- versions: ReflectMetadataAnalyzer.versions(props.function),
93
- parameters,
94
- };
139
+ if (errors.length) {
140
+ ctx.project.errors.push({
141
+ file: ctx.controller.file,
142
+ class: ctx.controller.class.name,
143
+ function: ctx.function.name,
144
+ from: ctx.name,
145
+ contents: errors,
146
+ });
147
+ return null;
148
+ }
149
+ return {
150
+ protocol: "websocket",
151
+ name: ctx.name,
152
+ paths: route.paths,
153
+ function: ctx.function,
154
+ versions: ReflectMetadataAnalyzer.versions(ctx.function),
155
+ parameters,
156
+ imports: ImportAnalyzer.unique(imports),
157
+ description: ctx.metadata.description ?? null,
158
+ jsDocTags: ctx.metadata.jsDocTags,
95
159
  };
160
+ };
96
161
  }
@@ -0,0 +1,178 @@
1
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
2
+ import { IMetadata } from "typia/lib/schemas/metadata/IMetadata";
3
+ import { IMetadataComponents } from "typia/lib/schemas/metadata/IMetadataComponents";
4
+ import { IMetadataDictionary } from "typia/lib/schemas/metadata/IMetadataDictionary";
5
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
+ import { MetadataComponents } from "typia/lib/schemas/metadata/MetadataComponents";
7
+ import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
8
+ import { Escaper } from "typia/lib/utils/Escaper";
9
+
10
+ import { IReflectController } from "../structures/IReflectController";
11
+ import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
12
+ import { IReflectOperationError } from "../structures/IReflectOperationError";
13
+ import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
14
+ import { ITypedHttpRouteException } from "../structures/ITypedHttpRouteException";
15
+ import { ITypedHttpRouteParameter } from "../structures/ITypedHttpRouteParameter";
16
+ import { ITypedHttpRouteSuccess } from "../structures/ITypedHttpRouteSuccess";
17
+ import { PathUtil } from "../utils/PathUtil";
18
+
19
+ export namespace TypedHttpRouteAnalyzer {
20
+ export const dictionary = (
21
+ controllers: IReflectController[],
22
+ ): IMetadataDictionary => {
23
+ const individual: IMetadataComponents[] = [];
24
+ for (const c of controllers)
25
+ for (const o of c.operations) {
26
+ if (o.protocol !== "http") continue;
27
+ if (o.success) individual.push(o.success.components);
28
+ for (const p of o.parameters) individual.push(p.components);
29
+ for (const e of Object.values(o.exceptions))
30
+ individual.push(e.components);
31
+ }
32
+ const components: MetadataComponents = MetadataComponents.from({
33
+ objects: Object.values(
34
+ Object.fromEntries(
35
+ individual.map((c) => c.objects.map((o) => [o.name, o])).flat(),
36
+ ),
37
+ ),
38
+ arrays: Object.values(
39
+ Object.fromEntries(
40
+ individual.map((c) => c.arrays.map((a) => [a.name, a])).flat(),
41
+ ),
42
+ ),
43
+ tuples: Object.values(
44
+ Object.fromEntries(
45
+ individual.map((c) => c.tuples.map((t) => [t.name, t])).flat(),
46
+ ),
47
+ ),
48
+ aliases: Object.values(
49
+ Object.fromEntries(
50
+ individual.map((c) => c.aliases.map((a) => [a.name, a])).flat(),
51
+ ),
52
+ ),
53
+ });
54
+ return components.dictionary;
55
+ };
56
+
57
+ export const analyze = (props: {
58
+ controller: IReflectController;
59
+ errors: IReflectOperationError[];
60
+ dictionary: IMetadataDictionary;
61
+ operation: IReflectHttpOperation;
62
+ paths: string[];
63
+ }): ITypedHttpRoute[] => {
64
+ const errors: IReflectOperationError[] = [];
65
+ const cast = (
66
+ next: {
67
+ metadata: IMetadata;
68
+ validate: MetadataFactory.Validator;
69
+ },
70
+ from: string,
71
+ escape: boolean,
72
+ ): Metadata => {
73
+ const metadata: Metadata = Metadata.from(next.metadata, props.dictionary);
74
+ const metaErrors: MetadataFactory.IError[] = MetadataFactory.validate()({
75
+ escape,
76
+ constant: true,
77
+ absorb: true,
78
+ validate: next.validate,
79
+ })(next.validate)(metadata);
80
+ if (metaErrors.length)
81
+ errors.push({
82
+ file: props.controller.file,
83
+ class: props.controller.class.name,
84
+ function: props.operation.name,
85
+ from,
86
+ contents: metaErrors.map((e) => ({
87
+ name: e.name,
88
+ accessor:
89
+ e.explore.object !== null
90
+ ? join({
91
+ object: e.explore.object,
92
+ key: e.explore.property,
93
+ })
94
+ : null,
95
+ messages: e.messages,
96
+ })),
97
+ });
98
+ return metadata;
99
+ };
100
+ const exceptions: Record<
101
+ number | "2XX" | "3XX" | "4XX" | "5XX",
102
+ ITypedHttpRouteException
103
+ > = Object.fromEntries(
104
+ Object.entries(props.operation.exceptions).map(([key, value]) => [
105
+ key as any,
106
+ {
107
+ status: value.status,
108
+ description: value.description,
109
+ example: value.example,
110
+ examples: value.examples,
111
+ type: value.type,
112
+ metadata: cast(value, `exception (status: ${key})`, true),
113
+ },
114
+ ]),
115
+ );
116
+ const parameters: ITypedHttpRouteParameter[] =
117
+ props.operation.parameters.map((p) => ({
118
+ ...p,
119
+ metadata: cast(
120
+ p,
121
+ `parameter (name: ${JSON.stringify(p.name)})`,
122
+ p.category === "body" &&
123
+ (p.contentType === "application/json" || p.encrypted === true),
124
+ ),
125
+ }));
126
+ const success: ITypedHttpRouteSuccess = {
127
+ ...props.operation.success,
128
+ metadata: cast(
129
+ props.operation.success,
130
+ "success",
131
+ props.operation.success.encrypted ||
132
+ props.operation.success.contentType === "application/json",
133
+ ),
134
+ setHeaders: props.operation.jsDocTags
135
+ .filter(
136
+ (t) =>
137
+ t.text?.length &&
138
+ t.text[0].text &&
139
+ (t.name === "setHeader" || t.name === "assignHeaders"),
140
+ )
141
+ .map((t) =>
142
+ t.name === "setHeader"
143
+ ? {
144
+ type: "setter",
145
+ source: t.text![0].text.split(" ")[0].trim(),
146
+ target: t.text![0].text.split(" ")[1]?.trim(),
147
+ }
148
+ : {
149
+ type: "assigner",
150
+ source: t.text![0].text,
151
+ },
152
+ ),
153
+ };
154
+ if (errors.length) return [];
155
+ return props.paths.map((path) => ({
156
+ ...props.operation,
157
+ controller: props.controller,
158
+ path,
159
+ accessors: [...PathUtil.accessors(path), props.operation.name],
160
+ exceptions,
161
+ parameters,
162
+ success,
163
+ }));
164
+ };
165
+ }
166
+
167
+ const join = ({
168
+ object,
169
+ key,
170
+ }: {
171
+ object: MetadataObject;
172
+ key: string | object | null;
173
+ }) => {
174
+ if (key === null) return object.name;
175
+ else if (typeof key === "object") return `${object.name}[key]`;
176
+ else if (Escaper.variable(key)) return `${object.name}.${key}`;
177
+ return `${object.name}[${JSON.stringify(key)}]`;
178
+ };
@@ -0,0 +1,18 @@
1
+ import { IReflectController } from "../structures/IReflectController";
2
+ import { IReflectWebSocketOperation } from "../structures/IReflectWebSocketOperation";
3
+ import { ITypedWebSocketRoute } from "../structures/ITypedWebSocketRoute";
4
+ import { PathUtil } from "../utils/PathUtil";
5
+
6
+ export namespace TypedWebSocketRouteAnalyzer {
7
+ export const analyze = (props: {
8
+ controller: IReflectController;
9
+ operation: IReflectWebSocketOperation;
10
+ paths: string[];
11
+ }): ITypedWebSocketRoute[] =>
12
+ props.paths.map((path) => ({
13
+ ...props.operation,
14
+ controller: props.controller,
15
+ path,
16
+ accessors: [...PathUtil.accessors(path), props.operation.name],
17
+ }));
18
+ }
@@ -0,0 +1,15 @@
1
+ import { IOperationMetadata } from "../transformers/IOperationMetadata";
2
+
3
+ export function OperationMetadata(
4
+ metadata: IOperationMetadata,
5
+ ): MethodDecorator {
6
+ return function OperationMetadata(target, propertyKey, descriptor) {
7
+ Reflect.defineMetadata(
8
+ "nestia/OperationMetadata",
9
+ metadata,
10
+ target,
11
+ propertyKey,
12
+ );
13
+ return descriptor;
14
+ };
15
+ }
@@ -1,3 +1,4 @@
1
+ import { NoTransformConfigureError } from "@nestia/core/lib/decorators/internal/NoTransformConfigureError";
1
2
  import fs from "fs";
2
3
  import path from "path";
3
4
  import { register } from "ts-node";
@@ -32,15 +33,29 @@ export namespace NestiaConfigLoader {
32
33
 
33
34
  export const config = async (
34
35
  file: string,
35
- rawCompilerOptions: Record<string, any>,
36
+ compilerOptions: Record<string, any>,
36
37
  ): Promise<INestiaConfig> => {
37
38
  if (fs.existsSync(path.resolve(file)) === false)
38
39
  throw new Error(`Unable to find "${file}" file.`);
39
40
 
41
+ (NoTransformConfigureError as any).throws = false;
42
+ const plugins: any[] = [
43
+ ...typia
44
+ .assert<object[]>(compilerOptions.plugins ?? [])
45
+ .filter(
46
+ (x: any) =>
47
+ x.transform !== "@nestia/core/lib/transform" &&
48
+ x.transform !== "@nestia/sdk/lib/transform",
49
+ ),
50
+ { transform: "@nestia/sdk/lib/transform" },
51
+ ];
40
52
  register({
41
53
  emit: false,
42
- compilerOptions: rawCompilerOptions,
43
- require: rawCompilerOptions.baseUrl
54
+ compilerOptions: {
55
+ ...compilerOptions,
56
+ plugins,
57
+ },
58
+ require: compilerOptions.baseUrl
44
59
  ? ["tsconfig-paths/register"]
45
60
  : undefined,
46
61
  });
@@ -34,10 +34,7 @@ export namespace NestiaSdkCommand {
34
34
  );
35
35
 
36
36
  // GENERATE
37
- const app: NestiaSdkApplication = new NestiaSdkApplication(
38
- config,
39
- command.options,
40
- );
37
+ const app: NestiaSdkApplication = new NestiaSdkApplication(config);
41
38
  await task(app);
42
39
  };
43
40
 
@@ -1,64 +1,65 @@
1
- import fs from "fs";
2
- import ts from "typescript";
1
+ // import fs from "fs";
2
+ // import ts from "typescript";
3
3
 
4
- import { INestiaProject } from "../structures/INestiaProject";
5
- import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
6
- import { FilePrinter } from "./internal/FilePrinter";
7
- import { ImportDictionary } from "./internal/ImportDictionary";
8
- import { SdkHttpCloneProgrammer } from "./internal/SdkHttpCloneProgrammer";
4
+ // import { INestiaProject } from "../structures/INestiaProject";
5
+ // import { ITypedApplication } from "../structures/ITypedApplication";
6
+ // import { FilePrinter } from "./internal/FilePrinter";
7
+ // import { ImportDictionary } from "./internal/ImportDictionary";
8
+ // // import { SdkHttpCloneProgrammer } from "./internal/SdkHttpCloneProgrammer";
9
9
 
10
- export namespace CloneGenerator {
11
- export const write =
12
- (project: INestiaProject) =>
13
- async (routes: ITypedHttpRoute[]): Promise<void> => {
14
- const dict: Map<string, SdkHttpCloneProgrammer.IModule> =
15
- SdkHttpCloneProgrammer.write(project)(routes);
16
- if (dict.size === 0) return;
17
- try {
18
- await fs.promises.mkdir(`${project.config.output}/structures`);
19
- } catch {}
20
- for (const [key, value] of dict) await writeDtoFile(project)(key, value);
21
- };
10
+ // export namespace CloneGenerator {
11
+ // export const write = async (app: ITypedApplication): Promise<void> => {
12
+ // // const dict: Map<string, SdkHttpCloneProgrammer.IModule> =
13
+ // // SdkHttpCloneProgrammer.write(app.project)(
14
+ // // app.routes.filter((r) => r.protocol === "http"),
15
+ // // );
16
+ // if (dict.size === 0) return;
17
+ // try {
18
+ // await fs.promises.mkdir(`${app.project.config.output}/structures`);
19
+ // } catch {}
20
+ // for (const [key, value] of dict)
21
+ // await writeDtoFile(app.project)(key, value);
22
+ // };
22
23
 
23
- const writeDtoFile =
24
- (project: INestiaProject) =>
25
- async (
26
- key: string,
27
- value: SdkHttpCloneProgrammer.IModule,
28
- ): Promise<void> => {
29
- const location: string = `${project.config.output}/structures/${key}.ts`;
30
- const importer: ImportDictionary = new ImportDictionary(location);
31
- const statements: ts.Statement[] = iterate(importer)(value);
32
- if (statements.length === 0) return;
24
+ // const writeDtoFile =
25
+ // (project: INestiaProject) =>
26
+ // async (
27
+ // key: string,
28
+ // value: SdkHttpCloneProgrammer.IModule,
29
+ // ): Promise<void> => {
30
+ // const location: string = `${project.config.output}/structures/${key}.ts`;
31
+ // const importer: ImportDictionary = new ImportDictionary(location);
32
+ // const statements: ts.Statement[] = iterate(importer)(value);
33
+ // if (statements.length === 0) return;
33
34
 
34
- await FilePrinter.write({
35
- location,
36
- statements: [
37
- ...importer.toStatements(`${project.config.output}/structures`),
38
- ...(importer.empty() ? [] : [FilePrinter.enter()]),
39
- ...statements,
40
- ],
41
- });
42
- };
35
+ // await FilePrinter.write({
36
+ // location,
37
+ // statements: [
38
+ // ...importer.toStatements(`${project.config.output}/structures`),
39
+ // ...(importer.empty() ? [] : [FilePrinter.enter()]),
40
+ // ...statements,
41
+ // ],
42
+ // });
43
+ // };
43
44
 
44
- const iterate =
45
- (importer: ImportDictionary) =>
46
- (modulo: SdkHttpCloneProgrammer.IModule): ts.Statement[] => {
47
- const output: ts.Statement[] = [];
48
- if (modulo.programmer !== null) output.push(modulo.programmer(importer));
49
- if (modulo.children.size) {
50
- const internal: ts.Statement[] = [];
51
- for (const child of modulo.children.values())
52
- internal.push(...iterate(importer)(child));
53
- output.push(
54
- ts.factory.createModuleDeclaration(
55
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
56
- ts.factory.createIdentifier(modulo.name),
57
- ts.factory.createModuleBlock(internal),
58
- ts.NodeFlags.Namespace,
59
- ),
60
- );
61
- }
62
- return output;
63
- };
64
- }
45
+ // const iterate =
46
+ // (importer: ImportDictionary) =>
47
+ // (modulo: SdkHttpCloneProgrammer.IModule): ts.Statement[] => {
48
+ // const output: ts.Statement[] = [];
49
+ // if (modulo.programmer !== null) output.push(modulo.programmer(importer));
50
+ // if (modulo.children.size) {
51
+ // const internal: ts.Statement[] = [];
52
+ // for (const child of modulo.children.values())
53
+ // internal.push(...iterate(importer)(child));
54
+ // output.push(
55
+ // ts.factory.createModuleDeclaration(
56
+ // [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
57
+ // ts.factory.createIdentifier(modulo.name),
58
+ // ts.factory.createModuleBlock(internal),
59
+ // ts.NodeFlags.Namespace,
60
+ // ),
61
+ // );
62
+ // }
63
+ // return output;
64
+ // };
65
+ // }