native_topology.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. const Topology = require('../core').Topology;
  3. const ServerCapabilities = require('./topology_base').ServerCapabilities;
  4. const Cursor = require('../cursor');
  5. const translateOptions = require('../utils').translateOptions;
  6. class NativeTopology extends Topology {
  7. constructor(servers, options) {
  8. options = options || {};
  9. let clonedOptions = Object.assign(
  10. {},
  11. {
  12. cursorFactory: Cursor,
  13. reconnect: false,
  14. emitError: typeof options.emitError === 'boolean' ? options.emitError : true,
  15. maxPoolSize: typeof options.poolSize === 'number' ? options.poolSize : 5,
  16. minPoolSize: typeof options.minSize === 'number' ? options.minSize : 0,
  17. monitorCommands:
  18. typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false
  19. }
  20. );
  21. // Translate any SSL options and other connectivity options
  22. clonedOptions = translateOptions(clonedOptions, options);
  23. // Socket options
  24. var socketOptions =
  25. options.socketOptions && Object.keys(options.socketOptions).length > 0
  26. ? options.socketOptions
  27. : options;
  28. // Translate all the options to the core types
  29. clonedOptions = translateOptions(clonedOptions, socketOptions);
  30. super(servers, clonedOptions);
  31. }
  32. capabilities() {
  33. if (this.s.sCapabilities) return this.s.sCapabilities;
  34. if (this.lastIsMaster() == null) return null;
  35. this.s.sCapabilities = new ServerCapabilities(this.lastIsMaster());
  36. return this.s.sCapabilities;
  37. }
  38. // Command
  39. command(ns, cmd, options, callback) {
  40. super.command(ns.toString(), cmd, options, callback);
  41. }
  42. // Insert
  43. insert(ns, ops, options, callback) {
  44. super.insert(ns.toString(), ops, options, callback);
  45. }
  46. // Update
  47. update(ns, ops, options, callback) {
  48. super.update(ns.toString(), ops, options, callback);
  49. }
  50. // Remove
  51. remove(ns, ops, options, callback) {
  52. super.remove(ns.toString(), ops, options, callback);
  53. }
  54. }
  55. module.exports = NativeTopology;