-
-
Notifications
You must be signed in to change notification settings - Fork 628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: promise connection typescript mismatched to underlying code #3321
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<void>; | ||
|
@@ -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 QueryableAndExecutableBase, Pick<CorePool, 'escape' | 'escapeId' | 'format'> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pool doesn't extend Connection in code, so this better reflects the actual implementation |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is reflective of the actual implementation. |
||
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>; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,7 +335,9 @@ 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 +416,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 +431,7 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) { | |
sequenceId: number; | ||
} | ||
|
||
export { Connection }; | ||
declare class Connection extends BaseConnection { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed this to fix the pool connection inheritance giving a type error on reimplementing the promise |
||
promise(promiseImpl?: PromiseConstructor): PromiseConnection; | ||
} | ||
export { Connection, BaseConnection }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied from connection type, as these exist here in code. |
||
|
||
escape(value: any): string; | ||
|
||
escapeId(value: string | string[]): string; | ||
escapeId(values: string[]): string; | ||
|
||
config: PoolOptions; | ||
} | ||
|
||
|
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed inheritance type error for the promise function implementation. |
||
release(): void; | ||
promise(promiseImpl?: PromiseConstructor): PromisePool; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This connection field is defined on the promise Connection object, so this is now available everywhere this connection is used (including pool connection)