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

Use class-extends to wrap Pool #1541

Merged
merged 4 commits into from Jan 15, 2020
Merged

Conversation

NatalieWolfe
Copy link
Contributor

Using the es5-style pool wrapping from before makes it difficult to subclass BoundPool. Since Node 4.5 is the lowest supported version, it is possible to use es6-style classes.

The subsclassing issue stems from the fact that BoundPool was not applying Pool to this, instead returning a new Pool instance. It couldn't safely apply Pool since Pool is an es6 class and you must call es6 class constructors with new. By changing BoundPool to also be an es6 class we can call super and thus "apply" the Pool constructor to this.

Copy link
Collaborator

@charmander charmander left a comment

Choose a reason for hiding this comment

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

This is semver-major, though, since pg.Pool(…) will stop working without new. See #1505 (comment)

@brianc
Copy link
Owner

brianc commented Jan 5, 2018

@NatalieWolfe thanks for your work on this...and I apologize for the delay. I'm going to bundle this up with [https://github.com//pull/1503] because I think that also requires semver major, right @charmander?

@charmander
Copy link
Collaborator

charmander commented Jan 6, 2018

@brianc It depends on a pull request that should be a major version of pg-native, but I don’t think it needs to be a major version of pg. (The change to pg-native causes its client to emit error events in more situations, but the way it affects the pg wrapper can be considered a bugfix.)

@brianc
Copy link
Owner

brianc commented May 4, 2018

@charmander I think you might have responded to the wrong pull request here w/ your comment? Because this removes the ability to do const pool = pg.Pool() (now requiring new) it's a subtle breaking change which unfortunately requres a semver major. Once the minor patches settle down a bit here I'll do the semver major bump for this.

@sehrope
Copy link
Contributor

sehrope commented May 4, 2018

There's a bunch of stuff in node core that detects if it's not called as a constructor and if so silently returns the constructor invocation instead:

Here's an example from the zlib module:

function Gzip(opts) {
  if (!(this instanceof Gzip))
    return new Gzip(opts);
  Zlib.call(this, opts, GZIP);
}

Not sure if the rest of this PR would end up being semver major anyway but this approach might be something to consider to do this class changeover in a less intrusive way.

@NatalieWolfe
Copy link
Contributor Author

@sehrope That only works for function based classes. When you use the ES6 class keyword, usage of new is enforced at the language level.

@sehrope
Copy link
Contributor

sehrope commented May 4, 2018

Ah good point. Nevermind!

@charmander
Copy link
Collaborator

charmander commented May 4, 2018

@brianc Sorry for the ambiguous wording; it =

I'm going to bundle this up with [https://github.com//pull/1503]

#1503 is a bugfix.

@brianc brianc mentioned this pull request May 7, 2018
@charmander charmander added this to the pg@8.0 milestone Jun 17, 2018
charmander added a commit to charmander/node-postgres that referenced this pull request Dec 6, 2019
in preparation for brianc#1541. `eval` is a bit awkward, but it’s more accurate than an `instanceof` check and will work on platforms new enough to support pg 8 (i.e. only not Node 4).
charmander added a commit to charmander/node-postgres that referenced this pull request Dec 6, 2019
in preparation for brianc#1541. `eval` is a bit awkward, but it’s more accurate than an `instanceof` check and will work on platforms new enough to support pg 8 (i.e. only not Node 4).
charmander added a commit to charmander/node-postgres that referenced this pull request Dec 6, 2019
in preparation for brianc#1541. `eval` is a bit awkward, but it’s more accurate than an `instanceof` check and will work on platforms new enough to support pg 8 (i.e. only not Node 4).
brianc pushed a commit that referenced this pull request Dec 17, 2019
…2021)

* Warn when pg.Pool() isn’t called as a constructor

in preparation for #1541. `eval` is a bit awkward, but it’s more accurate than an `instanceof` check and will work on platforms new enough to support pg 8 (i.e. only not Node 4).

* Warn when Query() isn’t called as a constructor
@charmander charmander changed the base branch from master to bmc/8.0 January 15, 2020 20:12
@brianc brianc merged commit e3a35e9 into brianc:bmc/8.0 Jan 15, 2020
brianc added a commit that referenced this pull request Jan 28, 2020
* Use class-extends to wrap Pool

* Minimize diff

* Test `BoundPool` inheritance

Co-authored-by: Charmander <~@charmander.me>
Co-authored-by: Brian C <brian.m.carlson@gmail.com>
brianc added a commit that referenced this pull request Mar 30, 2020
* Drop support for EOL versions of node (#2062)

* Drop support for EOL versions of node

* Re-add testing for node@8.x

* Revert changes to .travis.yml

* Update packages/pg-pool/package.json

Co-Authored-By: Charmander <~@charmander.me>

Co-authored-by: Charmander <~@charmander.me>

* Remove password from stringified outputs (#2066)

* Remove password from stringified outputs

Theres a security concern where if you're not careful and you include your client or pool instance in console.log or stack traces it might include the database password.  To widen the pit of success I'm making that field non-enumerable.  You can still get at it...it just wont show up "by accident" when you're logging things now.

The backwards compatiblity impact of this is very small, but it is still technically somewhat an API change so...8.0.

* Implement feedback

* Fix more whitespace the autoformatter changed

* Simplify code a bit

* Remove password from stringified outputs (#2070)

* Keep ConnectionParameters’s password property writable

`Client` writes to it when `password` is a function.

* Avoid creating password property on pool options

when it didn’t exist previously.

* Allow password option to be non-enumerable

to avoid breaking uses like `new Pool(existingPool.options)`.

* Make password property definitions consistent

in formatting and configurability.

Co-authored-by: Charmander <~@charmander.me>

* Make `native` non-enumerable (#2065)

* Make `native` non-enumerable

Making it non-enumerable means less spurious "Cannot find module"
errors in your logs when iterating over `pg` objects.

`Object.defineProperty` has been available since Node 0.12.

See #1894 (comment)

* Add test for `native` enumeration

Co-authored-by: Gabe Gorelick <gabegorelick@gmail.com>

* Use class-extends to wrap Pool (#1541)

* Use class-extends to wrap Pool

* Minimize diff

* Test `BoundPool` inheritance

Co-authored-by: Charmander <~@charmander.me>
Co-authored-by: Brian C <brian.m.carlson@gmail.com>

* Continue support for creating a pg.Pool from another instance’s options (#2076)

* Add failing test for creating a `BoundPool` from another instance’s settings

* Continue support for creating a pg.Pool from another instance’s options

by dropping the requirement for the `password` property to be enumerable.

* Use user name as default database when user is non-default (#1679)

Not entirely backwards-compatible.

* Make native client password property consistent with others

i.e. configurable.

* Make notice messages not an instance of Error (#2090)

* Make notice messages not an instance of Error

Slight API cleanup to make a notice instance the same shape as it was, but not be an instance of error.  This is a backwards incompatible change though I expect the impact to be minimal.

Closes #1982

* skip notice test in travis

* Pin node@13.6 for regression in async iterators

* Check and see if node 13.8 is still borked on async iterator

* Yeah, node still has changed edge case behavior on stream

* Emit notice messages on travis

* Revert "Revert "Support additional tls.connect() options (#1996)" (#2010)" (#2113)

This reverts commit 510a273.

* Fix ssl tests (#2116)

* Convert Query to an ES6 class (#2126)

The last missing `new` deprecation warning for pg 8.

Co-authored-by: Charmander <~@charmander.me>
Co-authored-by: Gabe Gorelick <gabegorelick@gmail.com>
Co-authored-by: Natalie Wolfe <natalie@lifewanted.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants