mongodb 3.2.5 → 3.3.0-beta2

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 (133) hide show
  1. package/HISTORY.md +0 -10
  2. package/index.js +4 -4
  3. package/lib/admin.js +56 -56
  4. package/lib/aggregation_cursor.js +7 -3
  5. package/lib/bulk/common.js +18 -13
  6. package/lib/change_stream.js +196 -89
  7. package/lib/collection.js +217 -169
  8. package/lib/command_cursor.js +17 -7
  9. package/lib/core/auth/auth_provider.js +158 -0
  10. package/lib/core/auth/defaultAuthProviders.js +29 -0
  11. package/lib/core/auth/gssapi.js +241 -0
  12. package/lib/core/auth/mongo_credentials.js +81 -0
  13. package/lib/core/auth/mongocr.js +51 -0
  14. package/lib/core/auth/plain.js +35 -0
  15. package/lib/core/auth/scram.js +293 -0
  16. package/lib/core/auth/sspi.js +131 -0
  17. package/lib/core/auth/x509.js +26 -0
  18. package/lib/core/connection/apm.js +236 -0
  19. package/lib/core/connection/command_result.js +36 -0
  20. package/lib/core/connection/commands.js +507 -0
  21. package/lib/core/connection/connect.js +370 -0
  22. package/lib/core/connection/connection.js +624 -0
  23. package/lib/core/connection/logger.js +246 -0
  24. package/lib/core/connection/msg.js +219 -0
  25. package/lib/core/connection/pool.js +1285 -0
  26. package/lib/core/connection/utils.js +57 -0
  27. package/lib/core/cursor.js +752 -0
  28. package/lib/core/error.js +186 -0
  29. package/lib/core/index.js +50 -0
  30. package/lib/core/sdam/monitoring.js +228 -0
  31. package/lib/core/sdam/server.js +467 -0
  32. package/lib/core/sdam/server_description.js +163 -0
  33. package/lib/core/sdam/server_selectors.js +244 -0
  34. package/lib/core/sdam/srv_polling.js +135 -0
  35. package/lib/core/sdam/topology.js +1151 -0
  36. package/lib/core/sdam/topology_description.js +408 -0
  37. package/lib/core/sessions.js +711 -0
  38. package/lib/core/tools/smoke_plugin.js +61 -0
  39. package/lib/core/topologies/mongos.js +1337 -0
  40. package/lib/core/topologies/read_preference.js +202 -0
  41. package/lib/core/topologies/replset.js +1507 -0
  42. package/lib/core/topologies/replset_state.js +1121 -0
  43. package/lib/core/topologies/server.js +984 -0
  44. package/lib/core/topologies/shared.js +453 -0
  45. package/lib/core/transactions.js +167 -0
  46. package/lib/core/uri_parser.js +631 -0
  47. package/lib/core/utils.js +165 -0
  48. package/lib/core/wireprotocol/command.js +170 -0
  49. package/lib/core/wireprotocol/compression.js +73 -0
  50. package/lib/core/wireprotocol/constants.js +13 -0
  51. package/lib/core/wireprotocol/get_more.js +86 -0
  52. package/lib/core/wireprotocol/index.js +18 -0
  53. package/lib/core/wireprotocol/kill_cursors.js +70 -0
  54. package/lib/core/wireprotocol/query.js +224 -0
  55. package/lib/core/wireprotocol/shared.js +115 -0
  56. package/lib/core/wireprotocol/write_command.js +50 -0
  57. package/lib/cursor.js +40 -46
  58. package/lib/db.js +141 -95
  59. package/lib/dynamic_loaders.js +32 -0
  60. package/lib/error.js +12 -10
  61. package/lib/gridfs/chunk.js +2 -2
  62. package/lib/gridfs/grid_store.js +31 -25
  63. package/lib/gridfs-stream/index.js +4 -4
  64. package/lib/gridfs-stream/upload.js +1 -1
  65. package/lib/mongo_client.js +37 -15
  66. package/lib/operations/add_user.js +96 -0
  67. package/lib/operations/aggregate.js +24 -13
  68. package/lib/operations/aggregate_operation.js +127 -0
  69. package/lib/operations/bulk_write.js +104 -0
  70. package/lib/operations/close.js +47 -0
  71. package/lib/operations/collection_ops.js +28 -287
  72. package/lib/operations/collections.js +55 -0
  73. package/lib/operations/command.js +120 -0
  74. package/lib/operations/command_v2.js +43 -0
  75. package/lib/operations/common_functions.js +372 -0
  76. package/lib/operations/{mongo_client_ops.js → connect.js} +185 -157
  77. package/lib/operations/count.js +72 -0
  78. package/lib/operations/count_documents.js +46 -0
  79. package/lib/operations/create_collection.js +118 -0
  80. package/lib/operations/create_index.js +92 -0
  81. package/lib/operations/create_indexes.js +61 -0
  82. package/lib/operations/cursor_ops.js +3 -4
  83. package/lib/operations/db_ops.js +15 -12
  84. package/lib/operations/delete_many.js +25 -0
  85. package/lib/operations/delete_one.js +25 -0
  86. package/lib/operations/distinct.js +85 -0
  87. package/lib/operations/drop.js +53 -0
  88. package/lib/operations/drop_index.js +42 -0
  89. package/lib/operations/drop_indexes.js +23 -0
  90. package/lib/operations/estimated_document_count.js +33 -0
  91. package/lib/operations/execute_db_admin_command.js +34 -0
  92. package/lib/operations/execute_operation.js +165 -0
  93. package/lib/operations/explain.js +23 -0
  94. package/lib/operations/find_and_modify.js +98 -0
  95. package/lib/operations/find_one.js +33 -0
  96. package/lib/operations/find_one_and_delete.js +16 -0
  97. package/lib/operations/find_one_and_replace.js +18 -0
  98. package/lib/operations/find_one_and_update.js +19 -0
  99. package/lib/operations/geo_haystack_search.js +79 -0
  100. package/lib/operations/has_next.js +40 -0
  101. package/lib/operations/index_exists.js +39 -0
  102. package/lib/operations/index_information.js +23 -0
  103. package/lib/operations/indexes.js +22 -0
  104. package/lib/operations/insert_many.js +63 -0
  105. package/lib/operations/insert_one.js +75 -0
  106. package/lib/operations/is_capped.js +19 -0
  107. package/lib/operations/list_indexes.js +66 -0
  108. package/lib/operations/map_reduce.js +189 -0
  109. package/lib/operations/next.js +32 -0
  110. package/lib/operations/operation.js +63 -0
  111. package/lib/operations/options_operation.js +32 -0
  112. package/lib/operations/profiling_level.js +31 -0
  113. package/lib/operations/re_index.js +28 -0
  114. package/lib/operations/remove_user.js +52 -0
  115. package/lib/operations/rename.js +61 -0
  116. package/lib/operations/replace_one.js +47 -0
  117. package/lib/operations/set_profiling_level.js +48 -0
  118. package/lib/operations/stats.js +45 -0
  119. package/lib/operations/to_array.js +68 -0
  120. package/lib/operations/update_many.js +29 -0
  121. package/lib/operations/update_one.js +44 -0
  122. package/lib/operations/validate_collection.js +40 -0
  123. package/lib/read_concern.js +55 -0
  124. package/lib/topologies/mongos.js +3 -3
  125. package/lib/topologies/native_topology.js +22 -2
  126. package/lib/topologies/replset.js +3 -3
  127. package/lib/topologies/server.js +4 -4
  128. package/lib/topologies/topology_base.js +6 -6
  129. package/lib/url_parser.js +4 -3
  130. package/lib/utils.js +46 -59
  131. package/lib/write_concern.js +66 -0
  132. package/package.json +15 -6
  133. package/lib/.DS_Store +0 -0
package/lib/utils.js CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const MongoError = require('mongodb-core').MongoError;
4
- const ReadPreference = require('mongodb-core').ReadPreference;
3
+ const MongoError = require('./core').MongoError;
4
+ const ReadPreference = require('./core').ReadPreference;
5
+ const WriteConcern = require('./write_concern');
5
6
 
6
7
  var shallowClone = function(obj) {
7
8
  var copy = {};
@@ -361,7 +362,7 @@ var mergeOptionsAndWriteConcern = function(targetOptions, sourceOptions, keys, m
361
362
  * @param {array} args Arguments to apply the provided operation
362
363
  * @param {object} [options] Options that modify the behavior of the method
363
364
  */
364
- const executeOperation = (topology, operation, args, options) => {
365
+ const executeLegacyOperation = (topology, operation, args, options) => {
365
366
  if (topology == null) {
366
367
  throw new TypeError('This method requires a valid topology instance');
367
368
  }
@@ -422,7 +423,7 @@ const executeOperation = (topology, operation, args, options) => {
422
423
 
423
424
  // Return a Promise
424
425
  if (args[args.length - 1] != null) {
425
- throw new TypeError('final argument to `executeOperation` must be a callback');
426
+ throw new TypeError('final argument to `executeLegacyOperation` must be a callback');
426
427
  }
427
428
 
428
429
  return new Promise(function(resolve, reject) {
@@ -474,26 +475,16 @@ function applyWriteConcern(target, sources, options) {
474
475
  return target;
475
476
  }
476
477
 
477
- if (options.w != null || options.j != null || options.fsync != null) {
478
- const writeConcern = {};
479
- if (options.w != null) writeConcern.w = options.w;
480
- if (options.wtimeout != null) writeConcern.wtimeout = options.wtimeout;
481
- if (options.j != null) writeConcern.j = options.j;
482
- if (options.fsync != null) writeConcern.fsync = options.fsync;
478
+ const writeConcern = WriteConcern.fromOptions(options);
479
+ if (writeConcern) {
483
480
  return Object.assign(target, { writeConcern });
484
481
  }
485
482
 
486
- if (
487
- coll &&
488
- (coll.writeConcern.w != null || coll.writeConcern.j != null || coll.writeConcern.fsync != null)
489
- ) {
483
+ if (coll && coll.writeConcern) {
490
484
  return Object.assign(target, { writeConcern: Object.assign({}, coll.writeConcern) });
491
485
  }
492
486
 
493
- if (
494
- db &&
495
- (db.writeConcern.w != null || db.writeConcern.j != null || db.writeConcern.fsync != null)
496
- ) {
487
+ if (db && db.writeConcern) {
497
488
  return Object.assign(target, { writeConcern: Object.assign({}, db.writeConcern) });
498
489
  }
499
490
 
@@ -505,56 +496,27 @@ function applyWriteConcern(target, sources, options) {
505
496
  * determine the read preference (if there is one), but will also ensure the returned value is a
506
497
  * properly constructed instance of `ReadPreference`.
507
498
  *
499
+ * @param {Collection|Db|MongoClient} parent The parent of the operation on which to determine the read
500
+ * preference, used for determining the inherited read preference.
508
501
  * @param {Object} options The options passed into the method, potentially containing a read preference
509
- * @param {Object} sources Sources from which we can inherit a read preference
510
502
  * @returns {(ReadPreference|null)} The resolved read preference
511
503
  */
512
- function resolveReadPreference(options, sources) {
504
+ function resolveReadPreference(parent, options) {
513
505
  options = options || {};
514
- sources = sources || {};
515
-
516
- const db = sources.db;
517
- const coll = sources.collection;
518
- const defaultReadPreference = sources.default;
519
506
  const session = options.session;
520
507
 
508
+ const inheritedReadPreference = parent.readPreference;
509
+
521
510
  let readPreference;
522
511
  if (options.readPreference) {
523
- readPreference = options.readPreference;
512
+ readPreference = ReadPreference.fromOptions(options);
524
513
  } else if (session && session.inTransaction() && session.transaction.options.readPreference) {
525
514
  // The transaction’s read preference MUST override all other user configurable read preferences.
526
515
  readPreference = session.transaction.options.readPreference;
516
+ } else if (inheritedReadPreference != null) {
517
+ readPreference = inheritedReadPreference;
527
518
  } else {
528
- if (coll && coll.s.readPreference) {
529
- readPreference = coll.s.readPreference;
530
- } else if (db && db.s.readPreference) {
531
- readPreference = db.s.readPreference;
532
- } else if (defaultReadPreference) {
533
- readPreference = defaultReadPreference;
534
- }
535
- }
536
-
537
- // do we even have a read preference?
538
- if (readPreference == null) {
539
- return null;
540
- }
541
-
542
- // now attempt to convert the read preference if necessary
543
- if (typeof readPreference === 'string') {
544
- readPreference = new ReadPreference(readPreference);
545
- } else if (
546
- readPreference &&
547
- !(readPreference instanceof ReadPreference) &&
548
- typeof readPreference === 'object'
549
- ) {
550
- const mode = readPreference.mode || readPreference.preference;
551
- if (mode && typeof mode === 'string') {
552
- readPreference = new ReadPreference(mode, readPreference.tags, {
553
- maxStalenessSeconds: readPreference.maxStalenessSeconds
554
- });
555
- }
556
- } else if (!(readPreference instanceof ReadPreference)) {
557
- throw new TypeError('Invalid read preference: ' + readPreference);
519
+ throw new Error('No readPreference was provided or inherited.');
558
520
  }
559
521
 
560
522
  return readPreference;
@@ -699,6 +661,30 @@ try {
699
661
  SUPPORTS.ASYNC_ITERATOR = false;
700
662
  }
701
663
 
664
+ class MongoDBNamespace {
665
+ constructor(db, collection) {
666
+ this.db = db;
667
+ this.collection = collection;
668
+ }
669
+
670
+ toString() {
671
+ return this.collection ? `${this.db}.${this.collection}` : this.db;
672
+ }
673
+
674
+ withCollection(collection) {
675
+ return new MongoDBNamespace(this.db, collection);
676
+ }
677
+
678
+ static fromString(namespace) {
679
+ if (!namespace) {
680
+ throw new Error(`Cannot parse namespace from "${namespace}"`);
681
+ }
682
+
683
+ const index = namespace.indexOf('.');
684
+ return new MongoDBNamespace(namespace.substring(0, index), namespace.substring(index + 1));
685
+ }
686
+ }
687
+
702
688
  module.exports = {
703
689
  filterOptions,
704
690
  mergeOptions,
@@ -717,13 +703,14 @@ module.exports = {
717
703
  MAX_JS_INT: Number.MAX_SAFE_INTEGER + 1,
718
704
  mergeOptionsAndWriteConcern,
719
705
  translateReadPreference,
720
- executeOperation,
706
+ executeLegacyOperation,
721
707
  applyRetryableWrites,
722
708
  applyWriteConcern,
723
- resolveReadPreference,
724
709
  isPromiseLike,
725
710
  decorateWithCollation,
726
711
  decorateWithReadConcern,
727
712
  deprecateOptions,
728
- SUPPORTS
713
+ SUPPORTS,
714
+ MongoDBNamespace,
715
+ resolveReadPreference
729
716
  };
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * The **WriteConcern** class is a class that represents a MongoDB WriteConcern.
5
+ * @class
6
+ * @property {(number|string)} w The write concern
7
+ * @property {number} wtimeout The write concern timeout
8
+ * @property {boolean} j The journal write concern
9
+ * @property {boolean} fsync The file sync write concern
10
+ * @see https://docs.mongodb.com/manual/reference/write-concern/index.html
11
+ */
12
+ class WriteConcern {
13
+ /**
14
+ * Constructs a WriteConcern from the write concern properties.
15
+ * @param {(number|string)} [w] The write concern
16
+ * @param {number} [wtimeout] The write concern timeout
17
+ * @param {boolean} [j] The journal write concern
18
+ * @param {boolean} [fsync] The file sync write concern
19
+ */
20
+ constructor(w, wtimeout, j, fsync) {
21
+ if (w != null) {
22
+ this.w = w;
23
+ }
24
+ if (wtimeout != null) {
25
+ this.wtimeout = wtimeout;
26
+ }
27
+ if (j != null) {
28
+ this.j = j;
29
+ }
30
+ if (fsync != null) {
31
+ this.fsync = fsync;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Construct a WriteConcern given an options object.
37
+ *
38
+ * @param {object} options The options object from which to extract the write concern.
39
+ * @return {WriteConcern}
40
+ */
41
+ static fromOptions(options) {
42
+ if (
43
+ options == null ||
44
+ (options.writeConcern == null &&
45
+ options.w == null &&
46
+ options.wtimeout == null &&
47
+ options.j == null &&
48
+ options.fsync == null)
49
+ ) {
50
+ return;
51
+ }
52
+
53
+ if (options.writeConcern) {
54
+ return new WriteConcern(
55
+ options.writeConcern.w,
56
+ options.writeConcern.wtimeout,
57
+ options.writeConcern.j,
58
+ options.writeConcern.fsync
59
+ );
60
+ }
61
+
62
+ return new WriteConcern(options.w, options.wtimeout, options.j, options.fsync);
63
+ }
64
+ }
65
+
66
+ module.exports = WriteConcern;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "3.2.5",
3
+ "version": "3.3.0-beta2",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -16,13 +16,20 @@
16
16
  "driver",
17
17
  "official"
18
18
  ],
19
+ "peerOptionalDependencies": {
20
+ "kerberos": "^1.0.0",
21
+ "mongodb-client-encryption": "^1.0.0",
22
+ "mongodb-extjson": "^2.1.2",
23
+ "snappy": "^6.1.1",
24
+ "bson-ext": "^2.0.0"
25
+ },
19
26
  "dependencies": {
20
- "mongodb-core": "3.2.5",
27
+ "bson": "^1.1.1",
28
+ "require_optional": "^1.0.1",
21
29
  "safe-buffer": "^5.1.2"
22
30
  },
23
31
  "devDependencies": {
24
32
  "bluebird": "3.5.0",
25
- "bson": "^1.0.4",
26
33
  "chai": "^4.1.1",
27
34
  "chai-subset": "^1.6.0",
28
35
  "co": "4.6.0",
@@ -40,8 +47,10 @@
40
47
  "semver": "^5.5.0",
41
48
  "sinon": "^4.3.0",
42
49
  "sinon-chai": "^3.2.0",
50
+ "snappy": "^6.1.2",
43
51
  "standard-version": "^4.4.0",
44
- "worker-farm": "^1.5.0"
52
+ "worker-farm": "^1.5.0",
53
+ "wtfnode": "^0.8.0"
45
54
  },
46
55
  "license": "Apache-2.0",
47
56
  "engines": {
@@ -52,8 +61,8 @@
52
61
  },
53
62
  "scripts": {
54
63
  "atlas": "node ./test/atlas_connectivity_tests.js",
55
- "test": "npm run lint && mongodb-test-runner -t 60000 test/unit test/functional",
56
- "coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/unit test/functional",
64
+ "test": "npm run lint && mongodb-test-runner -t 60000 test/core test/unit test/functional",
65
+ "coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/core test/unit test/functional",
57
66
  "lint": "eslint lib test",
58
67
  "format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
59
68
  "bench": "node test/driverBench/",
package/lib/.DS_Store DELETED
Binary file