diff --git a/src/logger-factory.js b/src/logger-factory.js index 683bb4376..4a4e22d47 100644 --- a/src/logger-factory.js +++ b/src/logger-factory.js @@ -54,7 +54,7 @@ class LoggerFactory { opts = [opts]; } - this.appenders = _.compact(opts).map(o => { + this.appenders = opts.filter(Boolean).map(o => { // Built-in shorthand if (isString(o)) return Loggers.resolve({ type: o, options: { level: globalLogLevel } }); @@ -118,7 +118,7 @@ class LoggerFactory { const broker = this.broker; const appenders = this.appenders; - const logHandlers = _.compact(appenders.map(app => app.getLogHandler(bindings))); + const logHandlers = appenders.map(app => app.getLogHandler(bindings)).filter(Boolean); const hasNewLogEntryMiddleware = broker.middlewares && broker.middlewares.registeredHooks.newLogEntry; diff --git a/src/metrics/registry.js b/src/metrics/registry.js index 6843a4627..86e237242 100644 --- a/src/metrics/registry.js +++ b/src/metrics/registry.js @@ -65,7 +65,7 @@ class MetricRegistry { ? this.opts.reporter : [this.opts.reporter]; - this.reporter = _.compact(reporters).map(r => { + this.reporter = reporters.filter(Boolean).map(r => { const reporter = Reporters.resolve(r); reporter.init(this); return reporter; diff --git a/src/middlewares/action-hook.js b/src/middlewares/action-hook.js index 33a8a1018..4b7e5d035 100644 --- a/src/middlewares/action-hook.js +++ b/src/middlewares/action-hook.js @@ -6,7 +6,6 @@ "use strict"; -const _ = require("lodash"); const { isFunction, isString, match } = require("../utils"); module.exports = function actionHookMiddleware(broker) { @@ -43,13 +42,13 @@ module.exports = function actionHookMiddleware(broker) { if (isString(hooks)) return service && isFunction(service[hooks]) ? service[hooks] : null; if (Array.isArray(hooks)) { - return _.compact( - hooks.map(h => { + return hooks + .map(h => { if (isString(h)) return service && isFunction(service[h]) ? service[h] : null; return h; }) - ); + .filter(Boolean); } return hooks; diff --git a/src/registry/discoverers/etcd3.js b/src/registry/discoverers/etcd3.js index 5b5aaa16b..f5bb8f955 100644 --- a/src/registry/discoverers/etcd3.js +++ b/src/registry/discoverers/etcd3.js @@ -256,7 +256,7 @@ class Etcd3Discoverer extends BaseDiscoverer { }) .then(packets => { - _.compact(packets).map(packet => { + packets.filter(Boolean).map(packet => { if (packet.sender == this.broker.nodeID) return; removeFromArray(prevNodes, packet.sender); diff --git a/src/service-broker.js b/src/service-broker.js index 3777c6b9e..cc4a84a6f 100644 --- a/src/service-broker.js +++ b/src/service-broker.js @@ -350,7 +350,7 @@ class ServiceBroker { registerMiddlewares(userMiddlewares) { // Register user middlewares if (Array.isArray(userMiddlewares) && userMiddlewares.length > 0) { - _.compact(userMiddlewares).forEach(mw => this.middlewares.add(mw)); + userMiddlewares.filter(Boolean).forEach(mw => this.middlewares.add(mw)); } if (this.options.internalMiddlewares) { @@ -1024,8 +1024,8 @@ class ServiceBroker { if (!Array.isArray(serviceNames)) serviceNames = [serviceNames]; serviceNames = _.uniq( - _.compact( - serviceNames.map(x => { + serviceNames + .map(x => { if (utils.isPlainObject(x) && x.name) { if (Array.isArray(x.version)) { return x.version.map(v => @@ -1038,7 +1038,7 @@ class ServiceBroker { return x; } }) - ) + .filter(Boolean) ); if (serviceNames.length == 0) return this.Promise.resolve({ services: [], statuses: [] }); diff --git a/src/service.js b/src/service.js index 34c929d24..3eed75962 100644 --- a/src/service.js +++ b/src/service.js @@ -689,7 +689,7 @@ class Service { * @returns {Object} Merged schema */ mergeSchemaUniqArray(src, target) { - return _.uniqWith(_.compact(flatten([src, target])), _.isEqual); + return _.uniqWith(flatten([src, target]).filter(Boolean), _.isEqual); } /** @@ -720,9 +720,9 @@ class Service { const modHook = wrapToArray(src[k][k2]); const resHook = wrapToArray(target[k][k2]); - target[k][k2] = _.compact( - flatten(k === "before" ? [resHook, modHook] : [modHook, resHook]) - ); + target[k][k2] = flatten( + k === "before" ? [resHook, modHook] : [modHook, resHook] + ).filter(Boolean); }); }); @@ -752,9 +752,9 @@ class Service { const modHook = wrapToArray(srcAction.hooks[k]); const resHook = wrapToArray(targetAction.hooks[k]); - srcAction.hooks[k] = _.compact( - flatten(k === "before" ? [resHook, modHook] : [modHook, resHook]) - ); + srcAction.hooks[k] = flatten( + k === "before" ? [resHook, modHook] : [modHook, resHook] + ).filter(Boolean); }); } @@ -789,9 +789,11 @@ class Service { const modEvent = wrapToHandler(src[k]); const resEvent = wrapToHandler(target[k]); - let handler = _.compact( - flatten([resEvent ? resEvent.handler : null, modEvent ? modEvent.handler : null]) - ); + let handler = flatten([ + resEvent ? resEvent.handler : null, + modEvent ? modEvent.handler : null + ]).filter(Boolean); + if (handler.length === 1) handler = handler[0]; target[k] = _.defaultsDeep(modEvent, resEvent); @@ -810,7 +812,7 @@ class Service { * @returns {Object} Merged schema */ mergeSchemaLifecycleHandlers(src, target) { - return _.compact(flatten([target, src])); + return flatten([target, src]).filter(Boolean); } /** diff --git a/src/tracing/tracer.js b/src/tracing/tracer.js index 59a18a887..89746e26c 100644 --- a/src/tracing/tracer.js +++ b/src/tracing/tracer.js @@ -92,7 +92,7 @@ class Tracer { ? this.opts.exporter : [this.opts.exporter]; - this.exporter = _.compact(exporters).map(r => { + this.exporter = exporters.filter(Boolean).map(r => { const exporter = Exporters.resolve(r); exporter.init(this); return exporter; diff --git a/src/transporters/base.js b/src/transporters/base.js index 8f1524761..4429166e7 100644 --- a/src/transporters/base.js +++ b/src/transporters/base.js @@ -281,7 +281,7 @@ class BaseTransporter { ); } - return this.broker.Promise.all(_.compact(flatten(p, true))); + return this.broker.Promise.all(flatten(p, true).filter(Boolean)); }) ); });