All files / src/lib connection.ts

0% Statements 0/12
100% Branches 0/0
0% Functions 0/8
0% Lines 0/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                                                                                                                                                                     
import { ServerInterface as AsyncAPIServer, AsyncAPIDocumentInterface as AsyncAPIDocument } from '@asyncapi/parser'
 
interface IGleeQuoreConnectionConstructor {
  connection: any
  channels: string[]
  serverName: string
  server?: AsyncAPIServer
  parsedAsyncAPI: AsyncAPIDocument
}
 
class GleeQuoreConnection {
  private _rawConnection: any
  private _channels: string[]
  private _serverName: string
  private _AsyncAPIServer: AsyncAPIServer
  private _parsedAsyncAPI: AsyncAPIDocument
 
  /**
   * Instantiates a Glee connection.
   *
   * @param {Object} options
   * @param {any} options.connection The raw connection object this GleeQuoreConnection has to represent.
   * @param {String[]} options.channels The name of the channels associated to this connection.
   * @param {String} options.serverName  The name of the AsyncAPI server the connection is pointing to.
   * @param {AsyncAPIServer} options.server  The AsyncAPI server the connection is pointing to.
   * @param {AsyncAPIDocument} options.parsedAsyncAPI The AsyncAPI document.
   */
  constructor({
    connection,
    channels,
    serverName,
    server,
    parsedAsyncAPI,
  }: IGleeQuoreConnectionConstructor) {
    this._rawConnection = connection
    this._channels = channels
    this._serverName = serverName
    this._AsyncAPIServer = server
    this._parsedAsyncAPI = parsedAsyncAPI
  }
 
  get rawConnection(): any {
    return this._rawConnection
  }
 
  get channels(): string[] {
    return this._channels
  }
 
  get serverName(): string {
    return this._serverName
  }
 
  get AsyncAPIServer(): AsyncAPIServer {
    return this._AsyncAPIServer
  }
 
  get parsedAsyncAPI(): AsyncAPIDocument {
    return this._parsedAsyncAPI
  }
 
  /**
   * Checks whether a channel is associated with this connection.
   *
   * @param {String} channelName The name of the channel.
   * @return {Boolean}
   */
  hasChannel(channelName: string): boolean {
    return this.channels.includes(channelName)
  }
 
  /**
   * Returns the real connection object.
   *
   * @return {Any}
   */
  getRaw(): any {
    return this.rawConnection
  }
}
 
export default GleeQuoreConnection