hapipal / confidence

Dynamic, declarative configurations
Other
263 stars 43 forks source link

Confidence storing a javascript object #64

Closed Danlock closed 7 years ago

Danlock commented 7 years ago

Im using confidence to store plugins and routes in my manifest.json, but because confidence doesnt allow javascript object to be held (and therefore passed as plugin parameters to a plugin, like 'hapi-sequelize' for example) I cannot store my register object for hapi-sequelize in my manifest.json.

To workaround this issue i registered the hapi-sequelize plugin directly, but I wish to know if there is a way for this to work smoothly (register hapi sequelize inside my manifest.json), or any planned support for instances inside of parameters to plugins through Confidence?

The specific problem with hapi-sequelize is that the plugin requires a sequelize instance that cant be passed in through confidence.

Or maybe I am just doing something completely wrong. I hope so.

Thank in advance

patrickkettner commented 7 years ago

hey @danlock!

Not sure I follow what the ask is exactly. Are you wanting to store an instance of a sequalize object? If you could explain specifically which config type of you are trying to use, it would be helpful.

Danlock commented 7 years ago

hapi-sequelize registration needs a sequelize instance, like so

plugins: {
        register: require('hapi-sequelize'),
        options: [ {
      name: process.env.DB_NAME,
      models: [Path.normalize(__dirname + '/server/models/*.js')],
      sequelize: new Sequelize(/* etc...*/),
      sync: true,
      // forceSync: true,
    }],
}

However confidence throws an error on new sequelize(), when I try to Confidence.store this as my manifest.js to pass into hapijs. It seemed like it is not supported, which is why im asking if there is a way to make it work or if Confidence just doesn't support javascript objects.

patrickkettner commented 7 years ago

hey @danlock!

Confidence only works with javascript objects. What you are wanting is to save an instance of a n object. Those aren't, and won't be, supported. Honestly, it wouldnt really be possible any way. the Sequelize instance could include platform and/or arch dependent information that wouldn't be transferable between systems or versions.

I am going to guess that /* etc... */ is an object of somekind, right? That is what you should be putting in confidence. Then within your code, you call new Sequelize with the generated config object.

hope that helps!