Skip to content

Commit e3a8d7d

Browse files
committed
feat: COMPASS-3933: Upgrade to Electron 6 (#160)
* chore: Cleanup - update dependencies - remove currently unused `electron-rebuild` - remove `pre-commit` from package.json as its logic is now bundled into `mongodb-js-precommit` * refactor: Collapse lodash dependency Move away from `lodash.*` to top-level `lodash` that is far easier to maintain. * chore: Allow mongodb-security semver to update automatically * chore: connection-model update for kerberos electron 6 fix mongodb-js/connection-model#210 * fix(test): No idea how this test ever actually passed before... ✅ * feat(ci): Default test is now electron renderer So we can catch mismatched behaviors in the future as NODE-2387 uncovered * chore: update mongodb-runner mongodb-js/runner#158 * docs: Add note to README that tests now run via electron-mocha
1 parent ce6a6b6 commit e3a8d7d

File tree

7 files changed

+1267
-941
lines changed

7 files changed

+1267
-941
lines changed

packages/data-service/.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ addons:
1212
- gnome-keyring
1313
- python-gnomekeyring
1414
node_js:
15-
- 10.2.1
15+
- 12.4.0
1616
env:
1717
- MONGODB_VERSION=4.0.0 MONGODB_TOPOLOGY=standalone
1818
before_install:

packages/data-service/README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ npm install --save mongodb-data-service
1616
const Connection = require('mongodb-connection-model');
1717
const DataService = require('mongodb-data-service');
1818

19-
var service = new DataService(new Connection({
20-
hostname: '127.0.0.1',
21-
port: 27018,
22-
ns: 'data-service'
23-
}));
19+
var service = new DataService(
20+
new Connection({
21+
hostname: '127.0.0.1',
22+
port: 27018,
23+
ns: 'data-service'
24+
})
25+
);
2426
```
2527

2628
### Connecting to the server.
@@ -135,9 +137,19 @@ service.sample('database.collection', {});
135137
view_on: undefined,
136138
pipeline: undefined
137139
}
138-
]
140+
];
139141
```
140142

143+
## Contributing
144+
145+
### Running Tests
146+
147+
```bash
148+
npm test
149+
```
150+
151+
All tests in an electron renderer process thanks to [electron-mocha](https://npm.im/electron-mocha).
152+
141153
## License
142154

143155
Apache 2.0

packages/data-service/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) {

packages/data-service/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.

0 commit comments

Comments
 (0)