mongodb 3.0.0 → 3.0.4

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/url_parser.js CHANGED
@@ -10,7 +10,13 @@ module.exports = function(url, options, callback) {
10
10
  if (typeof options === 'function') (callback = options), (options = {});
11
11
  options = options || {};
12
12
 
13
- let result = parser.parse(url, true);
13
+ let result;
14
+ try {
15
+ result = parser.parse(url, true);
16
+ } catch (e) {
17
+ return callback(new Error('URL malformed, cannot be parsed'));
18
+ }
19
+
14
20
  if (result.protocol !== 'mongodb:' && result.protocol !== 'mongodb+srv:') {
15
21
  return callback(new Error('Invalid schema, expected `mongodb` or `mongodb+srv`'));
16
22
  }
@@ -48,8 +54,9 @@ module.exports = function(url, options, callback) {
48
54
  }
49
55
  }
50
56
 
57
+ let base = result.auth ? `mongodb://${result.auth}@` : `mongodb://`;
51
58
  let connectionStrings = addresses.map(function(address, i) {
52
- if (i === 0) return `mongodb://${address.name}:${address.port}`;
59
+ if (i === 0) return `${base}${address.name}:${address.port}`;
53
60
  else return `${address.name}:${address.port}`;
54
61
  });
55
62
 
package/lib/utils.js CHANGED
@@ -383,29 +383,44 @@ const executeOperation = (topology, operation, args, options) => {
383
383
  opOptions = args[args.length - 2];
384
384
  if (opOptions == null || opOptions.session == null) {
385
385
  session = topology.startSession();
386
- Object.assign(args[args.length - 2], { session: session });
386
+ const optionsIndex = args.length - 2;
387
+ args[optionsIndex] = Object.assign({}, args[optionsIndex], { session: session });
387
388
  } else if (opOptions.session && opOptions.session.hasEnded) {
388
389
  throw new MongoError('Use of expired sessions is not permitted');
389
390
  }
390
391
  }
391
392
 
392
- // Execute using callback
393
- if (typeof callback === 'function') {
394
- callback = args.pop();
395
- args.push((err, result) => {
393
+ const makeExecuteCallback = (resolve, reject) =>
394
+ function executeCallback(err, result) {
396
395
  if (session && !options.returnsCursor) {
397
396
  session.endSession(() => {
398
397
  delete opOptions.session;
399
- if (err) return callback(err, null);
400
- return resultMutator ? callback(null, resultMutator(result)) : callback(null, result);
398
+ if (err) return reject(err);
399
+ if (resultMutator) return resolve(resultMutator(result));
400
+ resolve(result);
401
401
  });
402
402
  } else {
403
- if (err) return callback(err, null);
404
- return resultMutator ? callback(null, resultMutator(result)) : callback(null, result);
403
+ if (err) return reject(err);
404
+ if (resultMutator) return resolve(resultMutator(result));
405
+ resolve(result);
405
406
  }
406
- });
407
+ };
407
408
 
408
- return operation.apply(null, args);
409
+ // Execute using callback
410
+ if (typeof callback === 'function') {
411
+ callback = args.pop();
412
+ const handler = makeExecuteCallback(
413
+ result => callback(null, result),
414
+ err => callback(err, null)
415
+ );
416
+ args.push(handler);
417
+
418
+ try {
419
+ return operation.apply(null, args);
420
+ } catch (e) {
421
+ handler(e);
422
+ throw e;
423
+ }
409
424
  }
410
425
 
411
426
  // Return a Promise
@@ -414,22 +429,14 @@ const executeOperation = (topology, operation, args, options) => {
414
429
  }
415
430
 
416
431
  return new Promise(function(resolve, reject) {
417
- args[args.length - 1] = (err, r) => {
418
- if (session && !options.returnsCursor) {
419
- session.endSession(() => {
420
- delete opOptions.session;
421
- if (err) return reject(err);
422
- if (resultMutator) return resolve(resultMutator(r));
423
- resolve(r);
424
- });
425
- } else {
426
- if (err) return reject(err);
427
- if (resultMutator) return resolve(resultMutator(r));
428
- resolve(r);
429
- }
430
- };
432
+ const handler = makeExecuteCallback(resolve, reject);
433
+ args[args.length - 1] = handler;
431
434
 
432
- operation.apply(null, args);
435
+ try {
436
+ return operation.apply(null, args);
437
+ } catch (e) {
438
+ handler(e);
439
+ }
433
440
  });
434
441
  };
435
442
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "3.0.0",
3
+ "version": "3.0.4",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -13,7 +13,7 @@
13
13
  "official"
14
14
  ],
15
15
  "dependencies": {
16
- "mongodb-core": "3.0.0"
16
+ "mongodb-core": "3.0.4"
17
17
  },
18
18
  "devDependencies": {
19
19
  "betterbenchmarks": "^0.1.0",
@@ -28,9 +28,11 @@
28
28
  "istanbul": "^0.4.5",
29
29
  "jsdoc": "3.5.4",
30
30
  "mongodb-extended-json": "^1.10.0",
31
+ "mongodb-mock-server": "^1.0.0",
31
32
  "mongodb-test-runner": "^1.1.18",
32
33
  "prettier": "^1.5.3",
33
34
  "semver": "5.4.1",
35
+ "sinon": "^4.3.0",
34
36
  "worker-farm": "^1.5.0"
35
37
  },
36
38
  "author": "Christian Kvalheim",