Skip to content

Commit

Permalink
fix: connection types mismatched code
Browse files Browse the repository at this point in the history
This fixes a number of small type errors compared to the underlying code. This is likely a breaking change for some users as it would have required some working around.

Should fix #3238 and #2667
  • Loading branch information
ashleybartlett committed Jan 13, 2025
1 parent d48f143 commit 120757f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
13 changes: 8 additions & 5 deletions promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import {
FieldPacket,
QueryOptions,
ConnectionOptions,
Connection as CoreConnection,
PoolOptions,
PoolClusterOptions,
Pool as CorePool,
PoolConnection as CorePoolConnection,
} from './index.js';
import { ExecutableBase as ExecutableBaseClass } from './typings/mysql/lib/protocol/sequences/promise/ExecutableBase.js';
import { QueryableBase as QueryableBaseClass } from './typings/mysql/lib/protocol/sequences/promise/QueryableBase.js';
Expand Down Expand Up @@ -42,6 +44,8 @@ export interface PreparedStatementInfo {
export interface Connection extends QueryableAndExecutableBase {
config: ConnectionOptions;

connection: CoreConnection;

threadId: number;

connect(): Promise<void>;
Expand Down Expand Up @@ -78,17 +82,16 @@ export interface Connection extends QueryableAndExecutableBase {

export interface PoolConnection extends Connection {
release(): void;
connection: Connection;
}

export interface Pool extends Connection {
export interface Pool extends Pick<CorePool, 'execute' | 'query' | 'escape' | 'escapeId' | 'format'> {
getConnection(): Promise<PoolConnection>;

releaseConnection(connection: PoolConnection): void;

on(event: 'connection', listener: (connection: PoolConnection) => any): this;
on(event: 'acquire', listener: (connection: PoolConnection) => any): this;
on(event: 'release', listener: (connection: PoolConnection) => any): this;
on(event: 'connection', listener: (connection: CorePoolConnection) => any): this;
on(event: 'acquire', listener: (connection: CorePoolConnection) => any): this;
on(event: 'release', listener: (connection: CorePoolConnection) => any): this;
on(event: 'enqueue', listener: () => any): this;

end(): Promise<void>;
Expand Down
9 changes: 5 additions & 4 deletions typings/mysql/lib/Connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export interface ConnectionOptions {
jsonStrings?: boolean;
}

declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
declare class BaseConnection extends QueryableBase(ExecutableBase(EventEmitter)) {
config: ConnectionOptions;

threadId: number;
Expand Down Expand Up @@ -414,8 +414,6 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {

serverHandshake(args: any): any;

promise(promiseImpl?: PromiseConstructor): PromiseConnection;

ping(callback?: (err: QueryError | null) => any): void;

writeOk(args?: OkPacketParams): void;
Expand All @@ -431,4 +429,7 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
sequenceId: number;
}

export { Connection };
declare class Connection extends BaseConnection {
promise(promiseImpl?: PromiseConstructor): PromiseConnection;
}
export { Connection, BaseConnection };
7 changes: 7 additions & 0 deletions typings/mysql/lib/Pool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) {

promise(promiseImpl?: PromiseConstructor): PromisePool;

format(sql: string, values?: any | any[] | { [param: string]: any }): string;

escape(value: any): string;

escapeId(value: string | string[]): string;
escapeId(values: string[]): string;

config: PoolOptions;
}

Expand Down
4 changes: 2 additions & 2 deletions typings/mysql/lib/PoolConnection.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection } from './Connection.js';
import { Connection, BaseConnection } from './Connection.js';
import { Pool as PromisePool } from '../../../promise.js';

declare class PoolConnection extends Connection {
declare class PoolConnection extends BaseConnection {
connection: Connection;
release(): void;
promise(promiseImpl?: PromiseConstructor): PromisePool;
Expand Down

0 comments on commit 120757f

Please sign in to comment.