From 4dbf1af06976ed6ea4f4c09b9caf620396be2de1 Mon Sep 17 00:00:00 2001 From: Jason Ford Date: Wed, 31 May 2023 23:03:50 -0700 Subject: [PATCH 001/171] Add note about case sensitivity of result of pg.escapeIdentifier (#2993) --- docs/pages/apis/utilities.mdx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/pages/apis/utilities.mdx b/docs/pages/apis/utilities.mdx index d33718081..921cba8e4 100644 --- a/docs/pages/apis/utilities.mdx +++ b/docs/pages/apis/utilities.mdx @@ -14,6 +14,9 @@ const escapedIdentifier = escapeIdentifier('FooIdentifier') console.log(escapedIdentifier) // '"FooIdentifier"' ``` + + **Note**: When using an identifier that is the result of this function in an operation like `CREATE TABLE ${escapedIdentifier(identifier)}`, the table that is created will be CASE SENSITIVE. If you use any capital letters in the escaped identifier, you must always refer to the created table like `SELECT * from "MyCaseSensitiveTable"`; queries like `SELECT * FROM MyCaseSensitiveTable` will result in a "Non-existent table" error since case information is stripped from the query. + ### pg.escapeLiteral From e2d8fa2dc29001e6578c4b8f111708fa96b094d0 Mon Sep 17 00:00:00 2001 From: Riku Rauhala Date: Tue, 6 Jun 2023 00:01:47 +0300 Subject: [PATCH 002/171] Fix a typo in README.md (#3002) Change finanical to financial --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 967431358..35d338000 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ You can also follow me [@briancarlson](https://twitter.com/briancarlson) if that ## Sponsorship :two_hearts: -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). +node-postgres's continued development has been made possible in part by generous financial support from [the community](https://github.com/brianc/node-postgres/blob/master/SPONSORS.md). 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. From 46cfb25baf8fdba87f71c3888fcb0021eaf829d3 Mon Sep 17 00:00:00 2001 From: Filipe Correa Date: Mon, 12 Jun 2023 21:50:40 +0200 Subject: [PATCH 003/171] Remove await from client release (#3006) Co-authored-by: Filipe Correa --- docs/pages/features/pooling.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/features/pooling.mdx b/docs/pages/features/pooling.mdx index 1e4e0cde2..e5e36345c 100644 --- a/docs/pages/features/pooling.mdx +++ b/docs/pages/features/pooling.mdx @@ -43,7 +43,7 @@ const client = await pool.connect() const res = await client.query('SELECT * FROM users WHERE id = $1', [1]) console.log(res.rows[0]) -await client.release() +client.release() ``` From 735683c5cb41bcbf043c6490be4b7f38cfe3ac48 Mon Sep 17 00:00:00 2001 From: Arian Mirahmadi Date: Wed, 14 Jun 2023 00:52:04 +0330 Subject: [PATCH 004/171] Fix typo in project-structure.md (#3008) --- docs/pages/guides/project-structure.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/guides/project-structure.md b/docs/pages/guides/project-structure.md index 94dcc1a30..2c6464a9e 100644 --- a/docs/pages/guides/project-structure.md +++ b/docs/pages/guides/project-structure.md @@ -44,7 +44,7 @@ That's it. But now everywhere else in my application instead of requiring `pg` d import * as db from '../db.js' app.get('/:id', async (req, res, next) => { - const result = await db.query('SELECT * FROM users WHERE id = $1', [req.params.id] + const result = await db.query('SELECT * FROM users WHERE id = $1', [req.params.id]) res.send(result.rows[0]) }) From eaafac36dc8f4a13f1fecc9e3420d35559fd8e2b Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Mon, 26 Jun 2023 11:36:32 -0500 Subject: [PATCH 005/171] Publish - pg-cloudflare@1.1.1 - pg-connection-string@2.6.1 - pg-cursor@2.10.1 - pg-pool@3.6.1 - pg-query-stream@4.5.1 - pg@8.11.1 --- packages/pg-cloudflare/package.json | 2 +- packages/pg-connection-string/package.json | 2 +- packages/pg-cursor/package.json | 4 ++-- packages/pg-pool/package.json | 2 +- packages/pg-query-stream/package.json | 6 +++--- packages/pg/package.json | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/pg-cloudflare/package.json b/packages/pg-cloudflare/package.json index 73a3a976f..bafd59934 100644 --- a/packages/pg-cloudflare/package.json +++ b/packages/pg-cloudflare/package.json @@ -1,6 +1,6 @@ { "name": "pg-cloudflare", - "version": "1.1.0", + "version": "1.1.1", "description": "A socket implementation that can run on Cloudflare Workers using native TCP connections.", "main": "dist/empty.js", "types": "dist/index.d.ts", diff --git a/packages/pg-connection-string/package.json b/packages/pg-connection-string/package.json index 42ad3563d..fc24058ae 100644 --- a/packages/pg-connection-string/package.json +++ b/packages/pg-connection-string/package.json @@ -1,6 +1,6 @@ { "name": "pg-connection-string", - "version": "2.6.0", + "version": "2.6.1", "description": "Functions for dealing with a PostgresSQL connection string", "main": "./index.js", "types": "./index.d.ts", diff --git a/packages/pg-cursor/package.json b/packages/pg-cursor/package.json index b383df4f4..f6abe572c 100644 --- a/packages/pg-cursor/package.json +++ b/packages/pg-cursor/package.json @@ -1,6 +1,6 @@ { "name": "pg-cursor", - "version": "2.10.0", + "version": "2.10.1", "description": "Query cursor extension for node-postgres", "main": "index.js", "directories": { @@ -18,7 +18,7 @@ "license": "MIT", "devDependencies": { "mocha": "^7.1.2", - "pg": "^8.11.0" + "pg": "^8.11.1" }, "peerDependencies": { "pg": "^8" diff --git a/packages/pg-pool/package.json b/packages/pg-pool/package.json index 38b36708f..8c76bf6e3 100644 --- a/packages/pg-pool/package.json +++ b/packages/pg-pool/package.json @@ -1,6 +1,6 @@ { "name": "pg-pool", - "version": "3.6.0", + "version": "3.6.1", "description": "Connection pool for node-postgres", "main": "index.js", "directories": { diff --git a/packages/pg-query-stream/package.json b/packages/pg-query-stream/package.json index a9a956a2e..2e219e6de 100644 --- a/packages/pg-query-stream/package.json +++ b/packages/pg-query-stream/package.json @@ -1,6 +1,6 @@ { "name": "pg-query-stream", - "version": "4.5.0", + "version": "4.5.1", "description": "Postgres query result returned as readable stream", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -37,7 +37,7 @@ "concat-stream": "~1.0.1", "eslint-plugin-promise": "^6.0.1", "mocha": "^7.1.2", - "pg": "^8.11.0", + "pg": "^8.11.1", "stream-spec": "~0.3.5", "ts-node": "^8.5.4", "typescript": "^4.0.3" @@ -46,6 +46,6 @@ "pg": "^8" }, "dependencies": { - "pg-cursor": "^2.10.0" + "pg-cursor": "^2.10.1" } } diff --git a/packages/pg/package.json b/packages/pg/package.json index 5368739c7..e3fdc25e1 100644 --- a/packages/pg/package.json +++ b/packages/pg/package.json @@ -1,6 +1,6 @@ { "name": "pg", - "version": "8.11.0", + "version": "8.11.1", "description": "PostgreSQL client - pure javascript & libpq with the same API", "keywords": [ "database", @@ -22,8 +22,8 @@ "dependencies": { "buffer-writer": "2.0.0", "packet-reader": "1.0.0", - "pg-connection-string": "^2.6.0", - "pg-pool": "^3.6.0", + "pg-connection-string": "^2.6.1", + "pg-pool": "^3.6.1", "pg-protocol": "^1.6.0", "pg-types": "^2.1.0", "pgpass": "1.x" @@ -39,7 +39,7 @@ "wrangler": "^2.16.0" }, "optionalDependencies": { - "pg-cloudflare": "^1.1.0" + "pg-cloudflare": "^1.1.1" }, "peerDependencies": { "pg-native": ">=3.0.1" From d17da9e1d956c6657ea46f1a140f99b40dfa9327 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 7 Jul 2023 17:47:00 -0500 Subject: [PATCH 006/171] Bump prettier from 2.7.1 to 2.8.8 (#3024) Bumps [prettier](https://github.com/prettier/prettier) from 2.7.1 to 2.8.8. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.7.1...2.8.8) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index dfd9b0312..4fef90e1b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^3.1.4", "lerna": "^3.19.0", - "prettier": "2.7.1", + "prettier": "2.8.8", "typescript": "^4.0.3" }, "prettier": { diff --git a/yarn.lock b/yarn.lock index 736fe4d0d..89365571f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5595,10 +5595,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@2.7.1: - version "2.7.1" - resolved "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz" - integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== +prettier@2.8.8: + version "2.8.8" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da" + integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q== process-nextick-args@~2.0.0: version "2.0.1" From 8d211e2be8a1c6f103edd6c43b0b145068b31ede Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 7 Jul 2023 17:47:09 -0500 Subject: [PATCH 007/171] Bump workerd from 1.20230419.0 to 1.20230518.0 (#3023) Bumps [workerd](https://github.com/cloudflare/workerd) from 1.20230419.0 to 1.20230518.0. - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/RELEASE.md) - [Commits](https://github.com/cloudflare/workerd/compare/v1.20230419.0...v1.20230518.0) --- updated-dependencies: - dependency-name: workerd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/yarn.lock b/yarn.lock index 89365571f..3ce65f3c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -30,30 +30,30 @@ dependencies: mime "^3.0.0" -"@cloudflare/workerd-darwin-64@1.20230419.0": - version "1.20230419.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20230419.0.tgz#9af54bba42eed1679e6e052b7972525fe108f19f" - integrity sha512-d2yId8NOkbdEC81PV9fWvihFcysukjTZVkEeiBwne/8HXy80QDfp7nOCzBENUC5KexB2eJyEjMus9mL/QO9DFQ== - -"@cloudflare/workerd-darwin-arm64@1.20230419.0": - version "1.20230419.0" - resolved "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20230419.0.tgz" - integrity sha512-U3JdRPvMaHVjlAGslXb4Vlfk1iIGbzj1q5QU2ml6htQSuqZ2Ie5cPTPLsA+9LJPqOXcXYUgXUkY3AIDja2Mh9g== - -"@cloudflare/workerd-linux-64@1.20230419.0": - version "1.20230419.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20230419.0.tgz#cc096524250b0ea5872305e99012530908473d62" - integrity sha512-XssdB19TaiNh5tQMj+8gUafshVqlIkpleoekGEdzFzKotzPNkTn27E+DZ5HnavfSPMonjWTQYosDoPr5Hx3I0Q== - -"@cloudflare/workerd-linux-arm64@1.20230419.0": - version "1.20230419.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20230419.0.tgz#4ca82073f1da29f8a646c32e0673432a3312b2c4" - integrity sha512-fQ3wwGvQVWA8YtKsSio0VyWphoLUY3YSw6C7Gs0x6TuLBzO5XWN04IH9BDYlaQCtlBKQpVzzDC8dhIaKgMehLg== - -"@cloudflare/workerd-windows-64@1.20230419.0": - version "1.20230419.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20230419.0.tgz#bd6b8940039db788a644a9d3de17f1f039f4bd85" - integrity sha512-lbPIvpdd3j0V1Y8jOgnDiYgGrKFzm6IEXPCvG/ZPnQfYT3oGb/nkZ2aSGVQUVZUgaRMbTWPegdIzTmn1OvRVMA== +"@cloudflare/workerd-darwin-64@1.20230518.0": + version "1.20230518.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20230518.0.tgz#d2c951670e11fa9263311dbb64d87c859cb88264" + integrity sha512-reApIf2/do6GjLlajU6LbRYh8gm/XcaRtzGbF8jo5IzyDSsdStmfNuvq7qssZXG92219Yp1kuTgR9+D1GGZGbg== + +"@cloudflare/workerd-darwin-arm64@1.20230518.0": + version "1.20230518.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20230518.0.tgz#ca8422ada85583426fef2bd882da188e23d1ca3b" + integrity sha512-1l+xdbmPddqb2YIHd1YJ3YG/Fl1nhayzcxfL30xfNS89zJn9Xn3JomM0XMD4mk0d5GruBP3q8BQZ1Uo4rRLF3A== + +"@cloudflare/workerd-linux-64@1.20230518.0": + version "1.20230518.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20230518.0.tgz#cc4039db047683866f5cd70b2d24d62548f36b31" + integrity sha512-/pfR+YBpMOPr2cAlwjtInil0hRZjD8KX9LqK9JkfkEiaBH8CYhnJQcOdNHZI+3OjcY09JnQtEVC5xC4nbW7Bvw== + +"@cloudflare/workerd-linux-arm64@1.20230518.0": + version "1.20230518.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20230518.0.tgz#c0e5983492390c719ce6fbbb0241de8fa4a43d8c" + integrity sha512-q3HQvn3J4uEkE0cfDAGG8zqzSZrD47cavB/Tzv4mNutqwg6B4wL3ifjtGeB55tnP2K2KL0GVmX4tObcvpUF4BA== + +"@cloudflare/workerd-windows-64@1.20230518.0": + version "1.20230518.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20230518.0.tgz#d0dcf6b51a1b6593e1c70b04e001bebcf2b703c1" + integrity sha512-vNEHKS5gKKduNOBYtQjcBopAmFT1iScuPWMZa2nJboSjOB9I/5oiVsUpSyk5Y2ARyrohXNz0y8D7p87YzTASWw== "@cloudflare/workers-types@^4.20230404.0": version "4.20230404.0" @@ -7073,15 +7073,15 @@ wordwrap@^1.0.0: integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= workerd@^1.20230419.0: - version "1.20230419.0" - resolved "https://registry.npmjs.org/workerd/-/workerd-1.20230419.0.tgz" - integrity sha512-A4/PhSgBqlne16cha1s3P3g2tXVKk0uC9pFyNYZTUc2i6f/uv/LKApTo0pPsNde+yBsPYKdK52uaBoGSs20CfA== + version "1.20230518.0" + resolved "https://registry.yarnpkg.com/workerd/-/workerd-1.20230518.0.tgz#4eac4c4b25d859f6f3c8bd826ed57aec12ab08dd" + integrity sha512-VNmK0zoNZXrwEEx77O/oQDVUzzyDjf5kKKK8bty+FmKCd5EQJCpqi8NlRKWLGMyyYrKm86MFz0kAsreTEs7HHA== optionalDependencies: - "@cloudflare/workerd-darwin-64" "1.20230419.0" - "@cloudflare/workerd-darwin-arm64" "1.20230419.0" - "@cloudflare/workerd-linux-64" "1.20230419.0" - "@cloudflare/workerd-linux-arm64" "1.20230419.0" - "@cloudflare/workerd-windows-64" "1.20230419.0" + "@cloudflare/workerd-darwin-64" "1.20230518.0" + "@cloudflare/workerd-darwin-arm64" "1.20230518.0" + "@cloudflare/workerd-linux-64" "1.20230518.0" + "@cloudflare/workerd-linux-arm64" "1.20230518.0" + "@cloudflare/workerd-windows-64" "1.20230518.0" wrangler@^2.16.0: version "2.17.0" From 970804b6c110fab500da9db71d68d04e0ecea406 Mon Sep 17 00:00:00 2001 From: Riku Rauhala Date: Sat, 8 Jul 2023 01:47:35 +0300 Subject: [PATCH 008/171] Update pg-connection-string url in connecting.mdx (#3005) --- docs/pages/features/connecting.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/features/connecting.mdx b/docs/pages/features/connecting.mdx index 212af68fd..3745024ca 100644 --- a/docs/pages/features/connecting.mdx +++ b/docs/pages/features/connecting.mdx @@ -127,7 +127,7 @@ client = new Client({ ## Connection URI -You can initialize both a pool and a client with a connection string URI as well. This is common in environments like Heroku where the database connection string is supplied to your application dyno through an environment variable. Connection string parsing brought to you by [pg-connection-string](https://github.com/iceddev/pg-connection-string). +You can initialize both a pool and a client with a connection string URI as well. This is common in environments like Heroku where the database connection string is supplied to your application dyno through an environment variable. Connection string parsing brought to you by [pg-connection-string](https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string). ```js import { Pool, Client } from 'pg' From 3644730d2b06be57bcb8fb9007b5f4ca8b56da83 Mon Sep 17 00:00:00 2001 From: Ben Reinhart Date: Tue, 18 Jul 2023 17:01:07 -0700 Subject: [PATCH 009/171] Remove early return for non commonjs environments (#3033) --- packages/pg/lib/crypto/utils-webcrypto.js | 83 +++++++++++++++++++++ packages/pg/lib/crypto/utils.js | 87 +---------------------- 2 files changed, 85 insertions(+), 85 deletions(-) create mode 100644 packages/pg/lib/crypto/utils-webcrypto.js diff --git a/packages/pg/lib/crypto/utils-webcrypto.js b/packages/pg/lib/crypto/utils-webcrypto.js new file mode 100644 index 000000000..0433f010c --- /dev/null +++ b/packages/pg/lib/crypto/utils-webcrypto.js @@ -0,0 +1,83 @@ +const nodeCrypto = require('crypto') + +module.exports = { + postgresMd5PasswordHash, + randomBytes, + deriveKey, + sha256, + hmacSha256, + md5, +} + +/** + * The Web Crypto API - grabbed from the Node.js library or the global + * @type Crypto + */ +const webCrypto = nodeCrypto.webcrypto || globalThis.crypto +/** + * The SubtleCrypto API for low level crypto operations. + * @type SubtleCrypto + */ +const subtleCrypto = webCrypto.subtle +const textEncoder = new TextEncoder() + +/** + * + * @param {*} length + * @returns + */ +function randomBytes(length) { + return webCrypto.getRandomValues(Buffer.alloc(length)) +} + +async function md5(string) { + try { + return nodeCrypto.createHash('md5').update(string, 'utf-8').digest('hex') + } catch (e) { + // `createHash()` failed so we are probably not in Node.js, use the WebCrypto API instead. + // Note that the MD5 algorithm on WebCrypto is not available in Node.js. + // This is why we cannot just use WebCrypto in all environments. + const data = typeof string === 'string' ? textEncoder.encode(string) : string + const hash = await subtleCrypto.digest('MD5', data) + return Array.from(new Uint8Array(hash)) + .map((b) => b.toString(16).padStart(2, '0')) + .join('') + } +} + +// See AuthenticationMD5Password at https://www.postgresql.org/docs/current/static/protocol-flow.html +async function postgresMd5PasswordHash(user, password, salt) { + var inner = await md5(password + user) + var outer = await md5(Buffer.concat([Buffer.from(inner), salt])) + return 'md5' + outer +} + +/** + * Create a SHA-256 digest of the given data + * @param {Buffer} data + */ +async function sha256(text) { + return await subtleCrypto.digest('SHA-256', text) +} + +/** + * Sign the message with the given key + * @param {ArrayBuffer} keyBuffer + * @param {string} msg + */ +async function hmacSha256(keyBuffer, msg) { + const key = await subtleCrypto.importKey('raw', keyBuffer, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']) + return await subtleCrypto.sign('HMAC', key, textEncoder.encode(msg)) +} + +/** + * Derive a key from the password and salt + * @param {string} password + * @param {Uint8Array} salt + * @param {number} iterations + */ +async function deriveKey(password, salt, iterations) { + const key = await subtleCrypto.importKey('raw', textEncoder.encode(password), 'PBKDF2', false, ['deriveBits']) + const params = { name: 'PBKDF2', hash: 'SHA-256', salt: salt, iterations: iterations } + return await subtleCrypto.deriveBits(params, key, 32 * 8, ['deriveBits']) +} diff --git a/packages/pg/lib/crypto/utils.js b/packages/pg/lib/crypto/utils.js index ca2b821c6..efd019b83 100644 --- a/packages/pg/lib/crypto/utils.js +++ b/packages/pg/lib/crypto/utils.js @@ -4,89 +4,6 @@ const useLegacyCrypto = parseInt(process.versions && process.versions.node && pr if (useLegacyCrypto) { // We are on an old version of Node.js that requires legacy crypto utilities. module.exports = require('./utils-legacy') - return -} - -const nodeCrypto = require('crypto') - -module.exports = { - postgresMd5PasswordHash, - randomBytes, - deriveKey, - sha256, - hmacSha256, - md5, -} - -/** - * The Web Crypto API - grabbed from the Node.js library or the global - * @type Crypto - */ -const webCrypto = nodeCrypto.webcrypto || globalThis.crypto -/** - * The SubtleCrypto API for low level crypto operations. - * @type SubtleCrypto - */ -const subtleCrypto = webCrypto.subtle -const textEncoder = new TextEncoder() - -/** - * - * @param {*} length - * @returns - */ -function randomBytes(length) { - return webCrypto.getRandomValues(Buffer.alloc(length)) -} - -async function md5(string) { - try { - return nodeCrypto.createHash('md5').update(string, 'utf-8').digest('hex') - } catch (e) { - // `createHash()` failed so we are probably not in Node.js, use the WebCrypto API instead. - // Note that the MD5 algorithm on WebCrypto is not available in Node.js. - // This is why we cannot just use WebCrypto in all environments. - const data = typeof string === 'string' ? textEncoder.encode(string) : string - const hash = await subtleCrypto.digest('MD5', data) - return Array.from(new Uint8Array(hash)) - .map((b) => b.toString(16).padStart(2, '0')) - .join('') - } -} - -// See AuthenticationMD5Password at https://www.postgresql.org/docs/current/static/protocol-flow.html -async function postgresMd5PasswordHash(user, password, salt) { - var inner = await md5(password + user) - var outer = await md5(Buffer.concat([Buffer.from(inner), salt])) - return 'md5' + outer -} - -/** - * Create a SHA-256 digest of the given data - * @param {Buffer} data - */ -async function sha256(text) { - return await subtleCrypto.digest('SHA-256', text) -} - -/** - * Sign the message with the given key - * @param {ArrayBuffer} keyBuffer - * @param {string} msg - */ -async function hmacSha256(keyBuffer, msg) { - const key = await subtleCrypto.importKey('raw', keyBuffer, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']) - return await subtleCrypto.sign('HMAC', key, textEncoder.encode(msg)) -} - -/** - * Derive a key from the password and salt - * @param {string} password - * @param {Uint8Array} salt - * @param {number} iterations - */ -async function deriveKey(password, salt, iterations) { - const key = await subtleCrypto.importKey('raw', textEncoder.encode(password), 'PBKDF2', false, ['deriveBits']) - const params = { name: 'PBKDF2', hash: 'SHA-256', salt: salt, iterations: iterations } - return await subtleCrypto.deriveBits(params, key, 32 * 8, ['deriveBits']) +} else { + module.exports = require('./utils-webcrypto'); } From cf24ef28ee2134b63576afba341452f8adfb8a4d Mon Sep 17 00:00:00 2001 From: Rafi Shamim Date: Fri, 21 Jul 2023 12:57:02 -0400 Subject: [PATCH 010/171] pg-connection-string: avoid clobbering port from queryparams (#2833) If the connection string is something like: postgresql://demo:password@/postgres?host=localhost&port=26258 Then the port from the query parameters should be used. Previously, the parsing function would end up with a null port, and the default port would end up being used by the connecetion package. --- packages/pg-connection-string/index.js | 5 ++++- packages/pg-connection-string/test/parse.js | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/pg-connection-string/index.js b/packages/pg-connection-string/index.js index fc2052365..c7fc72a36 100644 --- a/packages/pg-connection-string/index.js +++ b/packages/pg-connection-string/index.js @@ -38,7 +38,6 @@ function parse(str) { config.user = config.user || decodeURIComponent(result.username) config.password = config.password || decodeURIComponent(result.password) - config.port = result.port if (result.protocol == 'socket:') { config.host = decodeURI(result.pathname) config.database = result.searchParams.get('db') @@ -53,6 +52,10 @@ function parse(str) { // Only prepend the hostname to the pathname if it is not a URL encoded Unix socket host. result.pathname = hostname + result.pathname } + if (!config.port) { + // Only set the port if there is no equivalent query param. + config.port = result.port + } const pathname = result.pathname.slice(1) || null config.database = pathname ? decodeURI(pathname) : null diff --git a/packages/pg-connection-string/test/parse.js b/packages/pg-connection-string/test/parse.js index 749717d03..375aae4aa 100644 --- a/packages/pg-connection-string/test/parse.js +++ b/packages/pg-connection-string/test/parse.js @@ -318,4 +318,10 @@ describe('parse', function () { var subject = parse(connectionString) subject.keepalives.should.equal('0') }) + + it('use the port specified in the query parameters', function () { + var connectionString = 'postgres:///?host=localhost&port=1234' + var subject = parse(connectionString) + subject.port.should.equal('1234') + }) }) From a2a355a6807bf75d92d7f0cb0f219588811a5356 Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Mon, 31 Jul 2023 22:36:33 -0500 Subject: [PATCH 011/171] Publish - pg-connection-string@2.6.2 - pg-cursor@2.10.2 - pg-query-stream@4.5.2 - pg@8.11.2 --- packages/pg-connection-string/package.json | 2 +- packages/pg-cursor/package.json | 4 ++-- packages/pg-query-stream/package.json | 6 +++--- packages/pg/package.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/pg-connection-string/package.json b/packages/pg-connection-string/package.json index fc24058ae..f1dba4720 100644 --- a/packages/pg-connection-string/package.json +++ b/packages/pg-connection-string/package.json @@ -1,6 +1,6 @@ { "name": "pg-connection-string", - "version": "2.6.1", + "version": "2.6.2", "description": "Functions for dealing with a PostgresSQL connection string", "main": "./index.js", "types": "./index.d.ts", diff --git a/packages/pg-cursor/package.json b/packages/pg-cursor/package.json index f6abe572c..dc5c20865 100644 --- a/packages/pg-cursor/package.json +++ b/packages/pg-cursor/package.json @@ -1,6 +1,6 @@ { "name": "pg-cursor", - "version": "2.10.1", + "version": "2.10.2", "description": "Query cursor extension for node-postgres", "main": "index.js", "directories": { @@ -18,7 +18,7 @@ "license": "MIT", "devDependencies": { "mocha": "^7.1.2", - "pg": "^8.11.1" + "pg": "^8.11.2" }, "peerDependencies": { "pg": "^8" diff --git a/packages/pg-query-stream/package.json b/packages/pg-query-stream/package.json index 2e219e6de..6c0837007 100644 --- a/packages/pg-query-stream/package.json +++ b/packages/pg-query-stream/package.json @@ -1,6 +1,6 @@ { "name": "pg-query-stream", - "version": "4.5.1", + "version": "4.5.2", "description": "Postgres query result returned as readable stream", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -37,7 +37,7 @@ "concat-stream": "~1.0.1", "eslint-plugin-promise": "^6.0.1", "mocha": "^7.1.2", - "pg": "^8.11.1", + "pg": "^8.11.2", "stream-spec": "~0.3.5", "ts-node": "^8.5.4", "typescript": "^4.0.3" @@ -46,6 +46,6 @@ "pg": "^8" }, "dependencies": { - "pg-cursor": "^2.10.1" + "pg-cursor": "^2.10.2" } } diff --git a/packages/pg/package.json b/packages/pg/package.json index e3fdc25e1..117bfc3f5 100644 --- a/packages/pg/package.json +++ b/packages/pg/package.json @@ -1,6 +1,6 @@ { "name": "pg", - "version": "8.11.1", + "version": "8.11.2", "description": "PostgreSQL client - pure javascript & libpq with the same API", "keywords": [ "database", @@ -22,7 +22,7 @@ "dependencies": { "buffer-writer": "2.0.0", "packet-reader": "1.0.0", - "pg-connection-string": "^2.6.1", + "pg-connection-string": "^2.6.2", "pg-pool": "^3.6.1", "pg-protocol": "^1.6.0", "pg-types": "^2.1.0", From 58865b2c04777e3f79d6a90df3ab83ca65382730 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 12 Aug 2023 08:52:37 -0700 Subject: [PATCH 012/171] Bump workerd from 1.20230518.0 to 1.20230724.0 (#3036) Bumps [workerd](https://github.com/cloudflare/workerd) from 1.20230518.0 to 1.20230724.0. - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/RELEASE.md) - [Commits](https://github.com/cloudflare/workerd/compare/v1.20230518.0...v1.20230724.0) --- updated-dependencies: - dependency-name: workerd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/yarn.lock b/yarn.lock index 3ce65f3c9..696e9901a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -30,30 +30,30 @@ dependencies: mime "^3.0.0" -"@cloudflare/workerd-darwin-64@1.20230518.0": - version "1.20230518.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20230518.0.tgz#d2c951670e11fa9263311dbb64d87c859cb88264" - integrity sha512-reApIf2/do6GjLlajU6LbRYh8gm/XcaRtzGbF8jo5IzyDSsdStmfNuvq7qssZXG92219Yp1kuTgR9+D1GGZGbg== - -"@cloudflare/workerd-darwin-arm64@1.20230518.0": - version "1.20230518.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20230518.0.tgz#ca8422ada85583426fef2bd882da188e23d1ca3b" - integrity sha512-1l+xdbmPddqb2YIHd1YJ3YG/Fl1nhayzcxfL30xfNS89zJn9Xn3JomM0XMD4mk0d5GruBP3q8BQZ1Uo4rRLF3A== - -"@cloudflare/workerd-linux-64@1.20230518.0": - version "1.20230518.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20230518.0.tgz#cc4039db047683866f5cd70b2d24d62548f36b31" - integrity sha512-/pfR+YBpMOPr2cAlwjtInil0hRZjD8KX9LqK9JkfkEiaBH8CYhnJQcOdNHZI+3OjcY09JnQtEVC5xC4nbW7Bvw== - -"@cloudflare/workerd-linux-arm64@1.20230518.0": - version "1.20230518.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20230518.0.tgz#c0e5983492390c719ce6fbbb0241de8fa4a43d8c" - integrity sha512-q3HQvn3J4uEkE0cfDAGG8zqzSZrD47cavB/Tzv4mNutqwg6B4wL3ifjtGeB55tnP2K2KL0GVmX4tObcvpUF4BA== - -"@cloudflare/workerd-windows-64@1.20230518.0": - version "1.20230518.0" - resolved "https://registry.yarnpkg.com/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20230518.0.tgz#d0dcf6b51a1b6593e1c70b04e001bebcf2b703c1" - integrity sha512-vNEHKS5gKKduNOBYtQjcBopAmFT1iScuPWMZa2nJboSjOB9I/5oiVsUpSyk5Y2ARyrohXNz0y8D7p87YzTASWw== +"@cloudflare/workerd-darwin-64@1.20230724.0": + version "1.20230724.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20230724.0.tgz#95ee1a709e0ba4c1a20b473c48ba595b7cd4f45b" + integrity sha512-DQmFZWHhs8waQFYRb/Z8QmbitAvBMXnbUMUentp+3lS4eCYI0/iurTaQDiz5+ldUn9FTxD+1XuYZlTHzVNxoHw== + +"@cloudflare/workerd-darwin-arm64@1.20230724.0": + version "1.20230724.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20230724.0.tgz#7a820d739248907b84de09fff338bd192066ec79" + integrity sha512-C7T0v/lMjEX7c4iROSZKgIF1eGw3+sj/gFpBD6xwxfbIcrKBjncMypeLQNpRTCdBQr1W3sNpg9jagwuVX5ByZQ== + +"@cloudflare/workerd-linux-64@1.20230724.0": + version "1.20230724.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20230724.0.tgz#016b04a4539dfad617872608e143dc1f075c6935" + integrity sha512-o0F/hj73UXOQwkPkYqZuIxpjG8gAs2eoAGqxX1HSIYRf7iUhfFcPrupwjqlNqf7Oo1h46M+sClSFjr/ZU/LCjg== + +"@cloudflare/workerd-linux-arm64@1.20230724.0": + version "1.20230724.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20230724.0.tgz#6c92b46e0acf1b942b8f9c1a8f58919ad8bfd9e0" + integrity sha512-UpzCoo7LOuPWxFPw84TZQTPIawIDQNSb3XnC6ffMjUH/FVwHmHdngIFZxW+xjLHKMIzGNAqSn3eRHekKgO3QqA== + +"@cloudflare/workerd-windows-64@1.20230724.0": + version "1.20230724.0" + resolved "https://registry.yarnpkg.com/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20230724.0.tgz#062eca390c7224eabbbf4fd811054ba5f09b55b2" + integrity sha512-wVpPNu19fnvgsD8V6NiGPSuET0bzKmgn3wJ6RwAwQA+GQ0hdDIDVYd13aImhgO6jLfQvkduCDxeZluGZ7PPojQ== "@cloudflare/workers-types@^4.20230404.0": version "4.20230404.0" @@ -7073,15 +7073,15 @@ wordwrap@^1.0.0: integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= workerd@^1.20230419.0: - version "1.20230518.0" - resolved "https://registry.yarnpkg.com/workerd/-/workerd-1.20230518.0.tgz#4eac4c4b25d859f6f3c8bd826ed57aec12ab08dd" - integrity sha512-VNmK0zoNZXrwEEx77O/oQDVUzzyDjf5kKKK8bty+FmKCd5EQJCpqi8NlRKWLGMyyYrKm86MFz0kAsreTEs7HHA== + version "1.20230724.0" + resolved "https://registry.yarnpkg.com/workerd/-/workerd-1.20230724.0.tgz#4334a471dda59793f636aff142331b10bbd5f227" + integrity sha512-++D7JqS4/dk7zvtGpk+i/7G9bZtEl6lTtgAsIoSSGR1qJAxxEu21ktm9+FH0EYh7uKfizuM5H9lrTsR+3u44PA== optionalDependencies: - "@cloudflare/workerd-darwin-64" "1.20230518.0" - "@cloudflare/workerd-darwin-arm64" "1.20230518.0" - "@cloudflare/workerd-linux-64" "1.20230518.0" - "@cloudflare/workerd-linux-arm64" "1.20230518.0" - "@cloudflare/workerd-windows-64" "1.20230518.0" + "@cloudflare/workerd-darwin-64" "1.20230724.0" + "@cloudflare/workerd-darwin-arm64" "1.20230724.0" + "@cloudflare/workerd-linux-64" "1.20230724.0" + "@cloudflare/workerd-linux-arm64" "1.20230724.0" + "@cloudflare/workerd-windows-64" "1.20230724.0" wrangler@^2.16.0: version "2.17.0" From b5c5e52aa06da916454f693944fedeb7cc3e9a18 Mon Sep 17 00:00:00 2001 From: Koen Date: Tue, 15 Aug 2023 17:42:54 +0200 Subject: [PATCH 013/171] Option to use pre-shaped result rows; fixes #3042 (#3043) * Add property usePrebuiltEmptyResultObjects to Query constructor which generates pre-shaped result rows * Remove option and test for prebuiltEmptyResultObject * Remove errorneously added newline * Move all logic for prebuilding objects to Result * Move prebuilding to addFields * Use a clone as clone-base --------- Co-authored-by: HZ111 / Dev2 --- packages/pg/lib/result.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/pg/lib/result.js b/packages/pg/lib/result.js index 350609743..187c0d016 100644 --- a/packages/pg/lib/result.js +++ b/packages/pg/lib/result.js @@ -21,6 +21,7 @@ class Result { if (this.rowAsArray) { this.parseRow = this._parseRowAsArray } + this._prebuiltEmptyResultObject = null } // adds a command complete message @@ -60,14 +61,12 @@ class Result { } parseRow(rowData) { - var row = {} + var row = { ... this._prebuiltEmptyResultObject } for (var i = 0, len = rowData.length; i < len; i++) { var rawValue = rowData[i] var field = this.fields[i].name if (rawValue !== null) { row[field] = this._parsers[i](rawValue) - } else { - row[field] = null } } return row @@ -94,6 +93,14 @@ class Result { this._parsers[i] = types.getTypeParser(desc.dataTypeID, desc.format || 'text') } } + this._createPrebuiltEmptyResultObject() + } + _createPrebuiltEmptyResultObject() { + var row = {} + for (var i = 0; i < this.fields.length; i++) { + row[this.fields[i].name] = null + } + this._prebuiltEmptyResultObject = { ... row } } } From a84ebb3fe85edafb1b358965bdb5e3de58b12c5d Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Wed, 16 Aug 2023 16:50:05 -0700 Subject: [PATCH 014/171] Publish - pg-cursor@2.10.3 - pg-query-stream@4.5.3 - pg@8.11.3 --- packages/pg-cursor/package.json | 4 ++-- packages/pg-query-stream/package.json | 6 +++--- packages/pg/package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/pg-cursor/package.json b/packages/pg-cursor/package.json index dc5c20865..658dc8069 100644 --- a/packages/pg-cursor/package.json +++ b/packages/pg-cursor/package.json @@ -1,6 +1,6 @@ { "name": "pg-cursor", - "version": "2.10.2", + "version": "2.10.3", "description": "Query cursor extension for node-postgres", "main": "index.js", "directories": { @@ -18,7 +18,7 @@ "license": "MIT", "devDependencies": { "mocha": "^7.1.2", - "pg": "^8.11.2" + "pg": "^8.11.3" }, "peerDependencies": { "pg": "^8" diff --git a/packages/pg-query-stream/package.json b/packages/pg-query-stream/package.json index 6c0837007..295444615 100644 --- a/packages/pg-query-stream/package.json +++ b/packages/pg-query-stream/package.json @@ -1,6 +1,6 @@ { "name": "pg-query-stream", - "version": "4.5.2", + "version": "4.5.3", "description": "Postgres query result returned as readable stream", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -37,7 +37,7 @@ "concat-stream": "~1.0.1", "eslint-plugin-promise": "^6.0.1", "mocha": "^7.1.2", - "pg": "^8.11.2", + "pg": "^8.11.3", "stream-spec": "~0.3.5", "ts-node": "^8.5.4", "typescript": "^4.0.3" @@ -46,6 +46,6 @@ "pg": "^8" }, "dependencies": { - "pg-cursor": "^2.10.2" + "pg-cursor": "^2.10.3" } } diff --git a/packages/pg/package.json b/packages/pg/package.json index 117bfc3f5..ad46e75b9 100644 --- a/packages/pg/package.json +++ b/packages/pg/package.json @@ -1,6 +1,6 @@ { "name": "pg", - "version": "8.11.2", + "version": "8.11.3", "description": "PostgreSQL client - pure javascript & libpq with the same API", "keywords": [ "database", From 106ca8a1786dd9a3b6c790b6643f235be69f9106 Mon Sep 17 00:00:00 2001 From: Sehrope Sarkuni Date: Thu, 14 Sep 2023 15:43:14 -0400 Subject: [PATCH 015/171] Fix get value of last column with same name in result rows (#3063) * Add failing test for result rows with the same column names * Fix handling of duplicate column names in results to ensure last value is populated Fixes handling of result rows that have the same column name duplicated in the results to ensure that the last value is the one returned to the user. This was the old behavior but unintentionally broken when the pre-built object optimization was added. --- packages/pg/lib/result.js | 2 ++ .../test/integration/gh-issues/3062-tests.js | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 packages/pg/test/integration/gh-issues/3062-tests.js diff --git a/packages/pg/lib/result.js b/packages/pg/lib/result.js index 187c0d016..f9053c7a9 100644 --- a/packages/pg/lib/result.js +++ b/packages/pg/lib/result.js @@ -67,6 +67,8 @@ class Result { var field = this.fields[i].name if (rawValue !== null) { row[field] = this._parsers[i](rawValue) + } else { + row[field] = null } } return row diff --git a/packages/pg/test/integration/gh-issues/3062-tests.js b/packages/pg/test/integration/gh-issues/3062-tests.js new file mode 100644 index 000000000..7666751ed --- /dev/null +++ b/packages/pg/test/integration/gh-issues/3062-tests.js @@ -0,0 +1,21 @@ +'use strict' +const helper = require('../test-helper') +var assert = require('assert') +const suite = new helper.Suite() + +// https://github.com/brianc/node-postgres/issues/3062 +suite.testAsync('result fields with the same name should pick the last value', async () => { + const client = new helper.pg.Client() + await client.connect() + + const { rows: [shouldBeNullRow] } = await client.query('SELECT NULL AS test, 10 AS test, NULL AS test') + assert.equal(shouldBeNullRow.test, null) + + const { rows: [shouldBeTwelveRow] } = await client.query('SELECT NULL AS test, 10 AS test, 12 AS test') + assert.equal(shouldBeTwelveRow.test, 12) + + const { rows: [shouldBeAbcRow] } = await client.query(`SELECT NULL AS test, 10 AS test, 12 AS test, 'ABC' AS test`) + assert.equal(shouldBeAbcRow.test, 'ABC') + + await client.end() +}) From da0f5c5eb251853c5f99939433bbed33451c5989 Mon Sep 17 00:00:00 2001 From: Brian C Date: Fri, 15 Sep 2023 16:21:45 -0500 Subject: [PATCH 016/171] Remove 1 loop on rowDescription event (#3056) * Remove 1 loop on rowDescription event * Update packages/pg/lib/result.js Co-authored-by: Charmander <~@charmander.me> --------- Co-authored-by: Charmander <~@charmander.me> --- packages/pg/lib/result.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/pg/lib/result.js b/packages/pg/lib/result.js index f9053c7a9..98018a7d8 100644 --- a/packages/pg/lib/result.js +++ b/packages/pg/lib/result.js @@ -61,7 +61,7 @@ class Result { } parseRow(rowData) { - var row = { ... this._prebuiltEmptyResultObject } + var row = { ...this._prebuiltEmptyResultObject } for (var i = 0, len = rowData.length; i < len; i++) { var rawValue = rowData[i] var field = this.fields[i].name @@ -87,22 +87,20 @@ class Result { if (this.fields.length) { this._parsers = new Array(fieldDescriptions.length) } + + var row = {} + for (var i = 0; i < fieldDescriptions.length; i++) { var desc = fieldDescriptions[i] + row[desc.name] = null + if (this._types) { this._parsers[i] = this._types.getTypeParser(desc.dataTypeID, desc.format || 'text') } else { this._parsers[i] = types.getTypeParser(desc.dataTypeID, desc.format || 'text') } } - this._createPrebuiltEmptyResultObject() - } - _createPrebuiltEmptyResultObject() { - var row = {} - for (var i = 0; i < this.fields.length; i++) { - row[this.fields[i].name] = null - } - this._prebuiltEmptyResultObject = { ... row } + this._prebuiltEmptyResultObject = { ...row } } } From d21cc09556899b8038ec23613a801c19228637ca Mon Sep 17 00:00:00 2001 From: Sebastien Stettler Date: Fri, 15 Sep 2023 14:22:18 -0700 Subject: [PATCH 017/171] fix: conflict between browser URL object and Node URL object (#3061) I am running this package using electron, what i noticed was that due to the fact that the lines between node and browser environments become a bit blurred, the URL class that was being used was the one defined by the browser and not node. By making an explicit require it ensures the correct Class is used. While creating a test for this would be difficuilt i think adding an eslint rule to stop using globally defined objects and require imports instead would resolve issues like this in the future --- packages/pg-connection-string/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pg-connection-string/index.js b/packages/pg-connection-string/index.js index c7fc72a36..a005ffa20 100644 --- a/packages/pg-connection-string/index.js +++ b/packages/pg-connection-string/index.js @@ -1,9 +1,9 @@ 'use strict' - //Parse method copied from https://github.com/brianc/node-postgres //Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com) //MIT License +const { URL } = require('url') //parses a connection string function parse(str) { //unix socket From b1a8947738ce0af004cb926f79829bb2abc64aa6 Mon Sep 17 00:00:00 2001 From: Romain Gilliotte Date: Fri, 15 Sep 2023 23:23:05 +0200 Subject: [PATCH 018/171] Fail gracefully when connecting to other database (#3026) * Fail gracefully when connecting to other SGDB vendor * Make test more flexible. Adjust error wording to match native better. --------- Co-authored-by: Brian Carlson --- packages/pg-protocol/src/parser.ts | 2 +- .../test/integration/gh-issues/2627-tests.js | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 packages/pg/test/integration/gh-issues/2627-tests.js diff --git a/packages/pg-protocol/src/parser.ts b/packages/pg-protocol/src/parser.ts index f900193d7..1ad4e3abd 100644 --- a/packages/pg-protocol/src/parser.ts +++ b/packages/pg-protocol/src/parser.ts @@ -199,7 +199,7 @@ export class Parser { case MessageCodes.CopyData: return this.parseCopyData(offset, length, bytes) default: - assert.fail(`unknown message code: ${code.toString(16)}`) + return new DatabaseError('received invalid response: ' + code.toString(16), length, 'error') } } diff --git a/packages/pg/test/integration/gh-issues/2627-tests.js b/packages/pg/test/integration/gh-issues/2627-tests.js new file mode 100644 index 000000000..83e09b910 --- /dev/null +++ b/packages/pg/test/integration/gh-issues/2627-tests.js @@ -0,0 +1,63 @@ +'use strict' +const net = require('net') +const helper = require('./../test-helper') + +const suite = new helper.Suite() + +const options = { + host: 'localhost', + port: Math.floor(Math.random() * 2000) + 2000, + connectionTimeoutMillis: 2000, + user: 'not', + database: 'existing', +} + +// This is the content of the packets sent by a MySQL server during the handshake. +// Those were captured with the `mysql:8.0.33` docker image. +const MySqlHandshake = Buffer.from( + 'SgAAAAo4LjAuMjgAHwAAAB4dKyUJZ2p6AP///wIA/98VAAAAAAAAAAAA' + + 'AAo1YiNJajgKKGkpfgBjYWNoaW5nX3NoYTJfcGFzc3dvcmQAIQAAAf+EBC' + + 'MwOFMwMUdvdCBwYWNrZXRzIG91dCBvZiBvcmRlcg==', + 'base64' +) + +const serverWithInvalidResponse = (port, callback) => { + const sockets = new Set() + + const server = net.createServer((socket) => { + socket.write(MySqlHandshake) + + // This server sends an invalid response which should throw in pg-protocol + sockets.add(socket) + }) + + let closing = false + const closeServer = (done) => { + if (closing) return + closing = true + + server.close(done) + for (const socket of sockets) { + socket.destroy() + } + } + + server.listen(port, options.host, () => callback(closeServer)) +} + +suite.test('client should fail to connect', (done) => { + serverWithInvalidResponse(options.port, (closeServer) => { + const client = new helper.Client(options) + + client + .connect() + .then(() => { + done(new Error('Expected client.connect() to fail')) + }) + .catch((err) => { + assert(err) + assert(err.message.includes('invalid response')) + closeServer(done) + }) + }) +}) From b9a528cb3b62aa7de86a35467f8d3bbfb5457a56 Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Thu, 19 Oct 2023 18:27:11 +0300 Subject: [PATCH 019/171] eslintrc: update prettier base config (#3077) Co-authored-by: alxndrsn --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 4766b9889..bb77004ec 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "plugins": ["prettier"], "parser": "@typescript-eslint/parser", - "extends": ["plugin:prettier/recommended", "prettier/@typescript-eslint"], + "extends": ["plugin:prettier/recommended", "prettier"], "ignorePatterns": ["node_modules", "coverage", "packages/pg-protocol/dist/**/*", "packages/pg-query-stream/dist/**/*"], "parserOptions": { "ecmaVersion": 2017, From 16322c2d508d66c5a012b6e0ba2bf0e92c481966 Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Thu, 19 Oct 2023 18:27:25 +0300 Subject: [PATCH 020/171] Fix eslint violations (#3078) Co-authored-by: alxndrsn --- docs/theme.config.js | 5 ++- packages/pg-cursor/test/error-handling.js | 21 ++++++++++-- packages/pg-pool/index.js | 6 ++-- packages/pg-pool/test/idle-timeout-exit.js | 6 +++- packages/pg/bench.js | 3 +- packages/pg/lib/client.js | 6 ++-- packages/pg/lib/crypto/utils.js | 2 +- packages/pg/lib/native/client.js | 6 ++-- packages/pg/lib/query.js | 3 +- .../client/async-stack-trace-tests.js | 32 +++++++++---------- .../integration/client/sasl-scram-tests.js | 2 +- .../test/integration/gh-issues/3062-tests.js | 12 +++++-- .../test/integration/gh-issues/787-tests.js | 3 +- packages/pg/test/unit/client/escape-tests.js | 6 ++-- packages/pg/test/unit/utils-tests.js | 30 ++++++++++++++--- 15 files changed, 93 insertions(+), 50 deletions(-) diff --git a/docs/theme.config.js b/docs/theme.config.js index 00410f791..02e5327c3 100644 --- a/docs/theme.config.js +++ b/docs/theme.config.js @@ -30,7 +30,10 @@ export default { head: ( <> - +