Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Commit 1c17836

Browse files
committed
refactor: Collapse lodash dependency
Move away from `lodash.*` to top-level `lodash` that is far easier to maintain.
1 parent e928cde commit 1c17836

File tree

4 files changed

+65
-103
lines changed

4 files changed

+65
-103
lines changed

lib/instance-detail-helper.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ const toNS = require('mongodb-ns');
44
const security = require('mongodb-security');
55
const ReadPreference = require('mongodb').ReadPreference;
66
const URL = require('mongodb-url');
7-
const union = require('lodash.union');
8-
const map = require('lodash.map');
9-
const partial = require('lodash.partial');
10-
const has = require('lodash.has');
11-
const get = require('lodash.get');
12-
const uniqBy = require('lodash.uniqby');
13-
const flatten = require('lodash.flatten');
14-
const groupBy = require('lodash.groupby');
15-
const forEach = require('lodash.foreach');
16-
const omit = require('lodash.omit');
7+
const {
8+
union,
9+
map,
10+
partial,
11+
has,
12+
get,
13+
uniqBy,
14+
flatten,
15+
groupBy,
16+
forEach,
17+
omit
18+
} = require('lodash');
1719

1820
const debug = require('debug')('mongodb-data-service:instance-detail-helper');
1921

@@ -112,7 +114,11 @@ function getGenuineMongoDB(results, done) {
112114
const buildInfo = results.build.raw;
113115
const cmdLineOpts = results.cmdLineOpts;
114116

115-
debug('genuineMongoDB check: buildInfo and cmdLineOpts', buildInfo, cmdLineOpts);
117+
debug(
118+
'genuineMongoDB check: buildInfo and cmdLineOpts',
119+
buildInfo,
120+
cmdLineOpts
121+
);
116122

117123
const res = {
118124
isGenuine: true,
@@ -402,7 +408,10 @@ function getAllowedDatabases(results, done) {
402408
})
403409
);
404410

405-
done(null, databases.filter((f, i) => f && databases.indexOf(f) === i));
411+
done(
412+
null,
413+
databases.filter((f, i) => f && databases.indexOf(f) === i)
414+
);
406415
}
407416

408417
function parseCollection(resp) {
@@ -443,9 +452,9 @@ function getAllowedCollections(results, done) {
443452
};
444453
})
445454
)
446-
.filter((f) => f.name);
455+
.filter(f => f.name);
447456

448-
collections = uniqBy(collections, (c) => `${c.db}.${c.name}`);
457+
collections = uniqBy(collections, c => `${c.db}.${c.name}`);
449458
collections = map(collections, parseCollection);
450459
debug('allowed collections', collections);
451460
done(null, collections);
@@ -506,9 +515,9 @@ function getCollections(results, done) {
506515
// concat
507516
let collections = [].concat
508517
.apply(results.listCollections, results.allowedCollections)
509-
.filter((f) => f.name !== '');
518+
.filter(f => f.name !== '');
510519
// de-dupe based on _id
511-
collections = uniqBy(collections, (c) => c._id);
520+
collections = uniqBy(collections, c => c._id);
512521

513522
// @todo filter the ones that we can "count on"
514523
// async.filter(collections, function(collection, callback) {

lib/native-client.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
'use strict';
2-
3-
const map = require('lodash.map');
4-
const isFunction = require('lodash.isfunction');
5-
const assignIn = require('lodash.assignin');
6-
const assign = require('lodash.assign');
1+
const { map, isFunction, assignIn, assign } = require('lodash');
72
const async = require('async');
83
const EventEmitter = require('events');
4+
95
const connect = require('mongodb-connection-model').connect;
106
const getIndexes = require('mongodb-index-model').fetch;
117
const createSampleStream = require('mongodb-collection-sample');
128
const parseNamespace = require('mongodb-ns');
13-
const debug = require('debug')('mongodb-data-service:native-client');
9+
1410
const { getInstance } = require('./instance-detail-helper');
1511

12+
const debug = require('debug')('mongodb-data-service:native-client');
13+
1614
/**
1715
* The constant for a mongos.
1816
*/
@@ -93,27 +91,23 @@ class NativeClient extends EventEmitter {
9391
debug('connecting...');
9492
this.isWritable = false;
9593
this.isMongos = false;
96-
connect(
97-
this.model,
98-
this.setupListeners.bind(this),
99-
(err) => {
100-
if (err) {
101-
return done(this._translateMessage(err));
102-
}
94+
connect(this.model, this.setupListeners.bind(this), err => {
95+
if (err) {
96+
return done(this._translateMessage(err));
97+
}
10398

104-
this.isWritable = this.client.isWritable;
105-
this.isMongos = this.client.isMongos;
99+
this.isWritable = this.client.isWritable;
100+
this.isMongos = this.client.isMongos;
106101

107-
debug('connected!', {
108-
isWritable: this.isWritable,
109-
isMongos: this.isMongos
110-
});
102+
debug('connected!', {
103+
isWritable: this.isWritable,
104+
isMongos: this.isMongos
105+
});
111106

112-
this.client.on('status', evt => this.emit('status', evt));
113-
this.database = this.client.db(this.model.ns || ADMIN);
114-
done(null, this);
115-
}
116-
);
107+
this.client.on('status', evt => this.emit('status', evt));
108+
this.database = this.client.db(this.model.ns || ADMIN);
109+
done(null, this);
110+
});
117111
return this;
118112
}
119113

@@ -155,7 +149,8 @@ class NativeClient extends EventEmitter {
155149
debug('topologyDescriptionChanged', arguments);
156150
client.isWritable = this._isWritable(evt);
157151
client.isMongos = this._isMongos(evt);
158-
debug('updated to', {isWritable: client.isWritable,
152+
debug('updated to', {
153+
isWritable: client.isWritable,
159154
isMongos: client.isMongos
160155
});
161156

@@ -855,13 +850,16 @@ class NativeClient extends EventEmitter {
855850
options.viewOn = this._collectionName(sourceNs);
856851
options.pipeline = pipeline;
857852

858-
this._database(this._databaseName(sourceNs))
859-
.createCollection(name, options, (error, result) => {
853+
this._database(this._databaseName(sourceNs)).createCollection(
854+
name,
855+
options,
856+
(error, result) => {
860857
if (error) {
861858
return callback(this._translateMessage(error));
862859
}
863860
callback(null, result);
864-
});
861+
}
862+
);
865863
}
866864
/**
867865
* Update a view.

package-lock.json

Lines changed: 12 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,7 @@
2222
"dependencies": {
2323
"async": "^2.3.0",
2424
"debug": "^2.6.0",
25-
"lodash.assign": "^4.2.0",
26-
"lodash.assignin": "^4.2.0",
27-
"lodash.filter": "^4.6.0",
28-
"lodash.flatten": "^4.4.0",
29-
"lodash.foreach": "^4.5.0",
30-
"lodash.get": "^4.4.2",
31-
"lodash.groupby": "^4.6.0",
32-
"lodash.has": "^4.5.2",
33-
"lodash.isfunction": "^3.0.8",
34-
"lodash.map": "^4.6.0",
35-
"lodash.omit": "^4.5.0",
36-
"lodash.partial": "^4.2.1",
37-
"lodash.union": "^4.6.0",
38-
"lodash.uniqby": "^4.5.0",
25+
"lodash": "^4.17.0",
3926
"mongodb": "^3.4.0",
4027
"mongodb-collection-sample": "^4.4.4",
4128
"mongodb-connection-model": "^14.3.7",
@@ -49,7 +36,6 @@
4936
"devDependencies": {
5037
"chai": "^3.4.1",
5138
"eslint-config-mongodb-js": "^5.0.3",
52-
"lodash.find": "^4.6.0",
5339
"mocha": "^6.2.2",
5440
"mock-require": "^2.0.1",
5541
"mongodb-js-precommit": "^2.0.0",

0 commit comments

Comments
 (0)