Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ashleybartlett
Copy link

@ashleybartlett ashleybartlett commented Jan 13, 2025

This fixes a couple of type errors compared to the underlying code.

This is likely a breaking change for some users as it would have required some working around to make it work before.

Should fix #3238 and #2667

Some future improvements that i'd like to see is the exported promise interfaces are converted to classes, to match the underlying code, but that felt like a much bigger change.

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 sidorares#3238 and sidorares#2667
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.45%. Comparing base (d48f143) to head (4e75c24).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3321   +/-   ##
=======================================
  Coverage   88.45%   88.45%           
=======================================
  Files          83       83           
  Lines       13067    13067           
  Branches     1393     1393           
=======================================
  Hits        11558    11558           
  Misses       1509     1509           
Flag Coverage Δ
compression-0 88.45% <ø> (ø)
compression-1 88.45% <ø> (ø)
tls-0 87.84% <ø> (ø)
tls-1 88.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Mistakenly didn't use the promise execute and query import.
@@ -431,4 +431,7 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
sequenceId: number;
}

export { Connection };
declare class Connection extends BaseConnection {
Copy link
Author

Choose a reason for hiding this comment

The 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

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;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is reflective of the actual implementation.

}

export interface Pool extends Connection {
export interface Pool extends QueryableAndExecutableBase, Pick<CorePool, 'escape' | 'escapeId' | 'format'> {
Copy link
Author

Choose a reason for hiding this comment

The 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

@@ -42,6 +44,8 @@ export interface PreparedStatementInfo {
export interface Connection extends QueryableAndExecutableBase {
config: ConnectionOptions;

connection: CoreConnection;
Copy link
Author

@ashleybartlett ashleybartlett Jan 13, 2025

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)

@@ -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;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from connection type, as these exist here in code.

import { Pool as PromisePool } from '../../../promise.js';

declare class PoolConnection extends Connection {
declare class PoolConnection extends BaseConnection {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed inheritance type error for the promise function implementation.

@wellwelwel
Copy link
Collaborator

wellwelwel commented Jan 14, 2025

Thanks, @ashleybartlett!

The inheritance from base connections after #3081 makes perfect sense, but I'll keep the #3273 issue as related due to an unexpected breaking change when using instanceof.

I'm planning to run some regression tests in your changes just to make sure we wouldn't imply an additional breaking change.

@ashleybartlett
Copy link
Author

ashleybartlett commented Jan 14, 2025

I think that breaking change makes a lot of sense, as it was done under the hood, but i'm not sure if it's something that can be fixed properly.

Given it wasn't breaking existing checks, I can revert that change for the base type if it's going to be a problem, and it can be revisited in a breaking change release.

@ashleybartlett ashleybartlett changed the title fix: connection types mismatched code fix: Promise connection typescript mismatched to underlying code Jan 15, 2025
@ashleybartlett ashleybartlett changed the title fix: Promise connection typescript mismatched to underlying code fix: promise connection typescript mismatched to underlying code Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promise Pool events inherit original pool connection class, not promise pool
2 participants