pg 8.11.6 → 8.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -99,7 +99,6 @@ class Client extends EventEmitter {
99
99
  }
100
100
  this._connecting = true
101
101
 
102
- this.connectionTimeoutHandle
103
102
  if (this._connectionTimeoutMillis > 0) {
104
103
  this.connectionTimeoutHandle = setTimeout(() => {
105
104
  con._ending = true
@@ -378,11 +377,21 @@ class Client extends EventEmitter {
378
377
  }
379
378
 
380
379
  _handleCommandComplete(msg) {
380
+ if (this.activeQuery == null) {
381
+ const error = new Error('Received unexpected commandComplete message from backend.')
382
+ this._handleErrorEvent(error)
383
+ return
384
+ }
381
385
  // delegate commandComplete to active query
382
386
  this.activeQuery.handleCommandComplete(msg, this.connection)
383
387
  }
384
388
 
385
- _handleParseComplete(msg) {
389
+ _handleParseComplete() {
390
+ if (this.activeQuery == null) {
391
+ const error = new Error('Received unexpected parseComplete message from backend.')
392
+ this._handleErrorEvent(error)
393
+ return
394
+ }
386
395
  // if a prepared statement has a name and properly parses
387
396
  // we track that its already been executed so we don't parse
388
397
  // it again on the same client
@@ -515,7 +524,7 @@ class Client extends EventEmitter {
515
524
  query.callback = query.callback || values
516
525
  }
517
526
  } else {
518
- readTimeout = this.connectionParameters.query_timeout
527
+ readTimeout = config.query_timeout || this.connectionParameters.query_timeout
519
528
  query = new Query(config, values, callback)
520
529
  if (!query.callback) {
521
530
  result = new this._Promise((resolve, reject) => {
package/lib/connection.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
- var net = require('net')
4
3
  var EventEmitter = require('events').EventEmitter
5
4
 
6
5
  const { parse, serialize } = require('pg-protocol')
@@ -167,7 +167,7 @@ Client.prototype.query = function (config, values, callback) {
167
167
  config.callback = values
168
168
  }
169
169
  } else {
170
- readTimeout = this.connectionParameters.query_timeout
170
+ readTimeout = config.query_timeout || this.connectionParameters.query_timeout
171
171
  query = new NativeQuery(config, values, callback)
172
172
  if (!query.callback) {
173
173
  let resolveOut, rejectOut
@@ -10,6 +10,7 @@ var NativeQuery = (module.exports = function (config, values, callback) {
10
10
  this.text = config.text
11
11
  this.values = config.values
12
12
  this.name = config.name
13
+ this.queryMode = config.queryMode
13
14
  this.callback = config.callback
14
15
  this.state = 'new'
15
16
  this._arrayMode = config.rowMode === 'array'
@@ -159,6 +160,8 @@ NativeQuery.prototype.submit = function (client) {
159
160
  }
160
161
  var vals = this.values.map(utils.prepareValue)
161
162
  client.native.query(this.text, vals, after)
163
+ } else if (this.queryMode === 'extended') {
164
+ client.native.query(this.text, [], after)
162
165
  } else {
163
166
  client.native.query(this.text, after)
164
167
  }
package/lib/query.js CHANGED
@@ -16,6 +16,7 @@ class Query extends EventEmitter {
16
16
  this.rows = config.rows
17
17
  this.types = config.types
18
18
  this.name = config.name
19
+ this.queryMode = config.queryMode
19
20
  this.binary = config.binary
20
21
  // use unique portal name each time
21
22
  this.portal = config.portal || ''
@@ -32,6 +33,10 @@ class Query extends EventEmitter {
32
33
  }
33
34
 
34
35
  requiresPreparation() {
36
+ if (this.queryMode === 'extended') {
37
+ return true
38
+ }
39
+
35
40
  // named queries must always be prepared
36
41
  if (this.name) {
37
42
  return true
package/lib/stream.js CHANGED
@@ -1,28 +1,81 @@
1
+ const { getStream, getSecureStream } = getStreamFuncs()
2
+
3
+ module.exports = {
4
+ /**
5
+ * Get a socket stream compatible with the current runtime environment.
6
+ * @returns {Duplex}
7
+ */
8
+ getStream,
9
+ /**
10
+ * Get a TLS secured socket, compatible with the current environment,
11
+ * using the socket and other settings given in `options`.
12
+ * @returns {Duplex}
13
+ */
14
+ getSecureStream,
15
+ }
16
+
1
17
  /**
2
- * Get a socket stream compatible with the current runtime environment.
3
- * @returns {Duplex}
18
+ * The stream functions that work in Node.js
4
19
  */
5
- module.exports.getStream = function getStream(ssl) {
6
- const net = require('net')
7
- if (typeof net.Socket === 'function') {
20
+ function getNodejsStreamFuncs() {
21
+ function getStream(ssl) {
22
+ const net = require('net')
8
23
  return new net.Socket()
9
- } else {
10
- const { CloudflareSocket } = require('pg-cloudflare')
11
- return new CloudflareSocket(ssl)
24
+ }
25
+
26
+ function getSecureStream(options) {
27
+ var tls = require('tls')
28
+ return tls.connect(options)
29
+ }
30
+ return {
31
+ getStream,
32
+ getSecureStream,
12
33
  }
13
34
  }
14
35
 
15
36
  /**
16
- * Get a TLS secured socket, compatible with the current environment,
17
- * using the socket and other settings given in `options`.
18
- * @returns {Duplex}
37
+ * The stream functions that work in Cloudflare Workers
19
38
  */
20
- module.exports.getSecureStream = function getSecureStream(options) {
21
- var tls = require('tls')
22
- if (tls.connect) {
23
- return tls.connect(options)
24
- } else {
39
+ function getCloudflareStreamFuncs() {
40
+ function getStream(ssl) {
41
+ const { CloudflareSocket } = require('pg-cloudflare')
42
+ return new CloudflareSocket(ssl)
43
+ }
44
+
45
+ function getSecureStream(options) {
25
46
  options.socket.startTls(options)
26
47
  return options.socket
27
48
  }
49
+ return {
50
+ getStream,
51
+ getSecureStream,
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Are we running in a Cloudflare Worker?
57
+ *
58
+ * @returns true if the code is currently running inside a Cloudflare Worker.
59
+ */
60
+ function isCloudflareRuntime() {
61
+ // Since 2022-03-21 the `global_navigator` compatibility flag is on for Cloudflare Workers
62
+ // which means that `navigator.userAgent` will be defined.
63
+ if (typeof navigator === 'object' && navigator !== null && typeof navigator.userAgent === 'string') {
64
+ return navigator.userAgent === 'Cloudflare-Workers'
65
+ }
66
+ // In case `navigator` or `navigator.userAgent` is not defined then try a more sneaky approach
67
+ if (typeof Response === 'function') {
68
+ const resp = new Response(null, { cf: { thing: true } })
69
+ if (typeof resp.cf === 'object' && resp.cf !== null && resp.cf.thing) {
70
+ return true
71
+ }
72
+ }
73
+ return false
74
+ }
75
+
76
+ function getStreamFuncs() {
77
+ if (isCloudflareRuntime()) {
78
+ return getCloudflareStreamFuncs()
79
+ }
80
+ return getNodejsStreamFuncs()
28
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg",
3
- "version": "8.11.6",
3
+ "version": "8.13.0",
4
4
  "description": "PostgreSQL client - pure javascript & libpq with the same API",
5
5
  "keywords": [
6
6
  "database",
@@ -20,16 +20,16 @@
20
20
  "author": "Brian Carlson <brian.m.carlson@gmail.com>",
21
21
  "main": "./lib",
22
22
  "dependencies": {
23
- "pg-connection-string": "^2.6.4",
24
- "pg-pool": "^3.6.2",
25
- "pg-protocol": "^1.6.1",
23
+ "pg-connection-string": "^2.7.0",
24
+ "pg-pool": "^3.7.0",
25
+ "pg-protocol": "^1.7.0",
26
26
  "pg-types": "^2.1.0",
27
27
  "pgpass": "1.x"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@cloudflare/workers-types": "^4.20230404.0",
31
31
  "async": "2.6.4",
32
- "bluebird": "3.5.2",
32
+ "bluebird": "3.7.2",
33
33
  "co": "4.6.0",
34
34
  "pg-copy-streams": "0.3.0",
35
35
  "typescript": "^4.0.3",
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">= 8.0.0"
60
60
  },
61
- "gitHead": "2c3c6264db9d2c5d390a87c3ce958c6d71d444e1"
61
+ "gitHead": "92cb640fd316972e323ced6256b2acd89b1b58e0"
62
62
  }