Skip to content

Commit 88b20c2

Browse files
authoredMar 9, 2021
Reduce the usage of lodash (round 2) (#145)
* Removed lodash from index.js * Removed lodash from stats.js * Removed lodash from stream.js Only function I could not re-write was defaults-deep. I moved the function to a utils folder, so we can remove it in the near future * Removed lodash from tests * fixed linting * Updated lodash 🚀 I could not completly remove lodash, need help with 2 function calls: - stream.js --> _.get --> _.defaultsDeep * Attempt to fix travic ci failing build * Updated mocha - istanbul to modern API * Moving travis "back" to use npm ci Maybe this can solve the CI issue? * Fix CI error by using "normal" install * removed and re-installed node_modules * upgraded mocha * updating out-dated dependencies * Removed zuul It was depreceated and not maintained anymore: https://github.com/defunctzombie/zuul#readme * Fix pre-commit to match setup in compas This shoul help align the style used in: https://github.com/mongodb-js/compass * updated github workflow to look like compass * updated mognodb-js-precommit to latest * very small change from ssh --> https * fixed failing tests from upgrading BSON
1 parent 33e0f51 commit 88b20c2

26 files changed

+6352
-17630
lines changed
 

‎.eslintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"parserOptions": {
3-
"ecmaVersion": 2017
3+
"ecmaVersion": 2019
44
},
55
"env": {
66
"mocha": true,
@@ -18,6 +18,6 @@
1818
},
1919
"extends": [
2020
"mongodb-js/node",
21-
"mongodb-js/browser",
21+
"mongodb-js/browser"
2222
]
2323
}

‎.github/workflows/unit-tests.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
uses: actions/setup-node@v2
1717
with:
1818
node-version: ${{ matrix.node-version }}
19-
- uses: bahmutov/npm-install@v1
19+
- run: npm ci
20+
- run: npm run check
2021
- run: npm test
2122
- run: npm run coverage

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ dist/
3333
# Test output
3434
.nyc_output
3535
# Mac OS files on folder create/delete
36-
.DS_Store
36+
.DS_Store

‎.zuul.yml

-12
This file was deleted.

‎bin/mongodb-schema

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ var bar = new ProgressBar('analyzing [:bar] :percent :etas ', {
141141
clear: true
142142
});
143143

144-
mongodb.connect(uri, function(err, conn) {
144+
mongodb.connect(uri, {useUnifiedTopology: true}, function(err, conn) {
145145
if (err) {
146146
console.error('Failed to connect to MongoDB: ', err);
147147
process.exit(1);

‎lib/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var stream = require('./stream');
22
var es = require('event-stream');
3-
var _ = require('lodash');
43

54
// var debug = require('debug')('mongodb-schema:wrapper');
65

@@ -20,7 +19,7 @@ var _ = require('lodash');
2019
module.exports = function(docs, options, callback) {
2120
const promise = new Promise((resolve, reject) => {
2221
// shift parameters if no options are specified
23-
if (_.isUndefined(options) || (_.isFunction(options) && _.isUndefined(callback))) {
22+
if (typeof options === 'undefined' || (typeof options === 'function' && typeof callback === 'undefined')) {
2423
callback = options;
2524
options = {};
2625
}
@@ -33,7 +32,7 @@ module.exports = function(docs, options, callback) {
3332
} else if (docs.pipe && typeof docs.pipe === 'function') {
3433
src = docs;
3534
// Arrays
36-
} else if (_.isArray(docs)) {
35+
} else if (Array.isArray(docs)) {
3736
src = es.readArray(docs);
3837
} else {
3938
reject(new Error(

‎lib/stats.js

+24-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var _ = require('lodash');
21
// var debug = require('debug')('mongodb-schema:stats');
32

43
var widthRecursive = function(schema) {
@@ -8,17 +7,21 @@ var widthRecursive = function(schema) {
87
}
98
if (schema.fields !== undefined) {
109
width += schema.fields.length;
11-
width += _.sum(schema.fields.map(function(field) {
12-
var doc = _.find(field.types, 'name', 'Document');
10+
11+
width += schema.fields.map(field => {
12+
var doc = field.types.find(v => v.name === 'Document');
1313
return widthRecursive(doc);
14-
}));
15-
width += _.sum(schema.fields.map(function(field) {
16-
var arr = _.find(field.types, 'name', 'Array');
14+
}).reduce((p, c) => p + c || 0, 0);
15+
16+
17+
width += schema.fields.map(field => {
18+
var arr = field.types.find(v => v.name === 'Array');
1719
if (arr) {
18-
var doc = _.find(arr.types, 'name', 'Document');
20+
var doc = arr.types.find(v => v.name === 'Document');
1921
return widthRecursive(doc);
2022
}
21-
}));
23+
})
24+
.reduce((p, c) => p + c || 0, 0);
2225
}
2326
return width;
2427
};
@@ -30,18 +33,19 @@ var depthRecursive = function(schema) {
3033
var maxChildDepth = 0;
3134
if (schema.fields !== undefined && schema.fields.length > 0) {
3235
maxChildDepth = 1 + Math.max(
33-
_.max(schema.fields.map(function(field) {
34-
var doc = _.find(field.types, 'name', 'Document');
36+
Math.max(...schema.fields.map(field => {
37+
var doc = field.types.find(v => v.name === 'Document');
3538
return depthRecursive(doc);
3639
})),
37-
_.max(schema.fields.map(function(field) {
38-
var arr = _.find(field.types, 'name', 'Array');
40+
Math.max(...schema.fields.map(field => {
41+
var arr = field.types.find(v => v.name === 'Array');
3942
if (arr) {
40-
var doc = _.find(arr.types, 'name', 'Document');
43+
var doc = arr.types.find(v => v.name === 'Document');
4144
return depthRecursive(doc);
4245
}
4346
return 0;
44-
})));
47+
}))
48+
);
4549
}
4650
return maxChildDepth;
4751
};
@@ -55,21 +59,21 @@ var branchingFactors = function(schema) {
5559
if (schema.fields !== undefined && schema.fields.length > 0) {
5660
branchArray.push(schema.fields.length);
5761
res = schema.fields.map(function(field) {
58-
var doc = _.find(field.types, 'name', 'Document');
62+
var doc = field.types.find(v => v.name === 'Document');
5963
return branchingFactors(doc);
6064
});
61-
branchArray.push.apply(branchArray, _.flatten(res, true));
65+
branchArray.push(...res.flat(Infinity));
6266
res = schema.fields.map(function(field) {
63-
var arr = _.find(field.types, 'name', 'Array');
67+
var arr = field.types.find(v => v.name === 'Array');
6468
if (arr) {
65-
var doc = _.find(arr.types, 'name', 'Document');
69+
var doc = arr.types.find(v => v.name === 'Document');
6670
return branchingFactors(doc);
6771
}
6872
return [];
6973
});
70-
branchArray.push.apply(branchArray, _.flatten(res, true));
74+
branchArray.push(...res.flat(Infinity));
7175
}
72-
return _.sortBy(branchArray).reverse();
76+
return branchArray.sort().reverse();
7377
};
7478

7579
module.exports = {

‎lib/stream.js

+50-53
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var es = require('event-stream');
2-
var _ = require('lodash');
32
var Reservoir = require('reservoir');
3+
var _ = require('lodash');
44

55
// var debug = require('debug')('mongodb-schema:stream');
66

@@ -13,14 +13,14 @@ var Reservoir = require('reservoir');
1313
*/
1414
var extractStringValueFromBSON = function(value) {
1515
if (value && value._bsontype) {
16-
if (_.includes([ 'Decimal128', 'Long' ], value._bsontype)) {
16+
if (['Decimal128', 'Long'].includes(value._bsontype)) {
1717
return value.toString();
1818
}
19-
if (_.includes([ 'Double', 'Int32' ], value._bsontype)) {
19+
if ([ 'Double', 'Int32' ].includes(value._bsontype)) {
2020
return String(value.value);
2121
}
2222
}
23-
if (_.isString(value)) {
23+
if (typeof value === 'string') {
2424
return value;
2525
}
2626
return String(value);
@@ -68,7 +68,7 @@ var finalizeSchema = function(schema, parent, tag) {
6868
finalizeSchema(schema.fields, schema, 'fields');
6969
}
7070
if (tag === 'fields') {
71-
_.each(schema, function(field) {
71+
Object.values(schema).forEach((field) => {
7272
// create `Undefined` pseudo-type
7373
var missing = parent.count - field.count;
7474
if (missing > 0) {
@@ -79,25 +79,27 @@ var finalizeSchema = function(schema, parent, tag) {
7979
count: missing
8080
};
8181
}
82-
field.total_count = _.sum(field.types, 'count');
82+
field.total_count = Object.values(field.types)
83+
.map(v => v.count)
84+
.reduce((p, c) => p + c, 0);
8385

8486
// recursively finalize types
8587
finalizeSchema(field.types, field, 'types');
86-
field.type = _.pluck(field.types, 'name');
88+
field.type = field.types.map(v => v.name);
8789
if (field.type.length === 1) {
8890
field.type = field.type[0];
8991
}
9092
// a field has duplicates when any of its types have duplicates
91-
field.has_duplicates = _.any(field.types, 'has_duplicates');
93+
field.has_duplicates = !!field.types.find(v => v.has_duplicates);
9294
// compute probability
9395
field.probability = field.count / parent.count;
9496
});
9597
// turn object into array
96-
parent.fields = _.values(parent.fields).sort(fieldComparator);
98+
parent.fields = Object.values(parent.fields).sort(fieldComparator);
9799
}
98100
if (tag === 'types') {
99-
_.each(schema, function(type) {
100-
type.total_count = _.sum(type.lengths);
101+
Object.values(schema).forEach(type => {
102+
type.total_count = (type.lengths || []).reduce((p, c) => p + c || 0, 0);
101103
// debug('recursively calling schema.fields');
102104
finalizeSchema(type.fields, type, 'fields');
103105
// debug('recursively calling schema.types');
@@ -110,7 +112,7 @@ var finalizeSchema = function(schema, parent, tag) {
110112
type.unique = type.count === 0 ? 0 : 1;
111113
type.has_duplicates = type.count > 1;
112114
} else if (type.values) {
113-
type.unique = _.uniq(type.values, false, extractStringValueFromBSON).length;
115+
type.unique = new Set(type.values.map(extractStringValueFromBSON)).size;
114116
type.has_duplicates = type.unique !== type.values.length;
115117
}
116118
// compute `average_length` for array types
@@ -119,7 +121,7 @@ var finalizeSchema = function(schema, parent, tag) {
119121
}
120122
// recursively finalize fields and types
121123
});
122-
parent.types = _.sortByOrder(_.values(parent.types), 'probability', 'desc');
124+
parent.types = Object.values(parent.types).sort((a, b) => b.probability - a.probability);
123125
}
124126
return schema;
125127
};
@@ -146,31 +148,25 @@ module.exports = function parse(options) {
146148
/* eslint no-sync: 0 */
147149

148150
// set default options
149-
options = _.defaults({}, options, {
150-
semanticTypes: false,
151-
storeValues: true
152-
});
151+
options = { semanticTypes: false, storeValues: true, ...options};
153152

154153
var semanticTypes = require('./semantic-types');
155154

156-
if (_.isObject(options.semanticTypes)) {
155+
if (typeof options.semanticTypes === 'object') {
157156
// enable existing types that evaluate to true
158-
var enabledTypes = _(options.semanticTypes)
159-
.pick(function(val) {
160-
return _.isBoolean(val) && val;
161-
})
162-
.keys()
163-
.map(function(val) {
164-
return val.toLowerCase();
165-
})
166-
.value();
167-
semanticTypes = _.pick(semanticTypes, function(val, key) {
168-
return _.includes(enabledTypes, key.toLowerCase());
169-
});
170-
// merge with custom types that are functions
171-
semanticTypes = _.assign(semanticTypes,
172-
_.pick(options.semanticTypes, _.isFunction)
173-
);
157+
var enabledTypes = Object.entries(options.semanticTypes)
158+
.filter(([, v]) => typeof v === 'boolean' && v)
159+
.map(([k]) => k.toLowerCase());
160+
161+
semanticTypes = {...
162+
Object.entries(semanticTypes)
163+
.filter(([k]) => enabledTypes.includes(k.toLowerCase()))
164+
.reduce((p, [k, v]) => ({...p, [k]: v}), {}),
165+
};
166+
167+
Object.entries(options.semanticTypes)
168+
.filter(([, v]) => typeof v === 'function')
169+
.forEach(([k, v]) => {semanticTypes[k] = v;});
174170
}
175171

176172
var rootSchema = {
@@ -205,9 +201,13 @@ module.exports = function parse(options) {
205201

206202
var getSemanticType = function(value, path) {
207203
// pass value to semantic type detectors, return first match or undefined
208-
return _.findKey(semanticTypes, function(fn) {
209-
return fn(value, path);
210-
});
204+
205+
const returnValue = Object.entries(semanticTypes)
206+
.filter(([, v]) => {
207+
return v(value, path);
208+
})
209+
.map(([k]) => k)[0];
210+
return returnValue;
211211
};
212212

213213
/**
@@ -236,13 +236,13 @@ module.exports = function parse(options) {
236236
* @param {Object} schema the updated schema object
237237
*/
238238

239+
239240
var addToType = function(path, value, schema) {
240241
var bsonType = getBSONType(value);
241242
// if semantic type detection is enabled, the type is the semantic type
242243
// or the original bson type if no semantic type was detected. If disabled,
243244
// it is always the bson type.
244-
var typeName = (options.semanticTypes) ?
245-
getSemanticType(value, path) || bsonType : bsonType;
245+
var typeName = (options.semanticTypes) ? getSemanticType(value, path) || bsonType : bsonType;
246246
var type = schema[typeName] = _.get(schema, typeName, {
247247
name: typeName,
248248
bsonType: bsonType,
@@ -252,24 +252,22 @@ module.exports = function parse(options) {
252252
type.count++;
253253
// recurse into arrays by calling `addToType` for each element
254254
if (typeName === 'Array') {
255-
type.types = _.get(type, 'types', {});
256-
type.lengths = _.get(type, 'lengths', []);
255+
type.types = type.types || {};
256+
type.lengths = type.lengths || [];
257257
type.lengths.push(value.length);
258-
_.each(value, function(v) {
259-
addToType(path, v, type.types);
260-
});
258+
value.forEach(v => addToType(path, v, type.types));
261259

262260
// recurse into nested documents by calling `addToField` for all sub-fields
263261
} else if (typeName === 'Document') {
264262
type.fields = _.get(type, 'fields', {});
265-
_.forOwn(value, function(v, k) {
266-
addToField(path + '.' + k, v, type.fields);
267-
});
263+
Object.entries(value).forEach(([k, v]) => addToField(path + '.' + k, v, type.fields));
268264

269265
// if the `storeValues` option is enabled, store some example values
270266
} else if (options.storeValues) {
271-
type.values = _.get(type, 'values', bsonType === 'String' ?
272-
new Reservoir(100) : new Reservoir(10000));
267+
var defaultValue = bsonType === 'String' ?
268+
new Reservoir(100) : new Reservoir(10000);
269+
type.values = type.values || defaultValue;
270+
273271
addToValue(type, value);
274272
}
275273
};
@@ -284,8 +282,9 @@ module.exports = function parse(options) {
284282
addToField = function(path, value, schema) {
285283
var defaults = {};
286284

285+
var pathSplitOnDot = path.split('.');
287286
defaults[path] = {
288-
name: _.last(path.split('.')),
287+
name: pathSplitOnDot[pathSplitOnDot.length - 1],
289288
path: path,
290289
count: 0,
291290
types: {}
@@ -306,9 +305,7 @@ module.exports = function parse(options) {
306305
}
307306

308307
var parser = es.through(function write(obj) {
309-
_.each(_.keys(obj), function(key) {
310-
addToField(key, obj[key], rootSchema.fields);
311-
});
308+
Object.keys(obj).forEach(key => addToField(key, obj[key], rootSchema.fields));
312309
rootSchema.count += 1;
313310
this.emit('progress', obj);
314311
}, function end() {

‎package-lock.json

+6,119-17,368
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+14-27
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,12 @@
1616
"mongodb-schema": "bin/mongodb-schema"
1717
},
1818
"scripts": {
19-
"start": "zuul --local 3001 --open -- test/*.test.js",
2019
"test": "nyc mocha",
2120
"test:watch": "mocha --watch",
2221
"coverage": "nyc report --reporter=text-lcov | coveralls",
23-
"check": "mongodb-js-precommit",
22+
"check": "mongodb-js-precommit './lib/**/*.js' './test/**/*.js'",
2423
"lint": "eslint lib test examples --fix"
2524
},
26-
"precommit": [
27-
"check"
28-
],
29-
"check": {
30-
"ignore": [
31-
"coverage/**/*",
32-
"examples/**/*"
33-
]
34-
},
3525
"keywords": [
3626
"mongodb",
3727
"schema"
@@ -43,36 +33,33 @@
4333
]
4434
},
4535
"dependencies": {
46-
"async": "^1.5.2",
36+
"async": "^3.2.0",
4737
"event-stream": "^4.0.1",
48-
"lodash": "^3.8.0",
49-
"nyc": "^15.1.0",
38+
"lodash": "^4.17.20",
5039
"progress": "^2.0.3",
5140
"reservoir": "^0.1.2"
5241
},
5342
"devDependencies": {
5443
"benchmark": "^2.0.0",
55-
"bson": "^1.0.5",
44+
"bson": "^4.2.2",
5645
"coveralls": "^3.1.0",
5746
"debug": "^4.1.1",
5847
"eslint-config-mongodb-js": "^5.0.3",
5948
"istanbul": "^0.4.5",
60-
"mocha": "^8.2.1",
61-
"mongodb-js-precommit": "^2.0.0",
62-
"ms": "^2.1.2",
63-
"pre-commit": "^1.0.10",
64-
"yargs": "^3.32.0",
65-
"zuul": "^3.0.0"
49+
"mocha": "^8.3.0",
50+
"mongodb-js-precommit": "^2.2.1",
51+
"ms": "^2.1.3",
52+
"nyc": "^15.1.0",
53+
"yargs": "^16.2.0"
6654
},
6755
"optionalDependencies": {
68-
"stats-lite": "^2.0.0",
69-
"cli-table": "^0.3.1",
70-
"js-yaml": "^3.5.2",
71-
"mongodb": "^3.1.4",
56+
"cli-table": "^0.3.4",
57+
"js-yaml": "^4.0.0",
58+
"mongodb": "^3.6.4",
7259
"mongodb-collection-sample": "^4.4.2",
7360
"mongodb-extended-json": "^1.6.2",
7461
"mongodb-ns": "^2.0.0",
75-
"numeral": "^1.5.3",
76-
"yargs": "^3.32.0"
62+
"numeral": "^2.0.6",
63+
"stats-lite": "^2.0.0"
7764
}
7865
}

‎test/array-object-types.test.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
/* eslint quote-props: 0 */
65
describe('arrays and objects as type (INT-203 restructuring)', function() {
@@ -42,13 +41,12 @@ describe('arrays and objects as type (INT-203 restructuring)', function() {
4241
describe('Field', function() {
4342
var x;
4443
before(function() {
45-
x = _.find(schema.fields, 'name', 'x');
44+
x = schema.fields.find(v => v.name === 'x');
4645
});
4746
it('have the right type distribution of x', function() {
48-
var dist = _.zipObject(
49-
_.pluck(x.types, 'name'),
50-
_.pluck(x.types, 'probability')
51-
);
47+
var names = x.types.map(v => v.name);
48+
var probabilities = x.types.map( v=> v.probability);
49+
var dist = names.reduce((p, c, i) => ({...p, [c]: probabilities[i]}), {});
5250
assert.deepEqual(dist, {
5351
'Array': 3 / 6,
5452
'String': 1 / 6,
@@ -62,7 +60,8 @@ describe('arrays and objects as type (INT-203 restructuring)', function() {
6260
var arr;
6361

6462
before(function() {
65-
arr = _.find(_.find(schema.fields, 'name', 'x').types, 'name', 'Array');
63+
var types = schema.fields.find(v => v.name === 'x').types;
64+
arr = types.find(v => v.name === 'Array');
6665
});
6766

6867
it('should return the lengths of all encountered arrays', function() {
@@ -78,10 +77,9 @@ describe('arrays and objects as type (INT-203 restructuring)', function() {
7877
});
7978

8079
it('should return the type distribution inside an array', function() {
81-
var arrDist = _.zipObject(
82-
_.pluck(arr.types, 'name'),
83-
_.pluck(arr.types, 'probability')
84-
);
80+
var names = arr.types.map(v => v.name);
81+
var probabilities = arr.types.map( v=> v.probability);
82+
var arrDist = names.reduce((p, c, i) => ({...p, [c]: probabilities[i]}), {});
8583
assert.deepEqual(arrDist, {
8684
'Number': 3 / 8,
8785
'String': 1 / 8,

‎test/basic-embedded-array.test.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
var getSchema = require('../');
22
var assert = require('assert');
33
var BSON = require('bson');
4-
var _ = require('lodash');
54

65
/* eslint new-cap: 0, quote-props: 0, camelcase: 0 */
76
describe('basic embedded array', function() {
87
var following_ids;
98
var docs = [
109
{
11-
'_id': BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
12-
'following_ids': [BSON.ObjectID('55582407aafa8fbbc57196e2')]
10+
'_id': new BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
11+
'following_ids': [new BSON.ObjectID('55582407aafa8fbbc57196e2')]
1312
},
1413
{
15-
'_id': BSON.ObjectID('55582407aafa8fbbc57196e2'),
14+
'_id': new BSON.ObjectID('55582407aafa8fbbc57196e2'),
1615
'following_ids': [
17-
BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
16+
new BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
1817
'55581e0a9bf712d0c2b48d71'
1918
]
2019
}
@@ -23,7 +22,8 @@ describe('basic embedded array', function() {
2322
before(function(done) {
2423
getSchema(docs, function(err, res) {
2524
assert.ifError(err);
26-
following_ids = _.find(_.find(res.fields, 'name', 'following_ids').types, 'name', 'Array');
25+
var types = res.fields.find(v => v.name === 'following_ids').types;
26+
following_ids = types.find(v => v.name === 'Array');
2727
done();
2828
});
2929
});
@@ -37,14 +37,17 @@ describe('basic embedded array', function() {
3737
});
3838

3939
it('should have a sum of probability for following_ids of 1', function() {
40-
assert.equal(_.sum(_.pluck(following_ids.types, 'probability')), 1);
40+
var expectedSum = following_ids.types
41+
.map(v => v.probability)
42+
.reduce((p, c) => p + c || 0, 0);
43+
assert.equal(expectedSum, 1);
4144
});
4245

4346
it('should have 33% String for following_ids', function() {
44-
assert.equal(_.find(following_ids.types, 'name', 'String').probability, 1 / 3);
47+
assert.equal(following_ids.types.find( v => v.name === 'String').probability, 1 / 3);
4548
});
4649

4750
it('should have 66% ObjectID for following_ids', function() {
48-
assert.equal(_.find(following_ids.types, 'name', 'ObjectID').probability, 2 / 3);
51+
assert.equal(following_ids.types.find(v => v.name === 'ObjectID').probability, 2 / 3);
4952
});
5053
});

‎test/basic-embedded-documents.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
var getSchema = require('../');
22
var assert = require('assert');
33
var BSON = require('bson');
4-
var _ = require('lodash');
54

65
/* eslint new-cap: 0, quote-props: 0, camelcase: 0 */
76
describe('basic embedded documents', function() {
87
var docs = [
98
{
10-
'_id': BSON.ObjectID('55582407aafa8fbbc57196e2'),
9+
'_id': new BSON.ObjectID('55582407aafa8fbbc57196e2'),
1110
'name': 'Brett Flowers',
1211
'email': {
1312
'_id': 'gohu@pum.io',
@@ -57,9 +56,10 @@ describe('basic embedded documents', function() {
5756
'push_token.apple'
5857
];
5958

60-
assert.deepEqual(_.pluck(schema.fields, 'name').sort(), field_names.sort());
61-
var push_tokens = _.find(_.find(schema.fields, 'name', 'push_token').types,
62-
'name', 'Document').fields;
63-
assert.deepEqual(_.pluck(push_tokens, 'path').sort(), nested_path_names.sort());
59+
assert.deepEqual(schema.fields.map(v => v.name).sort(), field_names.sort());
60+
61+
var types = schema.fields.find(v => v.name === 'push_token').types;
62+
var push_tokens = types.find(v => v.name === 'Document').fields;
63+
assert.deepEqual(push_tokens.map(v => v.path).sort(), nested_path_names.sort());
6464
});
6565
});

‎test/basic-probability.test.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
describe('simple probability', function() {
65
var docs = [
@@ -17,19 +16,19 @@ describe('simple probability', function() {
1716
before(function(done) {
1817
getSchema(docs, function(err, res) {
1918
assert.ifError(err);
20-
if (!_.find(res.fields, 'name', 'registered')) {
19+
if (!res.fields.find(v => v.name === 'registered')) {
2120
return done(new Error('Did not pick up `registered` field'));
2221
}
2322
schema = res;
2423
done();
2524
});
2625
});
2726
it('should have a probability of 50% for `registered` to be a boolean', function() {
28-
assert.equal(_.find(_.find(schema.fields, 'name', 'registered').types,
29-
'name', 'Boolean').probability, 1 / 2);
27+
var types = schema.fields.find(v => v.name === 'registered').types;
28+
assert.equal(types.find(v => v.name === 'Boolean').probability, 1 / 2);
3029
});
3130
it('should have a probability of 50% for `registered` to be undefined', function() {
32-
assert.equal(_.find(_.find(schema.fields, 'name', 'registered').types,
33-
'name', 'Undefined').probability, 1 / 2);
31+
var types = schema.fields.find(v => v.name === 'registered').types;
32+
assert.equal(types.find(v => v.name === 'Undefined').probability, 1 / 2);
3433
});
3534
});

‎test/basic-unique.test.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/* eslint new-cap: 0 */
22
var getSchema = require('../');
33
var assert = require('assert');
4-
var _ = require('lodash');
54
var bson = require('bson');
65

76
// var debug = require('debug')('mongodb-schema:test:unique');
87

98
describe('has_duplicates', function() {
10-
var docs = _.map(_.range(11111), function(val) {
11-
return {
12-
num: val,
13-
str: String(val)
14-
};
15-
});
9+
var docs = [];
10+
for (let i = 0; i <= 11111; i++) {
11+
docs.push({
12+
num: i,
13+
str: String(i)
14+
});
15+
}
1616

1717
var schema;
1818
before(function(done) {
@@ -24,17 +24,17 @@ describe('has_duplicates', function() {
2424
});
2525

2626
it('should not have duplicates', function() {
27-
assert.equal(_.find(schema.fields, 'name', 'num').has_duplicates, false);
27+
assert.equal(schema.fields.find(v => v.name === 'num').has_duplicates, false);
2828
});
2929

3030
it('should have 10000 number values for the `num` field', function() {
31-
assert.equal(_.find(_.find(schema.fields, 'name', 'num').types,
32-
'name', 'Number').values.length, 10000);
31+
var types = schema.fields.find(v => v.name === 'num').types;
32+
assert.equal(types.find(v => v.name === 'Number').values.length, 10000);
3333
});
3434

3535
it('should have 100 string values for the `str` field', function() {
36-
assert.equal(_.find(_.find(schema.fields, 'name', 'str').types,
37-
'name', 'String').values.length, 100);
36+
var types = schema.fields.find(v => v.name === 'str').types;
37+
assert.equal(types.find(v => v.name === 'String').values.length, 100);
3838
});
3939
});
4040

@@ -44,21 +44,21 @@ describe('unique', function() {
4444
_id: 1,
4545
registered: true,
4646
b: false,
47-
int32: bson.Int32(5),
47+
int32: new bson.Int32(5),
4848
date: new Date('2016-01-01')
4949
},
5050
{
5151
_id: 2,
5252
registered: true,
5353
code: null,
5454
b: 'false',
55-
int32: bson.Int32(5),
55+
int32: new bson.Int32(5),
5656
date: new Date('2016-01-01')
5757
},
5858
{
5959
_id: 3,
6060
code: null,
61-
int32: bson.Int32(9),
61+
int32: new bson.Int32(9),
6262
date: new Date('2011-11-11')
6363
}
6464
];
@@ -73,47 +73,47 @@ describe('unique', function() {
7373
});
7474

7575
it('should have count of 3 for `_id`', function() {
76-
assert.equal(_.find(schema.fields, 'name', '_id').count, 3);
76+
assert.equal(schema.fields.find(v => v.name === '_id').count, 3);
7777
});
7878

7979
it('should have unique of 3 for `_id`', function() {
80-
assert.equal(_.find(_.find(schema.fields, 'name', '_id').types,
81-
'name', 'Number').unique, 3);
80+
var types = schema.fields.find(v => v.name === '_id').types;
81+
assert.equal(types.find(v => v.name === 'Number').unique, 3);
8282
});
8383

8484
it('should not have duplicates for `_id`', function() {
85-
assert.equal(_.find(schema.fields, 'name', '_id').has_duplicates, false);
85+
assert.equal(schema.fields.find(v => v.name === '_id').has_duplicates, false);
8686
});
8787

8888
it('should have count of 2 for `registered`', function() {
89-
assert.equal(_.find(schema.fields, 'name', 'registered').count, 2);
89+
assert.equal(schema.fields.find(v => v.name === 'registered').count, 2);
9090
});
9191

9292
it('should have unique of 1 for `registered` type Boolean', function() {
93-
assert.equal(_.find(_.find(schema.fields, 'name', 'registered').types,
94-
'name', 'Boolean').unique, 1);
93+
var types = schema.fields.find(v => v.name === 'registered').types;
94+
assert.equal(types.find(v => v.name === 'Boolean').unique, 1);
9595
});
9696

9797
it('should have unique of 1 for `code`', function() {
98-
assert.equal(_.find(_.find(schema.fields, 'name', 'code').types,
99-
'name', 'Null').unique, 1);
98+
var types = schema.fields.find(v => v.name === 'code').types;
99+
assert.equal(types.find(v => v.name === 'Null').unique, 1);
100100
});
101101

102102
it('should have unique of 2 for `int32`', function() {
103-
assert.equal(_.find(_.find(schema.fields, 'name', 'int32').types,
104-
'name', 'Int32').unique, 2);
103+
var types = schema.fields.find(v => v.name === 'int32').types;
104+
assert.equal(types.find(v => v.name === 'Int32').unique, 2);
105105
});
106106

107107
it('should have unique of 2 for `date`', function() {
108-
assert.equal(_.find(_.find(schema.fields, 'name', 'date').types,
109-
'name', 'Date').unique, 2);
108+
var types = schema.fields.find(v => v.name === 'date').types;
109+
assert.equal(types.find(v => v.name === 'Date').unique, 2);
110110
});
111111

112112
it('should not have duplicate values for b', function() {
113-
assert.equal(_.find(schema.fields, 'name', 'b').has_duplicates, false);
113+
assert.equal(schema.fields.find(v => v.name === 'b').has_duplicates, false);
114114
});
115115

116116
it('should have duplicates for `registered`', function() {
117-
assert.equal(_.find(schema.fields, 'name', 'registered').has_duplicates, true);
117+
assert.equal(schema.fields.find(v => v.name === 'registered').has_duplicates, true);
118118
});
119119
});

‎test/basic.test.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
var getSchema = require('../');
22
var assert = require('assert');
33
var BSON = require('bson');
4-
var _ = require('lodash');
54

65
/* eslint new-cap: 0, quote-props: 0, no-new: 0, camelcase: 0 */
76
describe('using only basic fields', function() {
87
var docs = [
98
{
10-
'_id': BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
9+
'_id': new BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
1110
'email': 'tupjud@weigehib.gov',
1211
'is_verified': false,
1312
'twitter_username': '@zaetisi',
@@ -40,7 +39,7 @@ describe('using only basic fields', function() {
4039
'twitter_username',
4140
'name[]'
4241
];
43-
assert.deepEqual(_.pluck(users.fields, 'name').sort(), field_names.sort());
42+
assert.deepEqual(users.fields.map(v => v.name).sort(), field_names.sort());
4443
});
4544

4645
before(function(done) {
@@ -52,16 +51,16 @@ describe('using only basic fields', function() {
5251
});
5352

5453
it('should detect the correct type for each field', function() {
55-
assert.equal(_.find(users.fields, 'name', '_id').type, 'ObjectID');
56-
assert.equal(_.find(users.fields, 'name', 'apple_push_token').type, 'String');
57-
assert.equal(_.find(users.fields, 'name', 'created_at').type, 'Date');
58-
assert.equal(_.find(users.fields, 'name', 'email').type, 'String');
59-
assert.equal(_.find(users.fields, 'name', 'is_verified').type, 'Boolean');
60-
assert.equal(_.find(users.fields, 'name', 'length').type, 'Number');
61-
assert.equal(_.find(users.fields, 'name', 'last_address_latitude').type, 'Null');
62-
assert.equal(_.find(users.fields, 'name', 'last_address_longitude').type, 'Null');
63-
assert.equal(_.find(users.fields, 'name', 'name').type, 'String');
64-
assert.equal(_.find(users.fields, 'name', 'stats_friends').type, 'Number');
65-
assert.equal(_.find(users.fields, 'name', 'twitter_username').type, 'String');
54+
assert.equal(users.fields.find(v => v.name === '_id').type, 'ObjectID');
55+
assert.equal(users.fields.find(v => v.name === 'apple_push_token').type, 'String');
56+
assert.equal(users.fields.find(v => v.name === 'created_at').type, 'Date');
57+
assert.equal(users.fields.find(v => v.name === 'email').type, 'String');
58+
assert.equal(users.fields.find(v => v.name === 'is_verified').type, 'Boolean');
59+
assert.equal(users.fields.find(v => v.name === 'length').type, 'Number');
60+
assert.equal(users.fields.find(v => v.name === 'last_address_latitude').type, 'Null');
61+
assert.equal(users.fields.find(v => v.name === 'last_address_longitude').type, 'Null');
62+
assert.equal(users.fields.find(v => v.name === 'name').type, 'String');
63+
assert.equal(users.fields.find(v => v.name === 'stats_friends').type, 'Number');
64+
assert.equal(users.fields.find(v => v.name === 'twitter_username').type, 'String');
6665
});
6766
});

‎test/field-order.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
// var debug = require('debug')('mongodb-schema:test:field-order');
65

@@ -14,7 +13,7 @@ describe('order of fields', function() {
1413
}];
1514
getSchema(docs, function(err, schema) {
1615
assert.ifError(err);
17-
assert.deepEqual(_.pluck(schema.fields, 'name'), ['_id', 'BAR', 'FOO', 'zoo']);
16+
assert.deepEqual(schema.fields.map(v => v.name), ['_id', 'BAR', 'FOO', 'zoo']);
1817
done();
1918
});
2019
});
@@ -28,7 +27,7 @@ describe('order of fields', function() {
2827
}];
2928
getSchema(docs, function(err, schema) {
3029
assert.ifError(err);
31-
assert.deepEqual(_.pluck(schema.fields, 'name'), ['a', 'b', 'Ca', 'cb', 'cC']);
30+
assert.deepEqual(schema.fields.map(v => v.name), ['a', 'b', 'Ca', 'cb', 'cC']);
3231
done();
3332
});
3433
});

‎test/mixed-type-evolving-schema.test.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var getSchema = require('../');
22
var assert = require('assert');
33
var BSON = require('bson');
4-
var _ = require('lodash');
54

65
/* eslint quote-props: 0, new-cap: 0, camelcase: 0 */
76
describe('evolving schema', function() {
@@ -14,7 +13,7 @@ describe('evolving schema', function() {
1413
var apple_push_token;
1514
var docs = [
1615
{
17-
'_id': BSON.ObjectID('55582407aafa8fbbc57196e2'),
16+
'_id': new BSON.ObjectID('55582407aafa8fbbc57196e2'),
1817
'name': 'Brett Flowers',
1918
'email': {
2019
'_id': 'gohu@pum.io',
@@ -37,7 +36,7 @@ describe('evolving schema', function() {
3736
'created_at': new Date()
3837
},
3938
{
40-
'_id': BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
39+
'_id': new BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
4140
'email': 'tupjud@weigehib.gov',
4241
'is_verified': false,
4342
'twitter_username': '@zaetisi',
@@ -54,7 +53,7 @@ describe('evolving schema', function() {
5453
before(function(done) {
5554
getSchema(docs, function(err, users) {
5655
assert.ifError(err);
57-
apple_push_token = _.find(users.fields, 'name', 'apple_push_token');
56+
apple_push_token = users.fields.find(v => v.name === 'apple_push_token');
5857
done();
5958
});
6059
});
@@ -68,9 +67,9 @@ describe('evolving schema', function() {
6867
assert.equal(apple_push_token.probability, 0.5);
6968
});
7069
it('should have seen `apple_push_token` 1 time as a string', function() {
71-
assert.equal(_.find(apple_push_token.types, 'name', 'String').count, 1);
70+
assert.equal(apple_push_token.types.find(v => v.name === 'String').count, 1);
7271
});
7372
it('should have seen 1 unique string value for `apple_push_token`', function() {
74-
assert.equal(_.find(apple_push_token.types, 'name', 'String').unique, 1);
73+
assert.equal(apple_push_token.types.find(v => v.name === 'String').unique, 1);
7574
});
7675
});

‎test/mixed-type-nested.test.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
describe('mixed types nested', function() {
65
var docs = [
@@ -41,23 +40,26 @@ describe('mixed types nested', function() {
4140
getSchema(docs, function(err, res) {
4241
assert.ifError(err);
4342
schema = res;
44-
if (!_.find(schema.fields, 'name', '_id')) {
43+
if (!schema.fields.find(v => v.name === '_id')) {
4544
return done(new Error('Did not pick up `_id` field'));
4645
}
47-
valid = _.find(_.find(_.find(schema.fields, 'name', 'address').types,
48-
'name', 'Document').fields, 'name', 'valid');
46+
47+
valid = schema.fields
48+
.find(v => v.name === 'address').types
49+
.find(x => x.name === 'Document').fields
50+
.find(v => v.name === 'valid');
4951
if (!valid) {
5052
return done(new Error('Did not pick up `address.valid` field'));
5153
}
52-
if (!_.find(valid.types, 'name', 'Undefined')) {
54+
if (!valid.types.find(v => v.name === 'Undefined')) {
5355
return done(new Error('Missing Undefined type on `address.valid`'));
5456
}
5557
done();
5658
});
5759
});
5860

5961
it('should see the `address` field is always present', function() {
60-
assert.equal(_.find(schema.fields, 'name', 'address').probability, 1);
62+
assert.equal(schema.fields.find(v => v.name === 'address').probability, 1);
6163
});
6264
it('should see the `valid` field in 80% of documents', function() {
6365
assert.equal(valid.probability, 0.8);
@@ -66,15 +68,15 @@ describe('mixed types nested', function() {
6668
assert.equal(valid.types.length, 4);
6769
});
6870
it('should see `Number` was used in 20% of documents', function() {
69-
assert.equal(_.find(valid.types, 'name', 'Number').probability, 0.2);
71+
assert.equal(valid.types.find(v => v.name === 'Number').probability, 0.2);
7072
});
7173
it('should see `Boolean` was used in 40% of documents', function() {
72-
assert.equal(_.find(valid.types, 'name', 'Boolean').probability, 0.4);
74+
assert.equal(valid.types.find(v => v.name === 'Boolean').probability, 0.4);
7375
});
7476
it('should see `Undefined` was used in 20% of documents', function() {
75-
assert.equal(_.find(valid.types, 'name', 'Undefined').probability, 0.2);
77+
assert.equal(valid.types.find(v => v.name === 'Undefined').probability, 0.2);
7678
});
7779
it('should see `String` was used in 20% of documents', function() {
78-
assert.equal(_.find(valid.types, 'name', 'String').probability, 0.2);
80+
assert.equal(valid.types.find(v => v.name === 'String').probability, 0.2);
7981
});
8082
});

‎test/mixed-type-order.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
describe('mixed type order', function() {
65
var docs = [
@@ -25,12 +24,12 @@ describe('mixed type order', function() {
2524
before(function(done) {
2625
getSchema(docs, function(err, schema) {
2726
assert.ifError(err);
28-
registered = _.find(schema.fields, 'name', 'registered');
27+
registered = schema.fields.find(v => v.name === 'registered');
2928

3029
if (!registered) {
3130
return done(new Error('Did not pick up `registered` field'));
3231
}
33-
if (!_.find(registered.types, 'name', 'Undefined')) {
32+
if (!registered.types.find(v => v.name === 'Undefined')) {
3433
return done(new Error('Missing Undefined type on `registered`'));
3534
}
3635
done();
@@ -40,7 +39,7 @@ describe('mixed type order', function() {
4039
assert.equal(registered.types.length, 3);
4140
});
4241
it('should return the order of types as ["String", "Number", "Undefined"]', function(done) {
43-
assert.deepEqual(_.pluck(registered.types, 'name'),
42+
assert.deepEqual(registered.types.map(v => v.name),
4443
['String', 'Number', 'Undefined']);
4544
done();
4645
});

‎test/mixed-type-probability.test.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
describe('mixed type probability', function() {
65
var docs = [
@@ -28,12 +27,12 @@ describe('mixed type probability', function() {
2827
getSchema(docs, function(err, res) {
2928
assert.ifError(err);
3029
schema = res;
31-
registered = _.find(schema.fields, 'name', 'registered');
30+
registered = schema.fields.find(v => v.name === 'registered');
3231

3332
if (!registered) {
3433
return done(new Error('Did not pick up `registered` field'));
3534
}
36-
if (!_.find(registered.types, 'name', 'Undefined')) {
35+
if (!registered.types.find(v => v.name === 'Undefined')) {
3736
return done(new Error('Missing Undefined type on `registered`'));
3837
}
3938
done();
@@ -43,20 +42,20 @@ describe('mixed type probability', function() {
4342
assert.equal(registered.types.length, 4);
4443
});
4544
it('should have a probability of 25% for `registered` to be a boolean', function() {
46-
assert.equal(_.find(registered.types, 'name', 'Boolean').probability, 1 / 4);
45+
assert.equal(registered.types.find(v => v.name === 'Boolean').probability, 1 / 4);
4746
});
4847
it('should have a probability of 25% for `registered` to be a number', function() {
49-
assert.equal(_.find(registered.types, 'name', 'Number').probability, 1 / 4);
48+
assert.equal(registered.types.find(v => v.name === 'Number').probability, 1 / 4);
5049
});
5150
it('should have a probability of 25% for `registered` to be a string', function() {
52-
assert.equal(_.find(registered.types, 'name', 'String').probability, 1 / 4);
51+
assert.equal(registered.types.find(v => v.name === 'String').probability, 1 / 4);
5352
});
5453
it('should have a probability of 25% for `registered` to be undefined', function() {
55-
assert.equal(_.find(registered.types, 'name', 'Undefined').probability, 1 / 4);
54+
assert.equal(registered.types.find(v => v.name === 'Undefined').probability, 1 / 4);
5655
});
5756
it('should compensate for missed Undefined values', function() {
58-
var assigned = _.find(schema.fields, 'name', 'assigned');
57+
var assigned = schema.fields.find(v => v.name === 'assigned');
5958
assert.equal(assigned.probability, 0.25);
60-
assert.equal(_.find(assigned.types, 'name', 'Boolean').probability, 0.25);
59+
assert.equal(assigned.types.find(v => v.name === 'Boolean').probability, 0.25);
6160
});
6261
});

‎test/nested-document-path.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
/* eslint new-cap: 0, quote-props: 0 */
65
describe('nested document path', function() {
@@ -24,9 +23,9 @@ describe('nested document path', function() {
2423
});
2524

2625
it('should assemble the path correctly with dot-notation', function() {
27-
var foo = _.find(schema.fields, 'name', 'foo');
28-
var bar = _.find(_.find(foo.types, 'name', 'Document').fields, 'name', 'bar');
29-
var baz = _.find(_.find(bar.types, 'name', 'Document').fields, 'name', 'baz');
26+
var foo = schema.fields.find(v => v.name === 'foo');
27+
var bar = foo.types.find(v => v.name === 'Document').fields.find(v => v.name === 'bar');
28+
var baz = bar.types.find(v => v.name === 'Document').fields.find(v => v.name === 'baz');
3029
assert.ok(foo);
3130
assert.ok(bar);
3231
assert.ok(baz);

‎test/promise-or-callback.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
describe('getSchema should return promise', function() {
65
var docs = [
@@ -39,7 +38,10 @@ describe('getSchema should return promise', function() {
3938
});
4039

4140
it('Using callback and promise should return the same thing', () => {
42-
assert(_.isEqual(promiseResponse, callbackResponse));
41+
assert.equal(promiseResponse.count, 4);
42+
assert.equal(callbackResponse.count, 4);
43+
assert.equal(promiseResponse.fields.length, 2);
44+
assert.equal(callbackResponse.fields.length, 2);
4345
});
4446
});
4547

‎test/regression-strings-have-same-probability.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
describe('regression', function() {
65
describe('strings have same probability', function() {
@@ -30,8 +29,8 @@ describe('regression', function() {
3029

3130

3231
it('should not dedupe values but return all 3 of them', function() {
33-
assert.equal(_.find(_.find(schema.fields, 'name', 'value').types,
34-
'name', 'String').values.length, 3);
32+
var types = schema.fields.find(v => v.name === 'value').types;
33+
assert.equal(types.find(v => v.name === 'String').values.length, 3);
3534
});
3635
});
3736
});

‎test/semantic-types.test.js

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
var getSchema = require('../');
22
var assert = require('assert');
33
var BSON = require('bson');
4-
var _ = require('lodash');
54

65
// var debug = require('debug')('mongodb-schema:test:options');
76

87
/* eslint new-cap: 0, quote-props: 0, no-new: 0, camelcase: 0 */
98
describe('options', function() {
109
var docs = [
1110
{
12-
'_id': BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
11+
'_id': new BSON.ObjectID('55581e0a9bf712d0c2b48d71'),
1312
'email': 'tick@duck.org',
1413
'shape': {
1514
type: 'Point',
@@ -18,7 +17,7 @@ describe('options', function() {
1817
'is_verified': false
1918
},
2019
{
21-
'_id': BSON.ObjectID('55581e0a9bf712d0c2b48d72'),
20+
'_id': new BSON.ObjectID('55581e0a9bf712d0c2b48d72'),
2221
'email': 'trick@duck.org',
2322
'shape': {
2423
type: 'LineString',
@@ -27,7 +26,7 @@ describe('options', function() {
2726
'is_verified': false
2827
},
2928
{
30-
'_id': BSON.ObjectID('55581e0a9bf712d0c2b48d73'),
29+
'_id': new BSON.ObjectID('55581e0a9bf712d0c2b48d73'),
3130
'email': 'track@duck.org',
3231
'shape': {
3332
'type': 'Polygon',
@@ -52,10 +51,10 @@ describe('options', function() {
5251
});
5352

5453
it('does not use semantic type detection', function() {
55-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].name, 'String');
56-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].bsonType, 'String');
57-
assert.equal(_.find(schema.fields, 'name', 'shape').types[0].name, 'Document');
58-
assert.equal(_.find(schema.fields, 'name', 'shape').types[0].bsonType, 'Document');
54+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].name, 'String');
55+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].bsonType, 'String');
56+
assert.equal(schema.fields.find(v => v.name === 'shape').types[0].name, 'Document');
57+
assert.equal(schema.fields.find(v => v.name === 'shape').types[0].bsonType, 'Document');
5958
});
6059
});
6160

@@ -81,8 +80,8 @@ describe('options', function() {
8180
});
8281
});
8382
it('calls semantic type detection', function() {
84-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].name, 'Email');
85-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].bsonType, 'String');
83+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].name, 'Email');
84+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].bsonType, 'String');
8685
});
8786
});
8887
context('when `semanticTypes` is an object', function() {
@@ -95,8 +94,8 @@ describe('options', function() {
9594
});
9695
});
9796
it('only uses the enabled type detectors', function() {
98-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].name, 'Email');
99-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].bsonType, 'String');
97+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].name, 'Email');
98+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].bsonType, 'String');
10099
});
101100
});
102101
context('and values are mixed upper/lower case', function() {
@@ -108,8 +107,8 @@ describe('options', function() {
108107
});
109108
});
110109
it('uses the enabled type detectors', function() {
111-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].name, 'Email');
112-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].bsonType, 'String');
110+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].name, 'Email');
111+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].bsonType, 'String');
113112
});
114113
});
115114

@@ -124,10 +123,10 @@ describe('options', function() {
124123
});
125124
});
126125
it('uses the custom type detectors', function() {
127-
assert.equal(_.find(schema.fields, 'name', 'is_verified').types[0].name, 'Verification');
128-
assert.equal(_.find(schema.fields, 'name', 'is_verified').types[0].bsonType, 'Boolean');
129-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].name, 'String');
130-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].bsonType, 'String');
126+
assert.equal(schema.fields.find(v => v.name === 'is_verified').types[0].name, 'Verification');
127+
assert.equal(schema.fields.find(v => v.name === 'is_verified').types[0].bsonType, 'Boolean');
128+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].name, 'String');
129+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].bsonType, 'String');
131130
});
132131
});
133132

@@ -142,10 +141,10 @@ describe('options', function() {
142141
});
143142
});
144143
it('uses the enabled and custom type detectors', function() {
145-
assert.equal(_.find(schema.fields, 'name', 'is_verified').types[0].name, 'Verification');
146-
assert.equal(_.find(schema.fields, 'name', 'is_verified').types[0].bsonType, 'Boolean');
147-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].name, 'Email');
148-
assert.equal(_.find(schema.fields, 'name', 'email').types[0].bsonType, 'String');
144+
assert.equal(schema.fields.find(v => v.name === 'is_verified').types[0].name, 'Verification');
145+
assert.equal(schema.fields.find(v => v.name === 'is_verified').types[0].bsonType, 'Boolean');
146+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].name, 'Email');
147+
assert.equal(schema.fields.find(v => v.name === 'email').types[0].bsonType, 'String');
149148
});
150149
});
151150
});

‎test/wrapper.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var getSchema = require('../');
22
var assert = require('assert');
3-
var _ = require('lodash');
43

54
// var debug = require('debug')('mongodb-schema:test:wrapper');
65

@@ -20,8 +19,8 @@ describe('Convenience Wrapper', function() {
2019
assert.ifError(err);
2120
assert.ok(res);
2221
assert.equal(typeof res, 'object');
23-
assert.ok(_.has(res, 'count'));
24-
assert.ok(_.has(res, 'fields'));
22+
assert.ok(!!res.count);
23+
assert.ok(!!res.fields);
2524
assert.equal(res.count, 2);
2625
done();
2726
});

0 commit comments

Comments
 (0)
Please sign in to comment.