@steadybrew/postgresjs 4.5.0-rc1 → 4.5.1
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/README.md +71 -1690
- package/cf/src/connection.js +21 -5
- package/cf/src/errors.js +2 -2
- package/cf/src/index.js +6 -2
- package/cf/src/query.js +1 -0
- package/cf/src/types.js +2 -2
- package/cjs/src/connection.js +21 -5
- package/cjs/src/errors.js +2 -2
- package/cjs/src/index.js +6 -2
- package/cjs/src/query.js +1 -0
- package/cjs/src/types.js +2 -2
- package/docs/api.md +1609 -0
- package/package.json +4 -3
- package/src/connection.js +21 -5
- package/src/errors.js +2 -2
- package/src/index.js +6 -2
- package/src/query.js +1 -0
- package/src/types.js +2 -2
- package/types/index.d.ts +7 -1
package/cf/src/connection.js
CHANGED
|
@@ -106,6 +106,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
106
106
|
, hostIndex = 0
|
|
107
107
|
, length = 0
|
|
108
108
|
, rows = 0
|
|
109
|
+
, copyPaused = false
|
|
109
110
|
, serverSignature = null
|
|
110
111
|
, nextWriteTimer = null
|
|
111
112
|
, incomings = null
|
|
@@ -464,6 +465,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
464
465
|
query = results = errorResponse = chunk = nextWriteTimer = barrier = null
|
|
465
466
|
result = new Result()
|
|
466
467
|
rows = 0
|
|
468
|
+
copyPaused = false
|
|
467
469
|
nonce = serverSignature = null
|
|
468
470
|
}
|
|
469
471
|
|
|
@@ -686,6 +688,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
686
688
|
|
|
687
689
|
function errored(err) {
|
|
688
690
|
stream && (stream.destroy(err), stream = null)
|
|
691
|
+
resumeCopy()
|
|
689
692
|
query && queryError(query, err)
|
|
690
693
|
}
|
|
691
694
|
|
|
@@ -802,7 +805,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
802
805
|
query.prepared && retryRoutines.has(errorResponse.routine) && delete statements[query.signature]
|
|
803
806
|
query.retried
|
|
804
807
|
? errored(query.retried)
|
|
805
|
-
: query.prepared && retryRoutines.has(errorResponse.routine) && query.owner === connection.owner && !barrier
|
|
808
|
+
: query.prepared && retryRoutines.has(errorResponse.routine) && query.owner === connection.owner && !barrier && !query.cancelled
|
|
806
809
|
&& (x[5] !== 69 || endsAbortedState.test(query.string))
|
|
807
810
|
? retry(query, errorResponse)
|
|
808
811
|
: errored(errorResponse)
|
|
@@ -816,6 +819,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
816
819
|
|
|
817
820
|
query = results = errorResponse = null
|
|
818
821
|
result = new Result()
|
|
822
|
+
rows = 0
|
|
819
823
|
|
|
820
824
|
dispatch('ready')
|
|
821
825
|
}
|
|
@@ -1048,8 +1052,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1048
1052
|
|
|
1049
1053
|
function mismatchReason(x, xs) {
|
|
1050
1054
|
return (
|
|
1055
|
+
(x === 'read-write' && xs.in_hot_standby === 'on' && 'is a standby') ||
|
|
1051
1056
|
(x === 'read-write' && xs.default_transaction_read_only === 'on' && 'is read-only') ||
|
|
1052
|
-
(x === 'read-only' && xs.default_transaction_read_only === 'off' && 'is read-write') ||
|
|
1057
|
+
(x === 'read-only' && xs.in_hot_standby === 'off' && xs.default_transaction_read_only === 'off' && 'is read-write') ||
|
|
1053
1058
|
(x === 'primary' && xs.in_hot_standby === 'on' && 'is a standby') ||
|
|
1054
1059
|
(x === 'standby' && xs.in_hot_standby === 'off' && 'is a primary') ||
|
|
1055
1060
|
(x === 'prefer-standby' && xs.in_hot_standby === 'off' && standbyPass() && 'is a primary') ||
|
|
@@ -1148,7 +1153,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1148
1153
|
|
|
1149
1154
|
function CopyOutResponse() {
|
|
1150
1155
|
stream = new Stream.Readable({
|
|
1151
|
-
read() { socket.resume() }
|
|
1156
|
+
read() { copyPaused = false; socket.resume() }
|
|
1152
1157
|
})
|
|
1153
1158
|
query.resolve(stream)
|
|
1154
1159
|
connection.owner && connection.owner.next()
|
|
@@ -1158,7 +1163,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1158
1163
|
function CopyBothResponse() {
|
|
1159
1164
|
stream = new Stream.Duplex({
|
|
1160
1165
|
autoDestroy: true,
|
|
1161
|
-
read() { socket.resume() },
|
|
1166
|
+
read() { copyPaused = false; socket.resume() },
|
|
1162
1167
|
/* c8 ignore next 11 */
|
|
1163
1168
|
write(chunk, encoding, callback) {
|
|
1164
1169
|
socket.write(b().d().raw(chunk).end(), callback)
|
|
@@ -1178,12 +1183,23 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1178
1183
|
}
|
|
1179
1184
|
|
|
1180
1185
|
function CopyData(x) {
|
|
1181
|
-
stream &&
|
|
1186
|
+
if (stream && !stream.push(x.subarray(5))) {
|
|
1187
|
+
copyPaused = true
|
|
1188
|
+
socket.pause()
|
|
1189
|
+
}
|
|
1182
1190
|
}
|
|
1183
1191
|
|
|
1184
1192
|
function CopyDone() {
|
|
1185
1193
|
stream && stream.push(null)
|
|
1186
1194
|
stream = null
|
|
1195
|
+
resumeCopy()
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
function resumeCopy() {
|
|
1199
|
+
if (copyPaused) {
|
|
1200
|
+
copyPaused = false
|
|
1201
|
+
socket.resume()
|
|
1202
|
+
}
|
|
1187
1203
|
}
|
|
1188
1204
|
|
|
1189
1205
|
function NoticeResponse(x) {
|
package/cf/src/errors.js
CHANGED
package/cf/src/index.js
CHANGED
|
@@ -703,8 +703,8 @@ function parseOptions(a, b) {
|
|
|
703
703
|
...Object.entries(defaults).reduce(
|
|
704
704
|
(acc, [k, d]) => {
|
|
705
705
|
const value = k in o ? o[k] : k in query
|
|
706
|
-
? (query[k]
|
|
707
|
-
: env['PG' + k.toUpperCase()]
|
|
706
|
+
? off(query[k])
|
|
707
|
+
: env['PG' + k.toUpperCase()] ? off(env['PG' + k.toUpperCase()]) : d
|
|
708
708
|
acc[k] = typeof value === 'string' && ints.includes(k)
|
|
709
709
|
? +value
|
|
710
710
|
: value
|
|
@@ -737,6 +737,10 @@ function parseOptions(a, b) {
|
|
|
737
737
|
return options
|
|
738
738
|
}
|
|
739
739
|
|
|
740
|
+
function off(x) {
|
|
741
|
+
return x === 'disable' || x === 'false' ? false : x
|
|
742
|
+
}
|
|
743
|
+
|
|
740
744
|
function tsa(o, url, env) {
|
|
741
745
|
const x = o.target_session_attrs || url.searchParams.get('target_session_attrs') || env.PGTARGETSESSIONATTRS
|
|
742
746
|
if (!x || ['read-write', 'read-only', 'primary', 'standby', 'prefer-standby'].includes(x))
|
package/cf/src/query.js
CHANGED
|
@@ -55,6 +55,7 @@ export class Query extends Promise {
|
|
|
55
55
|
if (!this.canceller || this.settled)
|
|
56
56
|
return Promise.resolve()
|
|
57
57
|
|
|
58
|
+
Promise.prototype.then.call(this, undefined, () => undefined)
|
|
58
59
|
const cancelled = this.canceller(this)
|
|
59
60
|
this.canceller = null
|
|
60
61
|
cancelled.catch(() => undefined)
|
package/cf/src/types.js
CHANGED
|
@@ -347,14 +347,14 @@ function arrayParserLoop(s, x, parser, typarray) {
|
|
|
347
347
|
export const toCamel = x => {
|
|
348
348
|
let str = x[0]
|
|
349
349
|
for (let i = 1; i < x.length; i++)
|
|
350
|
-
str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
|
|
350
|
+
str += x[i] === '_' && i + 1 < x.length ? x[++i].toUpperCase() : x[i]
|
|
351
351
|
return str
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
export const toPascal = x => {
|
|
355
355
|
let str = x[0].toUpperCase()
|
|
356
356
|
for (let i = 1; i < x.length; i++)
|
|
357
|
-
str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
|
|
357
|
+
str += x[i] === '_' && i + 1 < x.length ? x[++i].toUpperCase() : x[i]
|
|
358
358
|
return str
|
|
359
359
|
}
|
|
360
360
|
|
package/cjs/src/connection.js
CHANGED
|
@@ -104,6 +104,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
104
104
|
, hostIndex = 0
|
|
105
105
|
, length = 0
|
|
106
106
|
, rows = 0
|
|
107
|
+
, copyPaused = false
|
|
107
108
|
, serverSignature = null
|
|
108
109
|
, nextWriteTimer = null
|
|
109
110
|
, incomings = null
|
|
@@ -462,6 +463,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
462
463
|
query = results = errorResponse = chunk = nextWriteTimer = barrier = null
|
|
463
464
|
result = new Result()
|
|
464
465
|
rows = 0
|
|
466
|
+
copyPaused = false
|
|
465
467
|
nonce = serverSignature = null
|
|
466
468
|
}
|
|
467
469
|
|
|
@@ -684,6 +686,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
684
686
|
|
|
685
687
|
function errored(err) {
|
|
686
688
|
stream && (stream.destroy(err), stream = null)
|
|
689
|
+
resumeCopy()
|
|
687
690
|
query && queryError(query, err)
|
|
688
691
|
}
|
|
689
692
|
|
|
@@ -800,7 +803,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
800
803
|
query.prepared && retryRoutines.has(errorResponse.routine) && delete statements[query.signature]
|
|
801
804
|
query.retried
|
|
802
805
|
? errored(query.retried)
|
|
803
|
-
: query.prepared && retryRoutines.has(errorResponse.routine) && query.owner === connection.owner && !barrier
|
|
806
|
+
: query.prepared && retryRoutines.has(errorResponse.routine) && query.owner === connection.owner && !barrier && !query.cancelled
|
|
804
807
|
&& (x[5] !== 69 || endsAbortedState.test(query.string))
|
|
805
808
|
? retry(query, errorResponse)
|
|
806
809
|
: errored(errorResponse)
|
|
@@ -814,6 +817,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
814
817
|
|
|
815
818
|
query = results = errorResponse = null
|
|
816
819
|
result = new Result()
|
|
820
|
+
rows = 0
|
|
817
821
|
|
|
818
822
|
dispatch('ready')
|
|
819
823
|
}
|
|
@@ -1046,8 +1050,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1046
1050
|
|
|
1047
1051
|
function mismatchReason(x, xs) {
|
|
1048
1052
|
return (
|
|
1053
|
+
(x === 'read-write' && xs.in_hot_standby === 'on' && 'is a standby') ||
|
|
1049
1054
|
(x === 'read-write' && xs.default_transaction_read_only === 'on' && 'is read-only') ||
|
|
1050
|
-
(x === 'read-only' && xs.default_transaction_read_only === 'off' && 'is read-write') ||
|
|
1055
|
+
(x === 'read-only' && xs.in_hot_standby === 'off' && xs.default_transaction_read_only === 'off' && 'is read-write') ||
|
|
1051
1056
|
(x === 'primary' && xs.in_hot_standby === 'on' && 'is a standby') ||
|
|
1052
1057
|
(x === 'standby' && xs.in_hot_standby === 'off' && 'is a primary') ||
|
|
1053
1058
|
(x === 'prefer-standby' && xs.in_hot_standby === 'off' && standbyPass() && 'is a primary') ||
|
|
@@ -1146,7 +1151,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1146
1151
|
|
|
1147
1152
|
function CopyOutResponse() {
|
|
1148
1153
|
stream = new Stream.Readable({
|
|
1149
|
-
read() { socket.resume() }
|
|
1154
|
+
read() { copyPaused = false; socket.resume() }
|
|
1150
1155
|
})
|
|
1151
1156
|
query.resolve(stream)
|
|
1152
1157
|
connection.owner && connection.owner.next()
|
|
@@ -1156,7 +1161,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1156
1161
|
function CopyBothResponse() {
|
|
1157
1162
|
stream = new Stream.Duplex({
|
|
1158
1163
|
autoDestroy: true,
|
|
1159
|
-
read() { socket.resume() },
|
|
1164
|
+
read() { copyPaused = false; socket.resume() },
|
|
1160
1165
|
/* c8 ignore next 11 */
|
|
1161
1166
|
write(chunk, encoding, callback) {
|
|
1162
1167
|
socket.write(b().d().raw(chunk).end(), callback)
|
|
@@ -1176,12 +1181,23 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
1176
1181
|
}
|
|
1177
1182
|
|
|
1178
1183
|
function CopyData(x) {
|
|
1179
|
-
stream &&
|
|
1184
|
+
if (stream && !stream.push(x.subarray(5))) {
|
|
1185
|
+
copyPaused = true
|
|
1186
|
+
socket.pause()
|
|
1187
|
+
}
|
|
1180
1188
|
}
|
|
1181
1189
|
|
|
1182
1190
|
function CopyDone() {
|
|
1183
1191
|
stream && stream.push(null)
|
|
1184
1192
|
stream = null
|
|
1193
|
+
resumeCopy()
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
function resumeCopy() {
|
|
1197
|
+
if (copyPaused) {
|
|
1198
|
+
copyPaused = false
|
|
1199
|
+
socket.resume()
|
|
1200
|
+
}
|
|
1185
1201
|
}
|
|
1186
1202
|
|
|
1187
1203
|
function NoticeResponse(x) {
|
package/cjs/src/errors.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const PostgresError = module.exports.PostgresError = class PostgresError extends Error {
|
|
2
2
|
constructor(x) {
|
|
3
|
-
super(x.message)
|
|
3
|
+
super(typeof x === 'string' ? x : x.message)
|
|
4
4
|
this.name = this.constructor.name
|
|
5
|
-
Object.assign(this, x)
|
|
5
|
+
typeof x === 'string' || Object.assign(this, x)
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
package/cjs/src/index.js
CHANGED
|
@@ -702,8 +702,8 @@ function parseOptions(a, b) {
|
|
|
702
702
|
...Object.entries(defaults).reduce(
|
|
703
703
|
(acc, [k, d]) => {
|
|
704
704
|
const value = k in o ? o[k] : k in query
|
|
705
|
-
? (query[k]
|
|
706
|
-
: env['PG' + k.toUpperCase()]
|
|
705
|
+
? off(query[k])
|
|
706
|
+
: env['PG' + k.toUpperCase()] ? off(env['PG' + k.toUpperCase()]) : d
|
|
707
707
|
acc[k] = typeof value === 'string' && ints.includes(k)
|
|
708
708
|
? +value
|
|
709
709
|
: value
|
|
@@ -736,6 +736,10 @@ function parseOptions(a, b) {
|
|
|
736
736
|
return options
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
+
function off(x) {
|
|
740
|
+
return x === 'disable' || x === 'false' ? false : x
|
|
741
|
+
}
|
|
742
|
+
|
|
739
743
|
function tsa(o, url, env) {
|
|
740
744
|
const x = o.target_session_attrs || url.searchParams.get('target_session_attrs') || env.PGTARGETSESSIONATTRS
|
|
741
745
|
if (!x || ['read-write', 'read-only', 'primary', 'standby', 'prefer-standby'].includes(x))
|
package/cjs/src/query.js
CHANGED
|
@@ -55,6 +55,7 @@ const Query = module.exports.Query = class Query extends Promise {
|
|
|
55
55
|
if (!this.canceller || this.settled)
|
|
56
56
|
return Promise.resolve()
|
|
57
57
|
|
|
58
|
+
Promise.prototype.then.call(this, undefined, () => undefined)
|
|
58
59
|
const cancelled = this.canceller(this)
|
|
59
60
|
this.canceller = null
|
|
60
61
|
cancelled.catch(() => undefined)
|
package/cjs/src/types.js
CHANGED
|
@@ -346,14 +346,14 @@ function arrayParserLoop(s, x, parser, typarray) {
|
|
|
346
346
|
const toCamel = module.exports.toCamel = x => {
|
|
347
347
|
let str = x[0]
|
|
348
348
|
for (let i = 1; i < x.length; i++)
|
|
349
|
-
str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
|
|
349
|
+
str += x[i] === '_' && i + 1 < x.length ? x[++i].toUpperCase() : x[i]
|
|
350
350
|
return str
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
const toPascal = module.exports.toPascal = x => {
|
|
354
354
|
let str = x[0].toUpperCase()
|
|
355
355
|
for (let i = 1; i < x.length; i++)
|
|
356
|
-
str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
|
|
356
|
+
str += x[i] === '_' && i + 1 < x.length ? x[++i].toUpperCase() : x[i]
|
|
357
357
|
return str
|
|
358
358
|
}
|
|
359
359
|
|