text: const lib = require ('../@sap/cds-services')
  const Service = require ('./Service')
  
  module.exports = class ServiceClient extends Service .and (lib.Client) {
  
      static new (name, model, o) {
          const primary = o && o.primary || name === 'db'
          const srv = lib.connect.connect (name, o, primary)
          return Object.setPrototypeOf (srv, this.prototype)
      }
  
      // we should get rid of that:
      disconnect(...args) {
          const {cds} = global
          if (this.name)  delete cds.services [this.name]
          if (this === cds.db) cds.db = undefined
          { // REVISIT: pretty ugly that we have to keep that in mind to call the ugly's disconnect instead!
              const ugly = lib.connect
              if (!this._been_here && ugly.hasSession() && ugly.connect(0,0,true) === this) {
                  return this._been_here=1, ugly.disconnect(...args)
              }
          }
          return super.disconnect(...args)
      }
  
      // interims workarounds
      on(){} before(){} after(){} emit(){}
  
  }
  