@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.
- package/dist/asyncapi-document.builder.d.ts +1 -1
- package/dist/asyncapi-document.builder.js.map +1 -1
- package/dist/asyncapi.module.js +8 -5
- package/dist/asyncapi.module.js.map +1 -1
- package/dist/binding/asyncapi.kafka.interfaces.d.ts +1 -1
- package/dist/decorators/asyncapi-operation-for-meta-key.decorator.js +3 -3
- package/dist/decorators/asyncapi-operation-for-meta-key.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-operation.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-pub.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-service.decorator.d.ts +1 -1
- package/dist/decorators/asyncapi-service.decorator.js +2 -2
- package/dist/decorators/asyncapi-service.decorator.js.map +1 -1
- package/dist/decorators/asyncapi-sub.decorator.js.map +1 -1
- package/dist/explorers/asyncapi-class.explorer.js +1 -5
- package/dist/explorers/asyncapi-class.explorer.js.map +1 -1
- package/dist/explorers/asyncapi-operation.explorer.d.ts +1 -2
- package/dist/explorers/asyncapi-operation.explorer.js +2 -2
- package/dist/explorers/asyncapi-operation.explorer.js.map +1 -1
- package/dist/interface/asyncapi-common.interfaces.d.ts +1 -1
- package/dist/interface/asyncapi-server.interface.d.ts +1 -1
- package/dist/interface/asyncapi-template-options.interface.d.ts +2 -3
- package/dist/interface/index.d.ts +0 -1
- package/dist/interface/index.js +0 -1
- package/dist/interface/index.js.map +1 -1
- package/dist/services/asyncapi.explorer.d.ts +2 -4
- package/dist/services/asyncapi.explorer.js +8 -13
- package/dist/services/asyncapi.explorer.js.map +1 -1
- package/dist/services/asyncapi.generator.d.ts +4 -3
- package/dist/services/asyncapi.generator.js +72 -17
- package/dist/services/asyncapi.generator.js.map +1 -1
- package/dist/services/asyncapi.scanner.d.ts +1 -4
- package/dist/services/asyncapi.scanner.js +10 -31
- package/dist/services/asyncapi.scanner.js.map +1 -1
- package/dist/services/asyncapi.transformer.js.map +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/operation-object.factory.d.ts +2 -6
- package/dist/services/operation-object.factory.js +7 -14
- package/dist/services/operation-object.factory.js.map +1 -1
- package/dist/services/swagger-schema.factory.d.ts +6 -0
- package/dist/services/swagger-schema.factory.js +27 -0
- package/dist/services/swagger-schema.factory.js.map +1 -0
- package/dist/utils/decorator.utils.d.ts +2 -0
- package/dist/utils/decorator.utils.js +26 -0
- package/dist/utils/decorator.utils.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/{sample/felines/rto → utils}/index.js +2 -1
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/path.utils.d.ts +2 -0
- package/dist/utils/path.utils.js +8 -0
- package/dist/utils/path.utils.js.map +1 -0
- package/package.json +57 -37
- package/.prettierrc +0 -5
- package/CHANGELOG.md +0 -20
- package/dist/interface/generator-options.interface.d.ts +0 -22
- package/dist/interface/generator-options.interface.js +0 -3
- package/dist/interface/generator-options.interface.js.map +0 -1
- package/dist/sample/app.module.d.ts +0 -2
- package/dist/sample/app.module.js +0 -20
- package/dist/sample/app.module.js.map +0 -1
- package/dist/sample/common.d.ts +0 -3
- package/dist/sample/common.js +0 -40
- package/dist/sample/common.js.map +0 -1
- package/dist/sample/constants.d.ts +0 -12
- package/dist/sample/constants.js +0 -16
- package/dist/sample/constants.js.map +0 -1
- package/dist/sample/felines/class/cat.class.d.ts +0 -4
- package/dist/sample/felines/class/cat.class.js +0 -24
- package/dist/sample/felines/class/cat.class.js.map +0 -1
- package/dist/sample/felines/class/feline.class.d.ts +0 -19
- package/dist/sample/felines/class/feline.class.js +0 -20
- package/dist/sample/felines/class/feline.class.js.map +0 -1
- package/dist/sample/felines/class/index.d.ts +0 -5
- package/dist/sample/felines/class/index.js +0 -22
- package/dist/sample/felines/class/index.js.map +0 -1
- package/dist/sample/felines/class/lion.class.d.ts +0 -4
- package/dist/sample/felines/class/lion.class.js +0 -8
- package/dist/sample/felines/class/lion.class.js.map +0 -1
- package/dist/sample/felines/class/message.class.d.ts +0 -7
- package/dist/sample/felines/class/message.class.js +0 -28
- package/dist/sample/felines/class/message.class.js.map +0 -1
- package/dist/sample/felines/class/tiger.class.d.ts +0 -4
- package/dist/sample/felines/class/tiger.class.js +0 -8
- package/dist/sample/felines/class/tiger.class.js.map +0 -1
- package/dist/sample/felines/dto/create-feline.dto.d.ts +0 -4
- package/dist/sample/felines/dto/create-feline.dto.js +0 -28
- package/dist/sample/felines/dto/create-feline.dto.js.map +0 -1
- package/dist/sample/felines/dto/index.d.ts +0 -2
- package/dist/sample/felines/dto/index.js +0 -19
- package/dist/sample/felines/dto/index.js.map +0 -1
- package/dist/sample/felines/dto/journaling-data.dto.d.ts +0 -4
- package/dist/sample/felines/dto/journaling-data.dto.js +0 -8
- package/dist/sample/felines/dto/journaling-data.dto.js.map +0 -1
- package/dist/sample/felines/felines.constants.d.ts +0 -1
- package/dist/sample/felines/felines.constants.js +0 -5
- package/dist/sample/felines/felines.constants.js.map +0 -1
- package/dist/sample/felines/felines.controller.d.ts +0 -15
- package/dist/sample/felines/felines.controller.js +0 -101
- package/dist/sample/felines/felines.controller.js.map +0 -1
- package/dist/sample/felines/felines.gateway.d.ts +0 -16
- package/dist/sample/felines/felines.gateway.js +0 -90
- package/dist/sample/felines/felines.gateway.js.map +0 -1
- package/dist/sample/felines/felines.module.d.ts +0 -2
- package/dist/sample/felines/felines.module.js +0 -28
- package/dist/sample/felines/felines.module.js.map +0 -1
- package/dist/sample/felines/felines.service.d.ts +0 -8
- package/dist/sample/felines/felines.service.js +0 -33
- package/dist/sample/felines/felines.service.js.map +0 -1
- package/dist/sample/felines/rto/feline.rto.d.ts +0 -7
- package/dist/sample/felines/rto/feline.rto.js +0 -31
- package/dist/sample/felines/rto/feline.rto.js.map +0 -1
- package/dist/sample/felines/rto/index.d.ts +0 -1
- package/dist/sample/felines/rto/index.js.map +0 -1
- package/dist/sample/index.d.ts +0 -3
- package/dist/sample/index.js +0 -20
- package/dist/sample/index.js.map +0 -1
- package/dist/sample/main.d.ts +0 -1
- package/dist/sample/main.js +0 -30
- package/dist/sample/main.js.map +0 -1
- package/dist/src/asyncapi-document.builder.d.ts +0 -27
- package/dist/src/asyncapi-document.builder.js +0 -110
- package/dist/src/asyncapi-document.builder.js.map +0 -1
- package/dist/src/asyncapi.constants.d.ts +0 -6
- package/dist/src/asyncapi.constants.js +0 -11
- package/dist/src/asyncapi.constants.js.map +0 -1
- package/dist/src/asyncapi.module.d.ts +0 -8
- package/dist/src/asyncapi.module.js +0 -47
- package/dist/src/asyncapi.module.js.map +0 -1
- package/dist/src/binding/asyncapi.amqp.interfaces.d.ts +0 -38
- package/dist/src/binding/asyncapi.amqp.interfaces.js +0 -3
- package/dist/src/binding/asyncapi.amqp.interfaces.js.map +0 -1
- package/dist/src/binding/asyncapi.kafka.interfaces.d.ts +0 -21
- package/dist/src/binding/asyncapi.kafka.interfaces.js +0 -3
- package/dist/src/binding/asyncapi.kafka.interfaces.js.map +0 -1
- package/dist/src/binding/index.d.ts +0 -2
- package/dist/src/binding/index.js +0 -19
- package/dist/src/binding/index.js.map +0 -1
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.d.ts +0 -2
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.js +0 -37
- package/dist/src/decorators/asyncapi-operation-for-meta-key.decorator.js.map +0 -1
- package/dist/src/decorators/asyncapi-operation.decorator.d.ts +0 -2
- package/dist/src/decorators/asyncapi-operation.decorator.js +0 -9
- package/dist/src/decorators/asyncapi-operation.decorator.js.map +0 -1
- package/dist/src/decorators/asyncapi-pub.decorator.d.ts +0 -2
- package/dist/src/decorators/asyncapi-pub.decorator.js +0 -10
- package/dist/src/decorators/asyncapi-pub.decorator.js.map +0 -1
- package/dist/src/decorators/asyncapi-service.decorator.d.ts +0 -1
- package/dist/src/decorators/asyncapi-service.decorator.js +0 -9
- package/dist/src/decorators/asyncapi-service.decorator.js.map +0 -1
- package/dist/src/decorators/asyncapi-sub.decorator.d.ts +0 -2
- package/dist/src/decorators/asyncapi-sub.decorator.js +0 -10
- package/dist/src/decorators/asyncapi-sub.decorator.js.map +0 -1
- package/dist/src/decorators/index.d.ts +0 -4
- package/dist/src/decorators/index.js +0 -21
- package/dist/src/decorators/index.js.map +0 -1
- package/dist/src/explorers/asyncapi-class.explorer.d.ts +0 -5
- package/dist/src/explorers/asyncapi-class.explorer.js +0 -27
- package/dist/src/explorers/asyncapi-class.explorer.js.map +0 -1
- package/dist/src/explorers/asyncapi-operation.explorer.d.ts +0 -17
- package/dist/src/explorers/asyncapi-operation.explorer.js +0 -26
- package/dist/src/explorers/asyncapi-operation.explorer.js.map +0 -1
- package/dist/src/explorers/index.d.ts +0 -2
- package/dist/src/explorers/index.js +0 -19
- package/dist/src/explorers/index.js.map +0 -1
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -21
- package/dist/src/index.js.map +0 -1
- package/dist/src/interface/asyncapi-common.interfaces.d.ts +0 -126
- package/dist/src/interface/asyncapi-common.interfaces.js +0 -3
- package/dist/src/interface/asyncapi-common.interfaces.js.map +0 -1
- package/dist/src/interface/asyncapi-document-options.interface.d.ts +0 -3
- package/dist/src/interface/asyncapi-document-options.interface.js +0 -3
- package/dist/src/interface/asyncapi-document-options.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-message.interface.d.ts +0 -8
- package/dist/src/interface/asyncapi-message.interface.js +0 -3
- package/dist/src/interface/asyncapi-message.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-operation-headers.interface.d.ts +0 -6
- package/dist/src/interface/asyncapi-operation-headers.interface.js +0 -3
- package/dist/src/interface/asyncapi-operation-headers.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-operation-options-raw.interface.d.ts +0 -21
- package/dist/src/interface/asyncapi-operation-options-raw.interface.js +0 -3
- package/dist/src/interface/asyncapi-operation-options-raw.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-operation-options.interface.d.ts +0 -8
- package/dist/src/interface/asyncapi-operation-options.interface.js +0 -3
- package/dist/src/interface/asyncapi-operation-options.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-operation-payload.interface.d.ts +0 -2
- package/dist/src/interface/asyncapi-operation-payload.interface.js +0 -3
- package/dist/src/interface/asyncapi-operation-payload.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-server.interface.d.ts +0 -10
- package/dist/src/interface/asyncapi-server.interface.js +0 -3
- package/dist/src/interface/asyncapi-server.interface.js.map +0 -1
- package/dist/src/interface/asyncapi-template-options.interface.d.ts +0 -7
- package/dist/src/interface/asyncapi-template-options.interface.js +0 -3
- package/dist/src/interface/asyncapi-template-options.interface.js.map +0 -1
- package/dist/src/interface/denormalized-doc-resolvers.interface.d.ts +0 -6
- package/dist/src/interface/denormalized-doc-resolvers.interface.js +0 -3
- package/dist/src/interface/denormalized-doc-resolvers.interface.js.map +0 -1
- package/dist/src/interface/denormalized-doc.interface.d.ts +0 -10
- package/dist/src/interface/denormalized-doc.interface.js +0 -3
- package/dist/src/interface/denormalized-doc.interface.js.map +0 -1
- package/dist/src/interface/generator-options.interface.d.ts +0 -22
- package/dist/src/interface/generator-options.interface.js +0 -3
- package/dist/src/interface/generator-options.interface.js.map +0 -1
- package/dist/src/interface/index.d.ts +0 -11
- package/dist/src/interface/index.js +0 -28
- package/dist/src/interface/index.js.map +0 -1
- package/dist/src/services/asyncapi.explorer.d.ts +0 -12
- package/dist/src/services/asyncapi.explorer.js +0 -69
- package/dist/src/services/asyncapi.explorer.js.map +0 -1
- package/dist/src/services/asyncapi.generator.d.ts +0 -6
- package/dist/src/services/asyncapi.generator.js +0 -68
- package/dist/src/services/asyncapi.generator.js.map +0 -1
- package/dist/src/services/asyncapi.scanner.d.ts +0 -14
- package/dist/src/services/asyncapi.scanner.js +0 -71
- package/dist/src/services/asyncapi.scanner.js.map +0 -1
- package/dist/src/services/asyncapi.transformer.d.ts +0 -4
- package/dist/src/services/asyncapi.transformer.js +0 -33
- package/dist/src/services/asyncapi.transformer.js.map +0 -1
- package/dist/src/services/index.d.ts +0 -4
- package/dist/src/services/index.js +0 -21
- package/dist/src/services/index.js.map +0 -1
- package/dist/src/services/operation-object.factory.d.ts +0 -9
- package/dist/src/services/operation-object.factory.js +0 -37
- package/dist/src/services/operation-object.factory.js.map +0 -1
- package/dist/test/configs/jest-base.config.d.ts +0 -3
- package/dist/test/configs/jest-base.config.js +0 -20
- package/dist/test/configs/jest-base.config.js.map +0 -1
- package/dist/test/configs/jest-e2e.config.d.ts +0 -3
- package/dist/test/configs/jest-e2e.config.js +0 -16
- package/dist/test/configs/jest-e2e.config.js.map +0 -1
- package/dist/test/express.e2e-spec.d.ts +0 -1
- package/dist/test/express.e2e-spec.js +0 -89
- package/dist/test/express.e2e-spec.js.map +0 -1
- package/dist/test/fastify.e2e-spec.d.ts +0 -1
- package/dist/test/fastify.e2e-spec.js +0 -57
- package/dist/test/fastify.e2e-spec.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/eslint.config.mjs +0 -21
- package/misc/references/ref.html +0 -303
- package/misc/references/ref.json +0 -1
- package/misc/references/ref.yaml +0 -292
- package/misc/take-snaphots.sh +0 -8
- package/sample/app.module.ts +0 -7
- package/sample/common.ts +0 -49
- package/sample/constants.ts +0 -12
- package/sample/felines/class/cat.class.ts +0 -9
- package/sample/felines/class/feline.class.ts +0 -29
- package/sample/felines/class/index.ts +0 -5
- package/sample/felines/class/lion.class.ts +0 -5
- package/sample/felines/class/message.class.ts +0 -17
- package/sample/felines/class/tiger.class.ts +0 -5
- package/sample/felines/dto/create-feline.dto.ts +0 -13
- package/sample/felines/dto/index.ts +0 -2
- package/sample/felines/dto/journaling-data.dto.ts +0 -5
- package/sample/felines/felines.constants.ts +0 -1
- package/sample/felines/felines.controller.ts +0 -76
- package/sample/felines/felines.gateway.ts +0 -76
- package/sample/felines/felines.module.ts +0 -15
- package/sample/felines/felines.service.ts +0 -24
- package/sample/felines/rto/feline.rto.ts +0 -17
- package/sample/felines/rto/index.ts +0 -1
- package/sample/index.ts +0 -3
- package/sample/main.ts +0 -34
- package/src/asyncapi-document.builder.ts +0 -172
- package/src/asyncapi.constants.ts +0 -8
- package/src/asyncapi.module.ts +0 -65
- package/src/binding/asyncapi.amqp.interfaces.ts +0 -48
- package/src/binding/asyncapi.kafka.interfaces.ts +0 -35
- package/src/binding/index.ts +0 -2
- package/src/decorators/asyncapi-operation-for-meta-key.decorator.ts +0 -58
- package/src/decorators/asyncapi-operation.decorator.ts +0 -7
- package/src/decorators/asyncapi-pub.decorator.ts +0 -11
- package/src/decorators/asyncapi-service.decorator.ts +0 -9
- package/src/decorators/asyncapi-sub.decorator.ts +0 -11
- package/src/decorators/index.ts +0 -4
- package/src/explorers/asyncapi-class.explorer.ts +0 -26
- package/src/explorers/asyncapi-operation.explorer.ts +0 -40
- package/src/explorers/index.ts +0 -2
- package/src/index.ts +0 -4
- package/src/interface/asyncapi-common.interfaces.ts +0 -169
- package/src/interface/asyncapi-document-options.interface.ts +0 -3
- package/src/interface/asyncapi-message.interface.ts +0 -10
- package/src/interface/asyncapi-operation-headers.interface.ts +0 -6
- package/src/interface/asyncapi-operation-options-raw.interface.ts +0 -23
- package/src/interface/asyncapi-operation-options.interface.ts +0 -10
- package/src/interface/asyncapi-operation-payload.interface.ts +0 -3
- package/src/interface/asyncapi-server.interface.ts +0 -11
- package/src/interface/asyncapi-template-options.interface.ts +0 -20
- package/src/interface/denormalized-doc-resolvers.interface.ts +0 -6
- package/src/interface/denormalized-doc.interface.ts +0 -6
- package/src/interface/generator-options.interface.ts +0 -21
- package/src/interface/index.ts +0 -12
- package/src/services/asyncapi.explorer.ts +0 -112
- package/src/services/asyncapi.generator.ts +0 -45
- package/src/services/asyncapi.scanner.ts +0 -105
- package/src/services/asyncapi.transformer.ts +0 -33
- package/src/services/index.ts +0 -4
- package/src/services/operation-object.factory.ts +0 -55
- package/test/__mocks__/@asyncapi/generator.js +0 -41
- package/test/configs/jest-base.config.ts +0 -19
- package/test/configs/jest-e2e.config.js +0 -7
- package/test/configs/jest-e2e.config.ts +0 -19
- package/test/configs/jest-swagger-plugin.js +0 -16
- package/test/express.e2e-spec.ts +0 -64
- package/test/fastify.e2e-spec.ts +0 -65
- package/tsconfig.build.json +0 -4
- 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
|
-
}
|
package/src/binding/index.ts
DELETED
|
@@ -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
|
-
}
|
package/src/decorators/index.ts
DELETED
|
@@ -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
|
-
};
|
package/src/explorers/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -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,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,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,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
|
-
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
|
-
}
|
package/src/interface/index.ts
DELETED
|
@@ -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
|
-
}
|