mongoose 5.2.3 → 5.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.eslintignore +1 -0
  2. package/.travis.yml +1 -1
  3. package/History.md +58 -0
  4. package/README.md +6 -6
  5. package/lib/aggregate.js +22 -0
  6. package/lib/browser.js +2 -0
  7. package/lib/cast/boolean.js +5 -6
  8. package/lib/cast/number.js +49 -0
  9. package/lib/collection.js +2 -5
  10. package/lib/connection.js +22 -3
  11. package/lib/document.js +31 -3
  12. package/lib/driver.js +15 -0
  13. package/lib/drivers/browser/index.js +3 -0
  14. package/lib/drivers/node-mongodb-native/collection.js +23 -9
  15. package/lib/drivers/node-mongodb-native/index.js +1 -0
  16. package/lib/helpers/immediate.js +10 -0
  17. package/lib/helpers/populate/getSchemaTypes.js +80 -62
  18. package/lib/helpers/populate/getVirtual.js +2 -5
  19. package/lib/helpers/query/applyQueryMiddleware.js +37 -0
  20. package/lib/helpers/query/castUpdate.js +34 -12
  21. package/lib/index.js +6 -4
  22. package/lib/model.js +98 -100
  23. package/lib/query.js +125 -25
  24. package/lib/queryhelpers.js +21 -2
  25. package/lib/schema/boolean.js +40 -0
  26. package/lib/schema/documentarray.js +18 -5
  27. package/lib/schema/embedded.js +7 -2
  28. package/lib/schema/number.js +11 -31
  29. package/lib/schema/objectid.js +1 -4
  30. package/lib/schema.js +1 -1
  31. package/lib/schematype.js +35 -19
  32. package/lib/types/buffer.js +2 -2
  33. package/lib/types/decimal128.js +1 -1
  34. package/lib/types/documentarray.js +2 -2
  35. package/lib/types/embedded.js +2 -1
  36. package/lib/types/map.js +4 -0
  37. package/lib/types/objectid.js +1 -1
  38. package/lib/types/subdocument.js +2 -1
  39. package/lib/utils.js +17 -16
  40. package/migrating_to_5.md +1 -1
  41. package/package.json +4 -6
  42. package/tools/checkNodeVersion.js +7 -0
  43. package/tools/sharded.js +4 -1
  44. package/website.js +2 -1
  45. package/lib/drivers/index.js +0 -20
  46. package/lib/drivers/index.web.js +0 -5
package/lib/types/map.js CHANGED
@@ -90,6 +90,10 @@ class MongooseMap extends Map {
90
90
  return new Map(this);
91
91
  }
92
92
 
93
+ toObject() {
94
+ return new Map(this);
95
+ }
96
+
93
97
  toJSON() {
94
98
  let ret = {};
95
99
  const keys = this.keys();
@@ -8,7 +8,7 @@
8
8
  * @constructor ObjectId
9
9
  */
10
10
 
11
- var ObjectId = require('../drivers').ObjectId;
11
+ var ObjectId = require('../driver').get().ObjectId;
12
12
 
13
13
  /*!
14
14
  * Getter for convenience with populate, see gh-6115
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var Document = require('../document');
4
+ var immediate = require('../helpers/immediate');
4
5
  var internalToObjectOptions = require('../options').internalToObjectOptions;
5
6
  var utils = require('../utils');
6
7
 
@@ -68,7 +69,7 @@ Subdocument.prototype.save = function(options, fn) {
68
69
  */
69
70
 
70
71
  Subdocument.prototype.$__save = function(fn) {
71
- return utils.immediate(() => fn(null, this));
72
+ return immediate(() => fn(null, this));
72
73
  };
73
74
 
74
75
  Subdocument.prototype.$isValid = function(path) {
package/lib/utils.js CHANGED
@@ -8,6 +8,7 @@ const Decimal = require('./types/decimal128');
8
8
  const ObjectId = require('./types/objectid');
9
9
  const PromiseProvider = require('./promise_provider');
10
10
  const cloneRegExp = require('regexp-clone');
11
+ const get = require('lodash.get');
11
12
  const sliced = require('sliced');
12
13
  const mpath = require('mpath');
13
14
  const ms = require('ms');
@@ -59,8 +60,8 @@ exports.deepEqual = function deepEqual(a, b) {
59
60
  return a.getTime() === b.getTime();
60
61
  }
61
62
 
62
- if ((a instanceof ObjectId && b instanceof ObjectId) ||
63
- (a instanceof Decimal && b instanceof Decimal)) {
63
+ if ((isBsonType(a, 'ObjectID') && isBsonType(b, 'ObjectID')) ||
64
+ (isBsonType(a, 'Decimal128') && isBsonType(b, 'Decimal128'))) {
64
65
  return a.toString() === b.toString();
65
66
  }
66
67
 
@@ -137,6 +138,14 @@ exports.deepEqual = function deepEqual(a, b) {
137
138
  return true;
138
139
  };
139
140
 
141
+ /*!
142
+ * Get the bson type, if it exists
143
+ */
144
+
145
+ function isBsonType(obj, typename) {
146
+ return get(obj, '_bsontype', void 0) === typename;
147
+ }
148
+
140
149
  /*!
141
150
  * Get the last element of an array
142
151
  */
@@ -194,7 +203,7 @@ exports.clone = function clone(obj, options) {
194
203
  if (obj instanceof ObjectId) {
195
204
  return new ObjectId(obj.id);
196
205
  }
197
- if (obj instanceof Decimal) {
206
+ if (isBsonType(obj, 'Decimal128')) {
198
207
  if (options && options.flattenDecimals) {
199
208
  return obj.toJSON();
200
209
  }
@@ -417,7 +426,7 @@ exports.isObject = function(arg) {
417
426
  */
418
427
 
419
428
  exports.isPOJO = function(arg) {
420
- return arg != null && typeof arg === 'object';
429
+ return get(arg, 'constructor.name') === 'Object';
421
430
  };
422
431
 
423
432
  /*!
@@ -473,7 +482,10 @@ exports.isMongooseObject = function(v) {
473
482
  return false;
474
483
  }
475
484
 
476
- return v.$__ != null || v.isMongooseArray || v.isMongooseBuffer;
485
+ return v.$__ != null || // Document
486
+ v.isMongooseArray || // Array or Document Array
487
+ v.isMongooseBuffer || // Buffer
488
+ v.$isMongooseMap; // Map
477
489
  };
478
490
  var isMongooseObject = exports.isMongooseObject;
479
491
 
@@ -878,17 +890,6 @@ exports.each = function(arr, fn) {
878
890
  }
879
891
  };
880
892
 
881
- /*!
882
- * Centralize this so we can more easily work around issues with people
883
- * stubbing out `process.nextTick()` in tests using sinon:
884
- * https://github.com/sinonjs/lolex#automatically-incrementing-mocked-time
885
- * See gh-6074
886
- */
887
-
888
- exports.immediate = function immediate(cb) {
889
- return process.nextTick(cb);
890
- };
891
-
892
893
  /*!
893
894
  * ignore
894
895
  */
package/migrating_to_5.md CHANGED
@@ -134,7 +134,7 @@ const cursorWithOptions = MyModel.
134
134
 
135
135
  Due to changes in the MongoDB driver, connection strings must be URI encoded.
136
136
 
137
- If they are not, connections may fail with an illegeal character message.
137
+ If they are not, connections may fail with an illegal character message.
138
138
 
139
139
  #### Passwords which contain certain characters
140
140
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "5.2.3",
4
+ "version": "5.2.7",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -27,7 +27,7 @@
27
27
  "mongodb-core": "3.1.0",
28
28
  "mongoose-legacy-pluralize": "1.0.2",
29
29
  "mpath": "0.4.1",
30
- "mquery": "3.0.0",
30
+ "mquery": "3.1.2",
31
31
  "ms": "2.0.0",
32
32
  "regexp-clone": "0.0.1",
33
33
  "sliced": "1.0.1"
@@ -41,7 +41,7 @@
41
41
  "bluebird": "3.5.0",
42
42
  "co": "4.6.0",
43
43
  "dox": "0.3.1",
44
- "eslint": "4.14.0",
44
+ "eslint": "5.3.0",
45
45
  "highlight.js": "9.1.0",
46
46
  "jade": "1.11.0",
47
47
  "lodash": "4.17.5",
@@ -54,19 +54,17 @@
54
54
  "nyc": "11.8.0",
55
55
  "power-assert": "1.4.1",
56
56
  "q": "1.5.1",
57
- "rimraf": "2.6.2",
58
57
  "semver": "5.5.0",
59
58
  "tbd": "0.6.4",
60
59
  "uuid": "2.0.3",
61
60
  "uuid-parse": "1.0.0",
62
- "webpack": "4.12.0",
61
+ "webpack": "4.16.4",
63
62
  "validator": "5.4.0"
64
63
  },
65
64
  "directories": {
66
65
  "lib": "./lib/mongoose"
67
66
  },
68
67
  "scripts": {
69
- "fix-lint": "eslint . --fix",
70
68
  "lint": "eslint . --quiet",
71
69
  "release": "git pull && git push origin master --tags && npm publish",
72
70
  "release-legacy": "git pull origin 4.x && git push origin 4.x --tags && npm publish --tag legacy",
@@ -0,0 +1,7 @@
1
+ const version = process.version;
2
+ const semver = require('semver');
3
+
4
+ // Gnarly but this helps us avoid running eslint on node v4.
5
+ if (!semver.satisfies(version, process.argv[2])) {
6
+ throw new Error(`${version} does not satisfy "${process.argv[2]}"`);
7
+ }
package/tools/sharded.js CHANGED
@@ -13,7 +13,7 @@ co(function*() {
13
13
 
14
14
  yield topology.addShard([{
15
15
  options: {
16
- bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000`
16
+ bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000`, shardsvr: null
17
17
  }
18
18
  }], { replSet: 'rs1' });
19
19
 
@@ -29,9 +29,12 @@ co(function*() {
29
29
  binary: 'mongos'
30
30
  });
31
31
 
32
+ console.log('Start...');
32
33
  // Start up topology
33
34
  yield topology.start();
34
35
 
36
+ console.log('Started');
37
+
35
38
  // Shard db
36
39
  yield topology.enableSharding('test');
37
40
 
package/website.js CHANGED
@@ -25,7 +25,8 @@ const tests = [
25
25
  ...acquit.parse(fs.readFileSync('./test/webpack.test.js').toString()),
26
26
  ...acquit.parse(fs.readFileSync('./test/geojson.test.js').toString()),
27
27
  ...acquit.parse(fs.readFileSync('./test/docs/transactions.test.js').toString()),
28
- ...acquit.parse(fs.readFileSync('./test/schema.alias.test.js').toString())
28
+ ...acquit.parse(fs.readFileSync('./test/schema.alias.test.js').toString()),
29
+ ...acquit.parse(fs.readFileSync('./test/model.middleware.test.js').toString())
29
30
  ];
30
31
 
31
32
  function getVersion() {
@@ -1,20 +0,0 @@
1
- /*!
2
- * ignore
3
- */
4
-
5
- var driver;
6
-
7
- if (typeof window === 'undefined') {
8
- driver = require('./node-mongodb-native');
9
- if (global.MONGOOSE_DRIVER_PATH) {
10
- driver = require(global.MONGOOSE_DRIVER_PATH);
11
- }
12
- } else {
13
- driver = require('./browser');
14
- }
15
-
16
- /*!
17
- * ignore
18
- */
19
-
20
- module.exports = driver;
@@ -1,5 +0,0 @@
1
- /*!
2
- * ignore
3
- */
4
-
5
- module.exports = require('./browser');