Skip to content

Commit

Permalink
fix: remove remaining lodash references in core that got missed
Browse files Browse the repository at this point in the history
  • Loading branch information
arobson committed Feb 18, 2018
1 parent c50e04c commit 9aa3b04
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rabbot",
"version": "2.1.0",
"version": "2.0.0",
"description": "Abstractions to simplify working with the RabbitMQ",
"main": "src/index.js",
"engines": {
Expand Down
34 changes: 18 additions & 16 deletions src/amqp/exchange.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var _ = require('lodash');
var defer = require('../defer');
var info = require('../info');
var exLog = require('../log.js')('rabbot.exchange');
var topLog = require('../log.js')('rabbot.topology');
var format = require('util').format;
const defer = require('../defer');
const info = require('../info');
const exLog = require('../log.js')('rabbot.exchange');
const topLog = require('../log.js')('rabbot.topology');
const format = require('util').format;

/* log
* `rabbot.exchange`
Expand All @@ -20,12 +19,15 @@ var format = require('util').format;
const DIRECT_REPLY_TO = 'amq.rabbitmq.reply-to';
const DIRECT_REGEX = /^rabbit(mq)?$/i;

function aliasOptions (options, aliases) {
var aliased = _.transform(options, function (result, value, key) {
var alias = aliases[ key ];
result[ alias || key ] = value;
});
return _.omit(aliased, Array.prototype.slice.call(arguments, 2));
function aliasOptions (options, aliases, ...omit) {
const keys = Object.keys(options);
return keys.reduce((result, key) => {
const alias = aliases[ key ] || key;
if (omit.indexOf(key) < 0) {
result[ alias ] = options[ key ];
}
return result;
}, {});
}

function define (channel, options, connectionName) {
Expand All @@ -36,7 +38,7 @@ function define (channel, options, connectionName) {
options.type,
options.name,
connectionName,
JSON.stringify(_.omit(valid, [ 'name', 'type' ]))
JSON.stringify(valid)
);
if (options.name === '') {
return Promise.resolve(true);
Expand All @@ -50,9 +52,9 @@ function define (channel, options, connectionName) {
function getContentType (message) {
if (message.contentType) {
return message.contentType;
} else if (_.isString(message.body)) {
} else if (typeof message.body === 'string') {
return 'text/plain';
} else if (_.isObject(message.body) && !Buffer.isBuffer(message.body)) {
} else if (typeof message.body === 'object' && !Buffer.isBuffer(message.body)) {
return 'application/json';
} else {
return 'application/octet-stream';
Expand All @@ -65,7 +67,7 @@ function publish (channel, options, topology, log, serializers, message) {
var baseHeaders = {
'CorrelationId': message.correlationId
};
message.headers = _.merge(baseHeaders, message.headers);
message.headers = Object.assign(baseHeaders, message.headers);
var contentType = getContentType(message);
var serializer = serializers[ contentType ];
if (!serializer) {
Expand Down
16 changes: 9 additions & 7 deletions src/amqp/iomonad.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// This is probably not a true monad, but it seems close based on my current understanding.

var _ = require('lodash');
var Monologue = require('monologue.js');
var machina = require('machina');
var log = require('../log.js')('rabbot.io');
var staticId = 0;
const Monologue = require('monologue.js');
const machina = require('machina');
const log = require('../log.js')('rabbot.io');
let staticId = 0;

/* state definitions
acquiring - waiting to get back a connection or channel
Expand Down Expand Up @@ -345,8 +344,11 @@ module.exports = function (options, type, factory, target, close) {

Monologue.mixInto(IOMonad);
var machine = new IOMonad();
_.each(target.prototype, function (prop, name) {
if (_.isFunction(prop)) {

const names = Object.getOwnPropertyNames(target.prototype);
names.forEach(name => {
const prop = target.prototype[ name ];
if (typeof prop === 'function') {
machine[ name ] = function () {
var list = Array.prototype.slice.call(arguments, 0);
return machine.operate(name, list);
Expand Down
50 changes: 26 additions & 24 deletions src/amqp/queue.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
var _ = require('lodash');
var AckBatch = require('../ackBatch.js');
var postal = require('postal');
var dispatch = postal.channel('rabbit.dispatch');
var responses = postal.channel('rabbit.responses');
var info = require('../info');
var log = require('../log')('rabbot.queue');
var format = require('util').format;
var topLog = require('../log')('rabbot.topology');
var unhandledLog = require('../log')('rabbot.unhandled');
var noOp = function () {};
const AckBatch = require('../ackBatch.js');
const postal = require('postal');
const dispatch = postal.channel('rabbit.dispatch');
const responses = postal.channel('rabbit.responses');
const info = require('../info');
const log = require('../log')('rabbot.queue');
const format = require('util').format;
const topLog = require('../log')('rabbot.topology');
const unhandledLog = require('../log')('rabbot.unhandled');
const noOp = function () {};

/* log
* `rabbot.amqp-queue`
Expand All @@ -28,12 +27,15 @@ var noOp = function () {};
* queue declaration
*/

function aliasOptions (options, aliases) {
var aliased = _.transform(options, function (result, value, key) {
var alias = aliases[ key ];
result[ alias || key ] = value;
});
return _.omit(aliased, Array.prototype.slice.call(arguments, 2));
function aliasOptions (options, aliases, ...omit) {
const keys = Object.keys(options);
return keys.reduce((result, key) => {
const alias = aliases[ key ] || key;
if (omit.indexOf(key) < 0) {
result[ alias ] = options[ key ];
}
return result;
}, {});
}

function define (channel, options, subscriber, connectionName) {
Expand All @@ -45,7 +47,7 @@ function define (channel, options, subscriber, connectionName) {
deadLetterRoutingKey: 'deadLetterRoutingKey'
}, 'subscribe', 'limit', 'noBatch', 'unique');
topLog.info("Declaring queue '%s' on connection '%s' with the options: %s",
options.uniqueName, connectionName, JSON.stringify(_.omit(options, [ 'name' ])));
options.uniqueName, connectionName, JSON.stringify(options));
return channel.assertQueue(options.uniqueName, valid)
.then(function (q) {
if (options.limit) {
Expand All @@ -65,9 +67,9 @@ function finalize (channel, messages) {
function getContentType (body, options) {
if (options && options.contentType) {
return options.contentType;
} else if (_.isString(body)) {
} else if (typeof body === 'string') {
return 'text/plain';
} else if (_.isObject(body) && !body.length) {
} else if (typeof body === 'object' && !body.length) {
return 'application/json';
} else {
return 'application/octet-stream';
Expand Down Expand Up @@ -328,7 +330,7 @@ function subscribe (channelName, channel, topology, serializers, messages, optio
}

options.consumerTag = info.createTag(channelName);
if (_.keys(channel.item.consumers).length > 0) {
if (Object.keys(channel.item.consumers).length > 0) {
log.info('Duplicate subscription to queue %s ignored', channelName);
return Promise.resolve(options.consumerTag);
}
Expand All @@ -346,7 +348,7 @@ function subscribe (channelName, channel, topology, serializers, messages, optio
raw.reject = ops.reject.bind(ops);
raw.nack = ops.nack.bind(ops);
raw.reply = getReply(channel, serializers, raw, topology.replyQueue.name, topology.connection.name);
raw.type = _.isEmpty(raw.properties.type) ? raw.fields.routingKey : raw.properties.type;
raw.type = raw.properties.type || raw.fields.routingKey;
if (exclusive) {
options.exclusive = true;
}
Expand All @@ -368,7 +370,7 @@ function subscribe (channelName, channel, topology, serializers, messages, optio
raw.body = raw.content;
raw.contentEncoding = raw.properties.contentEncoding;
raw.quarantined = true;
topic = `${topic}.quarantined`
topic = `${topic}.quarantined`;
} else {
log.error("Could not deserialize message id %s on queue '%s', connection '%s' - no serializer defined",
raw.properties.messageId, channelName, topology.connection.name);
Expand All @@ -384,7 +386,7 @@ function subscribe (channelName, channel, topology, serializers, messages, optio
raw.quarantined = true;
raw.body = raw.content;
raw.contentEncoding = raw.properties.contentEncoding;
topic = `${topic}.quarantined`
topic = `${topic}.quarantined`;
} else {
track();
ops.reject();
Expand Down

0 comments on commit 9aa3b04

Please sign in to comment.