pg 8.12.0 → 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 +12 -3
- package/lib/connection.js +0 -1
- package/lib/native/client.js +1 -1
- package/lib/stream.js +69 -16
- package/package.json +6 -6
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(
|
|
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
package/lib/native/client.js
CHANGED
|
@@ -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
|
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
|
-
*
|
|
3
|
-
* @returns {Duplex}
|
|
18
|
+
* The stream functions that work in Node.js
|
|
4
19
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
20
|
+
function getNodejsStreamFuncs() {
|
|
21
|
+
function getStream(ssl) {
|
|
22
|
+
const net = require('net')
|
|
8
23
|
return new net.Socket()
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
}
|
|
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.
|
|
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.
|
|
24
|
-
"pg-pool": "^3.
|
|
25
|
-
"pg-protocol": "^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.
|
|
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": "
|
|
61
|
+
"gitHead": "92cb640fd316972e323ced6256b2acd89b1b58e0"
|
|
62
62
|
}
|