mongodb 3.0.4 → 3.0.8

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.
package/lib/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var MongoError = require('mongodb-core').MongoError,
4
- ReadPreference = require('mongodb-core').ReadPreference;
3
+ const MongoError = require('mongodb-core').MongoError;
4
+ const ReadPreference = require('mongodb-core').ReadPreference;
5
5
 
6
6
  var shallowClone = function(obj) {
7
7
  var copy = {};
@@ -378,11 +378,12 @@ const executeOperation = (topology, operation, args, options) => {
378
378
 
379
379
  // The driver sessions spec mandates that we implicitly create sessions for operations
380
380
  // that are not explicitly provided with a session.
381
- let session, opOptions;
381
+ let session, opOptions, owner;
382
382
  if (!options.skipSessions && topology.hasSessionSupport()) {
383
383
  opOptions = args[args.length - 2];
384
384
  if (opOptions == null || opOptions.session == null) {
385
- session = topology.startSession();
385
+ owner = Symbol();
386
+ session = topology.startSession({ owner });
386
387
  const optionsIndex = args.length - 2;
387
388
  args[optionsIndex] = Object.assign({}, args[optionsIndex], { session: session });
388
389
  } else if (opOptions.session && opOptions.session.hasEnded) {
@@ -392,7 +393,7 @@ const executeOperation = (topology, operation, args, options) => {
392
393
 
393
394
  const makeExecuteCallback = (resolve, reject) =>
394
395
  function executeCallback(err, result) {
395
- if (session && !options.returnsCursor) {
396
+ if (session && session.owner === owner && !options.returnsCursor) {
396
397
  session.endSession(() => {
397
398
  delete opOptions.session;
398
399
  if (err) return reject(err);
@@ -440,6 +441,51 @@ const executeOperation = (topology, operation, args, options) => {
440
441
  });
441
442
  };
442
443
 
444
+ /**
445
+ * Applies a write concern to a command based on well defined inheritance rules, optionally
446
+ * detecting support for the write concern in the first place.
447
+ *
448
+ * @param {Object} target the target command we will be applying the write concern to
449
+ * @param {Object} sources sources where we can inherit default write concerns from
450
+ * @param {Object} [options] optional settings passed into a command for write concern overrides
451
+ * @returns {Object} the (now) decorated target
452
+ */
453
+ function applyWriteConcern(target, sources, options) {
454
+ options = options || {};
455
+ const db = sources.db;
456
+ const coll = sources.collection;
457
+
458
+ // NOTE: there is probably a much better place for this
459
+ if (db && db.s.options.retryWrites) {
460
+ target.retryWrites = true;
461
+ }
462
+
463
+ if (options.w != null || options.j != null || options.fsync != null) {
464
+ const writeConcern = {};
465
+ if (options.w != null) writeConcern.w = options.w;
466
+ if (options.wtimeout != null) writeConcern.wtimeout = options.wtimeout;
467
+ if (options.j != null) writeConcern.j = options.j;
468
+ if (options.fsync != null) writeConcern.fsync = options.fsync;
469
+ return Object.assign(target, { writeConcern });
470
+ }
471
+
472
+ if (
473
+ coll &&
474
+ (coll.writeConcern.w != null || coll.writeConcern.j != null || coll.writeConcern.fsync != null)
475
+ ) {
476
+ return Object.assign(target, { writeConcern: Object.assign({}, coll.writeConcern) });
477
+ }
478
+
479
+ if (
480
+ db &&
481
+ (db.writeConcern.w != null || db.writeConcern.j != null || db.writeConcern.fsync != null)
482
+ ) {
483
+ return Object.assign(target, { writeConcern: Object.assign({}, db.writeConcern) });
484
+ }
485
+
486
+ return target;
487
+ }
488
+
443
489
  exports.filterOptions = filterOptions;
444
490
  exports.mergeOptions = mergeOptions;
445
491
  exports.translateOptions = translateOptions;
@@ -458,3 +504,4 @@ exports.MAX_JS_INT = 0x20000000000000;
458
504
  exports.mergeOptionsAndWriteConcern = mergeOptionsAndWriteConcern;
459
505
  exports.translateReadPreference = translateReadPreference;
460
506
  exports.executeOperation = executeOperation;
507
+ exports.applyWriteConcern = applyWriteConcern;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "3.0.4",
3
+ "version": "3.0.8",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -13,10 +13,9 @@
13
13
  "official"
14
14
  ],
15
15
  "dependencies": {
16
- "mongodb-core": "3.0.4"
16
+ "mongodb-core": "3.0.8"
17
17
  },
18
18
  "devDependencies": {
19
- "betterbenchmarks": "^0.1.0",
20
19
  "bluebird": "3.5.0",
21
20
  "bson": "^1.0.4",
22
21
  "chai": "^4.1.1",
@@ -27,7 +26,7 @@
27
26
  "eslint-plugin-prettier": "^2.2.0",
28
27
  "istanbul": "^0.4.5",
29
28
  "jsdoc": "3.5.4",
30
- "mongodb-extended-json": "^1.10.0",
29
+ "mongodb-extjson": "^2.1.1",
31
30
  "mongodb-mock-server": "^1.0.0",
32
31
  "mongodb-test-runner": "^1.1.18",
33
32
  "prettier": "^1.5.3",
@@ -48,7 +47,8 @@
48
47
  "coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/unit test/functional",
49
48
  "lint": "eslint lib test",
50
49
  "format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
51
- "changelog": "conventional-changelog -p angular -i HISTORY.md -s"
50
+ "changelog": "conventional-changelog -p angular -i HISTORY.md -s",
51
+ "bench": "node test/driverBench/"
52
52
  },
53
53
  "homepage": "https://github.com/mongodb/node-mongodb-native"
54
54
  }
package/lib/metadata.js DELETED
@@ -1,70 +0,0 @@
1
- 'use strict';
2
-
3
- var f = require('util').format;
4
-
5
- var Define = function(name, object, stream) {
6
- this.name = name;
7
- this.object = object;
8
- this.stream = typeof stream === 'boolean' ? stream : false;
9
- this.instrumentations = {};
10
- };
11
-
12
- Define.prototype.classMethod = function(name, options) {
13
- var keys = Object.keys(options).sort();
14
- var key = generateKey(keys, options);
15
-
16
- // Add a list of instrumentations
17
- if (this.instrumentations[key] == null) {
18
- this.instrumentations[key] = {
19
- methods: [],
20
- options: options
21
- };
22
- }
23
-
24
- // Push to list of method for this instrumentation
25
- this.instrumentations[key].methods.push(name);
26
- };
27
-
28
- var generateKey = function(keys, options) {
29
- var parts = [];
30
- for (var i = 0; i < keys.length; i++) {
31
- parts.push(f('%s=%s', keys[i], options[keys[i]]));
32
- }
33
-
34
- return parts.join();
35
- };
36
-
37
- Define.prototype.staticMethod = function(name, options) {
38
- options.static = true;
39
- var keys = Object.keys(options).sort();
40
- var key = generateKey(keys, options);
41
-
42
- // Add a list of instrumentations
43
- if (this.instrumentations[key] == null) {
44
- this.instrumentations[key] = {
45
- methods: [],
46
- options: options
47
- };
48
- }
49
-
50
- // Push to list of method for this instrumentation
51
- this.instrumentations[key].methods.push(name);
52
- };
53
-
54
- Define.prototype.generate = function() {
55
- // Generate the return object
56
- var object = {
57
- name: this.name,
58
- obj: this.object,
59
- stream: this.stream,
60
- instrumentations: []
61
- };
62
-
63
- for (var name in this.instrumentations) {
64
- object.instrumentations.push(this.instrumentations[name]);
65
- }
66
-
67
- return object;
68
- };
69
-
70
- module.exports = Define;