@achinet/nestjs-async 0.0.1 → 0.1.1
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.
- package/CHANGELOG.md +13 -0
- package/dist/decorators/asyncapi-operation-for-meta-key.decorator.js +1 -2
- package/dist/decorators/asyncapi-operation-for-meta-key.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-operation.decorator.js +1 -2
- package/dist/decorators/asyncapi-operation.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-pub.decorator.js +1 -2
- package/dist/decorators/asyncapi-pub.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-service.decorator.js +1 -2
- package/dist/decorators/asyncapi-service.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-sub.decorator.js +1 -2
- package/dist/decorators/asyncapi-sub.decorator.js.map +1 -1
- package/dist/explorers/asyncapi-operation.explorer.d.ts +8 -8
- package/dist/sample/app.module.d.ts +2 -0
- package/dist/sample/app.module.js +20 -0
- package/dist/sample/app.module.js.map +1 -0
- package/dist/sample/common.d.ts +3 -0
- package/dist/sample/common.js +40 -0
- package/dist/sample/common.js.map +1 -0
- package/dist/sample/constants.d.ts +12 -0
- package/dist/sample/constants.js +16 -0
- package/dist/sample/constants.js.map +1 -0
- package/dist/sample/felines/class/cat.class.d.ts +4 -0
- package/dist/sample/felines/class/cat.class.js +24 -0
- package/dist/sample/felines/class/cat.class.js.map +1 -0
- package/dist/sample/felines/class/feline.class.d.ts +19 -0
- package/dist/sample/felines/class/feline.class.js +20 -0
- package/dist/sample/felines/class/feline.class.js.map +1 -0
- package/dist/sample/felines/class/index.d.ts +5 -0
- package/dist/sample/felines/class/index.js +22 -0
- package/dist/sample/felines/class/index.js.map +1 -0
- package/dist/sample/felines/class/lion.class.d.ts +4 -0
- package/dist/sample/felines/class/lion.class.js +8 -0
- package/dist/sample/felines/class/lion.class.js.map +1 -0
- package/dist/sample/felines/class/message.class.d.ts +7 -0
- package/dist/sample/felines/class/message.class.js +28 -0
- package/dist/sample/felines/class/message.class.js.map +1 -0
- package/dist/sample/felines/class/tiger.class.d.ts +4 -0
- package/dist/sample/felines/class/tiger.class.js +8 -0
- package/dist/sample/felines/class/tiger.class.js.map +1 -0
- package/dist/sample/felines/dto/create-feline.dto.d.ts +4 -0
- package/dist/sample/felines/dto/create-feline.dto.js +28 -0
- package/dist/sample/felines/dto/create-feline.dto.js.map +1 -0
- package/dist/sample/felines/dto/index.d.ts +2 -0
- package/dist/sample/felines/dto/index.js +19 -0
- package/dist/sample/felines/dto/index.js.map +1 -0
- package/dist/sample/felines/dto/journaling-data.dto.d.ts +4 -0
- package/dist/sample/felines/dto/journaling-data.dto.js +8 -0
- package/dist/sample/felines/dto/journaling-data.dto.js.map +1 -0
- package/dist/sample/felines/felines.constants.d.ts +1 -0
- package/dist/sample/felines/felines.constants.js +5 -0
- package/dist/sample/felines/felines.constants.js.map +1 -0
- package/dist/sample/felines/felines.controller.d.ts +15 -0
- package/dist/sample/felines/felines.controller.js +101 -0
- package/dist/sample/felines/felines.controller.js.map +1 -0
- package/dist/sample/felines/felines.gateway.d.ts +16 -0
- package/dist/sample/felines/felines.gateway.js +90 -0
- package/dist/sample/felines/felines.gateway.js.map +1 -0
- package/dist/sample/felines/felines.module.d.ts +2 -0
- package/dist/sample/felines/felines.module.js +28 -0
- package/dist/sample/felines/felines.module.js.map +1 -0
- package/dist/sample/felines/felines.service.d.ts +8 -0
- package/dist/sample/felines/felines.service.js +33 -0
- package/dist/sample/felines/felines.service.js.map +1 -0
- package/dist/sample/felines/rto/feline.rto.d.ts +7 -0
- package/dist/sample/felines/rto/feline.rto.js +31 -0
- package/dist/sample/felines/rto/feline.rto.js.map +1 -0
- package/dist/sample/felines/rto/index.d.ts +1 -0
- package/dist/sample/felines/rto/index.js +18 -0
- package/dist/sample/felines/rto/index.js.map +1 -0
- package/dist/sample/index.d.ts +3 -0
- package/dist/sample/index.js +20 -0
- package/dist/sample/index.js.map +1 -0
- package/dist/sample/main.d.ts +1 -0
- package/dist/sample/main.js +30 -0
- package/dist/sample/main.js.map +1 -0
- package/dist/src/asyncapi-document.builder.d.ts +27 -0
- package/dist/src/asyncapi-document.builder.js +110 -0
- package/dist/src/asyncapi-document.builder.js.map +1 -0
- package/dist/src/asyncapi.constants.d.ts +6 -0
- package/dist/src/asyncapi.constants.js +11 -0
- package/dist/src/asyncapi.constants.js.map +1 -0
- package/dist/src/asyncapi.module.d.ts +8 -0
- package/dist/src/asyncapi.module.js +47 -0
- package/dist/src/asyncapi.module.js.map +1 -0
- package/dist/src/binding/asyncapi.amqp.interfaces.d.ts +38 -0
- package/dist/src/binding/asyncapi.amqp.interfaces.js +3 -0
- package/dist/src/binding/asyncapi.amqp.interfaces.js.map +1 -0
- package/dist/src/binding/asyncapi.kafka.interfaces.d.ts +21 -0
- package/dist/src/binding/asyncapi.kafka.interfaces.js +3 -0
- package/dist/src/binding/asyncapi.kafka.interfaces.js.map +1 -0
- package/dist/src/binding/index.d.ts +2 -0
- package/dist/src/binding/index.js +19 -0
- package/dist/src/binding/index.js.map +1 -0
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.d.ts +2 -0
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.js +37 -0
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.js.map +1 -0
- package/dist/src/decorators/asyncapi-operation.decorator.d.ts +2 -0
- package/dist/src/decorators/asyncapi-operation.decorator.js +9 -0
- package/dist/src/decorators/asyncapi-operation.decorator.js.map +1 -0
- package/dist/src/decorators/asyncapi-pub.decorator.d.ts +2 -0
- package/dist/src/decorators/asyncapi-pub.decorator.js +10 -0
- package/dist/src/decorators/asyncapi-pub.decorator.js.map +1 -0
- package/dist/src/decorators/asyncapi-service.decorator.d.ts +1 -0
- package/dist/src/decorators/asyncapi-service.decorator.js +9 -0
- package/dist/src/decorators/asyncapi-service.decorator.js.map +1 -0
- package/dist/src/decorators/asyncapi-sub.decorator.d.ts +2 -0
- package/dist/src/decorators/asyncapi-sub.decorator.js +10 -0
- package/dist/src/decorators/asyncapi-sub.decorator.js.map +1 -0
- package/dist/src/decorators/index.d.ts +4 -0
- package/dist/src/decorators/index.js +21 -0
- package/dist/src/decorators/index.js.map +1 -0
- package/dist/src/explorers/asyncapi-class.explorer.d.ts +5 -0
- package/dist/src/explorers/asyncapi-class.explorer.js +27 -0
- package/dist/src/explorers/asyncapi-class.explorer.js.map +1 -0
- package/dist/src/explorers/asyncapi-operation.explorer.d.ts +17 -0
- package/dist/src/explorers/asyncapi-operation.explorer.js +26 -0
- package/dist/src/explorers/asyncapi-operation.explorer.js.map +1 -0
- package/dist/src/explorers/index.d.ts +2 -0
- package/dist/src/explorers/index.js +19 -0
- package/dist/src/explorers/index.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interface/asyncapi-common.interfaces.d.ts +126 -0
- package/dist/src/interface/asyncapi-common.interfaces.js +3 -0
- package/dist/src/interface/asyncapi-common.interfaces.js.map +1 -0
- package/dist/src/interface/asyncapi-document-options.interface.d.ts +3 -0
- package/dist/src/interface/asyncapi-document-options.interface.js +3 -0
- package/dist/src/interface/asyncapi-document-options.interface.js.map +1 -0
- package/dist/src/interface/asyncapi-message.interface.d.ts +8 -0
- package/dist/src/interface/asyncapi-message.interface.js +3 -0
- package/dist/src/interface/asyncapi-message.interface.js.map +1 -0
- package/dist/src/interface/asyncapi-operation-headers.interface.d.ts +6 -0
- package/dist/src/interface/asyncapi-operation-headers.interface.js +3 -0
- package/dist/src/interface/asyncapi-operation-headers.interface.js.map +1 -0
- package/dist/src/interface/asyncapi-operation-options-raw.interface.d.ts +21 -0
- package/dist/src/interface/asyncapi-operation-options-raw.interface.js +3 -0
- package/dist/src/interface/asyncapi-operation-options-raw.interface.js.map +1 -0
- package/dist/src/interface/asyncapi-operation-options.interface.d.ts +8 -0
- package/dist/src/interface/asyncapi-operation-options.interface.js +3 -0
- package/dist/src/interface/asyncapi-operation-options.interface.js.map +1 -0
- package/dist/src/interface/asyncapi-operation-payload.interface.d.ts +2 -0
- package/dist/src/interface/asyncapi-operation-payload.interface.js +3 -0
- package/dist/src/interface/asyncapi-operation-payload.interface.js.map +1 -0
- package/dist/src/interface/asyncapi-server.interface.d.ts +10 -0
- package/dist/src/interface/asyncapi-server.interface.js +3 -0
- package/dist/src/interface/asyncapi-server.interface.js.map +1 -0
- package/dist/src/interface/asyncapi-template-options.interface.d.ts +7 -0
- package/dist/src/interface/asyncapi-template-options.interface.js +3 -0
- package/dist/src/interface/asyncapi-template-options.interface.js.map +1 -0
- package/dist/src/interface/denormalized-doc-resolvers.interface.d.ts +6 -0
- package/dist/src/interface/denormalized-doc-resolvers.interface.js +3 -0
- package/dist/src/interface/denormalized-doc-resolvers.interface.js.map +1 -0
- package/dist/src/interface/denormalized-doc.interface.d.ts +10 -0
- package/dist/src/interface/denormalized-doc.interface.js +3 -0
- package/dist/src/interface/denormalized-doc.interface.js.map +1 -0
- package/dist/src/interface/generator-options.interface.d.ts +22 -0
- package/dist/src/interface/generator-options.interface.js +3 -0
- package/dist/src/interface/generator-options.interface.js.map +1 -0
- package/dist/src/interface/index.d.ts +11 -0
- package/dist/src/interface/index.js +28 -0
- package/dist/src/interface/index.js.map +1 -0
- package/dist/src/services/asyncapi.explorer.d.ts +12 -0
- package/dist/src/services/asyncapi.explorer.js +69 -0
- package/dist/src/services/asyncapi.explorer.js.map +1 -0
- package/dist/src/services/asyncapi.generator.d.ts +6 -0
- package/dist/src/services/asyncapi.generator.js +68 -0
- package/dist/src/services/asyncapi.generator.js.map +1 -0
- package/dist/src/services/asyncapi.scanner.d.ts +14 -0
- package/dist/src/services/asyncapi.scanner.js +71 -0
- package/dist/src/services/asyncapi.scanner.js.map +1 -0
- package/dist/src/services/asyncapi.transformer.d.ts +4 -0
- package/dist/src/services/asyncapi.transformer.js +33 -0
- package/dist/src/services/asyncapi.transformer.js.map +1 -0
- package/dist/src/services/index.d.ts +4 -0
- package/dist/src/services/index.js +21 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/operation-object.factory.d.ts +9 -0
- package/dist/src/services/operation-object.factory.js +37 -0
- package/dist/src/services/operation-object.factory.js.map +1 -0
- package/dist/test/configs/jest-base.config.d.ts +3 -0
- package/dist/test/configs/jest-base.config.js +20 -0
- package/dist/test/configs/jest-base.config.js.map +1 -0
- package/dist/test/configs/jest-e2e.config.d.ts +3 -0
- package/dist/test/configs/jest-e2e.config.js +16 -0
- package/dist/test/configs/jest-e2e.config.js.map +1 -0
- package/dist/test/express.e2e-spec.d.ts +1 -0
- package/dist/test/express.e2e-spec.js +89 -0
- package/dist/test/express.e2e-spec.js.map +1 -0
- package/dist/test/fastify.e2e-spec.d.ts +1 -0
- package/dist/test/fastify.e2e-spec.js +57 -0
- package/dist/test/fastify.e2e-spec.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.mjs +21 -0
- package/misc/references/ref.html +303 -0
- package/misc/references/ref.json +1 -0
- package/misc/references/ref.yaml +292 -0
- package/misc/take-snaphots.sh +8 -0
- package/package.json +48 -41
- package/sample/app.module.ts +7 -0
- package/sample/common.ts +49 -0
- package/sample/constants.ts +12 -0
- package/sample/felines/class/cat.class.ts +9 -0
- package/sample/felines/class/feline.class.ts +29 -0
- package/sample/felines/class/index.ts +5 -0
- package/sample/felines/class/lion.class.ts +5 -0
- package/sample/felines/class/message.class.ts +17 -0
- package/sample/felines/class/tiger.class.ts +5 -0
- package/sample/felines/dto/create-feline.dto.ts +13 -0
- package/sample/felines/dto/index.ts +2 -0
- package/sample/felines/dto/journaling-data.dto.ts +5 -0
- package/sample/felines/felines.constants.ts +1 -0
- package/sample/felines/felines.controller.ts +76 -0
- package/sample/felines/felines.gateway.ts +76 -0
- package/sample/felines/felines.module.ts +15 -0
- package/sample/felines/felines.service.ts +24 -0
- package/sample/felines/rto/feline.rto.ts +17 -0
- package/sample/felines/rto/index.ts +1 -0
- package/sample/index.ts +3 -0
- package/sample/main.ts +34 -0
- package/src/asyncapi-document.builder.ts +5 -19
- package/src/asyncapi.module.ts +5 -16
- package/src/decorators/asyncapi-operation-for-meta-key.decorator.ts +4 -16
- package/src/decorators/asyncapi-operation.decorator.ts +1 -3
- package/src/decorators/asyncapi-pub.decorator.ts +6 -13
- package/src/decorators/asyncapi-sub.decorator.ts +6 -13
- package/src/explorers/asyncapi-class.explorer.ts +2 -6
- package/src/explorers/asyncapi-operation.explorer.ts +3 -12
- package/src/interface/asyncapi-common.interfaces.ts +1 -4
- package/src/interface/asyncapi-operation-options.interface.ts +2 -4
- package/src/interface/asyncapi-operation-payload.interface.ts +1 -5
- package/src/interface/asyncapi-server.interface.ts +1 -4
- package/src/interface/asyncapi-template-options.interface.ts +5 -5
- package/src/interface/denormalized-doc.interface.ts +1 -5
- package/src/services/asyncapi.explorer.ts +25 -34
- package/src/services/asyncapi.generator.ts +28 -16
- package/src/services/asyncapi.scanner.ts +39 -89
- package/src/services/asyncapi.transformer.ts +2 -8
- package/src/services/index.ts +0 -1
- package/src/services/operation-object.factory.ts +0 -1
- package/test/__mocks__/@asyncapi/generator.js +41 -0
- package/test/configs/jest-base.config.ts +19 -0
- package/test/configs/jest-e2e.config.js +7 -0
- package/test/configs/jest-e2e.config.ts +19 -0
- package/test/configs/jest-swagger-plugin.js +16 -0
- package/test/express.e2e-spec.ts +64 -0
- package/test/fastify.e2e-spec.ts +65 -0
- package/.eslintrc.js +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@achinet/nestjs-async",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
|
|
12
12
|
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
13
13
|
"clean": "rimraf dist",
|
|
14
|
-
"test": "jest"
|
|
14
|
+
"test": "jest --passWithNoTests",
|
|
15
|
+
"test:e2e": "jest --runInBand --config test/configs/jest-e2e.config.js"
|
|
15
16
|
},
|
|
16
17
|
"jest": {
|
|
17
18
|
"moduleFileExtensions": [
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"rootDir": "./",
|
|
26
27
|
"testRegex": ".*\\.spec\\.ts$",
|
|
27
28
|
"transform": {
|
|
28
|
-
"^.+\\.
|
|
29
|
+
"^.+\\.ts$": [
|
|
29
30
|
"@swc/jest",
|
|
30
31
|
{
|
|
31
32
|
"jsc": {
|
|
@@ -41,6 +42,9 @@
|
|
|
41
42
|
}
|
|
42
43
|
]
|
|
43
44
|
},
|
|
45
|
+
"moduleNameMapper": {
|
|
46
|
+
"^@asyncapi/generator$": "<rootDir>/test/__mocks__/@asyncapi/generator.js"
|
|
47
|
+
},
|
|
44
48
|
"collectCoverageFrom": [
|
|
45
49
|
"**/*.(t|j)s"
|
|
46
50
|
],
|
|
@@ -48,47 +52,50 @@
|
|
|
48
52
|
"testEnvironment": "node"
|
|
49
53
|
},
|
|
50
54
|
"devDependencies": {
|
|
51
|
-
"@nestjs/cli": "11.0.
|
|
52
|
-
"@nestjs/microservices": "11.
|
|
53
|
-
"@nestjs/platform-express": "11.
|
|
54
|
-
"@nestjs/platform-fastify": "11.
|
|
55
|
-
"@nestjs/platform-socket.io": "11.
|
|
56
|
-
"@nestjs/schematics": "11.0.
|
|
57
|
-
"@nestjs/testing": "11.
|
|
58
|
-
"@
|
|
59
|
-
"@types/
|
|
60
|
-
"@types/jest": "29.5.11",
|
|
55
|
+
"@nestjs/cli": "11.0.16",
|
|
56
|
+
"@nestjs/microservices": "11.1.13",
|
|
57
|
+
"@nestjs/platform-express": "11.1.13",
|
|
58
|
+
"@nestjs/platform-fastify": "11.1.13",
|
|
59
|
+
"@nestjs/platform-socket.io": "11.1.13",
|
|
60
|
+
"@nestjs/schematics": "11.0.9",
|
|
61
|
+
"@nestjs/testing": "11.1.13",
|
|
62
|
+
"@types/express": "5.0.6",
|
|
63
|
+
"@types/jest": "30.0.0",
|
|
61
64
|
"@types/js-yaml": "4.0.9",
|
|
62
|
-
"@types/
|
|
63
|
-
"@types/
|
|
64
|
-
"@types/
|
|
65
|
-
"@
|
|
66
|
-
"@typescript-eslint/
|
|
67
|
-
"eslint": "8.
|
|
68
|
-
"eslint
|
|
69
|
-
"eslint-
|
|
70
|
-
"eslint-plugin-
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"socket.io
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"ts-
|
|
81
|
-
"ts-
|
|
65
|
+
"@types/lodash": "^4.17.23",
|
|
66
|
+
"@types/node": "25.2.1",
|
|
67
|
+
"@types/supertest": "6.0.3",
|
|
68
|
+
"@types/url-join": "5.0.0",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "8.54.0",
|
|
70
|
+
"@typescript-eslint/parser": "8.54.0",
|
|
71
|
+
"eslint": "10.0.0",
|
|
72
|
+
"eslint-config-prettier": "10.1.8",
|
|
73
|
+
"eslint-plugin-import": "2.32.0",
|
|
74
|
+
"eslint-plugin-prettier": "5.5.5",
|
|
75
|
+
"husky": "9.1.7",
|
|
76
|
+
"jest": "30.2.0",
|
|
77
|
+
"lint-staged": "16.2.7",
|
|
78
|
+
"prettier": "3.8.1",
|
|
79
|
+
"release-it": "19.2.4",
|
|
80
|
+
"socket.io": "4.8.3",
|
|
81
|
+
"socket.io-client": "4.8.3",
|
|
82
|
+
"supertest": "7.2.2",
|
|
83
|
+
"ts-jest": "^29.4.6",
|
|
84
|
+
"ts-loader": "9.5.4",
|
|
85
|
+
"ts-node": "^10.9.2",
|
|
82
86
|
"tsconfig-paths": "4.2.0",
|
|
83
|
-
"typescript": "5.
|
|
87
|
+
"typescript": "5.9.3"
|
|
84
88
|
},
|
|
85
89
|
"dependencies": {
|
|
86
|
-
"@asyncapi/generator": "1.
|
|
87
|
-
"@asyncapi/html-template": "
|
|
88
|
-
"@nestjs/common": "^11.1.
|
|
89
|
-
"@nestjs/core": "^11.1.
|
|
90
|
-
"@nestjs/swagger": "^11.2.
|
|
91
|
-
"
|
|
92
|
-
"
|
|
90
|
+
"@asyncapi/generator": "^3.1.2",
|
|
91
|
+
"@asyncapi/html-template": "^3.5.4",
|
|
92
|
+
"@nestjs/common": "^11.1.13",
|
|
93
|
+
"@nestjs/core": "^11.1.13",
|
|
94
|
+
"@nestjs/swagger": "^11.2.6",
|
|
95
|
+
"@nestjs/websockets": "^11.1.13",
|
|
96
|
+
"@swc/core": "1.15.11",
|
|
97
|
+
"js-yaml": "4.1.1",
|
|
98
|
+
"lodash": "^4.17.23",
|
|
99
|
+
"reflect-metadata": "0.2.2"
|
|
93
100
|
}
|
|
94
101
|
}
|
package/sample/common.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { INestApplicationContext } from '@nestjs/common';
|
|
2
|
+
import { HOST, PORT, SERVER } from './constants';
|
|
3
|
+
import { Cat, Feline, Lion, Tiger } from './felines/class';
|
|
4
|
+
import { FelinesModule } from './felines/felines.module';
|
|
5
|
+
import {
|
|
6
|
+
AsyncApiDocument,
|
|
7
|
+
AsyncApiDocumentBuilder,
|
|
8
|
+
AsyncApiModule,
|
|
9
|
+
AsyncServerObject,
|
|
10
|
+
} from '../src';
|
|
11
|
+
|
|
12
|
+
export async function makeAsyncapiDocument(
|
|
13
|
+
app: INestApplicationContext,
|
|
14
|
+
): Promise<AsyncApiDocument> {
|
|
15
|
+
const asyncApiServer: AsyncServerObject = {
|
|
16
|
+
url: `ws://${HOST}:${PORT}`,
|
|
17
|
+
protocol: 'socket.io',
|
|
18
|
+
protocolVersion: '4',
|
|
19
|
+
description:
|
|
20
|
+
'Allows you to connect using the websocket protocol to our Socket.io server.',
|
|
21
|
+
security: [{ 'user-password': [] }],
|
|
22
|
+
variables: {
|
|
23
|
+
port: {
|
|
24
|
+
description: 'Secure connection (TLS) is available through port 443.',
|
|
25
|
+
default: '443',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
bindings: {},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const servers = Object.keys(SERVER).map((i) => ({
|
|
32
|
+
name: SERVER[i],
|
|
33
|
+
server: asyncApiServer,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
const asyncApiOptions = new AsyncApiDocumentBuilder()
|
|
37
|
+
.setTitle('Feline')
|
|
38
|
+
.setDescription('Feline server description here')
|
|
39
|
+
.setVersion('1.0')
|
|
40
|
+
.setDefaultContentType('application/json')
|
|
41
|
+
.addSecurity('user-password', { type: 'userPassword' })
|
|
42
|
+
.addServers(servers)
|
|
43
|
+
.build();
|
|
44
|
+
|
|
45
|
+
return AsyncApiModule.createDocument(app, asyncApiOptions, {
|
|
46
|
+
include: [FelinesModule],
|
|
47
|
+
extraModels: [Cat, Lion, Tiger, Feline],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const FELINES_MS = 'FELINES_MS';
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 {}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './feline.rto';
|
package/sample/index.ts
ADDED
package/sample/main.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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();
|
|
@@ -4,17 +4,10 @@ import {
|
|
|
4
4
|
TagObject,
|
|
5
5
|
} from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
|
6
6
|
import { isUndefined, negate, pickBy } from 'lodash';
|
|
7
|
-
import {
|
|
8
|
-
AsyncApiDocument,
|
|
9
|
-
AsyncSecuritySchemeObject,
|
|
10
|
-
AsyncServerObject,
|
|
11
|
-
} from './interface';
|
|
7
|
+
import { AsyncApiDocument, AsyncSecuritySchemeObject, AsyncServerObject } from './interface';
|
|
12
8
|
|
|
13
9
|
export class AsyncApiDocumentBuilder {
|
|
14
|
-
private readonly buildDocumentBase = (): Omit<
|
|
15
|
-
AsyncApiDocument,
|
|
16
|
-
'channels'
|
|
17
|
-
> => ({
|
|
10
|
+
private readonly buildDocumentBase = (): Omit<AsyncApiDocument, 'channels'> => ({
|
|
18
11
|
asyncapi: '2.5.0',
|
|
19
12
|
info: {
|
|
20
13
|
title: '',
|
|
@@ -27,8 +20,7 @@ export class AsyncApiDocumentBuilder {
|
|
|
27
20
|
components: {},
|
|
28
21
|
});
|
|
29
22
|
|
|
30
|
-
private readonly document: Omit<AsyncApiDocument, 'channels'> =
|
|
31
|
-
this.buildDocumentBase();
|
|
23
|
+
private readonly document: Omit<AsyncApiDocument, 'channels'> = this.buildDocumentBase();
|
|
32
24
|
|
|
33
25
|
public setTitle(title: string): this {
|
|
34
26
|
this.document.info.title = title;
|
|
@@ -65,9 +57,7 @@ export class AsyncApiDocumentBuilder {
|
|
|
65
57
|
return this;
|
|
66
58
|
}
|
|
67
59
|
|
|
68
|
-
public addServers(
|
|
69
|
-
servers: { name: string; server: AsyncServerObject }[],
|
|
70
|
-
): this {
|
|
60
|
+
public addServers(servers: { name: string; server: AsyncServerObject }[]): this {
|
|
71
61
|
for (const { name, server } of servers) {
|
|
72
62
|
this.addServer(name, server);
|
|
73
63
|
}
|
|
@@ -85,11 +75,7 @@ export class AsyncApiDocumentBuilder {
|
|
|
85
75
|
return this;
|
|
86
76
|
}
|
|
87
77
|
|
|
88
|
-
public addTag(
|
|
89
|
-
name: string,
|
|
90
|
-
description = '',
|
|
91
|
-
externalDocs?: ExternalDocumentationObject,
|
|
92
|
-
): this {
|
|
78
|
+
public addTag(name: string, description = '', externalDocs?: ExternalDocumentationObject): this {
|
|
93
79
|
this.document.tags = this.document.tags!.concat(
|
|
94
80
|
pickBy(
|
|
95
81
|
{
|
package/src/asyncapi.module.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
INestApplication,
|
|
3
|
-
INestApplicationContext,
|
|
4
|
-
Logger,
|
|
5
|
-
} from '@nestjs/common';
|
|
1
|
+
import { INestApplication, INestApplicationContext, Logger } from '@nestjs/common';
|
|
6
2
|
import { validatePath } from '@nestjs/swagger/dist/utils/validate-path.util';
|
|
7
3
|
import jsyaml from 'js-yaml';
|
|
8
|
-
import {
|
|
9
|
-
AsyncApiDocument,
|
|
10
|
-
AsyncApiDocumentOptions,
|
|
11
|
-
AsyncApiTemplateOptions,
|
|
12
|
-
} from './interface';
|
|
4
|
+
import { AsyncApiDocument, AsyncApiDocumentOptions, AsyncApiTemplateOptions } from './interface';
|
|
13
5
|
import { AsyncapiGenerator, AsyncapiScanner } from './services';
|
|
14
6
|
|
|
15
7
|
export class AsyncApiModule {
|
|
@@ -34,10 +26,7 @@ export class AsyncApiModule {
|
|
|
34
26
|
};
|
|
35
27
|
}
|
|
36
28
|
|
|
37
|
-
static async composeHtml(
|
|
38
|
-
contract: AsyncApiDocument,
|
|
39
|
-
templateOptions?: AsyncApiTemplateOptions,
|
|
40
|
-
) {
|
|
29
|
+
static async composeHtml(contract: AsyncApiDocument, templateOptions?: AsyncApiTemplateOptions) {
|
|
41
30
|
const generator = new AsyncapiGenerator(templateOptions);
|
|
42
31
|
return generator.generate(contract).catch((err) => {
|
|
43
32
|
this.logger.error(err);
|
|
@@ -63,12 +52,12 @@ export class AsyncApiModule {
|
|
|
63
52
|
res.send(html);
|
|
64
53
|
});
|
|
65
54
|
|
|
66
|
-
httpAdapter.get(finalPath
|
|
55
|
+
httpAdapter.get(`${finalPath}-json`, (req, res) => {
|
|
67
56
|
res.type('application/json');
|
|
68
57
|
res.send(jsonDocument);
|
|
69
58
|
});
|
|
70
59
|
|
|
71
|
-
httpAdapter.get(finalPath
|
|
60
|
+
httpAdapter.get(`${finalPath}-yaml`, (req, res) => {
|
|
72
61
|
res.type('text/yaml');
|
|
73
62
|
res.send(yamlDocument);
|
|
74
63
|
});
|