Skip to content

Commit

Permalink
fix: create promise-based PoolCluster typings
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Jun 24, 2023
1 parent 3902ca6 commit 7f38496
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions promise.d.ts
Expand Up @@ -8,6 +8,7 @@ import {
QueryOptions,
ConnectionOptions,
PoolOptions,
PoolClusterOptions,
Pool as CorePool,
} from './index.js';
import { ExecutableBase as ExecutableBaseClass } from './typings/mysql/lib/protocol/sequences/promise/ExecutableBase.js';
Expand Down Expand Up @@ -95,10 +96,36 @@ export interface Pool extends Connection {
pool: CorePool;
}

export interface PoolNamespace extends QueryableAndExecutableBase {
getConnection(): Promise<PoolConnection>;
}

export interface PoolCluster extends EventEmitter {
config: PoolClusterOptions;

add(config: PoolOptions): void;
add(group: string, connectionUri: string): void;
add(group: string, config: PoolOptions): void;

end(): Promise<void>;

getConnection(): Promise<PoolConnection>;
getConnection(group: string): Promise<PoolConnection>;
getConnection(group: string, selector: string): Promise<PoolConnection>;

of(pattern: string, selector?: string): PoolNamespace;

on(event: string, listener: (args: any[]) => void): this;
on(event: 'remove', listener: (nodeId: number) => void): this;
on(event: 'connection', listener: (connection: PoolConnection) => void): this;
}

export function createConnection(connectionUri: string): Promise<Connection>;
export function createConnection(
config: ConnectionOptions
): Promise<Connection>;

export function createPool(connectionUri: string): Pool;
export function createPool(config: PoolOptions): Pool;

export function createPoolCluster(config?: PoolClusterOptions): PoolCluster;
2 changes: 2 additions & 0 deletions typings/mysql/index.d.ts
Expand Up @@ -12,6 +12,7 @@ import {
import {
PoolCluster as BasePoolCluster,
PoolClusterOptions,
PoolNamespace,
} from './lib/PoolCluster.js';
import { PoolConnection as BasePoolConnection } from './lib/PoolConnection.js';
import {
Expand All @@ -25,6 +26,7 @@ export {
SslOptions,
PoolOptions,
PoolClusterOptions,
PoolNamespace,
QueryOptions,
QueryError,
PrepareStatementInfo,
Expand Down

0 comments on commit 7f38496

Please sign in to comment.