common.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports._advanceClusterTime = exports.drainTimerQueue = exports.ServerType = exports.TopologyType = exports.STATE_CONNECTED = exports.STATE_CONNECTING = exports.STATE_CLOSED = exports.STATE_CLOSING = void 0;
  4. const timers_1 = require("timers");
  5. // shared state names
  6. exports.STATE_CLOSING = 'closing';
  7. exports.STATE_CLOSED = 'closed';
  8. exports.STATE_CONNECTING = 'connecting';
  9. exports.STATE_CONNECTED = 'connected';
  10. /**
  11. * An enumeration of topology types we know about
  12. * @public
  13. */
  14. exports.TopologyType = Object.freeze({
  15. Single: 'Single',
  16. ReplicaSetNoPrimary: 'ReplicaSetNoPrimary',
  17. ReplicaSetWithPrimary: 'ReplicaSetWithPrimary',
  18. Sharded: 'Sharded',
  19. Unknown: 'Unknown',
  20. LoadBalanced: 'LoadBalanced'
  21. });
  22. /**
  23. * An enumeration of server types we know about
  24. * @public
  25. */
  26. exports.ServerType = Object.freeze({
  27. Standalone: 'Standalone',
  28. Mongos: 'Mongos',
  29. PossiblePrimary: 'PossiblePrimary',
  30. RSPrimary: 'RSPrimary',
  31. RSSecondary: 'RSSecondary',
  32. RSArbiter: 'RSArbiter',
  33. RSOther: 'RSOther',
  34. RSGhost: 'RSGhost',
  35. Unknown: 'Unknown',
  36. LoadBalancer: 'LoadBalancer'
  37. });
  38. /** @internal */
  39. function drainTimerQueue(queue) {
  40. queue.forEach(timers_1.clearTimeout);
  41. queue.clear();
  42. }
  43. exports.drainTimerQueue = drainTimerQueue;
  44. /** Shared function to determine clusterTime for a given topology or session */
  45. function _advanceClusterTime(entity, $clusterTime) {
  46. if (entity.clusterTime == null) {
  47. entity.clusterTime = $clusterTime;
  48. }
  49. else {
  50. if ($clusterTime.clusterTime.greaterThan(entity.clusterTime.clusterTime)) {
  51. entity.clusterTime = $clusterTime;
  52. }
  53. }
  54. }
  55. exports._advanceClusterTime = _advanceClusterTime;
  56. //# sourceMappingURL=common.js.map