@achinet/nestjs-async 0.1.1 → 0.3.0

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 (308) hide show
  1. package/dist/asyncapi-document.builder.d.ts +1 -1
  2. package/dist/asyncapi-document.builder.js.map +1 -1
  3. package/dist/asyncapi.module.js +8 -5
  4. package/dist/asyncapi.module.js.map +1 -1
  5. package/dist/binding/asyncapi.kafka.interfaces.d.ts +1 -1
  6. package/dist/decorators/asyncapi-operation-for-meta-key.decorator.js +3 -3
  7. package/dist/decorators/asyncapi-operation-for-meta-key.decorator.js.map +1 -1
  8. package/dist/decorators/asyncapi-operation.decorator.js.map +1 -1
  9. package/dist/decorators/asyncapi-pub.decorator.js.map +1 -1
  10. package/dist/decorators/asyncapi-service.decorator.d.ts +1 -1
  11. package/dist/decorators/asyncapi-service.decorator.js +2 -2
  12. package/dist/decorators/asyncapi-service.decorator.js.map +1 -1
  13. package/dist/decorators/asyncapi-sub.decorator.js.map +1 -1
  14. package/dist/explorers/asyncapi-class.explorer.js +1 -5
  15. package/dist/explorers/asyncapi-class.explorer.js.map +1 -1
  16. package/dist/explorers/asyncapi-operation.explorer.d.ts +1 -2
  17. package/dist/explorers/asyncapi-operation.explorer.js +2 -2
  18. package/dist/explorers/asyncapi-operation.explorer.js.map +1 -1
  19. package/dist/interface/asyncapi-common.interfaces.d.ts +1 -1
  20. package/dist/interface/asyncapi-server.interface.d.ts +1 -1
  21. package/dist/interface/asyncapi-template-options.interface.d.ts +2 -3
  22. package/dist/interface/index.d.ts +0 -1
  23. package/dist/interface/index.js +0 -1
  24. package/dist/interface/index.js.map +1 -1
  25. package/dist/services/asyncapi.explorer.d.ts +2 -4
  26. package/dist/services/asyncapi.explorer.js +8 -13
  27. package/dist/services/asyncapi.explorer.js.map +1 -1
  28. package/dist/services/asyncapi.generator.d.ts +4 -3
  29. package/dist/services/asyncapi.generator.js +72 -17
  30. package/dist/services/asyncapi.generator.js.map +1 -1
  31. package/dist/services/asyncapi.scanner.d.ts +1 -4
  32. package/dist/services/asyncapi.scanner.js +10 -31
  33. package/dist/services/asyncapi.scanner.js.map +1 -1
  34. package/dist/services/asyncapi.transformer.js.map +1 -1
  35. package/dist/services/index.d.ts +1 -1
  36. package/dist/services/index.js +1 -1
  37. package/dist/services/index.js.map +1 -1
  38. package/dist/services/operation-object.factory.d.ts +2 -6
  39. package/dist/services/operation-object.factory.js +7 -14
  40. package/dist/services/operation-object.factory.js.map +1 -1
  41. package/dist/services/swagger-schema.factory.d.ts +6 -0
  42. package/dist/services/swagger-schema.factory.js +27 -0
  43. package/dist/services/swagger-schema.factory.js.map +1 -0
  44. package/dist/utils/decorator.utils.d.ts +2 -0
  45. package/dist/utils/decorator.utils.js +26 -0
  46. package/dist/utils/decorator.utils.js.map +1 -0
  47. package/dist/utils/index.d.ts +2 -0
  48. package/dist/{sample/felines/rto → utils}/index.js +2 -1
  49. package/dist/utils/index.js.map +1 -0
  50. package/dist/utils/path.utils.d.ts +2 -0
  51. package/dist/utils/path.utils.js +8 -0
  52. package/dist/utils/path.utils.js.map +1 -0
  53. package/package.json +57 -37
  54. package/.prettierrc +0 -5
  55. package/CHANGELOG.md +0 -20
  56. package/dist/interface/generator-options.interface.d.ts +0 -22
  57. package/dist/interface/generator-options.interface.js +0 -3
  58. package/dist/interface/generator-options.interface.js.map +0 -1
  59. package/dist/sample/app.module.d.ts +0 -2
  60. package/dist/sample/app.module.js +0 -20
  61. package/dist/sample/app.module.js.map +0 -1
  62. package/dist/sample/common.d.ts +0 -3
  63. package/dist/sample/common.js +0 -40
  64. package/dist/sample/common.js.map +0 -1
  65. package/dist/sample/constants.d.ts +0 -12
  66. package/dist/sample/constants.js +0 -16
  67. package/dist/sample/constants.js.map +0 -1
  68. package/dist/sample/felines/class/cat.class.d.ts +0 -4
  69. package/dist/sample/felines/class/cat.class.js +0 -24
  70. package/dist/sample/felines/class/cat.class.js.map +0 -1
  71. package/dist/sample/felines/class/feline.class.d.ts +0 -19
  72. package/dist/sample/felines/class/feline.class.js +0 -20
  73. package/dist/sample/felines/class/feline.class.js.map +0 -1
  74. package/dist/sample/felines/class/index.d.ts +0 -5
  75. package/dist/sample/felines/class/index.js +0 -22
  76. package/dist/sample/felines/class/index.js.map +0 -1
  77. package/dist/sample/felines/class/lion.class.d.ts +0 -4
  78. package/dist/sample/felines/class/lion.class.js +0 -8
  79. package/dist/sample/felines/class/lion.class.js.map +0 -1
  80. package/dist/sample/felines/class/message.class.d.ts +0 -7
  81. package/dist/sample/felines/class/message.class.js +0 -28
  82. package/dist/sample/felines/class/message.class.js.map +0 -1
  83. package/dist/sample/felines/class/tiger.class.d.ts +0 -4
  84. package/dist/sample/felines/class/tiger.class.js +0 -8
  85. package/dist/sample/felines/class/tiger.class.js.map +0 -1
  86. package/dist/sample/felines/dto/create-feline.dto.d.ts +0 -4
  87. package/dist/sample/felines/dto/create-feline.dto.js +0 -28
  88. package/dist/sample/felines/dto/create-feline.dto.js.map +0 -1
  89. package/dist/sample/felines/dto/index.d.ts +0 -2
  90. package/dist/sample/felines/dto/index.js +0 -19
  91. package/dist/sample/felines/dto/index.js.map +0 -1
  92. package/dist/sample/felines/dto/journaling-data.dto.d.ts +0 -4
  93. package/dist/sample/felines/dto/journaling-data.dto.js +0 -8
  94. package/dist/sample/felines/dto/journaling-data.dto.js.map +0 -1
  95. package/dist/sample/felines/felines.constants.d.ts +0 -1
  96. package/dist/sample/felines/felines.constants.js +0 -5
  97. package/dist/sample/felines/felines.constants.js.map +0 -1
  98. package/dist/sample/felines/felines.controller.d.ts +0 -15
  99. package/dist/sample/felines/felines.controller.js +0 -101
  100. package/dist/sample/felines/felines.controller.js.map +0 -1
  101. package/dist/sample/felines/felines.gateway.d.ts +0 -16
  102. package/dist/sample/felines/felines.gateway.js +0 -90
  103. package/dist/sample/felines/felines.gateway.js.map +0 -1
  104. package/dist/sample/felines/felines.module.d.ts +0 -2
  105. package/dist/sample/felines/felines.module.js +0 -28
  106. package/dist/sample/felines/felines.module.js.map +0 -1
  107. package/dist/sample/felines/felines.service.d.ts +0 -8
  108. package/dist/sample/felines/felines.service.js +0 -33
  109. package/dist/sample/felines/felines.service.js.map +0 -1
  110. package/dist/sample/felines/rto/feline.rto.d.ts +0 -7
  111. package/dist/sample/felines/rto/feline.rto.js +0 -31
  112. package/dist/sample/felines/rto/feline.rto.js.map +0 -1
  113. package/dist/sample/felines/rto/index.d.ts +0 -1
  114. package/dist/sample/felines/rto/index.js.map +0 -1
  115. package/dist/sample/index.d.ts +0 -3
  116. package/dist/sample/index.js +0 -20
  117. package/dist/sample/index.js.map +0 -1
  118. package/dist/sample/main.d.ts +0 -1
  119. package/dist/sample/main.js +0 -30
  120. package/dist/sample/main.js.map +0 -1
  121. package/dist/src/asyncapi-document.builder.d.ts +0 -27
  122. package/dist/src/asyncapi-document.builder.js +0 -110
  123. package/dist/src/asyncapi-document.builder.js.map +0 -1
  124. package/dist/src/asyncapi.constants.d.ts +0 -6
  125. package/dist/src/asyncapi.constants.js +0 -11
  126. package/dist/src/asyncapi.constants.js.map +0 -1
  127. package/dist/src/asyncapi.module.d.ts +0 -8
  128. package/dist/src/asyncapi.module.js +0 -47
  129. package/dist/src/asyncapi.module.js.map +0 -1
  130. package/dist/src/binding/asyncapi.amqp.interfaces.d.ts +0 -38
  131. package/dist/src/binding/asyncapi.amqp.interfaces.js +0 -3
  132. package/dist/src/binding/asyncapi.amqp.interfaces.js.map +0 -1
  133. package/dist/src/binding/asyncapi.kafka.interfaces.d.ts +0 -21
  134. package/dist/src/binding/asyncapi.kafka.interfaces.js +0 -3
  135. package/dist/src/binding/asyncapi.kafka.interfaces.js.map +0 -1
  136. package/dist/src/binding/index.d.ts +0 -2
  137. package/dist/src/binding/index.js +0 -19
  138. package/dist/src/binding/index.js.map +0 -1
  139. package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.d.ts +0 -2
  140. package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.js +0 -37
  141. package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.js.map +0 -1
  142. package/dist/src/decorators/asyncapi-operation.decorator.d.ts +0 -2
  143. package/dist/src/decorators/asyncapi-operation.decorator.js +0 -9
  144. package/dist/src/decorators/asyncapi-operation.decorator.js.map +0 -1
  145. package/dist/src/decorators/asyncapi-pub.decorator.d.ts +0 -2
  146. package/dist/src/decorators/asyncapi-pub.decorator.js +0 -10
  147. package/dist/src/decorators/asyncapi-pub.decorator.js.map +0 -1
  148. package/dist/src/decorators/asyncapi-service.decorator.d.ts +0 -1
  149. package/dist/src/decorators/asyncapi-service.decorator.js +0 -9
  150. package/dist/src/decorators/asyncapi-service.decorator.js.map +0 -1
  151. package/dist/src/decorators/asyncapi-sub.decorator.d.ts +0 -2
  152. package/dist/src/decorators/asyncapi-sub.decorator.js +0 -10
  153. package/dist/src/decorators/asyncapi-sub.decorator.js.map +0 -1
  154. package/dist/src/decorators/index.d.ts +0 -4
  155. package/dist/src/decorators/index.js +0 -21
  156. package/dist/src/decorators/index.js.map +0 -1
  157. package/dist/src/explorers/asyncapi-class.explorer.d.ts +0 -5
  158. package/dist/src/explorers/asyncapi-class.explorer.js +0 -27
  159. package/dist/src/explorers/asyncapi-class.explorer.js.map +0 -1
  160. package/dist/src/explorers/asyncapi-operation.explorer.d.ts +0 -17
  161. package/dist/src/explorers/asyncapi-operation.explorer.js +0 -26
  162. package/dist/src/explorers/asyncapi-operation.explorer.js.map +0 -1
  163. package/dist/src/explorers/index.d.ts +0 -2
  164. package/dist/src/explorers/index.js +0 -19
  165. package/dist/src/explorers/index.js.map +0 -1
  166. package/dist/src/index.d.ts +0 -4
  167. package/dist/src/index.js +0 -21
  168. package/dist/src/index.js.map +0 -1
  169. package/dist/src/interface/asyncapi-common.interfaces.d.ts +0 -126
  170. package/dist/src/interface/asyncapi-common.interfaces.js +0 -3
  171. package/dist/src/interface/asyncapi-common.interfaces.js.map +0 -1
  172. package/dist/src/interface/asyncapi-document-options.interface.d.ts +0 -3
  173. package/dist/src/interface/asyncapi-document-options.interface.js +0 -3
  174. package/dist/src/interface/asyncapi-document-options.interface.js.map +0 -1
  175. package/dist/src/interface/asyncapi-message.interface.d.ts +0 -8
  176. package/dist/src/interface/asyncapi-message.interface.js +0 -3
  177. package/dist/src/interface/asyncapi-message.interface.js.map +0 -1
  178. package/dist/src/interface/asyncapi-operation-headers.interface.d.ts +0 -6
  179. package/dist/src/interface/asyncapi-operation-headers.interface.js +0 -3
  180. package/dist/src/interface/asyncapi-operation-headers.interface.js.map +0 -1
  181. package/dist/src/interface/asyncapi-operation-options-raw.interface.d.ts +0 -21
  182. package/dist/src/interface/asyncapi-operation-options-raw.interface.js +0 -3
  183. package/dist/src/interface/asyncapi-operation-options-raw.interface.js.map +0 -1
  184. package/dist/src/interface/asyncapi-operation-options.interface.d.ts +0 -8
  185. package/dist/src/interface/asyncapi-operation-options.interface.js +0 -3
  186. package/dist/src/interface/asyncapi-operation-options.interface.js.map +0 -1
  187. package/dist/src/interface/asyncapi-operation-payload.interface.d.ts +0 -2
  188. package/dist/src/interface/asyncapi-operation-payload.interface.js +0 -3
  189. package/dist/src/interface/asyncapi-operation-payload.interface.js.map +0 -1
  190. package/dist/src/interface/asyncapi-server.interface.d.ts +0 -10
  191. package/dist/src/interface/asyncapi-server.interface.js +0 -3
  192. package/dist/src/interface/asyncapi-server.interface.js.map +0 -1
  193. package/dist/src/interface/asyncapi-template-options.interface.d.ts +0 -7
  194. package/dist/src/interface/asyncapi-template-options.interface.js +0 -3
  195. package/dist/src/interface/asyncapi-template-options.interface.js.map +0 -1
  196. package/dist/src/interface/denormalized-doc-resolvers.interface.d.ts +0 -6
  197. package/dist/src/interface/denormalized-doc-resolvers.interface.js +0 -3
  198. package/dist/src/interface/denormalized-doc-resolvers.interface.js.map +0 -1
  199. package/dist/src/interface/denormalized-doc.interface.d.ts +0 -10
  200. package/dist/src/interface/denormalized-doc.interface.js +0 -3
  201. package/dist/src/interface/denormalized-doc.interface.js.map +0 -1
  202. package/dist/src/interface/generator-options.interface.d.ts +0 -22
  203. package/dist/src/interface/generator-options.interface.js +0 -3
  204. package/dist/src/interface/generator-options.interface.js.map +0 -1
  205. package/dist/src/interface/index.d.ts +0 -11
  206. package/dist/src/interface/index.js +0 -28
  207. package/dist/src/interface/index.js.map +0 -1
  208. package/dist/src/services/asyncapi.explorer.d.ts +0 -12
  209. package/dist/src/services/asyncapi.explorer.js +0 -69
  210. package/dist/src/services/asyncapi.explorer.js.map +0 -1
  211. package/dist/src/services/asyncapi.generator.d.ts +0 -6
  212. package/dist/src/services/asyncapi.generator.js +0 -68
  213. package/dist/src/services/asyncapi.generator.js.map +0 -1
  214. package/dist/src/services/asyncapi.scanner.d.ts +0 -14
  215. package/dist/src/services/asyncapi.scanner.js +0 -71
  216. package/dist/src/services/asyncapi.scanner.js.map +0 -1
  217. package/dist/src/services/asyncapi.transformer.d.ts +0 -4
  218. package/dist/src/services/asyncapi.transformer.js +0 -33
  219. package/dist/src/services/asyncapi.transformer.js.map +0 -1
  220. package/dist/src/services/index.d.ts +0 -4
  221. package/dist/src/services/index.js +0 -21
  222. package/dist/src/services/index.js.map +0 -1
  223. package/dist/src/services/operation-object.factory.d.ts +0 -9
  224. package/dist/src/services/operation-object.factory.js +0 -37
  225. package/dist/src/services/operation-object.factory.js.map +0 -1
  226. package/dist/test/configs/jest-base.config.d.ts +0 -3
  227. package/dist/test/configs/jest-base.config.js +0 -20
  228. package/dist/test/configs/jest-base.config.js.map +0 -1
  229. package/dist/test/configs/jest-e2e.config.d.ts +0 -3
  230. package/dist/test/configs/jest-e2e.config.js +0 -16
  231. package/dist/test/configs/jest-e2e.config.js.map +0 -1
  232. package/dist/test/express.e2e-spec.d.ts +0 -1
  233. package/dist/test/express.e2e-spec.js +0 -89
  234. package/dist/test/express.e2e-spec.js.map +0 -1
  235. package/dist/test/fastify.e2e-spec.d.ts +0 -1
  236. package/dist/test/fastify.e2e-spec.js +0 -57
  237. package/dist/test/fastify.e2e-spec.js.map +0 -1
  238. package/dist/tsconfig.tsbuildinfo +0 -1
  239. package/eslint.config.mjs +0 -21
  240. package/misc/references/ref.html +0 -303
  241. package/misc/references/ref.json +0 -1
  242. package/misc/references/ref.yaml +0 -292
  243. package/misc/take-snaphots.sh +0 -8
  244. package/sample/app.module.ts +0 -7
  245. package/sample/common.ts +0 -49
  246. package/sample/constants.ts +0 -12
  247. package/sample/felines/class/cat.class.ts +0 -9
  248. package/sample/felines/class/feline.class.ts +0 -29
  249. package/sample/felines/class/index.ts +0 -5
  250. package/sample/felines/class/lion.class.ts +0 -5
  251. package/sample/felines/class/message.class.ts +0 -17
  252. package/sample/felines/class/tiger.class.ts +0 -5
  253. package/sample/felines/dto/create-feline.dto.ts +0 -13
  254. package/sample/felines/dto/index.ts +0 -2
  255. package/sample/felines/dto/journaling-data.dto.ts +0 -5
  256. package/sample/felines/felines.constants.ts +0 -1
  257. package/sample/felines/felines.controller.ts +0 -76
  258. package/sample/felines/felines.gateway.ts +0 -76
  259. package/sample/felines/felines.module.ts +0 -15
  260. package/sample/felines/felines.service.ts +0 -24
  261. package/sample/felines/rto/feline.rto.ts +0 -17
  262. package/sample/felines/rto/index.ts +0 -1
  263. package/sample/index.ts +0 -3
  264. package/sample/main.ts +0 -34
  265. package/src/asyncapi-document.builder.ts +0 -172
  266. package/src/asyncapi.constants.ts +0 -8
  267. package/src/asyncapi.module.ts +0 -65
  268. package/src/binding/asyncapi.amqp.interfaces.ts +0 -48
  269. package/src/binding/asyncapi.kafka.interfaces.ts +0 -35
  270. package/src/binding/index.ts +0 -2
  271. package/src/decorators/asyncapi-operation-for-meta-key.decorator.ts +0 -58
  272. package/src/decorators/asyncapi-operation.decorator.ts +0 -7
  273. package/src/decorators/asyncapi-pub.decorator.ts +0 -11
  274. package/src/decorators/asyncapi-service.decorator.ts +0 -9
  275. package/src/decorators/asyncapi-sub.decorator.ts +0 -11
  276. package/src/decorators/index.ts +0 -4
  277. package/src/explorers/asyncapi-class.explorer.ts +0 -26
  278. package/src/explorers/asyncapi-operation.explorer.ts +0 -40
  279. package/src/explorers/index.ts +0 -2
  280. package/src/index.ts +0 -4
  281. package/src/interface/asyncapi-common.interfaces.ts +0 -169
  282. package/src/interface/asyncapi-document-options.interface.ts +0 -3
  283. package/src/interface/asyncapi-message.interface.ts +0 -10
  284. package/src/interface/asyncapi-operation-headers.interface.ts +0 -6
  285. package/src/interface/asyncapi-operation-options-raw.interface.ts +0 -23
  286. package/src/interface/asyncapi-operation-options.interface.ts +0 -10
  287. package/src/interface/asyncapi-operation-payload.interface.ts +0 -3
  288. package/src/interface/asyncapi-server.interface.ts +0 -11
  289. package/src/interface/asyncapi-template-options.interface.ts +0 -20
  290. package/src/interface/denormalized-doc-resolvers.interface.ts +0 -6
  291. package/src/interface/denormalized-doc.interface.ts +0 -6
  292. package/src/interface/generator-options.interface.ts +0 -21
  293. package/src/interface/index.ts +0 -12
  294. package/src/services/asyncapi.explorer.ts +0 -112
  295. package/src/services/asyncapi.generator.ts +0 -45
  296. package/src/services/asyncapi.scanner.ts +0 -105
  297. package/src/services/asyncapi.transformer.ts +0 -33
  298. package/src/services/index.ts +0 -4
  299. package/src/services/operation-object.factory.ts +0 -55
  300. package/test/__mocks__/@asyncapi/generator.js +0 -41
  301. package/test/configs/jest-base.config.ts +0 -19
  302. package/test/configs/jest-e2e.config.js +0 -7
  303. package/test/configs/jest-e2e.config.ts +0 -19
  304. package/test/configs/jest-swagger-plugin.js +0 -16
  305. package/test/express.e2e-spec.ts +0 -64
  306. package/test/fastify.e2e-spec.ts +0 -65
  307. package/tsconfig.build.json +0 -4
  308. package/tsconfig.json +0 -8
@@ -1,45 +0,0 @@
1
- import fs from 'fs/promises';
2
- import jsyaml from 'js-yaml';
3
- import os from 'os';
4
- import path from 'path';
5
- import { AsyncApiDocument, AsyncApiTemplateOptions, GeneratorOptions } from '../interface';
6
-
7
- export class AsyncapiGenerator {
8
- private readonly templateOptions?: AsyncApiTemplateOptions;
9
-
10
- constructor(templateOptions?: AsyncApiTemplateOptions) {
11
- this.templateOptions = templateOptions;
12
- }
13
-
14
- public async generate(contract: AsyncApiDocument): Promise<string> {
15
- // Lazy-load @asyncapi/generator to avoid loading it at module initialization time.
16
- // This allows tests and code that only use decorators to work without
17
- // requiring the full generator dependency tree (which has nested semver issues in Jest).
18
- const { default: Generator } = await import('@asyncapi/generator');
19
-
20
- const yaml = jsyaml.dump(contract);
21
- const tmpDir = path.join(os.tmpdir(), `asyncapi-${Date.now()}-${Math.random().toString(36).slice(2)}`);
22
-
23
- const generator: GeneratorOptions = new Generator('@asyncapi/html-template', tmpDir, {
24
- forceWrite: true,
25
- templateParams: {
26
- singleFile: true,
27
- ...this.templateOptions,
28
- },
29
- });
30
-
31
- await generator.generateFromString(yaml, {
32
- resolve: {
33
- file: false,
34
- },
35
- });
36
-
37
- const htmlPath = path.join(tmpDir, 'index.html');
38
- const html = await fs.readFile(htmlPath, 'utf-8');
39
-
40
- // Clean up temp directory
41
- await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
42
-
43
- return html;
44
- }
45
- }
@@ -1,105 +0,0 @@
1
- import { INestApplicationContext, Type } from '@nestjs/common';
2
- import { MODULE_PATH } from '@nestjs/common/constants';
3
- import { Injectable, InjectionToken } from '@nestjs/common/interfaces';
4
- import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
5
- import { Module } from '@nestjs/core/injector/module';
6
- import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
7
- import { ModelPropertiesAccessor } from '@nestjs/swagger/dist/services/model-properties-accessor';
8
- import { SchemaObjectFactory } from '@nestjs/swagger/dist/services/schema-object-factory';
9
- import { SwaggerTypesMapper } from '@nestjs/swagger/dist/services/swagger-types-mapper';
10
- import { stripLastSlash } from '@nestjs/swagger/dist/utils/strip-last-slash.util';
11
- import { flatten, isEmpty } from 'lodash';
12
- import { AsyncApiDocument, AsyncApiDocumentOptions, DenormalizedDoc } from '../interface';
13
- import { AsyncApiExplorer } from './asyncapi.explorer';
14
- import { AsyncapiTransformer } from './asyncapi.transformer';
15
-
16
- export class AsyncapiScanner {
17
- private readonly transformer = new AsyncapiTransformer();
18
-
19
- private readonly explorer = new AsyncApiExplorer();
20
-
21
- private readonly modelPropertiesAccessor = new ModelPropertiesAccessor();
22
-
23
- private readonly swaggerTypesMapper = new SwaggerTypesMapper();
24
-
25
- private readonly schemaObjectFactory = new SchemaObjectFactory(this.modelPropertiesAccessor, this.swaggerTypesMapper);
26
-
27
- public scanApplication(
28
- app: INestApplicationContext,
29
- options: AsyncApiDocumentOptions,
30
- ): Omit<AsyncApiDocument, 'asyncapi' | 'info'> {
31
- const {
32
- deepScanRoutes,
33
- include: includedModules = [],
34
- extraModels = [],
35
- ignoreGlobalPrefix = false,
36
- operationIdFactory,
37
- } = options;
38
-
39
- const { container } = app as any;
40
- const modules: Module[] = this.getModules(container.getModules(), includedModules);
41
- const globalPrefix = !ignoreGlobalPrefix ? stripLastSlash(this.getGlobalPrefix(app)) : '';
42
-
43
- const denormalizedChannels = modules.reduce((channels, { providers, metatype, imports, controllers }) => {
44
- let allProviders = new Map([...providers, ...controllers]);
45
-
46
- if (deepScanRoutes) {
47
- // only load submodules routes if asked
48
- const isGlobal = (module: Type<any>) => !container.isGlobalModule(module);
49
-
50
- Array.from(imports.values())
51
- .filter(isGlobal as any)
52
- .map(({ providers: relatedProviders, controllers: relatedControllers }) => ({
53
- relatedProviders,
54
- relatedControllers,
55
- }))
56
- .forEach(({ relatedProviders, relatedControllers }) => {
57
- allProviders = new Map([...allProviders, ...relatedProviders, ...relatedControllers]);
58
- });
59
- }
60
- const path = metatype ? Reflect.getMetadata(MODULE_PATH, metatype) : undefined;
61
-
62
- return [...channels, ...this.scanModuleProviders(allProviders, path, globalPrefix, operationIdFactory)];
63
- }, []);
64
-
65
- const schemas = this.explorer.getSchemas();
66
- this.addExtraModels(schemas, extraModels);
67
- const normalizedChannels = this.transformer.normalizeChannels(flatten(denormalizedChannels));
68
- return {
69
- ...normalizedChannels,
70
- components: { schemas },
71
- };
72
- }
73
-
74
- private scanModuleProviders(
75
- providers: Map<InjectionToken, InstanceWrapper<Injectable>>,
76
- modulePath?: string,
77
- globalPrefix?: string,
78
- operationIdFactory?: (controllerKey: string, methodKey: string) => string,
79
- ): DenormalizedDoc[] {
80
- const denormalizedArray = [...providers.values()].reduce((denormalized, prov) => {
81
- const object = this.explorer.explorerAsyncapiServices(prov, modulePath, globalPrefix, operationIdFactory);
82
- return [...denormalized, ...object];
83
- }, []);
84
-
85
- return flatten(denormalizedArray) as any;
86
- }
87
-
88
- private getModules(modulesContainer: Map<string, Module>, include: Function[]): Module[] {
89
- if (!include || isEmpty(include)) {
90
- return [...modulesContainer.values()];
91
- }
92
- return [...modulesContainer.values()].filter(({ metatype }) => include.some((item) => item === metatype));
93
- }
94
-
95
- private getGlobalPrefix(app: INestApplicationContext): string {
96
- const internalConfigRef = (app as any).config;
97
- return internalConfigRef?.getGlobalPrefix() || '';
98
- }
99
-
100
- private addExtraModels(schemas: Record<string, SchemaObject>, extraModels: Function[]) {
101
- extraModels.forEach((item) => {
102
- this.schemaObjectFactory.exploreModelSchema(item, schemas);
103
- });
104
- }
105
- }
@@ -1,33 +0,0 @@
1
- import { AsyncChannelObject, AsyncChannelsObject, DenormalizedDoc } from '../interface';
2
-
3
- export class AsyncapiTransformer {
4
- public normalizeChannels(denormalizedDocs: DenormalizedDoc[]): Record<'channels', AsyncChannelsObject> {
5
- const flatChannels = denormalizedDocs.map((doc: DenormalizedDoc) => {
6
- const key = doc.root?.name;
7
- const value: AsyncChannelObject = {
8
- description: doc.root?.description,
9
- bindings: doc.root?.bindings,
10
- parameters: doc.root?.parameters,
11
- subscribe: doc.operations?.sub,
12
- publish: doc.operations?.pub,
13
- };
14
- return { key, value };
15
- });
16
-
17
- const channels = flatChannels.reduce((acc, { key, value }) => {
18
- // skip entries without a channel name
19
- if (!key) return acc;
20
-
21
- if (!acc[key]) {
22
- acc[key] = value;
23
- }
24
-
25
- acc[key].publish = acc[key].publish ?? value.publish;
26
- acc[key].subscribe = acc[key].subscribe ?? value.subscribe;
27
-
28
- return acc;
29
- }, {} as AsyncChannelsObject);
30
-
31
- return { channels };
32
- }
33
- }
@@ -1,4 +0,0 @@
1
- export * from './asyncapi.generator';
2
- export * from './operation-object.factory';
3
- export * from './asyncapi.explorer';
4
- export * from './asyncapi.scanner';
@@ -1,55 +0,0 @@
1
- import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
2
- import { ModelPropertiesAccessor } from '@nestjs/swagger/dist/services/model-properties-accessor';
3
- import { SchemaObjectFactory } from '@nestjs/swagger/dist/services/schema-object-factory';
4
- import { SwaggerTypesMapper } from '@nestjs/swagger/dist/services/swagger-types-mapper';
5
- import { getSchemaPath } from '@nestjs/swagger/dist/utils';
6
- import { AsyncApiOperationOptionsRaw, AsyncMessageObject, AsyncOperationObject, OneOfMessageType } from '../interface';
7
-
8
- export class OperationObjectFactory {
9
- private readonly modelPropertiesAccessor = new ModelPropertiesAccessor();
10
-
11
- private readonly swaggerTypesMapper = new SwaggerTypesMapper();
12
-
13
- private readonly schemaObjectFactory = new SchemaObjectFactory(this.modelPropertiesAccessor, this.swaggerTypesMapper);
14
-
15
- create(
16
- operation: AsyncApiOperationOptionsRaw,
17
- produces: string[],
18
- schemas: Record<string, SchemaObject>,
19
- ): AsyncOperationObject {
20
- const { message } = operation;
21
- const { oneOf } = message as OneOfMessageType;
22
-
23
- if (oneOf) {
24
- return {
25
- ...operation,
26
- message: {
27
- oneOf: oneOf.map((i) => ({
28
- ...i,
29
- payload: {
30
- $ref: getSchemaPath(this.getDtoName(i as AsyncMessageObject, schemas)),
31
- },
32
- })),
33
- },
34
- };
35
- }
36
-
37
- return {
38
- ...operation,
39
- message: {
40
- ...operation.message,
41
- payload: {
42
- $ref: getSchemaPath(this.getDtoName(message as AsyncMessageObject, schemas)),
43
- },
44
- },
45
- };
46
- }
47
-
48
- private getDtoName(message: AsyncMessageObject, schemas: Record<string, SchemaObject>): string {
49
- if (!message.payload || !message.payload.type) {
50
- throw new Error('Async message payload or payload.type is undefined; ensure message.payload is provided.');
51
- }
52
- const messagePayloadType = message.payload.type as Function;
53
- return this.schemaObjectFactory.exploreModelSchema(messagePayloadType, schemas);
54
- }
55
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Mock for @asyncapi/generator to avoid ESM issues in Jest tests.
3
- */
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
-
8
- class MockGenerator {
9
- constructor(templateName, targetDir, options = {}) {
10
- this.templateName = templateName;
11
- this.targetDir = targetDir;
12
- this.options = options;
13
- }
14
-
15
- async generateFromString(yaml) {
16
- const html = `<!DOCTYPE html>
17
- <html>
18
- <head>
19
- <title>AsyncAPI Documentation</title>
20
- </head>
21
- <body>
22
- <h1>AsyncAPI Documentation</h1>
23
- <p>Mock HTML generated for testing</p>
24
- <pre>${yaml.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</pre>
25
- </body>
26
- </html>`;
27
-
28
- // Create the target directory and write the file
29
- fs.mkdirSync(this.targetDir, { recursive: true });
30
- fs.writeFileSync(path.join(this.targetDir, 'index.html'), html, 'utf-8');
31
-
32
- return html;
33
- }
34
-
35
- async generate(asyncapi) {
36
- return this.generateFromString(JSON.stringify(asyncapi, null, 2));
37
- }
38
- }
39
-
40
- module.exports = MockGenerator;
41
- module.exports.default = MockGenerator;
@@ -1,19 +0,0 @@
1
- import { JestConfigWithTsJest } from 'ts-jest';
2
-
3
- export const baseConfig: JestConfigWithTsJest = {
4
- moduleFileExtensions: ['js', 'json', 'ts'],
5
- rootDir: '../../',
6
- transform: {
7
- '^.+\\.(t|j)s$': 'ts-jest',
8
- },
9
- collectCoverageFrom: ['**/*.(t|j)s'],
10
- coverageDirectory: './coverage',
11
- testEnvironment: 'node',
12
- moduleNameMapper: {
13
- '#lib(|/.*)$': '<rootDir>/lib/$1',
14
- '#sample(|/.*)$': '<rootDir>/sample/$1',
15
- '#test(|/.*)$': '<rootDir>/test/$1',
16
- },
17
- };
18
-
19
- export default baseConfig;
@@ -1,7 +0,0 @@
1
- // Forzamos ts-node desde aquí antes de importar la config real
2
- require('ts-node').register({
3
- transpileOnly: true,
4
- });
5
-
6
- // Si usas `export default` en tu config.ts:
7
- module.exports = require('./jest-e2e.config.ts').default;
@@ -1,19 +0,0 @@
1
- import { JestConfigWithTsJest } from 'ts-jest';
2
- import { baseConfig } from './jest-base.config';
3
-
4
- export const e2eConfig: JestConfigWithTsJest = {
5
- ...baseConfig,
6
- testRegex: '.\\.e2e-spec\\.ts$',
7
- transform: {
8
- '^.+\\.(t|j)s$': [
9
- 'ts-jest',
10
- {
11
- astTransformers: {
12
- before: ['test/configs/jest-swagger-plugin.js'],
13
- },
14
- },
15
- ],
16
- },
17
- };
18
-
19
- export default e2eConfig;
@@ -1,16 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-var-requires
2
- const transformer = require('@nestjs/swagger/plugin');
3
-
4
- module.exports.name = 'nestjs-swagger-transformer';
5
- // you should change the version number anytime you change the configuration below - otherwise, jest will not detect changes
6
- module.exports.version = 1;
7
-
8
- module.exports.factory = (cs) => {
9
- return transformer.before(
10
- {
11
- introspectComments: true,
12
- dtoFileNameSuffix: ['.dto.ts', '.class.ts'],
13
- },
14
- cs.program, // "cs.tsCompiler.program" for older versions of Jest (<= v27)
15
- );
16
- };
@@ -1,64 +0,0 @@
1
- import { NestFactory } from '@nestjs/core';
2
- import { ExpressAdapter, NestExpressApplication } from '@nestjs/platform-express';
3
- import * as fs from 'fs/promises';
4
- import jsyaml from 'js-yaml';
5
- import request from 'supertest';
6
- import { AsyncApiModule } from '../src';
7
- import { AppModule } from '../sample/app.module';
8
- import { makeAsyncapiDocument } from '../sample/common';
9
- import { DOC_RELATIVE_PATH } from '../sample/constants';
10
-
11
- describe('Express AsyncAPI', () => {
12
- let app: NestExpressApplication;
13
-
14
- beforeAll(async () => {
15
- app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter(), { logger: false });
16
- const asyncapiDocument = await makeAsyncapiDocument(app);
17
- await AsyncApiModule.setup(DOC_RELATIVE_PATH, app, asyncapiDocument);
18
-
19
- await app.init();
20
- });
21
-
22
- it('should serve doc html', async () => {
23
- const { text } = await request(app.getHttpServer())
24
- .get(DOC_RELATIVE_PATH)
25
- .expect(200)
26
- .expect('Content-Type', /text\/html/);
27
- const htmlSample = await fs.readFile('./misc/references/ref.html', {
28
- encoding: 'utf8',
29
- });
30
- expect(text).toEqual(htmlSample);
31
- });
32
-
33
- it('should serve doc json', async () => {
34
- const { text } = await request(app.getHttpServer())
35
- .get(`${DOC_RELATIVE_PATH}-json`)
36
- .expect(200)
37
- .expect('Content-Type', /application\/json/);
38
-
39
- const jsonFetched = JSON.parse(text);
40
- const jsonReferenceSample = JSON.parse(
41
- await fs.readFile('./misc/references/ref.json', {
42
- encoding: 'utf8',
43
- }),
44
- );
45
-
46
- expect(jsonFetched).toEqual(jsonReferenceSample);
47
- });
48
-
49
- it('should serve doc yaml', async () => {
50
- const { text } = await request(app.getHttpServer())
51
- .get(`${DOC_RELATIVE_PATH}-yaml`)
52
- .expect(200)
53
- .expect('Content-Type', /text\/yaml/);
54
-
55
- const yamlFetched = jsyaml.load(text);
56
- const yamlReferenceSample = jsyaml.load(
57
- await fs.readFile('./misc/references/ref.yaml', {
58
- encoding: 'utf8',
59
- }),
60
- );
61
-
62
- expect(yamlFetched).toEqual(yamlReferenceSample);
63
- });
64
- });
@@ -1,65 +0,0 @@
1
- import { NestFactory } from '@nestjs/core';
2
- import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
3
- import fs from 'fs/promises';
4
- import jsyaml from 'js-yaml';
5
- import request from 'supertest';
6
- import { AsyncApiModule } from '../src';
7
- import { AppModule } from '../sample/app.module';
8
- import { makeAsyncapiDocument } from '../sample/common';
9
- import { DOC_RELATIVE_PATH } from '../sample/constants';
10
-
11
- describe('Fastify AsyncAPI', () => {
12
- let app: NestFastifyApplication;
13
-
14
- beforeAll(async () => {
15
- app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter(), { logger: false });
16
- const asyncapiDocument = await makeAsyncapiDocument(app);
17
- await AsyncApiModule.setup(DOC_RELATIVE_PATH, app, asyncapiDocument);
18
-
19
- await app.init();
20
- await app.getHttpAdapter().getInstance().ready();
21
- });
22
-
23
- it('should serve doc html', async () => {
24
- const { text } = await request(app.getHttpServer())
25
- .get(DOC_RELATIVE_PATH)
26
- .expect(200)
27
- .expect('Content-Type', /text\/html/);
28
- const htmlSample = await fs.readFile('./misc/references/ref.html', {
29
- encoding: 'utf8',
30
- });
31
- expect(text).toEqual(htmlSample);
32
- });
33
-
34
- it('should serve doc json', async () => {
35
- const { text } = await request(app.getHttpServer())
36
- .get(`${DOC_RELATIVE_PATH}-json`)
37
- .expect(200)
38
- .expect('Content-Type', /application\/json/);
39
-
40
- const jsonFetched = JSON.parse(text);
41
- const jsonReferenceSample = JSON.parse(
42
- await fs.readFile('./misc/references/ref.json', {
43
- encoding: 'utf8',
44
- }),
45
- );
46
-
47
- expect(jsonFetched).toEqual(jsonReferenceSample);
48
- });
49
-
50
- it('should serve doc yaml', async () => {
51
- const { text } = await request(app.getHttpServer())
52
- .get(`${DOC_RELATIVE_PATH}-yaml`)
53
- .expect(200)
54
- .expect('Content-Type', /text\/yaml/);
55
-
56
- const yamlFetched = jsyaml.load(text);
57
- const yamlReferenceSample = jsyaml.load(
58
- await fs.readFile('./misc/references/ref.yaml', {
59
- encoding: 'utf8',
60
- }),
61
- );
62
-
63
- expect(yamlFetched).toEqual(yamlReferenceSample);
64
- });
65
- });
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4
- }
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "@achinet/tsconfig/nestjs.json",
3
- "compilerOptions": {
4
- "outDir": "dist"
5
- },
6
- "exclude": ["node_modules", "dist"]
7
- }
8
-