research-virtualfortknox / msb-client-websocket-nodejs

The nodeJs client library to connect to the websocket interface of the MSB (Manufacturing Service Bus)
Apache License 2.0
7 stars 5 forks source link

Event and Function schemas can not be found when MsbClient is abstracted #8

Closed tom3012 closed 5 years ago

tom3012 commented 5 years ago

I'm submitting a ...

Current behavior:

If you want to extend the MsbClient class in an own class, the working directory of the files function_schema.json and event_schema.json will be changed and the files will no longer be accessible. Look at the example:

import * as _MsbClient from '@vfk_research/msb-client-websocket-nodejs'

class MsbClient extends _MsbClient {
  constructor(type: string, uuid: string, name: string, description: string, token: string) {
    super(type, uuid, name, description, token)
  }

  // do something with the own class
}

export default new MsbClient(...)

Expected behavior:

Would be nice to have the option, to extend the class with own code for better code structure.

Steps to reproduce:

  1. Create an own class and extend MsbClient
  2. Start the client

MSB client version: 1.0.6

MSB server version: x.y.z-RELEASE

Anything else:

I did not create a PR because I'm not sure if there is a deeper meaning to the usage of fs.readFileSync. One possible solution:

// {...}
// line 694: let schema = JSON.parse(fs.readFileSync(__dirname + '/function_schema.json', 'utf8'));
let schema = require('./function_schema.json')
// {...}
// line 784: let schema = JSON.parse(fs.readFileSync(__dirname + '/event_schema.json', 'utf8'));
let schema = require('./event_schema.json')
// {...}
creadicted commented 5 years ago

Since JSON can be imported directly you should do so. Then it also will be added when bundled.

import event_schema from './event_schema.json';
import function_schema from './function_schema.json';
ipamaas commented 5 years ago

Thanks for reporting! Added a new release 1.0.7 to support this.

See: https://github.com/research-virtualfortknox/msb-client-websocket-nodejs/releases/tag/v1.0.7