UNPKG

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