@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,35 +0,0 @@
1
- /**
2
- * Kafka binding
3
- * @see https://github.com/asyncapi/bindings/tree/master/kafka
4
- */
5
- import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
6
-
7
- export interface KafkaServerBinding {
8
- schemaRegistryUrl: string;
9
- schemaRegistryVendor: string;
10
- /**
11
- * x.y.z
12
- */
13
- bindingVersion: string;
14
- }
15
-
16
- export interface KafkaChannelBinding {
17
- topic: string;
18
- partitions: number;
19
- replicas: number;
20
- /**
21
- * x.y.z
22
- */
23
- bindingVersion: string;
24
- }
25
-
26
- export interface KafkaOperationBinding {
27
- groupId?: SchemaObject;
28
- clientId?: SchemaObject;
29
- bindingVersion?: string;
30
- }
31
-
32
- export interface KafkaMessageBinding {
33
- key?: SchemaObject;
34
- bindingVersion?: string;
35
- }
@@ -1,2 +0,0 @@
1
- export * from './asyncapi.amqp.interfaces';
2
- export * from './asyncapi.kafka.interfaces';
@@ -1,58 +0,0 @@
1
- import { createMethodDecorator } from '@nestjs/swagger/dist/decorators/helpers';
2
- import {
3
- AsyncApiOperationHeaders,
4
- AsyncApiOperationOptions,
5
- AsyncMessageObject,
6
- AsyncOperationObject,
7
- } from '../interface';
8
- import { OneAsyncApiMessage } from '../interface/asyncapi-message.interface';
9
-
10
- function makeHeaders(headers?: AsyncApiOperationHeaders) {
11
- return headers
12
- ? {
13
- type: 'object',
14
- properties: Object.entries(headers)
15
- .map(([key, value]) => ({
16
- [key]: {
17
- type: 'string',
18
- ...value,
19
- },
20
- }))
21
- .reduce((acc, j) => ({ ...acc, ...j }), {}),
22
- }
23
- : undefined;
24
- }
25
-
26
- function makeMessage(message: OneAsyncApiMessage, defaultName: string): AsyncMessageObject {
27
- return {
28
- ...message,
29
- name: message.name || defaultName,
30
- payload: {
31
- type: message.payload,
32
- },
33
- headers: makeHeaders(message.headers),
34
- };
35
- }
36
-
37
- export function AsyncApiOperationForMetaKey(metaKey: string, options: AsyncApiOperationOptions[]): MethodDecorator {
38
- return (target, propertyKey: string | symbol, descriptor) => {
39
- const methodName = `${target.constructor.name}#${String(propertyKey)}`;
40
-
41
- const transformedOptions: AsyncOperationObject[] = options.map((i) => {
42
- const message = Array.isArray(i.message)
43
- ? {
44
- oneOf: i.message.map((j, index) => makeMessage(j, `${methodName}#${index}`)),
45
- }
46
- : makeMessage(i.message, methodName);
47
-
48
- const transformedOptionInstance = {
49
- ...i,
50
- message,
51
- };
52
-
53
- return transformedOptionInstance;
54
- });
55
-
56
- return createMethodDecorator(metaKey, transformedOptions)(target, propertyKey, descriptor);
57
- };
58
- }
@@ -1,7 +0,0 @@
1
- import { DECORATORS } from '../asyncapi.constants';
2
- import { AsyncApiOperationOptions } from '../interface';
3
- import { AsyncApiOperationForMetaKey } from './asyncapi-operation-for-meta-key.decorator';
4
-
5
- export function AsyncApiOperation(...options: AsyncApiOperationOptions[]): MethodDecorator {
6
- return AsyncApiOperationForMetaKey(DECORATORS.AsyncApiOperation, options);
7
- }
@@ -1,11 +0,0 @@
1
- import { DECORATORS } from '../asyncapi.constants';
2
- import { AsyncApiOperationOptions, AsyncApiSpecificOperationOptions } from '../interface';
3
- import { AsyncApiOperationForMetaKey } from './asyncapi-operation-for-meta-key.decorator';
4
-
5
- export function AsyncApiPub(...specificOperationOptions: AsyncApiSpecificOperationOptions[]) {
6
- const options: AsyncApiOperationOptions[] = specificOperationOptions.map((i) => ({
7
- ...i,
8
- type: 'pub',
9
- }));
10
- return AsyncApiOperationForMetaKey(DECORATORS.AsyncApiPub, options);
11
- }
@@ -1,9 +0,0 @@
1
- import { createMixedDecorator } from '@nestjs/swagger/dist/decorators/helpers';
2
- import { DECORATORS } from '../asyncapi.constants';
3
-
4
- /**
5
- * Mark class that has to be scanned for AsyncApi operations
6
- */
7
- export function AsyncApi() {
8
- return createMixedDecorator(DECORATORS.AsyncApiClass, true);
9
- }
@@ -1,11 +0,0 @@
1
- import { DECORATORS } from '../asyncapi.constants';
2
- import { AsyncApiOperationOptions, AsyncApiSpecificOperationOptions } from '../interface';
3
- import { AsyncApiOperationForMetaKey } from './asyncapi-operation-for-meta-key.decorator';
4
-
5
- export function AsyncApiSub(...specificOperationOptions: AsyncApiSpecificOperationOptions[]) {
6
- const options: AsyncApiOperationOptions[] = specificOperationOptions.map((i) => ({
7
- ...i,
8
- type: 'sub',
9
- }));
10
- return AsyncApiOperationForMetaKey(DECORATORS.AsyncApiSub, options);
11
- }
@@ -1,4 +0,0 @@
1
- export * from './asyncapi-service.decorator';
2
- export * from './asyncapi-operation.decorator';
3
- export * from './asyncapi-sub.decorator';
4
- export * from './asyncapi-pub.decorator';
@@ -1,26 +0,0 @@
1
- import { Type } from '@nestjs/common';
2
- import { CONTROLLER_WATERMARK } from '@nestjs/common/constants';
3
- import { DECORATORS } from '../asyncapi.constants';
4
-
5
- let GATEWAY_METADATA;
6
- try {
7
- // eslint-disable-next-line
8
- const wsConstants = require('@nestjs/websockets/constants');
9
- GATEWAY_METADATA = wsConstants.GATEWAY_METADATA;
10
- } catch {
11
- GATEWAY_METADATA = '__gateway__'; // in case @nestjs/websockets is not installed GATEWAY_METADATA value is irrelevant
12
- }
13
-
14
- export const asyncApiClassAnnotationLabels = [DECORATORS.AsyncApiClass, CONTROLLER_WATERMARK, GATEWAY_METADATA];
15
-
16
- export const exploreAsyncapiClassMetadata = (metatype: Type<unknown>) => {
17
- return Reflect.getMetadata(DECORATORS.AsyncApiClass, metatype);
18
- };
19
-
20
- export const exploreControllerMetadata = (metatype: Type<unknown>) => {
21
- return Reflect.getMetadata(CONTROLLER_WATERMARK, metatype);
22
- };
23
-
24
- export const exploreGatewayMetadata = (metatype: Type<unknown>) => {
25
- return Reflect.getMetadata(GATEWAY_METADATA, metatype);
26
- };
@@ -1,40 +0,0 @@
1
- import { Type } from '@nestjs/common';
2
- import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
3
- import { DECORATORS } from '../asyncapi.constants';
4
- import { AsyncApiOperationOptionsRaw } from '../interface';
5
- import { OperationObjectFactory } from '../services';
6
-
7
- const operationObjectFactory = new OperationObjectFactory();
8
-
9
- export const exploreAsyncApiOperationMetadata = (
10
- schemas: Record<string, SchemaObject>,
11
- _instance: object,
12
- _prototype: Type<unknown>,
13
- method: object,
14
- ) => {
15
- const metadataOperations: AsyncApiOperationOptionsRaw[] = Reflect.getMetadata(DECORATORS.AsyncApiOperation, method);
16
- const metadataSubs: AsyncApiOperationOptionsRaw[] = Reflect.getMetadata(DECORATORS.AsyncApiSub, method);
17
- const metadataPubs: AsyncApiOperationOptionsRaw[] = Reflect.getMetadata(DECORATORS.AsyncApiPub, method);
18
-
19
- const metadataCombined = [
20
- ...(metadataOperations ? Object.values(metadataOperations) : []),
21
- ...(metadataSubs ? Object.values(metadataSubs) : []),
22
- ...(metadataPubs ? Object.values(metadataPubs) : []),
23
- ];
24
-
25
- return metadataCombined.map((option: AsyncApiOperationOptionsRaw) => {
26
- const { channel, type } = option;
27
-
28
- const methodTypeData = {
29
- ...option,
30
- ...operationObjectFactory.create(option, ['application/json'], schemas),
31
- channel: undefined,
32
- type: undefined,
33
- };
34
-
35
- return {
36
- channel,
37
- [type]: methodTypeData,
38
- };
39
- });
40
- };
@@ -1,2 +0,0 @@
1
- export * from './asyncapi-operation.explorer';
2
- export * from './asyncapi-class.explorer';
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './asyncapi-document.builder';
2
- export * from './interface';
3
- export * from './asyncapi.module';
4
- export * from './decorators';
@@ -1,169 +0,0 @@
1
- import {
2
- InfoObject,
3
- ReferenceObject,
4
- SchemaObject,
5
- ServerVariableObject,
6
- } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
7
- import {
8
- AmqpChannelBinding,
9
- AmqpMessageBinding,
10
- AmqpOperationBinding,
11
- AmqpServerBinding,
12
- KafkaChannelBinding,
13
- KafkaMessageBinding,
14
- KafkaOperationBinding,
15
- KafkaServerBinding,
16
- } from '../binding';
17
- import { AsyncOperationPayload } from './asyncapi-operation-payload.interface';
18
- import { AsyncServerObject } from './asyncapi-server.interface';
19
-
20
- export interface AsyncApiDocument {
21
- asyncapi: string;
22
- id?: string;
23
- info: InfoObject;
24
- servers?: Record<string, AsyncServerObject>;
25
- channels: AsyncChannelsObject;
26
- components?: AsyncComponentsObject;
27
- tags?: AsyncTagObject[];
28
- externalDocs?: ExternalDocumentationObject;
29
- defaultContentType?: string;
30
- }
31
-
32
- export type AsyncChannelsObject = Record<string, AsyncChannelObject>;
33
- export interface AsyncChannelObject {
34
- description?: string;
35
- subscribe?: AsyncOperationObject;
36
- publish?: AsyncOperationObject;
37
- parameters?: Record<string, ParameterObject>;
38
- bindings?: Record<string, KafkaChannelBinding | AmqpChannelBinding>;
39
- }
40
-
41
- export interface AsyncServerVariableObject extends ServerVariableObject {
42
- examples?: string[];
43
- }
44
-
45
- export type SecurityObject = Record<string, string[]>;
46
-
47
- export interface AsyncComponentsObject {
48
- schemas?: Record<string, SchemaObject>;
49
- messages?: Record<string, AsyncMessageObject>;
50
- securitySchemes?: Record<string, AsyncSecuritySchemeObject>;
51
- parameters?: Record<string, ParameterObject>;
52
- correlationIds?: Record<string, AsyncCorrelationObject>;
53
- operationTraits?: Record<string, AsyncOperationTraitObject>;
54
- messageTraits?: Record<string, AsyncMessageTraitObject>;
55
- serverBindings?: Record<string, KafkaServerBinding | AmqpServerBinding>;
56
- channelBindings?: Record<string, KafkaChannelBinding | AmqpChannelBinding>;
57
- operationBindings?: Record<string, KafkaOperationBinding | AmqpOperationBinding>;
58
- messageBindings?: Record<string, KafkaMessageBinding | AmqpMessageBinding>;
59
- }
60
-
61
- export interface AsyncMessageObject extends AsyncMessageTraitObject {
62
- payload?: {
63
- type?: AsyncOperationPayload;
64
- $ref?: AsyncOperationPayload;
65
- };
66
- }
67
-
68
- export type MessageType = AsyncMessageObject | ReferenceObject;
69
- export interface OneOfMessageType {
70
- oneOf: MessageType[];
71
- }
72
-
73
- export type AsyncOperationMessage = OneOfMessageType | MessageType;
74
-
75
- export interface AsyncOperationObject {
76
- channel: string;
77
- operationId?: string;
78
- summary?: string;
79
- description?: string;
80
- tags?: AsyncTagObject[];
81
- externalDocs?: ExternalDocumentationObject;
82
- bindings?: Record<string, KafkaOperationBinding | AmqpOperationBinding>;
83
- traits?: Record<string, AsyncOperationTraitObject>;
84
- message?: AsyncOperationMessage;
85
- }
86
-
87
- export interface AsyncOperationTraitObject {
88
- operationId?: string;
89
- summary?: string;
90
- description?: string;
91
- tags?: AsyncTagObject[];
92
- externalDocs?: ExternalDocumentationObject;
93
- bindings?: Record<string, KafkaOperationBinding | AmqpOperationBinding>;
94
- }
95
-
96
- export interface AsyncMessageTraitObject {
97
- headers?: SchemaObject;
98
- correlationId?: AsyncCorrelationObject;
99
- schemaFormat?: string;
100
- contentType?: string;
101
- name?: string;
102
- title?: string;
103
- summary?: string;
104
- description?: string;
105
- tags?: AsyncTagObject[];
106
- externalDocs?: ExternalDocumentationObject;
107
- bindings?: Record<string, KafkaMessageBinding | AmqpMessageBinding>;
108
- }
109
-
110
- export interface AsyncCorrelationObject {
111
- description?: string;
112
- location: string;
113
- }
114
-
115
- export interface AsyncTagObject {
116
- name: string;
117
- description?: string;
118
- externalDocs?: ExternalDocumentationObject;
119
- }
120
-
121
- export interface AsyncSecuritySchemeObject {
122
- type: SecuritySchemeType;
123
- description?: string;
124
- name?: string;
125
- in?: string;
126
- scheme?: string;
127
- bearerFormat?: string;
128
- flows?: OAuthFlowsObject;
129
- openIdConnectUrl?: string;
130
- }
131
-
132
- export declare type SecuritySchemeType =
133
- | 'userPassword'
134
- | 'apiKey'
135
- | 'X509'
136
- | 'symmetricEncryption'
137
- | 'asymmetricEncryption'
138
- | 'http'
139
- | 'oauth2'
140
- | 'openIdConnect';
141
-
142
- export interface OAuthFlowsObject {
143
- implicit?: OAuthFlowObject;
144
- password?: OAuthFlowObject;
145
- clientCredentials?: OAuthFlowObject;
146
- authorizationCode?: OAuthFlowObject;
147
- }
148
-
149
- export interface OAuthFlowObject {
150
- authorizationUrl?: string;
151
- tokenUrl?: string;
152
- refreshUrl?: string;
153
- scopes: ScopesObject;
154
- }
155
-
156
- export type ScopesObject = Record<string, unknown>;
157
-
158
- export type ParameterObject = BaseParameterObject;
159
-
160
- export interface BaseParameterObject {
161
- description?: string;
162
- schema?: SchemaObject | ReferenceObject;
163
- location?: string;
164
- }
165
-
166
- export interface ExternalDocumentationObject {
167
- description?: string;
168
- url: string;
169
- }
@@ -1,3 +0,0 @@
1
- import { SwaggerDocumentOptions } from '@nestjs/swagger';
2
-
3
- export interface AsyncApiDocumentOptions extends SwaggerDocumentOptions {}
@@ -1,10 +0,0 @@
1
- import { AsyncApiOperationHeaders } from './asyncapi-operation-headers.interface';
2
- import { AsyncOperationPayload } from './asyncapi-operation-payload.interface';
3
-
4
- export interface OneAsyncApiMessage {
5
- name?: string;
6
- payload: AsyncOperationPayload;
7
- headers?: AsyncApiOperationHeaders;
8
- }
9
-
10
- export type AsyncApiMessage = OneAsyncApiMessage | OneAsyncApiMessage[];
@@ -1,6 +0,0 @@
1
- export interface AsyncApiOperationHeaders {
2
- [key: string]: {
3
- description: string;
4
- [key: string]: unknown;
5
- };
6
- }
@@ -1,23 +0,0 @@
1
- import { AsyncOperationObject } from './asyncapi-common.interfaces';
2
- import { AsyncOperationPayload } from './asyncapi-operation-payload.interface';
3
-
4
- export interface RawAsyncApiMessage {
5
- name?: string;
6
- payload: {
7
- type: AsyncOperationPayload;
8
- };
9
- headers?: {
10
- type: 'object';
11
- properties: {
12
- [key: string]: {
13
- description: string;
14
- type: 'string';
15
- [key: string]: unknown;
16
- };
17
- };
18
- };
19
- }
20
-
21
- export interface AsyncApiOperationOptionsRaw extends AsyncOperationObject {
22
- type: 'sub' | 'pub';
23
- }
@@ -1,10 +0,0 @@
1
- import { AsyncOperationObject } from './asyncapi-common.interfaces';
2
- import { AsyncApiMessage } from './asyncapi-message.interface';
3
-
4
- export interface AsyncApiSpecificOperationOptions extends Omit<AsyncOperationObject, 'message'> {
5
- message: AsyncApiMessage;
6
- }
7
-
8
- export interface AsyncApiOperationOptions extends AsyncApiSpecificOperationOptions {
9
- type: 'pub' | 'sub';
10
- }
@@ -1,3 +0,0 @@
1
- import { Type } from '@nestjs/common';
2
-
3
- export type AsyncOperationPayload = Type<unknown> | Function | [Function] | string;
@@ -1,11 +0,0 @@
1
- import { ServerObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
2
- import { AmqpServerBinding, KafkaServerBinding } from '../binding';
3
- import { AsyncServerVariableObject, SecurityObject } from './asyncapi-common.interfaces';
4
-
5
- export interface AsyncServerObject extends Omit<ServerObject, 'variables'> {
6
- variables?: Record<string, AsyncServerVariableObject>;
7
- protocol: string;
8
- protocolVersion?: string;
9
- security?: SecurityObject[];
10
- bindings?: Record<string, KafkaServerBinding | AmqpServerBinding>;
11
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * @see https://github.com/asyncapi/html-template#supported-parameters
3
- * */
4
- export interface AsyncApiTemplateOptions {
5
- /** @default byTagsNoRoot * */
6
- sidebarOrganization?: 'byTags' | 'byTagsNoRoot';
7
- /**
8
- * @example /docs
9
- * */
10
- baseHref?: string;
11
- /** @default true * */
12
- singleFile?: boolean;
13
- /** @example asyncapi.html * */
14
- outFilename?: string;
15
- /**
16
- * @description Generates output HTML as PDF
17
- * @default false
18
- */
19
- pdf?: boolean;
20
- }
@@ -1,6 +0,0 @@
1
- export interface DenormalizedDocResolvers {
2
- root: Function[];
3
- security: Function[];
4
- tags: Function[];
5
- operations: Function[];
6
- }
@@ -1,6 +0,0 @@
1
- import { AsyncApiDocument, AsyncChannelObject, AsyncOperationObject } from './asyncapi-common.interfaces';
2
-
3
- export interface DenormalizedDoc extends Partial<AsyncApiDocument> {
4
- root?: { name: string } & AsyncChannelObject;
5
- operations?: { pub: AsyncOperationObject; sub: AsyncOperationObject };
6
- }
@@ -1,21 +0,0 @@
1
- import { AsyncApiDocument } from './asyncapi-common.interfaces';
2
- import { AsyncApiTemplateOptions } from './asyncapi-template-options.interface';
3
-
4
- export interface GeneratorOptions {
5
- templateName: string;
6
- targetDir: string;
7
- entrypoint?: string;
8
- noOverwriteGlobs: string[];
9
- disabledHooks: { [key: string]: string | boolean | string[] };
10
- output: 'string' | 'fs';
11
- forceWrite: boolean;
12
- debug: boolean;
13
- install: boolean;
14
- templateConfig: Record<string, unknown>;
15
- hooks: Record<string, unknown>;
16
- templateParams: AsyncApiTemplateOptions;
17
- generate: (document: AsyncApiDocument) => Promise<void>;
18
- generateFromURL: (url: string) => Promise<void>;
19
- generateFromFile: (path: string) => Promise<void>;
20
- generateFromString: (yaml: string, args?: unknown) => Promise<string>;
21
- }
@@ -1,12 +0,0 @@
1
- export * from './asyncapi-common.interfaces';
2
- export * from './asyncapi-template-options.interface';
3
- export * from './asyncapi-operation-headers.interface';
4
- export * from './asyncapi-operation-payload.interface';
5
- export * from './asyncapi-operation-options.interface';
6
- export * from './asyncapi-document-options.interface';
7
- export * from './asyncapi-server.interface';
8
- export * from './denormalized-doc.interface';
9
- export * from './denormalized-doc-resolvers.interface';
10
- export * from './generator-options.interface';
11
-
12
- export * from './asyncapi-operation-options-raw.interface';
@@ -1,112 +0,0 @@
1
- import { Type } from '@nestjs/common';
2
- import { MetadataScanner } from '@nestjs/core';
3
- import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
4
- import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
5
- import { flatten } from 'lodash';
6
- import {
7
- asyncApiClassAnnotationLabels,
8
- exploreAsyncapiClassMetadata,
9
- exploreAsyncApiOperationMetadata,
10
- exploreControllerMetadata,
11
- exploreGatewayMetadata,
12
- } from '../explorers';
13
- import { DenormalizedDoc, DenormalizedDocResolvers } from '../interface';
14
-
15
- export class AsyncApiExplorer {
16
- private readonly metadataScanner = new MetadataScanner();
17
-
18
- private readonly schemas: SchemaObject[] = [];
19
-
20
- private readonly schemaRefsStack: string[] = [];
21
-
22
- private operationIdFactory = (controllerKey: string, methodKey: string) =>
23
- controllerKey ? `${controllerKey}_${methodKey}` : methodKey;
24
-
25
- public explorerAsyncapiServices(
26
- wrapper: InstanceWrapper,
27
- modulePath?: string,
28
- globalPrefix?: string,
29
- operationIdFactory?: (controllerKey: string, methodKey: string) => string,
30
- ) {
31
- if (operationIdFactory) {
32
- this.operationIdFactory = operationIdFactory;
33
- }
34
-
35
- const { instance, metatype } = wrapper;
36
- if (
37
- !instance ||
38
- !metatype ||
39
- !Reflect.getMetadataKeys(metatype).find((label) => asyncApiClassAnnotationLabels.includes(label))
40
- ) {
41
- return [];
42
- }
43
-
44
- const prototype = Object.getPrototypeOf(instance);
45
- const documentResolvers: DenormalizedDocResolvers = {
46
- root: [exploreAsyncapiClassMetadata, exploreControllerMetadata, exploreGatewayMetadata],
47
- security: [],
48
- tags: [],
49
- operations: [exploreAsyncApiOperationMetadata],
50
- };
51
-
52
- return this.generateDenormalizedDocument(
53
- metatype as Type<unknown>,
54
- prototype,
55
- instance,
56
- documentResolvers,
57
- modulePath,
58
- globalPrefix,
59
- );
60
- }
61
-
62
- public getSchemas(): Record<string, SchemaObject> {
63
- const ret = { ...this.schemas } as unknown as Record<string, SchemaObject>;
64
- return ret;
65
- }
66
-
67
- private generateDenormalizedDocument(
68
- metatype: Type<unknown>,
69
- prototype: Type<unknown>,
70
- instance: object,
71
- documentResolvers: DenormalizedDocResolvers,
72
- _modulePath?: string,
73
- _globalPrefix?: string,
74
- ): DenormalizedDoc[] {
75
- const denormalizedAsyncapiServices = this.metadataScanner.scanFromPrototype<unknown, DenormalizedDoc[]>(
76
- instance,
77
- prototype,
78
- (name) => {
79
- const targetCallback = prototype[name];
80
- const methodMetadata = documentResolvers.root.reduce((_metadata, fn) => {
81
- const serviceMetadata = fn(metatype);
82
-
83
- const channels = documentResolvers.operations.reduce((operationsParam, exploreOperationsMeta) => {
84
- const operations = operationsParam;
85
- const meta = exploreOperationsMeta(this.schemas, instance, prototype, targetCallback);
86
- if (!meta) {
87
- return operations;
88
- }
89
-
90
- meta.forEach((op) => {
91
- // @eslint-disable-next-line
92
- if (Object.prototype.hasOwnProperty.call(operations, op.channel)) {
93
- operations[op.channel] = { ...operations[op.channel], ...op };
94
- } else {
95
- operations[op.channel] = op;
96
- }
97
- });
98
- return operations;
99
- }, {});
100
-
101
- return Object.keys(channels).map((channel) => ({
102
- root: { ...serviceMetadata, name: channel },
103
- operations: channels[channel],
104
- }));
105
- }, []);
106
- return methodMetadata;
107
- },
108
- );
109
-
110
- return flatten(denormalizedAsyncapiServices);
111
- }
112
- }