@achinet/nestjs-async 0.2.0 → 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 +54 -34
  54. package/.prettierrc +0 -5
  55. package/CHANGELOG.md +0 -26
  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,12 +0,0 @@
1
- export const DOC_RELATIVE_PATH = '/async-api';
2
- export const BOOTSTRAP = 'Bootstrap';
3
- export const PORT = 4001;
4
- export const HOST = '0.0.0.0';
5
- export const SERVER = {
6
- europe: 'europe',
7
- asia: 'asia',
8
- northAmerica: 'north-america',
9
- southAmerica: 'south-america',
10
- africa: 'africa',
11
- australia: 'australia',
12
- };
@@ -1,9 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger';
2
- import { Feline } from './feline.class';
3
-
4
- export class Cat extends Feline {
5
- @ApiProperty({
6
- example: 'Maine Coon',
7
- })
8
- breed: string;
9
- }
@@ -1,29 +0,0 @@
1
- enum PawsEnum {
2
- left = 'left',
3
- right = 'right',
4
- }
5
-
6
- enum GendersEnum {
7
- male = 'male',
8
- female = 'female',
9
- }
10
-
11
- export abstract class Feline {
12
- id: number;
13
-
14
- name: string;
15
-
16
- age: number;
17
-
18
- gender: GendersEnum;
19
-
20
- dominantPaw: PawsEnum;
21
-
22
- tags: string[];
23
-
24
- birthDatetime: Date;
25
-
26
- constructor(initializer: Record<string, unknown>) {
27
- Object.assign(this, initializer);
28
- }
29
- }
@@ -1,5 +0,0 @@
1
- export * from './feline.class';
2
- export * from './cat.class';
3
- export * from './lion.class';
4
- export * from './tiger.class';
5
- export * from './message.class';
@@ -1,5 +0,0 @@
1
- import { Feline } from './feline.class';
2
-
3
- export class Lion extends Feline {
4
- roarVolume: number;
5
- }
@@ -1,17 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger';
2
-
3
- export abstract class Message<T extends Record<string, any>> {
4
- @ApiProperty({ format: 'uuid' })
5
- correlationId: string;
6
-
7
- @ApiProperty({ format: 'x.y.z', example: '1.0.1' })
8
- version: string;
9
-
10
- timestamp: Date;
11
-
12
- abstract payload: T;
13
-
14
- constructor(partialData: Partial<Message<T>>) {
15
- Object.assign(this, partialData);
16
- }
17
- }
@@ -1,5 +0,0 @@
1
- import { Feline } from './feline.class';
2
-
3
- export class Tiger extends Feline {
4
- numberOfStripes: number;
5
- }
@@ -1,13 +0,0 @@
1
- import { ApiProperty, getSchemaPath } from '@nestjs/swagger';
2
- import { Cat, Feline, Lion, Message, Tiger } from '../class';
3
-
4
- export class CreateFelineDto extends Message<Feline> {
5
- @ApiProperty({
6
- oneOf: [
7
- { $ref: getSchemaPath(Cat) },
8
- { $ref: getSchemaPath(Lion) },
9
- { $ref: getSchemaPath(Tiger) },
10
- ],
11
- })
12
- payload: Feline;
13
- }
@@ -1,2 +0,0 @@
1
- export * from '../class/message.class';
2
- export * from './create-feline.dto';
@@ -1,5 +0,0 @@
1
- import { Message } from '../class';
2
-
3
- export class JournalingDataDto extends Message<Record<string, unknown>> {
4
- payload: Record<string, unknown>;
5
- }
@@ -1 +0,0 @@
1
- export const FELINES_MS = 'FELINES_MS';
@@ -1,76 +0,0 @@
1
- import { Controller, Get, Inject, Logger } from '@nestjs/common';
2
- import { ClientProxy, EventPattern } from '@nestjs/microservices';
3
- import { CreateFelineDto } from './dto';
4
- import { AsyncApiPub, AsyncApiSub } from '../../src';
5
- import { Cat, Feline } from '../../sample/felines/class';
6
- import { JournalingDataDto } from '../../sample/felines/dto/journaling-data.dto';
7
- import { FELINES_MS } from '../../sample/felines/felines.constants';
8
- import { FelinesService } from '../../sample/felines/felines.service';
9
- import { FelineRto } from '../../sample/felines/rto';
10
-
11
- const EventPatternsMS = {
12
- createFeline: 'ms/create/feline',
13
- journal: 'ms/journal',
14
- };
15
-
16
- /**
17
- * How to use AsyncApi in a microservices
18
- */
19
- @Controller()
20
- export class FelinesController {
21
- private logger: Logger = new Logger(FelinesController.name);
22
-
23
- constructor(
24
- @Inject(FELINES_MS)
25
- private readonly client: ClientProxy,
26
- private readonly felinesService: FelinesService,
27
- ) {}
28
-
29
- @AsyncApiSub({
30
- channel: EventPatternsMS.journal,
31
- message: {
32
- payload: JournalingDataDto,
33
- },
34
- })
35
- @EventPattern(EventPatternsMS.journal)
36
- async journal(dataForJournaling: JournalingDataDto) {
37
- const dataForJournalingString = JSON.stringify(dataForJournaling, null, 4);
38
- this.logger.log(`journaling:\n${dataForJournalingString}`);
39
- }
40
-
41
- @AsyncApiPub({
42
- channel: EventPatternsMS.createFeline,
43
- message: {
44
- payload: CreateFelineDto,
45
- },
46
- })
47
- @AsyncApiSub({
48
- channel: EventPatternsMS.createFeline,
49
- message: {
50
- payload: FelineRto,
51
- },
52
- })
53
- @EventPattern(EventPatternsMS.createFeline)
54
- async createFeline(createFelineDto: CreateFelineDto) {
55
- const feline = await this.felinesService.create(createFelineDto);
56
- this.logger.debug(`feline created:\n${JSON.stringify(feline)}`);
57
- this.publishCreatedFeline(feline);
58
- }
59
-
60
- publishCreatedFeline(feline: Feline) {
61
- const felineRto = new FelineRto({ payload: feline });
62
- return this.client.emit(EventPatternsMS.journal, felineRto);
63
- }
64
-
65
- @Get()
66
- async do() {
67
- const cat = new Cat({
68
- id: 123,
69
- name: 'demo',
70
- });
71
-
72
- const felineRto = new CreateFelineDto({ payload: cat });
73
-
74
- await this.createFeline(felineRto);
75
- }
76
- }
@@ -1,76 +0,0 @@
1
- import { Logger } from '@nestjs/common';
2
- import {
3
- ConnectedSocket,
4
- MessageBody,
5
- OnGatewayDisconnect,
6
- OnGatewayInit,
7
- SubscribeMessage,
8
- WebSocketGateway,
9
- WebSocketServer,
10
- } from '@nestjs/websockets';
11
- import { Namespace, Server } from 'socket.io';
12
- import { Socket } from 'socket.io-client';
13
- import { FelinesService } from './/felines.service';
14
- import { CreateFelineDto } from './dto';
15
- import { FelineExtendedRto, FelineRto } from './rto';
16
- import { AsyncApiPub, AsyncApiSub } from '../../src';
17
-
18
- const EventPatternsWS = {
19
- createFeline: 'ws/create/feline',
20
- };
21
-
22
- /**
23
- * How to use AsyncApi in a websockets
24
- */
25
- @WebSocketGateway({ transports: ['websocket'], namespace: 'ws' })
26
- export class FelinesGateway implements OnGatewayInit, OnGatewayDisconnect {
27
- @WebSocketServer()
28
- private readonly server: Server;
29
- private readonly logger: Logger = new Logger(FelinesGateway.name);
30
-
31
- constructor(private readonly felinesService: FelinesService) {}
32
-
33
- afterInit(nsp: Namespace) {
34
- this.logger.log(`Gateway server init: ${nsp?.name}`);
35
- }
36
-
37
- handleDisconnect(client: Socket) {
38
- this.logger.log(`Client disconnected: ${client.id}`);
39
- }
40
-
41
- @SubscribeMessage(EventPatternsWS.createFeline)
42
- @AsyncApiPub({
43
- channel: EventPatternsWS.createFeline,
44
- message: {
45
- payload: CreateFelineDto,
46
- },
47
- })
48
- async createFeline(
49
- @ConnectedSocket() client: Socket,
50
- @MessageBody() createFelineDto: CreateFelineDto,
51
- ) {
52
- this.logger.log(
53
- `data from client ${client.id} : ${JSON.stringify(createFelineDto)}`,
54
- );
55
-
56
- const feline = await this.felinesService.create(createFelineDto);
57
- await this.emitCreatedFeline(new FelineRto({ payload: feline }));
58
- }
59
-
60
- @AsyncApiSub({
61
- channel: EventPatternsWS.createFeline,
62
- message: [
63
- {
64
- name: 'oneOf demo #1',
65
- payload: FelineRto,
66
- },
67
- {
68
- name: 'oneOf demo #2',
69
- payload: FelineExtendedRto,
70
- },
71
- ],
72
- })
73
- async emitCreatedFeline(felineRto: FelineRto) {
74
- this.server.emit(EventPatternsWS.createFeline, felineRto);
75
- }
76
- }
@@ -1,15 +0,0 @@
1
- import { Module } from '@nestjs/common';
2
- import { ClientsModule, Transport } from '@nestjs/microservices';
3
- import { FELINES_MS } from './felines.constants';
4
- import { FelinesController } from './felines.controller';
5
- import { FelinesGateway } from './felines.gateway';
6
- import { FelinesService } from './felines.service';
7
-
8
- @Module({
9
- imports: [
10
- ClientsModule.register([{ name: FELINES_MS, transport: Transport.TCP }]),
11
- ],
12
- providers: [FelinesService, FelinesGateway],
13
- controllers: [FelinesController],
14
- })
15
- export class FelinesModule {}
@@ -1,24 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { Feline } from './class';
3
- import { CreateFelineDto } from './dto';
4
-
5
- @Injectable()
6
- export class FelinesService {
7
- private readonly felines: Feline[] = [];
8
-
9
- async get(id: number): Promise<Feline> {
10
- return this.felines[id];
11
- }
12
-
13
- async delete(id: number): Promise<boolean> {
14
- const felineToDelete = this.get(id);
15
- delete this.felines[id];
16
- return !!felineToDelete;
17
- }
18
-
19
- async create(createFelineDto: CreateFelineDto): Promise<Feline> {
20
- const feline = createFelineDto.payload;
21
- this.felines.push(feline);
22
- return feline;
23
- }
24
- }
@@ -1,17 +0,0 @@
1
- import { ApiProperty, getSchemaPath } from '@nestjs/swagger';
2
- import { Cat, Feline, Lion, Message, Tiger } from '../class';
3
-
4
- export class FelineRto extends Message<Feline> {
5
- @ApiProperty({
6
- oneOf: [
7
- { $ref: getSchemaPath(Cat) },
8
- { $ref: getSchemaPath(Lion) },
9
- { $ref: getSchemaPath(Tiger) },
10
- ],
11
- })
12
- payload: Feline;
13
- }
14
-
15
- export class FelineExtendedRto extends FelineRto {
16
- extra: string;
17
- }
@@ -1 +0,0 @@
1
- export * from './feline.rto';
package/sample/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './app.module';
2
- export * from './common';
3
- export * from './constants';
package/sample/main.ts DELETED
@@ -1,34 +0,0 @@
1
- import { INestApplication, Logger } from '@nestjs/common';
2
- import { NestFactory } from '@nestjs/core';
3
- import { MicroserviceOptions, Transport } from '@nestjs/microservices';
4
- import { ExpressAdapter } from '@nestjs/platform-express';
5
- import { FastifyAdapter } from '@nestjs/platform-fastify';
6
- import { AppModule } from './app.module';
7
- import { makeAsyncapiDocument } from './common';
8
- import { BOOTSTRAP, DOC_RELATIVE_PATH, HOST, PORT } from './constants';
9
- import { AsyncApiModule } from '../src';
10
-
11
- const USE_FASTIFY = false;
12
-
13
- const adapter = USE_FASTIFY
14
- ? new FastifyAdapter({
15
- ignoreTrailingSlash: false,
16
- })
17
- : new ExpressAdapter();
18
-
19
- async function bootstrap(): Promise<void> {
20
- const app = await NestFactory.create<INestApplication>(AppModule, adapter, {});
21
- const asyncapiDocument = await makeAsyncapiDocument(app);
22
- await AsyncApiModule.setup(DOC_RELATIVE_PATH, app, asyncapiDocument);
23
-
24
- app.connectMicroservice<MicroserviceOptions>({ transport: Transport.TCP });
25
-
26
- await app.startAllMicroservices();
27
- await app.listen(PORT, HOST);
28
-
29
- const baseUrl = `http://${HOST}:${PORT}`;
30
- const docUrl = baseUrl + DOC_RELATIVE_PATH;
31
- Logger.log(`Server started at ${baseUrl}; AsyncApi at ${docUrl};`, BOOTSTRAP);
32
- }
33
-
34
- bootstrap();
@@ -1,172 +0,0 @@
1
- import {
2
- ExternalDocumentationObject,
3
- SecuritySchemeObject,
4
- TagObject,
5
- } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
6
- import { isUndefined, negate, pickBy } from 'lodash';
7
- import { AsyncApiDocument, AsyncSecuritySchemeObject, AsyncServerObject } from './interface';
8
-
9
- export class AsyncApiDocumentBuilder {
10
- private readonly buildDocumentBase = (): Omit<AsyncApiDocument, 'channels'> => ({
11
- asyncapi: '2.5.0',
12
- info: {
13
- title: '',
14
- description: '',
15
- version: '1.0.0',
16
- contact: {},
17
- },
18
- tags: [],
19
- servers: {},
20
- components: {},
21
- });
22
-
23
- private readonly document: Omit<AsyncApiDocument, 'channels'> = this.buildDocumentBase();
24
-
25
- public setTitle(title: string): this {
26
- this.document.info.title = title;
27
- return this;
28
- }
29
-
30
- public setDescription(description: string): this {
31
- this.document.info.description = description;
32
- return this;
33
- }
34
-
35
- public setVersion(version: string): this {
36
- this.document.info.version = version;
37
- return this;
38
- }
39
-
40
- public setTermsOfService(termsOfService: string): this {
41
- this.document.info.termsOfService = termsOfService;
42
- return this;
43
- }
44
-
45
- public setContact(name: string, url: string, email: string): this {
46
- this.document.info.contact = { name, url, email };
47
- return this;
48
- }
49
-
50
- public setLicense(name: string, url: string): this {
51
- this.document.info.license = { name, url };
52
- return this;
53
- }
54
-
55
- public addServer(name: string, server: AsyncServerObject): this {
56
- this.document.servers![name] = server;
57
- return this;
58
- }
59
-
60
- public addServers(servers: { name: string; server: AsyncServerObject }[]): this {
61
- for (const { name, server } of servers) {
62
- this.addServer(name, server);
63
- }
64
-
65
- return this;
66
- }
67
-
68
- public setExternalDoc(description: string, url: string): this {
69
- this.document.externalDocs = { description, url };
70
- return this;
71
- }
72
-
73
- public setDefaultContentType(contentType: string) {
74
- this.document.defaultContentType = contentType;
75
- return this;
76
- }
77
-
78
- public addTag(name: string, description = '', externalDocs?: ExternalDocumentationObject): this {
79
- this.document.tags = this.document.tags!.concat(
80
- pickBy(
81
- {
82
- name,
83
- description,
84
- externalDocs,
85
- },
86
- negate(isUndefined),
87
- ) as TagObject,
88
- );
89
- return this;
90
- }
91
-
92
- public addSecurity(name: string, options: AsyncSecuritySchemeObject): this {
93
- this.document.components!.securitySchemes = {
94
- ...(this.document.components!.securitySchemes || {}),
95
- [name]: options,
96
- };
97
- return this;
98
- }
99
-
100
- public addBearerAuth(
101
- options: SecuritySchemeObject = {
102
- type: 'http',
103
- },
104
- name = 'bearer',
105
- ): this {
106
- this.addSecurity(name, {
107
- scheme: 'bearer',
108
- bearerFormat: 'JWT',
109
- ...options,
110
- });
111
- return this;
112
- }
113
-
114
- public addOAuth2(
115
- options: SecuritySchemeObject = {
116
- type: 'oauth2',
117
- },
118
- name = 'oauth2',
119
- ): this {
120
- this.addSecurity(name, {
121
- flows: {},
122
- ...options,
123
- });
124
- return this;
125
- }
126
-
127
- public addApiKey(
128
- options: SecuritySchemeObject = {
129
- type: 'apiKey',
130
- },
131
- name = 'api_key',
132
- ): this {
133
- this.addSecurity(name, {
134
- in: 'header',
135
- name,
136
- ...options,
137
- });
138
- return this;
139
- }
140
-
141
- public addBasicAuth(
142
- options: SecuritySchemeObject = {
143
- type: 'http',
144
- },
145
- name = 'basic',
146
- ): this {
147
- this.addSecurity(name, {
148
- scheme: 'basic',
149
- ...options,
150
- });
151
- return this;
152
- }
153
-
154
- public addCookieAuth(
155
- cookieName = 'connect.sid',
156
- options: SecuritySchemeObject = {
157
- type: 'apiKey',
158
- },
159
- securityName = 'cookie',
160
- ): this {
161
- this.addSecurity(securityName, {
162
- in: 'cookie',
163
- name: cookieName,
164
- ...options,
165
- });
166
- return this;
167
- }
168
-
169
- public build(): Omit<AsyncApiDocument, 'components' | 'channels'> {
170
- return this.document;
171
- }
172
- }
@@ -1,8 +0,0 @@
1
- const DECORATORS_PREFIX = 'asyncapi';
2
-
3
- export const DECORATORS = {
4
- AsyncApiClass: `${DECORATORS_PREFIX}/class`,
5
- AsyncApiOperation: `${DECORATORS_PREFIX}/operation`,
6
- AsyncApiPub: `${DECORATORS_PREFIX}/pub`,
7
- AsyncApiSub: `${DECORATORS_PREFIX}/sub`,
8
- };
@@ -1,65 +0,0 @@
1
- import { INestApplication, INestApplicationContext, Logger } from '@nestjs/common';
2
- import { validatePath } from '@nestjs/swagger/dist/utils/validate-path.util';
3
- import jsyaml from 'js-yaml';
4
- import { AsyncApiDocument, AsyncApiDocumentOptions, AsyncApiTemplateOptions } from './interface';
5
- import { AsyncapiGenerator, AsyncapiScanner } from './services';
6
-
7
- export class AsyncApiModule {
8
- private static readonly logger = new Logger(AsyncApiModule.name);
9
-
10
- public static createDocument(
11
- app: INestApplicationContext,
12
- config: Omit<AsyncApiDocument, 'channels'>,
13
- options: AsyncApiDocumentOptions = {},
14
- ): AsyncApiDocument {
15
- const asyncapiScanner = new AsyncapiScanner();
16
- const document = asyncapiScanner.scanApplication(app, options);
17
-
18
- document.components = {
19
- ...(config.components || {}),
20
- ...document.components,
21
- };
22
-
23
- return {
24
- ...config,
25
- ...document,
26
- };
27
- }
28
-
29
- static async composeHtml(contract: AsyncApiDocument, templateOptions?: AsyncApiTemplateOptions) {
30
- const generator = new AsyncapiGenerator(templateOptions);
31
- return generator.generate(contract).catch((err) => {
32
- this.logger.error(err);
33
- throw err;
34
- });
35
- }
36
-
37
- public static async setup(
38
- path: string,
39
- app: INestApplication,
40
- document: AsyncApiDocument,
41
- templateOptions?: AsyncApiTemplateOptions,
42
- ) {
43
- const httpAdapter = app.getHttpAdapter();
44
- const finalPath = validatePath(path);
45
-
46
- const html = await this.composeHtml(document, templateOptions);
47
- const yamlDocument = jsyaml.dump(document);
48
- const jsonDocument = JSON.stringify(document);
49
-
50
- httpAdapter.get(finalPath, (req, res) => {
51
- res.type('text/html');
52
- res.send(html);
53
- });
54
-
55
- httpAdapter.get(`${finalPath}-json`, (req, res) => {
56
- res.type('application/json');
57
- res.send(jsonDocument);
58
- });
59
-
60
- httpAdapter.get(`${finalPath}-yaml`, (req, res) => {
61
- res.type('text/yaml');
62
- res.send(yamlDocument);
63
- });
64
- }
65
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * AMPQ binding
3
- * @see https://github.com/asyncapi/bindings/tree/master/amqp
4
- */
5
-
6
- /**
7
- * This object MUST NOT contain any properties. Its name is reserved for future use.
8
- */
9
- export interface AmqpServerBinding {}
10
-
11
- export interface AmqpChannelBinding {
12
- is: string;
13
- exchange?: {
14
- name: string;
15
- type: string;
16
- durable?: boolean;
17
- autoDelete?: boolean;
18
- vhost?: string;
19
- };
20
- queue?: {
21
- name: string;
22
- durable?: boolean;
23
- exclusive?: boolean;
24
- autoDelete?: boolean;
25
- vhost?: string;
26
- };
27
- bindingVersion?: string;
28
- }
29
-
30
- export interface AmqpOperationBinding {
31
- expiration?: number;
32
- userId?: string;
33
- cc?: string[];
34
- priority?: number;
35
- deliveryMode?: number;
36
- mandatory?: boolean;
37
- bcc?: string[];
38
- replyTo?: string;
39
- timestamp?: boolean;
40
- ack?: boolean;
41
- bindingVersion?: string;
42
- }
43
-
44
- export interface AmqpMessageBinding {
45
- contentEncoding?: string;
46
- messageType?: string;
47
- bindingVersion?: string;
48
- }