kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.44k stars 124 forks source link

SDK method index.exists returns empty object #1276

Closed sbressey closed 5 years ago

sbressey commented 5 years ago

When using the index.exists method with JS6 SDK, I always get an empty object instead of getting a boolean response.

Expected Behavior

method should return boolean and not an object

Steps to Reproduce

1.Create a kuzzle plugin 2.get the sdk in init method : this.kuzzle = this.context.accessors.sdk; 3.Call the index.exists mehod : const exists = await this.kuzzle.index.exists(indexName) 4.variable exists is an empty object

Context (Environment)

Kuzzle : kuzzleio/plugin-dev:1.6.4 ES : 5.6.10

Aschen commented 5 years ago

Hi @sbressey,

I wasn't able to reproduce your issue with the following minimalist plugin. Can you provide me the code that trigger the bug?

class CorePlugin {
  constructor () {
    this.context = null;
    this.config = {};
    this.hooks = {};
    this.pipes = {};
    this.controllers = {
      'myNewController': {
        'myNewAction': 'test'
      }
    };
    this.routes = [
      {verb: 'get', url: '/test', controller: 'myNewController', action: 'myNewAction'},
    ];
  }

  init (customConfig, context) {
    this.config = Object.assign(this.config, customConfig);
    this.context = context;
    this.kuzzle = this.context.accessors.sdk;
  }

  async test () {
    const exists = await this.kuzzle.index.exists('nyc-open-data');
    console.log(exists);
    return `Index exists? : ${exists}`;
  }
}

module.exports = CorePlugin;

curl localhost:7512/_plugin/kuzzle-core-plugin-boilerplate/test

sbressey commented 5 years ago

Found the issue : my custom method call using index.create missed an await before. index.create is working as expected.