events.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ServerHeartbeatFailedEvent = exports.ServerHeartbeatSucceededEvent = exports.ServerHeartbeatStartedEvent = exports.TopologyClosedEvent = exports.TopologyOpeningEvent = exports.TopologyDescriptionChangedEvent = exports.ServerClosedEvent = exports.ServerOpeningEvent = exports.ServerDescriptionChangedEvent = void 0;
  4. const constants_1 = require("../constants");
  5. /**
  6. * Emitted when server description changes, but does NOT include changes to the RTT.
  7. * @public
  8. * @category Event
  9. */
  10. class ServerDescriptionChangedEvent {
  11. /** @internal */
  12. constructor(topologyId, address, previousDescription, newDescription) {
  13. this.name = constants_1.SERVER_DESCRIPTION_CHANGED;
  14. this.topologyId = topologyId;
  15. this.address = address;
  16. this.previousDescription = previousDescription;
  17. this.newDescription = newDescription;
  18. }
  19. }
  20. exports.ServerDescriptionChangedEvent = ServerDescriptionChangedEvent;
  21. /**
  22. * Emitted when server is initialized.
  23. * @public
  24. * @category Event
  25. */
  26. class ServerOpeningEvent {
  27. /** @internal */
  28. constructor(topologyId, address) {
  29. /** @internal */
  30. this.name = constants_1.SERVER_OPENING;
  31. this.topologyId = topologyId;
  32. this.address = address;
  33. }
  34. }
  35. exports.ServerOpeningEvent = ServerOpeningEvent;
  36. /**
  37. * Emitted when server is closed.
  38. * @public
  39. * @category Event
  40. */
  41. class ServerClosedEvent {
  42. /** @internal */
  43. constructor(topologyId, address) {
  44. /** @internal */
  45. this.name = constants_1.SERVER_CLOSED;
  46. this.topologyId = topologyId;
  47. this.address = address;
  48. }
  49. }
  50. exports.ServerClosedEvent = ServerClosedEvent;
  51. /**
  52. * Emitted when topology description changes.
  53. * @public
  54. * @category Event
  55. */
  56. class TopologyDescriptionChangedEvent {
  57. /** @internal */
  58. constructor(topologyId, previousDescription, newDescription) {
  59. /** @internal */
  60. this.name = constants_1.TOPOLOGY_DESCRIPTION_CHANGED;
  61. this.topologyId = topologyId;
  62. this.previousDescription = previousDescription;
  63. this.newDescription = newDescription;
  64. }
  65. }
  66. exports.TopologyDescriptionChangedEvent = TopologyDescriptionChangedEvent;
  67. /**
  68. * Emitted when topology is initialized.
  69. * @public
  70. * @category Event
  71. */
  72. class TopologyOpeningEvent {
  73. /** @internal */
  74. constructor(topologyId) {
  75. /** @internal */
  76. this.name = constants_1.TOPOLOGY_OPENING;
  77. this.topologyId = topologyId;
  78. }
  79. }
  80. exports.TopologyOpeningEvent = TopologyOpeningEvent;
  81. /**
  82. * Emitted when topology is closed.
  83. * @public
  84. * @category Event
  85. */
  86. class TopologyClosedEvent {
  87. /** @internal */
  88. constructor(topologyId) {
  89. /** @internal */
  90. this.name = constants_1.TOPOLOGY_CLOSED;
  91. this.topologyId = topologyId;
  92. }
  93. }
  94. exports.TopologyClosedEvent = TopologyClosedEvent;
  95. /**
  96. * Emitted when the server monitor’s hello command is started - immediately before
  97. * the hello command is serialized into raw BSON and written to the socket.
  98. *
  99. * @public
  100. * @category Event
  101. */
  102. class ServerHeartbeatStartedEvent {
  103. /** @internal */
  104. constructor(connectionId, awaited) {
  105. /** @internal */
  106. this.name = constants_1.SERVER_HEARTBEAT_STARTED;
  107. this.connectionId = connectionId;
  108. this.awaited = awaited;
  109. }
  110. }
  111. exports.ServerHeartbeatStartedEvent = ServerHeartbeatStartedEvent;
  112. /**
  113. * Emitted when the server monitor’s hello succeeds.
  114. * @public
  115. * @category Event
  116. */
  117. class ServerHeartbeatSucceededEvent {
  118. /** @internal */
  119. constructor(connectionId, duration, reply, awaited) {
  120. /** @internal */
  121. this.name = constants_1.SERVER_HEARTBEAT_SUCCEEDED;
  122. this.connectionId = connectionId;
  123. this.duration = duration;
  124. this.reply = reply ?? {};
  125. this.awaited = awaited;
  126. }
  127. }
  128. exports.ServerHeartbeatSucceededEvent = ServerHeartbeatSucceededEvent;
  129. /**
  130. * Emitted when the server monitor’s hello fails, either with an “ok: 0” or a socket exception.
  131. * @public
  132. * @category Event
  133. */
  134. class ServerHeartbeatFailedEvent {
  135. /** @internal */
  136. constructor(connectionId, duration, failure, awaited) {
  137. /** @internal */
  138. this.name = constants_1.SERVER_HEARTBEAT_FAILED;
  139. this.connectionId = connectionId;
  140. this.duration = duration;
  141. this.failure = failure;
  142. this.awaited = awaited;
  143. }
  144. }
  145. exports.ServerHeartbeatFailedEvent = ServerHeartbeatFailedEvent;
  146. //# sourceMappingURL=events.js.map