From 523b527544960bc0a4e9acafb2c7921cbf1fa8aa Mon Sep 17 00:00:00 2001 From: souvik Date: Fri, 22 Sep 2023 15:25:00 +0530 Subject: [PATCH] fix: some minor issues --- src/index.ts | 26 +++++++++++++------------- src/lib/functions.ts | 5 +---- src/registerAdapters.ts | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/index.ts b/src/index.ts index 73ffd8d82..fb6ceb7aa 100755 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,7 @@ export default async function GleeAppInitializer() { await registerAuth(GLEE_AUTH_DIR) const parsedAsyncAPI = await getParsedAsyncAPI() - const channelNames = parsedAsyncAPI.channelNames() + const channelNames = parsedAsyncAPI.channels().map(e => e.address()) const app = new Glee(config) @@ -78,15 +78,15 @@ export default async function GleeAppInitializer() { await generateDocs(parsedAsyncAPI, config, null) channelNames.forEach((channelName) => { - const channel = parsedAsyncAPI.channel(channelName) - if (channel.hasPublish()) { - const operationId = channel.publish().json('operationId') + const channel = parsedAsyncAPI.channels().get(channelName) + if (channel.operations().filterBySend().length !==0) { + const operationId = channel.operations()[0].operationId() + const publishOperation = channel.operations().filterBySend()[0] if (operationId) { const schema = { - oneOf: channel - .publish() - .messages() - .map((message) => message.payload().json()), + oneOf: publishOperation + .messages() + .map(m => m.payload().json()), } as any app.use(channelName, validate(schema), (event, next) => { triggerFunction({ @@ -99,12 +99,12 @@ export default async function GleeAppInitializer() { }) } } - if (channel.hasSubscribe()) { + if (channel.operations().filterByReceive().length !== 0) { + const subscribeOperation = channel.operations().filterByReceive()[0] const schema = { - oneOf: channel - .subscribe() - .messages() - .map((message) => message.payload().json()), + oneOf: subscribeOperation + .messages() + .map(m => m.payload().json()), } as any app.useOutbound(channelName, validate(schema), json2string) } diff --git a/src/lib/functions.ts b/src/lib/functions.ts index 16c02f0ff..f046d3abb 100644 --- a/src/lib/functions.ts +++ b/src/lib/functions.ts @@ -118,10 +118,7 @@ export async function trigger({ res?.send?.forEach((msg) => { const localServerProtocols = ['ws', 'wss', 'http', 'https'] - const serverProtocol = parsedAsyncAPI - .server(msg.server || message.serverName) - .protocol() - .toLowerCase() + const serverProtocol = parsedAsyncAPI.servers().get(msg.server || message.serverName).protocol().toLocaleLowerCase() const isBroadcast = localServerProtocols.includes(serverProtocol) && !isRemoteServer(parsedAsyncAPI, msg.server) diff --git a/src/registerAdapters.ts b/src/registerAdapters.ts index 8fa2e493c..3ac2e0241 100644 --- a/src/registerAdapters.ts +++ b/src/registerAdapters.ts @@ -1,4 +1,4 @@ -import { AsyncAPIDocumentV2 as AsyncAPIDocument, ServerInterface } from '@asyncapi/parser' +import { AsyncAPIDocumentInterface as AsyncAPIDocument, ServerInterface } from '@asyncapi/parser' import MqttAdapter from './adapters/mqtt/index.js' import WebSocketServerAdapter from './adapters/ws/server.js' import WebsocketClientAdapter from './adapters/ws/client.js'