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

feat: COMPASS-3933: Upgrade to Electron 6 #160

Merged
merged 8 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ addons:
- gnome-keyring
- python-gnomekeyring
node_js:
- 10.2.1
- 12.4.0
env:
- MONGODB_VERSION=4.0.0 MONGODB_TOPOLOGY=standalone
before_install:
Expand Down
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ npm install --save mongodb-data-service
const Connection = require('mongodb-connection-model');
const DataService = require('mongodb-data-service');

var service = new DataService(new Connection({
hostname: '127.0.0.1',
port: 27018,
ns: 'data-service'
}));
var service = new DataService(
new Connection({
hostname: '127.0.0.1',
port: 27018,
ns: 'data-service'
})
);
```

### Connecting to the server.
Expand Down Expand Up @@ -135,9 +137,19 @@ service.sample('database.collection', {});
view_on: undefined,
pipeline: undefined
}
]
];
```

## Contributing

### Running Tests

```bash
npm test
```

All tests in an electron renderer process thanks to [electron-mocha](https://npm.im/electron-mocha).

## License

Apache 2.0
Expand Down
41 changes: 25 additions & 16 deletions lib/instance-detail-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ const toNS = require('mongodb-ns');
const security = require('mongodb-security');
const ReadPreference = require('mongodb').ReadPreference;
const URL = require('mongodb-url');
const union = require('lodash.union');
const map = require('lodash.map');
const partial = require('lodash.partial');
const has = require('lodash.has');
const get = require('lodash.get');
const uniqBy = require('lodash.uniqby');
const flatten = require('lodash.flatten');
const groupBy = require('lodash.groupby');
const forEach = require('lodash.foreach');
const omit = require('lodash.omit');
const {
union,
map,
partial,
has,
get,
uniqBy,
flatten,
groupBy,
forEach,
omit
} = require('lodash');

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

Expand Down Expand Up @@ -112,7 +114,11 @@ function getGenuineMongoDB(results, done) {
const buildInfo = results.build.raw;
const cmdLineOpts = results.cmdLineOpts;

debug('genuineMongoDB check: buildInfo and cmdLineOpts', buildInfo, cmdLineOpts);
debug(
'genuineMongoDB check: buildInfo and cmdLineOpts',
buildInfo,
cmdLineOpts
);

const res = {
isGenuine: true,
Expand Down Expand Up @@ -402,7 +408,10 @@ function getAllowedDatabases(results, done) {
})
);

done(null, databases.filter((f, i) => f && databases.indexOf(f) === i));
done(
null,
databases.filter((f, i) => f && databases.indexOf(f) === i)
);
}

function parseCollection(resp) {
Expand Down Expand Up @@ -443,9 +452,9 @@ function getAllowedCollections(results, done) {
};
})
)
.filter((f) => f.name);
.filter(f => f.name);

collections = uniqBy(collections, (c) => `${c.db}.${c.name}`);
collections = uniqBy(collections, c => `${c.db}.${c.name}`);
collections = map(collections, parseCollection);
debug('allowed collections', collections);
done(null, collections);
Expand Down Expand Up @@ -506,9 +515,9 @@ function getCollections(results, done) {
// concat
let collections = [].concat
.apply(results.listCollections, results.allowedCollections)
.filter((f) => f.name !== '');
.filter(f => f.name !== '');
// de-dupe based on _id
collections = uniqBy(collections, (c) => c._id);
collections = uniqBy(collections, c => c._id);

// @todo filter the ones that we can "count on"
// async.filter(collections, function(collection, callback) {
Expand Down
56 changes: 27 additions & 29 deletions lib/native-client.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
'use strict';

const map = require('lodash.map');
const isFunction = require('lodash.isfunction');
const assignIn = require('lodash.assignin');
const assign = require('lodash.assign');
const { map, isFunction, assignIn, assign } = require('lodash');
const async = require('async');
const EventEmitter = require('events');

const connect = require('mongodb-connection-model').connect;
const getIndexes = require('mongodb-index-model').fetch;
const createSampleStream = require('mongodb-collection-sample');
const parseNamespace = require('mongodb-ns');
const debug = require('debug')('mongodb-data-service:native-client');

const { getInstance } = require('./instance-detail-helper');

const debug = require('debug')('mongodb-data-service:native-client');

/**
* The constant for a mongos.
*/
Expand Down Expand Up @@ -93,27 +91,23 @@ class NativeClient extends EventEmitter {
debug('connecting...');
this.isWritable = false;
this.isMongos = false;
connect(
this.model,
this.setupListeners.bind(this),
(err) => {
if (err) {
return done(this._translateMessage(err));
}
connect(this.model, this.setupListeners.bind(this), err => {
if (err) {
return done(this._translateMessage(err));
}

this.isWritable = this.client.isWritable;
this.isMongos = this.client.isMongos;
this.isWritable = this.client.isWritable;
this.isMongos = this.client.isMongos;

debug('connected!', {
isWritable: this.isWritable,
isMongos: this.isMongos
});
debug('connected!', {
isWritable: this.isWritable,
isMongos: this.isMongos
});

this.client.on('status', evt => this.emit('status', evt));
this.database = this.client.db(this.model.ns || ADMIN);
done(null, this);
}
);
this.client.on('status', evt => this.emit('status', evt));
this.database = this.client.db(this.model.ns || ADMIN);
done(null, this);
});
return this;
}

Expand Down Expand Up @@ -155,7 +149,8 @@ class NativeClient extends EventEmitter {
debug('topologyDescriptionChanged', arguments);
client.isWritable = this._isWritable(evt);
client.isMongos = this._isMongos(evt);
debug('updated to', {isWritable: client.isWritable,
debug('updated to', {
isWritable: client.isWritable,
isMongos: client.isMongos
});

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

this._database(this._databaseName(sourceNs))
.createCollection(name, options, (error, result) => {
this._database(this._databaseName(sourceNs)).createCollection(
name,
options,
(error, result) => {
if (error) {
return callback(this._translateMessage(error));
}
callback(null, result);
});
}
);
}
/**
* Update a view.
Expand Down
Loading