Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: brianc/node-postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: pg@8.5.1
Choose a base ref
...
head repository: brianc/node-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: pg@8.6.0
Choose a head ref

Commits on Nov 27, 2020

  1. Fix typo (#2422)

    Co-authored-by: Wolfgang Walther <wolfgangwalther@users.noreply.github.com>
    sonicdoe and wolfgangwalther authored Nov 27, 2020
    Copy the full SHA
    c6aa29a View commit details

Commits on Nov 30, 2020

  1. Fix double readyForQuery (#2420)

    This is fixing a double readyForQuery message being sent from the backend (because we were calling sync after an error, which I already fixed in the main driver).  Also closes #2333
    brianc authored Nov 30, 2020
    Copy the full SHA
    4fde8b7 View commit details
  2. Update sponsors & readme

    brianc committed Nov 30, 2020
    Copy the full SHA
    5de36c7 View commit details
  3. Publish

     - pg-cursor@2.5.2
     - pg-query-stream@4.0.0
    brianc committed Nov 30, 2020
    Copy the full SHA
    fa4549a View commit details
  4. Update changelog for pg-query-stream

    Document the conversion to typescript as a semver major change. Closes #2412.
    brianc committed Nov 30, 2020
    Copy the full SHA
    54b8752 View commit details

Commits on Dec 3, 2020

  1. Copy the full SHA
    afb3bf3 View commit details

Commits on Dec 30, 2020

  1. Add more SASL validation and fix tests (#2436)

    * Add sha256 SASL helper
    
    * Rename internal createHMAC(...) to hmacSha256(...)
    
    * Add parseAttributePairs(...) helper for SASL
    
    * Tighten arg checks in SASL xorBuffers(...)
    
    * Add SASL nonce check for printable chars
    
    * Add SASL server salt and server signature base64 validation
    
    * Add check for non-empty SASL server nonce
    
    * Rename SASL helper to parseServerFirstMessage(...)
    
    * Add parameter validation to SASL continueSession(...)
    
    * Split out SASL final message parsing into parseServerFinalMessage(...)
    
    * Fix SCRAM tests
    
    Removes custom assert.throws(...) so that the real one from the assert package is used and
    fixes the SCRAM tests to reflect the updated error messages and actual checking of errors.
    
    Previously the custom assert.throws(...) was ignoring the error signature validation.
    sehrope authored Dec 30, 2020
    Copy the full SHA
    a109e8c View commit details
  2. Make tests pass in github codespaces (#2437)

    * Make tests pass in github codespaces
    
    There were a few tests which didn't specify a host or port which wasn't working well inside the codespaces docker environment.  Added host & port where required.  Also noticed one test wasn't actually _testing_, it was just `console.log`-ing its output, so I added proper assertions there.  Finally set `PGTESTNOSSL: true` in the codespaces environment until I can get the postgres docker container configured w/ SSL...which I will do l8r.
    
    * lint
    brianc authored Dec 30, 2020
    Copy the full SHA
    daeafe8 View commit details
  3. docs(README.md): add link to documentation repo (#2434)

    since it's currently the only way to look up documentation for old versions
    jedwards1211 authored Dec 30, 2020
    Copy the full SHA
    3f3f1a7 View commit details

Commits on Jan 19, 2021

  1. Fix typo (#2444)

    Jumpaku authored Jan 19, 2021
    Copy the full SHA
    fae2c98 View commit details

Commits on Jan 23, 2021

  1. Fix typo (#2442)

    6be3b90 added support for the `sslmode` parameter, not `ssl-mode`.
    sonicdoe authored Jan 23, 2021
    Copy the full SHA
    4bc5583 View commit details

Commits on Jan 27, 2021

  1. update license copyright year (#2450)

    updates license copyright year to 2021
    kaue authored Jan 27, 2021
    Copy the full SHA
    b4f61ad View commit details
  2. Bump ini from 1.3.5 to 1.3.8 (#2430)

    Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8.
    - [Release notes](https://github.com/isaacs/ini/releases)
    - [Commits](npm/ini@v1.3.5...v1.3.8)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 27, 2021
    Copy the full SHA
    4cb73eb View commit details

Commits on Jan 29, 2021

  1. Fix README to separate sponsors onto separate lines (#2459)

    Splits sponsor listings onto multiple lines by putting them in list elements.
    
    Also removes hidden inline png that does not render on the README.
    sehrope authored Jan 29, 2021
    Copy the full SHA
    25f658f View commit details

Commits on Mar 12, 2021

  1. Add missing metadata to package.jsons (#2487)

    Co-authored-by: Emily Marigold Klassen <forivall@users.noreply.github.com>
    forivall and forivall authored Mar 12, 2021
    Copy the full SHA
    5a41a56 View commit details
  2. Adding pg to peerDependencies (#2471)

    * Adding pg to peerDependencies
    
    Yarn2 requires strict imports, I.E. all project dependencies need to exist in that project's package.json.
    
    * pg version should be locked on the major version
    
    Co-authored-by: Charmander <~@charmander.me>
    
    Co-authored-by: Charmander <~@charmander.me>
    ed0wolf and charmander authored Mar 12, 2021
    Copy the full SHA
    2a7c614 View commit details
  3. Update SPONSORS.md

    brianc authored Mar 12, 2021
    Copy the full SHA
    61dfda7 View commit details
  4. Remove dead badge from readme

    brianc authored Mar 12, 2021
    Copy the full SHA
    69af1cc View commit details
  5. [pg-protocol] use literals instead of const enum (#2490)

    Co-authored-by: Emily Marigold Klassen <forivall@users.noreply.github.com>
    forivall and forivall authored Mar 12, 2021
    Copy the full SHA
    45fa27e View commit details

Commits on Mar 22, 2021

  1. pg: Re-export DatabaseError from 'pg-protocol' (#2445)

    * pg: Re-export DatabaseError from 'pg-protocol'
    
    Before, users would have to import DatabaseError from 'pg-protocol'.  If
    there are multiple versions of 'pg-protocol', you might end up using the
    wrong one.
    
    Closes #2378
    
    * Update error-handling-tests.js
    
    * Update query-error-handling-tests.js
    
    Co-authored-by: Brian C <brian.m.carlson@gmail.com>
    cakoose and brianc authored Mar 22, 2021
    Copy the full SHA
    4b22927 View commit details

Commits on Apr 2, 2021

  1. Copy the full SHA
    3dc79b6 View commit details

Commits on Apr 6, 2021

  1. Copy the full SHA
    6121bd3 View commit details

Commits on Apr 13, 2021

  1. Copy the full SHA
    d99b574 View commit details
  2. Copy the full SHA
    8faf8a0 View commit details
  3. Update changelog

    brianc committed Apr 13, 2021
    Copy the full SHA
    3115be6 View commit details
  4. Publish

     - pg-connection-string@2.5.0
     - pg-cursor@2.6.0
     - pg-pool@3.3.0
     - pg-protocol@1.5.0
     - pg-query-stream@4.1.0
     - pg@8.6.0
    brianc committed Apr 13, 2021
    Copy the full SHA
    d459479 View commit details
Showing with 468 additions and 181 deletions.
  1. +3 −0 .devcontainer/docker-compose.yml
  2. +12 −1 CHANGELOG.md
  3. +1 −1 LICENSE
  4. +12 −4 README.md
  5. +6 −0 SPONSORS.md
  6. +6 −1 packages/pg-connection-string/README.md
  7. +3 −2 packages/pg-connection-string/package.json
  8. +24 −6 packages/pg-cursor/index.js
  9. +7 −3 packages/pg-cursor/package.json
  10. +3 −2 packages/pg-pool/package.json
  11. +1 −1 packages/pg-protocol/README.md
  12. +6 −1 packages/pg-protocol/package.json
  13. +35 −0 packages/pg-protocol/src/inbound-parser.test.ts
  14. +54 −46 packages/pg-protocol/src/messages.ts
  15. +25 −13 packages/pg-protocol/src/parser.ts
  16. +10 −0 packages/pg-protocol/src/testing/test-buffers.ts
  17. +3 −7 packages/pg-query-stream/README.md
  18. +5 −5 packages/pg-query-stream/package.json
  19. +6 −3 packages/pg-query-stream/test/concat.ts
  20. +69 −0 packages/pg-query-stream/test/error.ts
  21. +5 −0 packages/pg/README.md
  22. +0 −1 packages/pg/lib/connection.js
  23. +2 −0 packages/pg/lib/index.js
  24. +110 −52 packages/pg/lib/sasl.js
  25. +6 −5 packages/pg/package.json
  26. +3 −1 packages/pg/test/integration/client/connection-parameter-tests.js
  27. +7 −0 packages/pg/test/integration/client/error-handling-tests.js
  28. +1 −1 packages/pg/test/integration/client/promise-api-tests.js
  29. +7 −0 packages/pg/test/integration/client/query-error-handling-tests.js
  30. +2 −2 packages/pg/test/integration/gh-issues/2079-tests.js
  31. +0 −10 packages/pg/test/test-helper.js
  32. +31 −10 packages/pg/test/unit/client/sasl-scram-tests.js
  33. +3 −3 yarn.lock
3 changes: 3 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -25,6 +25,9 @@ services:
PGUSER: user
PGDATABASE: data
PGHOST: db
# set this to true in the development environment until I can get SSL setup on the
# docker postgres instance
PGTESTNOSSL: true

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,17 @@ For richer information consult the commit log on github with referenced pull req

We do not include break-fix version release in this file.

### pg@8.6.0

- Better [SASL](https://github.com/brianc/node-postgres/pull/2436) error messages & more validation on bad configuration.
- Export [DatabaseError](https://github.com/brianc/node-postgres/pull/2445).
- Add [ParameterDescription](https://github.com/brianc/node-postgres/pull/2464) support to protocol parsing.
- Fix typescript [typedefs](https://github.com/brianc/node-postgres/pull/2490) with `--isolatedModules`.

### pg-query-stream@4.0.0

- Library has been [converted](https://github.com/brianc/node-postgres/pull/2376) to Typescript. The behavior is identical, but there could be subtle breaking changes due to class names changing or other small inconsistencies introduced by the conversion.

### pg@8.5.0

- Fix bug forwarding [ssl key](https://github.com/brianc/node-postgres/pull/2394).
@@ -14,7 +25,7 @@ We do not include break-fix version release in this file.

- Switch to optional peer dependencies & remove [semver](https://github.com/brianc/node-postgres/commit/a02dfac5ad2e2abf0dc3a9817f953938acdc19b1) package which has been a small thorn in the side of a few users.
- Export `DatabaseError` from [pg-protocol](https://github.com/brianc/node-postgres/commit/58258430d52ee446721cc3e6611e26f8bcaa67f5).
- Add support for `ssl-mode` in the [connection string](https://github.com/brianc/node-postgres/commit/6be3b9022f83efc721596cc41165afaa07bfceb0).
- Add support for `sslmode` in the [connection string](https://github.com/brianc/node-postgres/commit/6be3b9022f83efc721596cc41165afaa07bfceb0).

### pg@8.3.0

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2010 - 2020 Brian Carlson
Copyright (c) 2010 - 2021 Brian Carlson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# node-postgres

[![Build Status](https://secure.travis-ci.org/brianc/node-postgres.svg?branch=master)](http://travis-ci.org/brianc/node-postgres)
[![Dependency Status](https://david-dm.org/brianc/node-postgres.svg?path=packages/pg)](https://david-dm.org/brianc/node-postgres?path=packages/pg)
<span class="badge-npmversion"><a href="https://npmjs.org/package/pg" title="View this project on NPM"><img src="https://img.shields.io/npm/v/pg.svg" alt="NPM version" /></a></span>
<span class="badge-npmdownloads"><a href="https://npmjs.org/package/pg" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/pg.svg" alt="NPM downloads" /></a></span>

@@ -24,6 +23,8 @@ Each package in this repo should have its own readme more focused on how to deve

### :star: [Documentation](https://node-postgres.com) :star:

The source repo for the documentation is https://github.com/brianc/node-postgres-docs.

### Features

- Pure JavaScript client and native libpq bindings share _the same API_
@@ -57,9 +58,16 @@ You can also follow me [@briancarlson](https://twitter.com/briancarlson) if that
node-postgres's continued development has been made possible in part by generous finanical support from [the community](https://github.com/brianc/node-postgres/blob/master/SPONSORS.md) and these featured sponsors:

<div align="center">
<a href="https://crate.io" target="_blank">
<img height="80" src="https://node-postgres.com/crate-io.png" />
</a>
<p>
<a href="https://crate.io" target="_blank">
<img height="80" src="https://node-postgres.com/crate-io.png" />
</a>
</p>
<p>
<a href="https://www.eaze.com" target="_blank">
<img height="80" src="https://node-postgres.com/eaze.png" />
</a>
</p>
</div>

If you or your company are benefiting from node-postgres and would like to help keep the project financially sustainable [please consider supporting](https://github.com/sponsors/brianc) its development.
6 changes: 6 additions & 0 deletions SPONSORS.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@ node-postgres is made possible by the helpful contributors from the community as
- [CrateDB](https://crate.io/)
- [BitMEX](https://www.bitmex.com/app/trade/XBTUSD)
- [Dataform](https://dataform.co/)
- [Eaze](https://www.eaze.com/)
- [simpleanalytics](https://simpleanalytics.com/)
- [n8n.io]https://n8n.io/

# Supporters

@@ -34,3 +37,6 @@ node-postgres is made possible by the helpful contributors from the community as
- Trevor Linton
- Ian Walter
- @Guido4000
- [Martti Laine](https://github.com/codeclown)
- [Tim Nolet](https://github.com/tnolet)
- [checkly](https://github.com/checkly)
7 changes: 6 additions & 1 deletion packages/pg-connection-string/README.md
Original file line number Diff line number Diff line change
@@ -22,13 +22,14 @@ var config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')

The resulting config contains a subset of the following properties:

* `host` - Postgres server hostname or, for UNIX doamain sockets, the socket filename
* `host` - Postgres server hostname or, for UNIX domain sockets, the socket filename
* `port` - port on which to connect
* `user` - User with which to authenticate to the server
* `password` - Corresponding password
* `database` - Database name within the server
* `client_encoding` - string encoding the client will use
* `ssl`, either a boolean or an object with properties
* `rejectUnauthorized`
* `cert`
* `key`
* `ca`
@@ -65,6 +66,10 @@ Query parameters follow a `?` character, including the following special query p
* `host=<host>` - sets `host` property, overriding the URL's host
* `encoding=<encoding>` - sets the `client_encoding` property
* `ssl=1`, `ssl=true`, `ssl=0`, `ssl=false` - sets `ssl` to true or false, accordingly
* `sslmode=<sslmode>`
* `sslmode=disable` - sets `ssl` to false
* `sslmode=no-verify` - sets `ssl` to `{ rejectUnauthorized: false }`
* `sslmode=prefer`, `sslmode=require`, `sslmode=verify-ca`, `sslmode=verify-full` - sets `ssl` to true
* `sslcert=<filename>` - reads data from the given file and includes the result as `ssl.cert`
* `sslkey=<filename>` - reads data from the given file and includes the result as `ssl.key`
* `sslrootcert=<filename>` - reads data from the given file and includes the result as `ssl.ca`
5 changes: 3 additions & 2 deletions packages/pg-connection-string/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-connection-string",
"version": "2.4.0",
"version": "2.5.0",
"description": "Functions for dealing with a PostgresSQL connection string",
"main": "./index.js",
"types": "./index.d.ts",
@@ -11,7 +11,8 @@
},
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git"
"url": "git://github.com/brianc/node-postgres.git",
"directory": "packages/pg-connection-string"
},
"keywords": [
"pg",
30 changes: 24 additions & 6 deletions packages/pg-cursor/index.js
Original file line number Diff line number Diff line change
@@ -28,6 +28,9 @@ util.inherits(Cursor, EventEmitter)
Cursor.prototype._ifNoData = function () {
this.state = 'idle'
this._shiftQueue()
if (this.connection) {
this.connection.removeListener('rowDescription', this._rowDescription)
}
}

Cursor.prototype._rowDescription = function () {
@@ -37,6 +40,7 @@ Cursor.prototype._rowDescription = function () {
}

Cursor.prototype.submit = function (connection) {
this.state = 'submitted'
this.connection = connection
this._portal = 'C_' + nextUniqueID++

@@ -87,7 +91,12 @@ Cursor.prototype._closePortal = function () {
// open can lock tables for modification if inside a transaction.
// see https://github.com/brianc/node-pg-cursor/issues/56
this.connection.close({ type: 'P', name: this._portal })
this.connection.sync()

// If we've received an error we already sent a sync message.
// do not send another sync as it triggers another readyForQuery message.
if (this.state !== 'error') {
this.connection.sync()
}
}

Cursor.prototype.handleRowDescription = function (msg) {
@@ -138,8 +147,18 @@ Cursor.prototype.handleEmptyQuery = function () {
}

Cursor.prototype.handleError = function (msg) {
this.connection.removeListener('noData', this._ifNoData)
this.connection.removeListener('rowDescription', this._rowDescription)
// If we're in an initialized state we've never been submitted
// and don't have a connection instance reference yet.
// This can happen if you queue a stream and close the client before
// the client has submitted the stream. In this scenario we don't have
// a connection so there's nothing to unsubscribe from.
if (this.state !== 'initialized') {
this.connection.removeListener('noData', this._ifNoData)
this.connection.removeListener('rowDescription', this._rowDescription)
// call sync to trigger a readyForQuery
this.connection.sync()
}

this.state = 'error'
this._error = msg
// satisfy any waiting callback
@@ -155,8 +174,6 @@ Cursor.prototype.handleError = function (msg) {
// only dispatch error events if we have a listener
this.emit('error', msg)
}
// call sync to keep this connection from hanging
this.connection.sync()
}

Cursor.prototype._getRows = function (rows, cb) {
@@ -189,6 +206,7 @@ Cursor.prototype.close = function (cb) {
return
}
}

this._closePortal()
this.state = 'done'
if (cb) {
@@ -199,7 +217,7 @@ Cursor.prototype.close = function (cb) {
}

Cursor.prototype.read = function (rows, cb) {
if (this.state === 'idle') {
if (this.state === 'idle' || this.state === 'submitted') {
return this._getRows(rows, cb)
}
if (this.state === 'busy' || this.state === 'initialized') {
10 changes: 7 additions & 3 deletions packages/pg-cursor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-cursor",
"version": "2.5.1",
"version": "2.6.0",
"description": "Query cursor extension for node-postgres",
"main": "index.js",
"directories": {
@@ -11,12 +11,16 @@
},
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git"
"url": "git://github.com/brianc/node-postgres.git",
"directory": "packages/pg-cursor"
},
"author": "Brian M. Carlson",
"license": "MIT",
"devDependencies": {
"mocha": "^7.1.2",
"pg": "^8.5.1"
"pg": "^8.6.0"
},
"peerDependencies": {
"pg": "^8"
}
}
5 changes: 3 additions & 2 deletions packages/pg-pool/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-pool",
"version": "3.2.2",
"version": "3.3.0",
"description": "Connection pool for node-postgres",
"main": "index.js",
"directories": {
@@ -11,7 +11,8 @@
},
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git"
"url": "git://github.com/brianc/node-postgres.git",
"directory": "packages/pg-pool"
},
"keywords": [
"pg",
2 changes: 1 addition & 1 deletion packages/pg-protocol/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# pg-protocol

Low level postgres wire protocol parser and serailizer written in Typescript. Used by node-postgres. Needs more documentation. :smile:
Low level postgres wire protocol parser and serializer written in Typescript. Used by node-postgres. Needs more documentation. :smile:
7 changes: 6 additions & 1 deletion packages/pg-protocol/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-protocol",
"version": "1.4.0",
"version": "1.5.0",
"description": "The postgres client/server binary protocol, implemented in TypeScript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -22,6 +22,11 @@
"prepublish": "yarn build",
"pretest": "yarn build"
},
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git",
"directory": "packages/pg-protocol"
},
"files": [
"/dist/*{js,ts,map}",
"/src"
35 changes: 35 additions & 0 deletions packages/pg-protocol/src/inbound-parser.test.ts
Original file line number Diff line number Diff line change
@@ -144,6 +144,35 @@ var expectedTwoRowMessage = {
],
}

var emptyParameterDescriptionBuffer = new BufferList()
.addInt16(0) // number of parameters
.join(true, 't')

var oneParameterDescBuf = buffers.parameterDescription([1111])

var twoParameterDescBuf = buffers.parameterDescription([2222, 3333])

var expectedEmptyParameterDescriptionMessage = {
name: 'parameterDescription',
length: 6,
parameterCount: 0,
dataTypeIDs: [],
}

var expectedOneParameterMessage = {
name: 'parameterDescription',
length: 10,
parameterCount: 1,
dataTypeIDs: [1111],
}

var expectedTwoParameterMessage = {
name: 'parameterDescription',
length: 14,
parameterCount: 2,
dataTypeIDs: [2222, 3333],
}

var testForMessage = function (buffer: Buffer, expectedMessage: any) {
it('recieves and parses ' + expectedMessage.name, async () => {
const messages = await parseBuffers([buffer])
@@ -245,6 +274,12 @@ describe('PgPacketStream', function () {
testForMessage(twoRowBuf, expectedTwoRowMessage)
})

describe('parameterDescription messages', function () {
testForMessage(emptyParameterDescriptionBuffer, expectedEmptyParameterDescriptionMessage)
testForMessage(oneParameterDescBuf, expectedOneParameterMessage)
testForMessage(twoParameterDescBuf, expectedTwoParameterMessage)
})

describe('parsing rows', function () {
describe('parsing empty row', function () {
testForMessage(emptyRowFieldBuf, {
Loading