Skip to content

Commit

Permalink
fix: some minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Souvikns committed Sep 22, 2023
1 parent 35a7c68 commit 523b527
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
26 changes: 13 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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({
Expand All @@ -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)
}
Expand Down
5 changes: 1 addition & 4 deletions src/lib/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/registerAdapters.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 523b527

Please sign in to comment.