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

Commit a0287fd

Browse files
authored
COMPASS-4017: Update driver and cleanup (#210)
* remove old deps * update mocha, driver, remove old connect with backoff * `mongodb-core` is deprecated and merged back into `mongodb` * chore: Update dependencies - mongodb-js/compass#1873 is upgrading electron - mongodb-js-fmt is deprecated * fix: update package-lock * chore: update kerberos for electron 6 * 👕 * fix: Driver handles setting default namespace 👕 ✅ * fix(tests): Explicitly close driver connections ✅ * refactor: Collapse lodash dependency Move away from `lodash.*` to top-level `lodash` that is far easier to maintain.
1 parent 0d7d84c commit a0287fd

11 files changed

+1016
-700
lines changed

.jsfmtrc

Lines changed: 0 additions & 174 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- 10.2.1
4+
- 12.4.0
55
addons:
66
apt:
77
sources:

lib/connect-with-backoff.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/connect.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
const { EventEmitter } = require('events');
12
const fs = require('fs');
23
const async = require('async');
3-
const includes = require('lodash.includes');
4-
const clone = require('lodash.clone');
5-
const assign = require('lodash.assign');
6-
const isString = require('lodash.isstring');
7-
const isFunction = require('lodash.isfunction');
8-
const omit = require('lodash.omit');
9-
const MongoClient = require('mongodb').MongoClient;
10-
const parseConnectionString = require('mongodb-core').parseConnectionString;
4+
const {
5+
includes,
6+
clone,
7+
assign,
8+
isString,
9+
isFunction,
10+
omit
11+
} = require('lodash');
12+
const { MongoClient } = require('mongodb');
13+
const { parseConnectionString } = require('mongodb/lib/core');
1114
const Connection = require('./extended-model');
1215
const createSSHTunnel = require('./ssh-tunnel');
13-
const EventEmitter = require('events').EventEmitter;
16+
1417
const debug = require('debug')('mongodb-connection-model:connect');
1518

16-
const needToLoadSSLFiles = (model) => !includes(
17-
['NONE', 'UNVALIDATED'],
18-
model.sslType
19-
);
19+
const needToLoadSSLFiles = model =>
20+
!includes(['NONE', 'UNVALIDATED'], model.sslType);
2021

2122
const loadOptions = (model, done) => {
2223
if (!needToLoadSSLFiles(model)) {
@@ -28,18 +29,19 @@ const loadOptions = (model, done) => {
2829
const tasks = {};
2930
const opts = clone(model.driverOptions, true);
3031

31-
Object.keys(opts).map((key) => {
32+
Object.keys(opts).map(key => {
3233
if (key.indexOf('ssl') === -1) {
3334
return;
3435
}
3536

3637
if (Array.isArray(opts[key])) {
37-
opts[key].forEach((value) => {
38+
opts[key].forEach(value => {
3839
if (typeof value === 'string') {
39-
tasks[key] = (cb) => async.parallel(
40-
opts[key].map((k) => fs.readFile.bind(null, k)),
41-
cb
42-
);
40+
tasks[key] = cb =>
41+
async.parallel(
42+
opts[key].map(k => fs.readFile.bind(null, k)),
43+
cb
44+
);
4345
}
4446
});
4547
}
@@ -60,7 +62,7 @@ const loadOptions = (model, done) => {
6062
return done(err);
6163
}
6264

63-
Object.keys(res).map((key) => {
65+
Object.keys(res).map(key => {
6466
opts[key] = res[key];
6567
});
6668

@@ -90,7 +92,7 @@ const validateURL = (model, done) => {
9092
});
9193
};
9294

93-
const getStatusStateString = (evt) => {
95+
const getStatusStateString = evt => {
9496
if (!evt) {
9597
return 'UNKNOWN';
9698
}
@@ -145,7 +147,7 @@ const getTasks = (model, setupListeners) => {
145147
}
146148
};
147149

148-
ctx.skip = (reason) => {
150+
ctx.skip = reason => {
149151
state.emit('status', { message, skipped: true, reason });
150152

151153
if (cb) {
@@ -167,19 +169,21 @@ const getTasks = (model, setupListeners) => {
167169
* TODO (imlucas) dns.lookup() model.hostname and model.sshTunnelHostname to check for typos
168170
*/
169171
assign(tasks, {
170-
'Load SSL files': (cb) => {
172+
'Load SSL files': cb => {
171173
const ctx = status('Load SSL files', cb);
172174

173175
if (!needToLoadSSLFiles(model)) {
174-
return ctx.skip('The selected SSL mode does not need to load any files.');
176+
return ctx.skip(
177+
'The selected SSL mode does not need to load any files.'
178+
);
175179
}
176180

177181
loadOptions(model, ctx);
178182
}
179183
});
180184

181185
assign(tasks, {
182-
'Create SSH Tunnel': (cb) => {
186+
'Create SSH Tunnel': cb => {
183187
const ctx = status('Create SSH Tunnel', cb);
184188

185189
if (model.sshTunnel === 'NONE') {
@@ -191,7 +195,7 @@ const getTasks = (model, setupListeners) => {
191195
});
192196

193197
assign(tasks, {
194-
'Connect to MongoDB': (cb) => {
198+
'Connect to MongoDB': cb => {
195199
const ctx = status('Connect to MongoDB');
196200

197201
// @note: Durran:
@@ -281,23 +285,25 @@ const connect = (model, setupListeners, done) => {
281285
}
282286

283287
if (!isFunction(done)) {
284-
done = (err) => {
288+
done = err => {
285289
if (err) {
286290
throw err;
287291
}
288292
};
289293
}
290294

291295
const tasks = getTasks(model, setupListeners);
292-
const logTaskStatus = require('debug')('mongodb-connection-model:connect:status');
296+
const logTaskStatus = require('debug')(
297+
'mongodb-connection-model:connect:status'
298+
);
293299

294-
tasks.state.on('status', (evt) => {
300+
tasks.state.on('status', evt => {
295301
logTaskStatus('%s [%s]', evt.message, getStatusStateString(evt));
296302
});
297303

298304
logTaskStatus('Connecting...');
299305

300-
async.series(tasks, (err) => {
306+
async.series(tasks, err => {
301307
if (err) {
302308
logTaskStatus('Error connecting:', err);
303309

0 commit comments

Comments
 (0)