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

Commit df805e6

Browse files
committed
chore: Project cleanup
- upgrade eslint-config-mongodb-js, mongodb-js-precommit, mongodb-runner and mongodb-js-errors - 🔒 Resolve all `npm audit` issues - Cleanup travis and other dotfiles - Fix test hang. See mongodb-js/data-service#139
1 parent 0a687ad commit df805e6

File tree

7 files changed

+3621
-2609
lines changed

7 files changed

+3621
-2609
lines changed

.jsfmtrc

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

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
language: node_js
2-
sudo: required
2+
sudo: false
33
node_js:
44
- 8.9.3
5-
script: npm run-script ci
5+
- 10.2.1
6+
script:
7+
- npm run check
8+
- npm test
69
cache:
710
directories:
811
- node_modules

lib/fetch.js

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ function attach(anything, done) {
2828
function getIndexes(done, results) {
2929
var client = results.client;
3030
var ns = mongodbNS(results.namespace);
31-
client.db(ns.database).collection(ns.collection).indexes(function(err, indexes) {
32-
if (err) {
33-
done(err);
34-
}
35-
// add ns field to each index
36-
_.each(indexes, function(idx) {
37-
idx.ns = ns.ns;
31+
client
32+
.db(ns.database)
33+
.collection(ns.collection)
34+
.indexes(function(err, indexes) {
35+
if (err) {
36+
done(err);
37+
}
38+
// add ns field to each index
39+
_.each(indexes, function(idx) {
40+
idx.ns = ns.ns;
41+
});
42+
done(null, indexes);
3843
});
39-
done(null, indexes);
40-
});
4144
}
4245

4346
/**
@@ -49,11 +52,18 @@ function getIndexStats(done, results) {
4952
var client = results.client;
5053
var ns = mongodbNS(results.namespace);
5154
var pipeline = [
52-
{ $indexStats: { } },
53-
{ $project: { name: 1, usageHost: '$host', usageCount: '$accesses.ops', usageSince: '$accesses.since' } }
55+
{ $indexStats: {} },
56+
{
57+
$project: {
58+
name: 1,
59+
usageHost: '$host',
60+
usageCount: '$accesses.ops',
61+
usageSince: '$accesses.since'
62+
}
63+
}
5464
];
5565
var collection = client.db(ns.database).collection(ns.collection);
56-
collection.aggregate(pipeline, { cursor: {}}).toArray(function(err, res) {
66+
collection.aggregate(pipeline, { cursor: {} }).toArray(function(err, res) {
5767
if (err) {
5868
if (isNotAuthorizedError(err)) {
5969
/**
@@ -86,20 +96,25 @@ function getIndexStats(done, results) {
8696
function getIndexSizes(done, results) {
8797
var client = results.client;
8898
var ns = mongodbNS(results.namespace);
89-
client.db(ns.database).collection(ns.collection).stats(function(err, res) {
90-
if (err) {
91-
if (isNotAuthorizedError(err)) {
92-
debug('Not authorized to get collection stats. Returning default for indexSizes {}.');
93-
return done(null, {});
99+
client
100+
.db(ns.database)
101+
.collection(ns.collection)
102+
.stats(function(err, res) {
103+
if (err) {
104+
if (isNotAuthorizedError(err)) {
105+
debug(
106+
'Not authorized to get collection stats. Returning default for indexSizes {}.'
107+
);
108+
return done(null, {});
109+
}
110+
return done(err);
94111
}
95-
return done(err);
96-
}
97112

98-
res = _.mapValues(res.indexSizes, function(size) {
99-
return {size: size};
113+
res = _.mapValues(res.indexSizes, function(size) {
114+
return { size: size };
115+
});
116+
done(null, res);
100117
});
101-
done(null, res);
102-
});
103118
}
104119

105120
/**
@@ -120,7 +135,7 @@ function combineStatsAndIndexes(done, results) {
120135

121136
/**
122137
* get basic index information via `db.collection.indexes()`
123-
* @param {MongoClient} db db handle from mongodb driver
138+
* @param {MongoClient} client handle from mongodb driver
124139
* @param {String} namespace namespace for which to get indexes
125140
* @param {Function} done callback
126141
*/
@@ -131,7 +146,12 @@ function getIndexDetails(client, namespace, done) {
131146
getIndexes: ['client', 'namespace', getIndexes],
132147
getIndexStats: ['client', 'namespace', getIndexStats],
133148
getIndexSizes: ['client', 'namespace', getIndexSizes],
134-
indexes: ['getIndexes', 'getIndexStats', 'getIndexSizes', combineStatsAndIndexes]
149+
indexes: [
150+
'getIndexes',
151+
'getIndexStats',
152+
'getIndexSizes',
153+
combineStatsAndIndexes
154+
]
135155
};
136156

137157
async.auto(tasks, function(err, results) {
@@ -144,5 +164,4 @@ function getIndexDetails(client, namespace, done) {
144164
});
145165
}
146166

147-
148167
module.exports = getIndexDetails;

0 commit comments

Comments
 (0)