From 120757ff17f34cf5cd4d157bc4329398679e1a1f Mon Sep 17 00:00:00 2001 From: Ashley Bartlett Date: Tue, 14 Jan 2025 09:41:46 +1100 Subject: [PATCH 1/3] fix: connection types mismatched code 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 --- promise.d.ts | 13 ++++++++----- typings/mysql/lib/Connection.d.ts | 9 +++++---- typings/mysql/lib/Pool.d.ts | 7 +++++++ typings/mysql/lib/PoolConnection.d.ts | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/promise.d.ts b/promise.d.ts index e9f3e08a1d..b700520548 100644 --- a/promise.d.ts +++ b/promise.d.ts @@ -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'; @@ -42,6 +44,8 @@ export interface PreparedStatementInfo { export interface Connection extends QueryableAndExecutableBase { config: ConnectionOptions; + connection: CoreConnection; + threadId: number; connect(): Promise; @@ -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 { getConnection(): Promise; 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; diff --git a/typings/mysql/lib/Connection.d.ts b/typings/mysql/lib/Connection.d.ts index 6af95e1f7d..61c4584196 100644 --- a/typings/mysql/lib/Connection.d.ts +++ b/typings/mysql/lib/Connection.d.ts @@ -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; @@ -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; @@ -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 }; diff --git a/typings/mysql/lib/Pool.d.ts b/typings/mysql/lib/Pool.d.ts index 042495e71f..1941830fb3 100644 --- a/typings/mysql/lib/Pool.d.ts +++ b/typings/mysql/lib/Pool.d.ts @@ -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; } diff --git a/typings/mysql/lib/PoolConnection.d.ts b/typings/mysql/lib/PoolConnection.d.ts index cce4ef726e..26fd81bb0d 100644 --- a/typings/mysql/lib/PoolConnection.d.ts +++ b/typings/mysql/lib/PoolConnection.d.ts @@ -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; From 09009acd8322b15a8389a5ad3079fa414c757598 Mon Sep 17 00:00:00 2001 From: Ashley Bartlett Date: Tue, 14 Jan 2025 10:15:36 +1100 Subject: [PATCH 2/3] chore(lint): fix lint error --- typings/mysql/lib/Connection.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/typings/mysql/lib/Connection.d.ts b/typings/mysql/lib/Connection.d.ts index 61c4584196..d8698258fa 100644 --- a/typings/mysql/lib/Connection.d.ts +++ b/typings/mysql/lib/Connection.d.ts @@ -335,7 +335,9 @@ export interface ConnectionOptions { jsonStrings?: boolean; } -declare class BaseConnection extends QueryableBase(ExecutableBase(EventEmitter)) { +declare class BaseConnection extends QueryableBase( + ExecutableBase(EventEmitter), +) { config: ConnectionOptions; threadId: number; From 4e75c240b89aab51f4eb1c7f57e392c886289b76 Mon Sep 17 00:00:00 2001 From: Ashley Bartlett Date: Tue, 14 Jan 2025 10:19:06 +1100 Subject: [PATCH 3/3] fix: Wrong type inheritance for promise pool Mistakenly didn't use the promise execute and query import. --- promise.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/promise.d.ts b/promise.d.ts index b700520548..295e65c8d1 100644 --- a/promise.d.ts +++ b/promise.d.ts @@ -84,7 +84,7 @@ export interface PoolConnection extends Connection { release(): void; } -export interface Pool extends Pick { +export interface Pool extends QueryableAndExecutableBase, Pick { getConnection(): Promise; releaseConnection(connection: PoolConnection): void;