nats-hemera
Advanced tools
Comparing version 2.4.3 to 3.0.0
@@ -0,0 +0,0 @@ 'use strict' |
@@ -51,3 +51,2 @@ 'use strict' | ||
INVALID_EXTENSION_TYPE: 'Invalid extension type', | ||
PLUGIN_NAME_REQUIRED: 'Plugin name is required', | ||
MISSING_DECORATE_DEPENDENCY: 'Missing decorate dependency', | ||
@@ -66,3 +65,4 @@ DECORATION_ALREADY_DEFINED: 'Decoration has been already added', | ||
TRANSPORT_OPTIONS_DIFFER_DESC: | ||
'Could not register pattern "%s" because pattern "%s" has different transport configuration but the same topic. Please use a different topic name!' | ||
'Could not register pattern "%s" because pattern "%s" has different transport configuration but the same topic. Please use a different topic name!', | ||
PLUGIN_DEP_STRINGS: 'The dependencies should be an array of strings' | ||
} |
@@ -24,5 +24,5 @@ 'use strict' | ||
const SuperError = require('super-error') | ||
const Hoek = require('hoek') | ||
const Joi = require('joi') | ||
const Avvio = require('avvio') | ||
const Hoek = require('hoek') | ||
const Series = require('fastseries') | ||
@@ -146,5 +146,9 @@ | ||
const proto = Object.getPrototypeOf(res) | ||
const pluginCount = Object.keys(this._plugins).length + 1 | ||
const pluginName = | ||
plugin[Symbol.for('name')] || 'anonymous-' + pluginCount | ||
const pluginDeps = plugin[Symbol.for('dependencies')] || [] | ||
if (hemera._config.childLogger) { | ||
res.log = hemera.log.child({ plugin: opts.name }) | ||
res.log = hemera.log.child({ plugin: pluginName }) | ||
} | ||
@@ -155,3 +159,4 @@ | ||
options: opts, | ||
name: opts.name | ||
name: pluginName, | ||
dependencies: pluginDeps | ||
} | ||
@@ -173,3 +178,3 @@ | ||
this._plugins[opts.name] = res | ||
this._plugins[pluginName] = res | ||
@@ -458,18 +463,23 @@ return res | ||
} | ||
/** | ||
* | ||
* | ||
* @returns | ||
* @param {any} deps | ||
* @memberof Hemera | ||
*/ | ||
_use(plugin, opts) { | ||
const pluginOpts = Hoek.clone(plugin.options || {}) | ||
const options = Hoek.applyToDefaults(pluginOpts, opts || {}, true) | ||
if (!options.name) { | ||
throw new Errors.HemeraError(Constants.PLUGIN_NAME_REQUIRED) | ||
checkPluginDependencies(plugin) { | ||
const deps = plugin[Symbol.for('dependencies')] | ||
if (!deps) return | ||
if (!Array.isArray(deps)) { | ||
throw new Error(Constants.PLUGIN_DEP_STRINGS) | ||
} | ||
this.register(plugin.plugin, options) | ||
deps.forEach(dependency => { | ||
if (!this._plugins[dependency]) { | ||
throw new Error( | ||
`The dependency '${dependency}' was not registered before plugin '${this | ||
.plugin$.name}'` | ||
) | ||
} | ||
}) | ||
} | ||
@@ -480,23 +490,23 @@ | ||
* | ||
* @returns | ||
* @memberof Hemera | ||
*/ | ||
_use(plugin, opts, shallowKeys) { | ||
let pluginOpts = Hoek.clone(plugin[Symbol.for('options')] || {}) | ||
pluginOpts = Object.assign(pluginOpts, opts) | ||
this.register(plugin, pluginOpts) | ||
} | ||
/** | ||
* | ||
* | ||
* @param {any} plugin | ||
* @param {any} opts | ||
* @param {any} cb | ||
* @returns | ||
* @memberof Hemera | ||
*/ | ||
use(plugin, opts) { | ||
// name has to be set in plugin options | ||
// when we register an array of plugins it would collide | ||
if (opts && opts.name) { | ||
delete opts.name | ||
} | ||
if (_.isArray(plugin)) { | ||
plugin.forEach(p => { | ||
this._use(p, opts) | ||
}) | ||
} else { | ||
use(plugins, opts) { | ||
const p = _.isArray(plugins) ? plugins : [plugins] | ||
p.forEach(plugin => { | ||
this._use(plugin, opts) | ||
} | ||
}) | ||
return this._avvio | ||
@@ -503,0 +513,0 @@ } |
{ | ||
"name": "nats-hemera", | ||
"author": "Dustin Deus (https://github.com/StarpTech)", | ||
"version": "2.4.3", | ||
"version": "3.0.0", | ||
"main": "lib/index.js", | ||
@@ -39,7 +39,7 @@ "homepage": "https://hemerajs.github.io/hemera/", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=6" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"avvio": "3.0.x", | ||
"avvio": "3.2.x", | ||
"bloomrun": "4.0.x", | ||
@@ -56,3 +56,3 @@ "errio": "1.2.x", | ||
"pino": "4.7.x", | ||
"super-error": "2.1.x", | ||
"super-error": "2.2.x", | ||
"tinysonic": "1.3.x" | ||
@@ -59,0 +59,0 @@ }, |
71754
2777
+ Addedavvio@3.2.0(transitive)
+ Addedsuper-error@2.2.1(transitive)
- Removedavvio@3.0.0(transitive)
- Removedsuper-error@2.1.1(transitive)
Updatedavvio@3.2.x
Updatedsuper-error@2.2.x