connection_pool_events.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ConnectionPoolClearedEvent = exports.ConnectionCheckedInEvent = exports.ConnectionCheckedOutEvent = exports.ConnectionCheckOutFailedEvent = exports.ConnectionCheckOutStartedEvent = exports.ConnectionClosedEvent = exports.ConnectionReadyEvent = exports.ConnectionCreatedEvent = exports.ConnectionPoolClosedEvent = exports.ConnectionPoolReadyEvent = exports.ConnectionPoolCreatedEvent = exports.ConnectionPoolMonitoringEvent = void 0;
  4. const constants_1 = require("../constants");
  5. /**
  6. * The base export class for all monitoring events published from the connection pool
  7. * @public
  8. * @category Event
  9. */
  10. class ConnectionPoolMonitoringEvent {
  11. /** @internal */
  12. constructor(pool) {
  13. this.time = new Date();
  14. this.address = pool.address;
  15. }
  16. }
  17. exports.ConnectionPoolMonitoringEvent = ConnectionPoolMonitoringEvent;
  18. /**
  19. * An event published when a connection pool is created
  20. * @public
  21. * @category Event
  22. */
  23. class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
  24. /** @internal */
  25. constructor(pool) {
  26. super(pool);
  27. /** @internal */
  28. this.name = constants_1.CONNECTION_POOL_CREATED;
  29. if (pool.options.credentials != null) {
  30. // Intentionally remove credentials: NODE-5460
  31. this.options = { ...pool.options, credentials: {} };
  32. }
  33. else {
  34. this.options = pool.options;
  35. }
  36. }
  37. }
  38. exports.ConnectionPoolCreatedEvent = ConnectionPoolCreatedEvent;
  39. /**
  40. * An event published when a connection pool is ready
  41. * @public
  42. * @category Event
  43. */
  44. class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
  45. /** @internal */
  46. constructor(pool) {
  47. super(pool);
  48. /** @internal */
  49. this.name = constants_1.CONNECTION_POOL_READY;
  50. }
  51. }
  52. exports.ConnectionPoolReadyEvent = ConnectionPoolReadyEvent;
  53. /**
  54. * An event published when a connection pool is closed
  55. * @public
  56. * @category Event
  57. */
  58. class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
  59. /** @internal */
  60. constructor(pool) {
  61. super(pool);
  62. /** @internal */
  63. this.name = constants_1.CONNECTION_POOL_CLOSED;
  64. }
  65. }
  66. exports.ConnectionPoolClosedEvent = ConnectionPoolClosedEvent;
  67. /**
  68. * An event published when a connection pool creates a new connection
  69. * @public
  70. * @category Event
  71. */
  72. class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
  73. /** @internal */
  74. constructor(pool, connection) {
  75. super(pool);
  76. /** @internal */
  77. this.name = constants_1.CONNECTION_CREATED;
  78. this.connectionId = connection.id;
  79. }
  80. }
  81. exports.ConnectionCreatedEvent = ConnectionCreatedEvent;
  82. /**
  83. * An event published when a connection is ready for use
  84. * @public
  85. * @category Event
  86. */
  87. class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
  88. /** @internal */
  89. constructor(pool, connection) {
  90. super(pool);
  91. /** @internal */
  92. this.name = constants_1.CONNECTION_READY;
  93. this.connectionId = connection.id;
  94. }
  95. }
  96. exports.ConnectionReadyEvent = ConnectionReadyEvent;
  97. /**
  98. * An event published when a connection is closed
  99. * @public
  100. * @category Event
  101. */
  102. class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
  103. /** @internal */
  104. constructor(pool, connection, reason, error) {
  105. super(pool);
  106. /** @internal */
  107. this.name = constants_1.CONNECTION_CLOSED;
  108. this.connectionId = connection.id;
  109. this.reason = reason;
  110. this.serviceId = connection.serviceId;
  111. this.error = error ?? null;
  112. }
  113. }
  114. exports.ConnectionClosedEvent = ConnectionClosedEvent;
  115. /**
  116. * An event published when a request to check a connection out begins
  117. * @public
  118. * @category Event
  119. */
  120. class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
  121. /** @internal */
  122. constructor(pool) {
  123. super(pool);
  124. /** @internal */
  125. this.name = constants_1.CONNECTION_CHECK_OUT_STARTED;
  126. }
  127. }
  128. exports.ConnectionCheckOutStartedEvent = ConnectionCheckOutStartedEvent;
  129. /**
  130. * An event published when a request to check a connection out fails
  131. * @public
  132. * @category Event
  133. */
  134. class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
  135. /** @internal */
  136. constructor(pool, reason, error) {
  137. super(pool);
  138. /** @internal */
  139. this.name = constants_1.CONNECTION_CHECK_OUT_FAILED;
  140. this.reason = reason;
  141. this.error = error;
  142. }
  143. }
  144. exports.ConnectionCheckOutFailedEvent = ConnectionCheckOutFailedEvent;
  145. /**
  146. * An event published when a connection is checked out of the connection pool
  147. * @public
  148. * @category Event
  149. */
  150. class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
  151. /** @internal */
  152. constructor(pool, connection) {
  153. super(pool);
  154. /** @internal */
  155. this.name = constants_1.CONNECTION_CHECKED_OUT;
  156. this.connectionId = connection.id;
  157. }
  158. }
  159. exports.ConnectionCheckedOutEvent = ConnectionCheckedOutEvent;
  160. /**
  161. * An event published when a connection is checked into the connection pool
  162. * @public
  163. * @category Event
  164. */
  165. class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
  166. /** @internal */
  167. constructor(pool, connection) {
  168. super(pool);
  169. /** @internal */
  170. this.name = constants_1.CONNECTION_CHECKED_IN;
  171. this.connectionId = connection.id;
  172. }
  173. }
  174. exports.ConnectionCheckedInEvent = ConnectionCheckedInEvent;
  175. /**
  176. * An event published when a connection pool is cleared
  177. * @public
  178. * @category Event
  179. */
  180. class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
  181. /** @internal */
  182. constructor(pool, options = {}) {
  183. super(pool);
  184. /** @internal */
  185. this.name = constants_1.CONNECTION_POOL_CLEARED;
  186. this.serviceId = options.serviceId;
  187. this.interruptInUseConnections = options.interruptInUseConnections;
  188. }
  189. }
  190. exports.ConnectionPoolClearedEvent = ConnectionPoolClearedEvent;
  191. //# sourceMappingURL=connection_pool_events.js.map