PoolCluster.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { EventEmitter } from 'events';
  2. import { PoolConnection } from './PoolConnection.js';
  3. import { PoolOptions } from './Pool.js';
  4. import { ExecutableBase as ExecutableBaseClass } from './protocol/sequences/ExecutableBase.js';
  5. import { QueryableBase as QueryableBaseClass } from './protocol/sequences/QueryableBase.js';
  6. // Expose class interfaces
  7. declare class QueryableAndExecutableBase extends QueryableBaseClass(
  8. ExecutableBaseClass(EventEmitter),
  9. ) {}
  10. export interface PoolClusterOptions {
  11. /**
  12. * If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
  13. */
  14. canRetry?: boolean;
  15. /**
  16. * If connection fails, node's errorCount increases. When errorCount is greater than removeNodeErrorCount,
  17. * remove a node in the PoolCluster. (Default: 5)
  18. */
  19. removeNodeErrorCount?: number;
  20. /**
  21. * If connection fails, specifies the number of milliseconds before another connection attempt will be made.
  22. * If set to 0, then node will be removed instead and never re-used. (Default: 0)
  23. */
  24. restoreNodeTimeout?: number;
  25. /**
  26. * The default selector. (Default: RR)
  27. * RR: Select one alternately. (Round-Robin)
  28. * RANDOM: Select the node by random function.
  29. * ORDER: Select the first node available unconditionally.
  30. */
  31. defaultSelector?: string;
  32. }
  33. export interface PoolNamespace extends QueryableAndExecutableBase {
  34. getConnection(
  35. callback: (
  36. err: NodeJS.ErrnoException | null,
  37. connection: PoolConnection,
  38. ) => any,
  39. ): void;
  40. }
  41. declare class PoolCluster extends EventEmitter {
  42. config: PoolClusterOptions;
  43. add(config: PoolOptions): void;
  44. add(group: string, connectionUri: string): void;
  45. add(group: string, config: PoolOptions): void;
  46. end(): void;
  47. getConnection(
  48. callback: (
  49. err: NodeJS.ErrnoException | null,
  50. connection: PoolConnection,
  51. ) => void,
  52. ): void;
  53. getConnection(
  54. group: string,
  55. callback: (
  56. err: NodeJS.ErrnoException | null,
  57. connection: PoolConnection,
  58. ) => void,
  59. ): void;
  60. getConnection(
  61. group: string,
  62. selector: string,
  63. callback: (
  64. err: NodeJS.ErrnoException | null,
  65. connection: PoolConnection,
  66. ) => void,
  67. ): void;
  68. of(pattern: string, selector?: string): PoolNamespace;
  69. on(event: string, listener: (...args: any[]) => void): this;
  70. on(event: 'remove', listener: (nodeId: number) => void): this;
  71. on(event: 'warn', listener: (err: Error) => void): this;
  72. }
  73. export { PoolCluster };