UNPKG

2.45 kBTypeScriptView Raw
1import { Gauge, Counter, Histogram } from 'prom-client';
2import { ExtendedGaugeInternal } from 'prometheus-extended-gauge';
3import { Pool, Factory } from 'generic-pool';
4/**
5 * Sensible defaults for the connection pool options
6 */
7export declare const DEFAULT_CONNECTION_POOL_OPTIONS: PoolConfig<any>;
8/**
9 * Base interface for the configuration information needed to create a new connection
10 */
11export interface ConnectionConfig {
12}
13/**
14 * Class for the config of a Pool.
15 * This class is not supposed to be extended, as the framework does not expose methods to override the creation of the
16 * connection pools.
17 */
18export interface PoolConfig<C extends ConnectionConfig> {
19 max?: number;
20 min?: number;
21 maxWaitingClients?: number;
22 testOnBorrow?: boolean;
23 acquireTimeoutMillis?: number;
24 evictionRunIntervalMillis?: number;
25 numTestsPerRun?: number;
26 softIdleTimeoutMillis?: number;
27 idleTimeoutMillis?: number;
28 connectionConfig?: C;
29}
30export declare abstract class ConnectionPool<T> {
31 abstract getName(): string;
32 abstract isReadonly(): boolean;
33 abstract getConnection(): Promise<T>;
34 abstract release(connection: T): any;
35 abstract start(): any;
36 abstract stop(): any;
37}
38export declare class InstrumentedFactory<T> implements Factory<T> {
39 validateFailedCounter: Counter.Internal;
40 connectErrorsCounter: Counter.Internal;
41 connectTimeHistogram: Histogram.Internal;
42 totalGauge: Gauge.Internal;
43 factory: Factory<T>;
44 constructor(factory: Factory<T>, name: string, readonly: boolean);
45 create(): Promise<T>;
46 destroy(client: T): Promise<undefined>;
47 validate(client: T): Promise<boolean>;
48}
49export declare class InstrumentedConnectionPool<C, CC extends ConnectionConfig> extends ConnectionPool<C> {
50 readonly: boolean;
51 name: string;
52 activeGauge: ExtendedGaugeInternal;
53 useTimeHistogram: Histogram.Internal;
54 acquireErrorsCounter: Counter.Internal;
55 pool: Pool<C>;
56 acquireTimeHistogram: Histogram.Internal;
57 options: PoolConfig<CC>;
58 private status;
59 maxConnectionLimitGauge: Gauge.Internal;
60 constructor(factory: Factory<C>, options: PoolConfig<CC>, name: string, readonly: boolean);
61 getName(): string;
62 isReadonly(): boolean;
63 getConnection(): Promise<C>;
64 private getGenericPoolOptions();
65 release(connection: C): void;
66 start(): Promise<void>;
67 stop(): Promise<void>;
68 getOptions(): PoolConfig<CC>;
69}