Skip to content

Commit

Permalink
fix eslint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
KhudaDad414 committed Nov 20, 2023
1 parent 1155325 commit 10cc240
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"error",
"multi-line"
],
"security/detect-non-literal-fs-filename": "off",
"@typescript-eslint/no-explicit-any": "off",
"semi": [
"warn",
Expand Down
4 changes: 3 additions & 1 deletion src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsyncAPIDocumentInterface as AsyncAPIDocument, ChannelInterface, ChannelParameterInterface, MessageInterface } from '@asyncapi/parser'
import { AsyncAPIDocumentInterface as AsyncAPIDocument, ChannelInterface, ChannelParameterInterface } from '@asyncapi/parser'
import Ajv from 'ajv'
import betterAjvErrors from 'better-ajv-errors'
import { pathToRegexp } from 'path-to-regexp'
Expand Down Expand Up @@ -171,6 +171,7 @@ function jsonPointer(obj: any, pointer: string): any {
if (current === null || typeof current !== 'object') {
return undefined
}
// eslint-disable-next-line
current = current[part]
}

Expand All @@ -180,6 +181,7 @@ function jsonPointer(obj: any, pointer: string): any {
export function extractExpressionValueFromMessage(message: { headers: any, payload: any }, expression: string): any {

// Parse the expression
// eslint-disable-next-line
const match = expression.match(/^\$message\.(header|payload)(#.*)?$/)
if (!match) {
throw new Error(`${expression} is invalid.`)
Expand Down
72 changes: 40 additions & 32 deletions src/registerAdapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,7 @@ function registerAdapterForServer(
} else if (['amqp', 'amqps'].includes(protocol)) {
// TODO: Implement AMQP support
} else if (['ws', 'wss'].includes(protocol)) {
const configWsAdapter = config?.ws?.server?.adapter
if (remoteServers && remoteServers.includes(serverName)) {
app.addAdapter(WebsocketClientAdapter, {
serverName,
server,
parsedAsyncAPI,
})
} else {
if (!configWsAdapter || configWsAdapter === 'native') {
app.addAdapter(WebSocketServerAdapter, {
serverName,
server,
parsedAsyncAPI,
})
} else if (configWsAdapter === 'socket.io') {
app.addAdapter(SocketIOAdapter, {
serverName,
server,
parsedAsyncAPI,
})
} else if (typeof configWsAdapter === 'object') {
app.addAdapter(configWsAdapter, {
serverName,
server,
parsedAsyncAPI,
})
} else {
throw new Error(
`Unknown value for websocket.adapter found in glee.config.js: ${config.ws.server.adapter}. Allowed values are 'native-websocket', 'socket.io', or a reference to a custom Glee adapter.`
)
}
}
registerWebsocketsAdapter(serverName, server, app, parsedAsyncAPI, config, remoteServers)
} else if (['http', 'https'].includes(protocol)) {
if (remoteServers && remoteServers.includes(serverName)) {
app.addAdapter(HttpClientAdapter, {
Expand Down Expand Up @@ -123,3 +92,42 @@ function registerAdapterForCluster(
throw new Error(`Unknown value for cluster.adapter in glee.config.js`)
}
}
function registerWebsocketsAdapter(serverName: string,
server: ServerInterface,
app: Glee,
parsedAsyncAPI: AsyncAPIDocument,
config: GleeConfig, remoteServers) {
const configWsAdapter = config?.ws?.server?.adapter
if (remoteServers && remoteServers.includes(serverName)) {
app.addAdapter(WebsocketClientAdapter, {
serverName,
server,
parsedAsyncAPI,
})
} else {
if (!configWsAdapter || configWsAdapter === 'native') {
app.addAdapter(WebSocketServerAdapter, {
serverName,
server,
parsedAsyncAPI,
})
} else if (configWsAdapter === 'socket.io') {
app.addAdapter(SocketIOAdapter, {
serverName,
server,
parsedAsyncAPI,
})
} else if (typeof configWsAdapter === 'object') {
app.addAdapter(configWsAdapter, {
serverName,
server,
parsedAsyncAPI,
})
} else {
throw new Error(
`Unknown value for websocket.adapter found in glee.config.js: ${config.ws.server.adapter}. Allowed values are 'native-websocket', 'socket.io', or a reference to a custom Glee adapter.`
)
}
}
}

0 comments on commit 10cc240

Please sign in to comment.