@tradejs/cli 2.0.4 → 2.0.6

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/dist/cli.js CHANGED
@@ -6,11 +6,20 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __esm = (fn, res) => function __init() {
10
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ var __esm = (fn, res, err) => function __init() {
10
+ if (err) throw err[0];
11
+ try {
12
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
13
+ } catch (e) {
14
+ throw err = [e], e;
15
+ }
11
16
  };
12
17
  var __commonJS = (cb, mod) => function __require() {
13
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
+ try {
19
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
+ } catch (e) {
21
+ throw mod = 0, e;
22
+ }
14
23
  };
15
24
  var __export = (target, all) => {
16
25
  for (var name in all)
@@ -934,9 +943,9 @@ Return a corrected unified diff only. Keep the same allowed paths.`
934
943
  }
935
944
  });
936
945
 
937
- // ../../node_modules/debug/node_modules/ms/index.js
946
+ // ../../node_modules/ms/index.js
938
947
  var require_ms = __commonJS({
939
- "../../node_modules/debug/node_modules/ms/index.js"(exports2, module2) {
948
+ "../../node_modules/ms/index.js"(exports2, module2) {
940
949
  "use strict";
941
950
  var s = 1e3;
942
951
  var m = s * 60;
@@ -1051,9 +1060,9 @@ var require_ms = __commonJS({
1051
1060
  }
1052
1061
  });
1053
1062
 
1054
- // ../../node_modules/debug/src/common.js
1063
+ // ../../node_modules/list-it/node_modules/debug/src/common.js
1055
1064
  var require_common = __commonJS({
1056
- "../../node_modules/debug/src/common.js"(exports2, module2) {
1065
+ "../../node_modules/list-it/node_modules/debug/src/common.js"(exports2, module2) {
1057
1066
  "use strict";
1058
1067
  function setup(env) {
1059
1068
  createDebug.debug = createDebug;
@@ -1155,50 +1164,64 @@ var require_common = __commonJS({
1155
1164
  createDebug.namespaces = namespaces;
1156
1165
  createDebug.names = [];
1157
1166
  createDebug.skips = [];
1158
- let i;
1159
- const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
1160
- const len = split.length;
1161
- for (i = 0; i < len; i++) {
1162
- if (!split[i]) {
1163
- continue;
1167
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
1168
+ for (const ns of split) {
1169
+ if (ns[0] === "-") {
1170
+ createDebug.skips.push(ns.slice(1));
1171
+ } else {
1172
+ createDebug.names.push(ns);
1164
1173
  }
1165
- namespaces = split[i].replace(/\*/g, ".*?");
1166
- if (namespaces[0] === "-") {
1167
- createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$"));
1174
+ }
1175
+ }
1176
+ function matchesTemplate(search, template) {
1177
+ let searchIndex = 0;
1178
+ let templateIndex = 0;
1179
+ let starIndex = -1;
1180
+ let matchIndex = 0;
1181
+ while (searchIndex < search.length) {
1182
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
1183
+ if (template[templateIndex] === "*") {
1184
+ starIndex = templateIndex;
1185
+ matchIndex = searchIndex;
1186
+ templateIndex++;
1187
+ } else {
1188
+ searchIndex++;
1189
+ templateIndex++;
1190
+ }
1191
+ } else if (starIndex !== -1) {
1192
+ templateIndex = starIndex + 1;
1193
+ matchIndex++;
1194
+ searchIndex = matchIndex;
1168
1195
  } else {
1169
- createDebug.names.push(new RegExp("^" + namespaces + "$"));
1196
+ return false;
1170
1197
  }
1171
1198
  }
1199
+ while (templateIndex < template.length && template[templateIndex] === "*") {
1200
+ templateIndex++;
1201
+ }
1202
+ return templateIndex === template.length;
1172
1203
  }
1173
1204
  function disable() {
1174
1205
  const namespaces = [
1175
- ...createDebug.names.map(toNamespace),
1176
- ...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)
1206
+ ...createDebug.names,
1207
+ ...createDebug.skips.map((namespace) => "-" + namespace)
1177
1208
  ].join(",");
1178
1209
  createDebug.enable("");
1179
1210
  return namespaces;
1180
1211
  }
1181
1212
  function enabled(name) {
1182
- if (name[name.length - 1] === "*") {
1183
- return true;
1184
- }
1185
- let i;
1186
- let len;
1187
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
1188
- if (createDebug.skips[i].test(name)) {
1213
+ for (const skip of createDebug.skips) {
1214
+ if (matchesTemplate(name, skip)) {
1189
1215
  return false;
1190
1216
  }
1191
1217
  }
1192
- for (i = 0, len = createDebug.names.length; i < len; i++) {
1193
- if (createDebug.names[i].test(name)) {
1218
+ for (const ns of createDebug.names) {
1219
+ if (matchesTemplate(name, ns)) {
1194
1220
  return true;
1195
1221
  }
1196
1222
  }
1197
1223
  return false;
1198
1224
  }
1199
- function toNamespace(regexp) {
1200
- return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
1201
- }
1202
1225
  function coerce(val) {
1203
1226
  if (val instanceof Error) {
1204
1227
  return val.stack || val.message;
@@ -1215,9 +1238,9 @@ var require_common = __commonJS({
1215
1238
  }
1216
1239
  });
1217
1240
 
1218
- // ../../node_modules/debug/src/browser.js
1241
+ // ../../node_modules/list-it/node_modules/debug/src/browser.js
1219
1242
  var require_browser = __commonJS({
1220
- "../../node_modules/debug/src/browser.js"(exports2, module2) {
1243
+ "../../node_modules/list-it/node_modules/debug/src/browser.js"(exports2, module2) {
1221
1244
  "use strict";
1222
1245
  exports2.formatArgs = formatArgs;
1223
1246
  exports2.save = save;
@@ -1318,10 +1341,11 @@ var require_browser = __commonJS({
1318
1341
  if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
1319
1342
  return false;
1320
1343
  }
1344
+ let m;
1321
1345
  return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
1322
1346
  typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
1323
1347
  // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
1324
- typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
1348
+ typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
1325
1349
  typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
1326
1350
  }
1327
1351
  function formatArgs(args30) {
@@ -1359,7 +1383,7 @@ var require_browser = __commonJS({
1359
1383
  function load() {
1360
1384
  let r;
1361
1385
  try {
1362
- r = exports2.storage.getItem("debug");
1386
+ r = exports2.storage.getItem("debug") || exports2.storage.getItem("DEBUG");
1363
1387
  } catch (error) {
1364
1388
  }
1365
1389
  if (!r && typeof process !== "undefined" && "env" in process) {
@@ -1406,21 +1430,19 @@ var require_supports_color = __commonJS({
1406
1430
  var tty = require("tty");
1407
1431
  var hasFlag = require_has_flag();
1408
1432
  var { env } = process;
1409
- var flagForceColor;
1433
+ var forceColor;
1410
1434
  if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
1411
- flagForceColor = 0;
1435
+ forceColor = 0;
1412
1436
  } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
1413
- flagForceColor = 1;
1437
+ forceColor = 1;
1414
1438
  }
1415
- function envForceColor() {
1416
- if ("FORCE_COLOR" in env) {
1417
- if (env.FORCE_COLOR === "true") {
1418
- return 1;
1419
- }
1420
- if (env.FORCE_COLOR === "false") {
1421
- return 0;
1422
- }
1423
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
1439
+ if ("FORCE_COLOR" in env) {
1440
+ if (env.FORCE_COLOR === "true") {
1441
+ forceColor = 1;
1442
+ } else if (env.FORCE_COLOR === "false") {
1443
+ forceColor = 0;
1444
+ } else {
1445
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
1424
1446
  }
1425
1447
  }
1426
1448
  function translateLevel(level) {
@@ -1434,22 +1456,15 @@ var require_supports_color = __commonJS({
1434
1456
  has16m: level >= 3
1435
1457
  };
1436
1458
  }
1437
- function supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
1438
- const noFlagForceColor = envForceColor();
1439
- if (noFlagForceColor !== void 0) {
1440
- flagForceColor = noFlagForceColor;
1441
- }
1442
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
1459
+ function supportsColor(haveStream, streamIsTTY) {
1443
1460
  if (forceColor === 0) {
1444
1461
  return 0;
1445
1462
  }
1446
- if (sniffFlags) {
1447
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
1448
- return 3;
1449
- }
1450
- if (hasFlag("color=256")) {
1451
- return 2;
1452
- }
1463
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
1464
+ return 3;
1465
+ }
1466
+ if (hasFlag("color=256")) {
1467
+ return 2;
1453
1468
  }
1454
1469
  if (haveStream && !streamIsTTY && forceColor === void 0) {
1455
1470
  return 0;
@@ -1466,7 +1481,7 @@ var require_supports_color = __commonJS({
1466
1481
  return 1;
1467
1482
  }
1468
1483
  if ("CI" in env) {
1469
- if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
1484
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
1470
1485
  return 1;
1471
1486
  }
1472
1487
  return min;
@@ -1478,7 +1493,7 @@ var require_supports_color = __commonJS({
1478
1493
  return 3;
1479
1494
  }
1480
1495
  if ("TERM_PROGRAM" in env) {
1481
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
1496
+ const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
1482
1497
  switch (env.TERM_PROGRAM) {
1483
1498
  case "iTerm.app":
1484
1499
  return version >= 3 ? 3 : 2;
@@ -1497,24 +1512,21 @@ var require_supports_color = __commonJS({
1497
1512
  }
1498
1513
  return min;
1499
1514
  }
1500
- function getSupportLevel(stream, options = {}) {
1501
- const level = supportsColor(stream, {
1502
- streamIsTTY: stream && stream.isTTY,
1503
- ...options
1504
- });
1515
+ function getSupportLevel(stream) {
1516
+ const level = supportsColor(stream, stream && stream.isTTY);
1505
1517
  return translateLevel(level);
1506
1518
  }
1507
1519
  module2.exports = {
1508
1520
  supportsColor: getSupportLevel,
1509
- stdout: getSupportLevel({ isTTY: tty.isatty(1) }),
1510
- stderr: getSupportLevel({ isTTY: tty.isatty(2) })
1521
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
1522
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
1511
1523
  };
1512
1524
  }
1513
1525
  });
1514
1526
 
1515
- // ../../node_modules/debug/src/node.js
1527
+ // ../../node_modules/list-it/node_modules/debug/src/node.js
1516
1528
  var require_node = __commonJS({
1517
- "../../node_modules/debug/src/node.js"(exports2, module2) {
1529
+ "../../node_modules/list-it/node_modules/debug/src/node.js"(exports2, module2) {
1518
1530
  "use strict";
1519
1531
  var tty = require("tty");
1520
1532
  var util = require("util");
@@ -1655,7 +1667,7 @@ var require_node = __commonJS({
1655
1667
  return (/* @__PURE__ */ new Date()).toISOString() + " ";
1656
1668
  }
1657
1669
  function log(...args30) {
1658
- return process.stderr.write(util.format(...args30) + "\n");
1670
+ return process.stderr.write(util.formatWithOptions(exports2.inspectOpts, ...args30) + "\n");
1659
1671
  }
1660
1672
  function save(namespaces) {
1661
1673
  if (namespaces) {
@@ -1687,9 +1699,9 @@ var require_node = __commonJS({
1687
1699
  }
1688
1700
  });
1689
1701
 
1690
- // ../../node_modules/debug/src/index.js
1702
+ // ../../node_modules/list-it/node_modules/debug/src/index.js
1691
1703
  var require_src = __commonJS({
1692
- "../../node_modules/debug/src/index.js"(exports2, module2) {
1704
+ "../../node_modules/list-it/node_modules/debug/src/index.js"(exports2, module2) {
1693
1705
  "use strict";
1694
1706
  if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
1695
1707
  module2.exports = require_browser();
@@ -14394,11 +14406,16 @@ var require_pg_types = __commonJS({
14394
14406
  var require_defaults = __commonJS({
14395
14407
  "../../node_modules/pg/lib/defaults.js"(exports2, module2) {
14396
14408
  "use strict";
14409
+ var user;
14410
+ try {
14411
+ user = process.platform === "win32" ? process.env.USERNAME : process.env.USER;
14412
+ } catch {
14413
+ }
14397
14414
  module2.exports = {
14398
14415
  // database host. defaults to localhost
14399
14416
  host: "localhost",
14400
14417
  // database user's name
14401
- user: process.platform === "win32" ? process.env.USERNAME : process.env.USER,
14418
+ user,
14402
14419
  // name of database to connect
14403
14420
  database: void 0,
14404
14421
  // database user's password
@@ -14423,6 +14440,8 @@ var require_defaults = __commonJS({
14423
14440
  idleTimeoutMillis: 3e4,
14424
14441
  client_encoding: "",
14425
14442
  ssl: false,
14443
+ // SSL negotiation style: 'postgres' (traditional SSLRequest) or 'direct'
14444
+ sslnegotiation: void 0,
14426
14445
  application_name: void 0,
14427
14446
  fallback_application_name: void 0,
14428
14447
  options: void 0,
@@ -14457,8 +14476,7 @@ var require_utils = __commonJS({
14457
14476
  "../../node_modules/pg/lib/utils.js"(exports2, module2) {
14458
14477
  "use strict";
14459
14478
  var defaults2 = require_defaults();
14460
- var util = require("util");
14461
- var { isDate } = util.types || util;
14479
+ var { isDate } = require("util/types");
14462
14480
  function escapeElement(elementRepresentation) {
14463
14481
  const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
14464
14482
  return '"' + escaped + '"';
@@ -14467,28 +14485,23 @@ var require_utils = __commonJS({
14467
14485
  let result = "{";
14468
14486
  for (let i = 0; i < val.length; i++) {
14469
14487
  if (i > 0) {
14470
- result = result + ",";
14471
- }
14472
- if (val[i] === null || typeof val[i] === "undefined") {
14473
- result = result + "NULL";
14474
- } else if (Array.isArray(val[i])) {
14475
- result = result + arrayString(val[i]);
14476
- } else if (ArrayBuffer.isView(val[i])) {
14477
- let item = val[i];
14488
+ result += ",";
14489
+ }
14490
+ let item = val[i];
14491
+ if (item == null) {
14492
+ result += "NULL";
14493
+ } else if (Array.isArray(item)) {
14494
+ result += arrayString(item);
14495
+ } else if (ArrayBuffer.isView(item)) {
14478
14496
  if (!(item instanceof Buffer)) {
14479
- const buf = Buffer.from(item.buffer, item.byteOffset, item.byteLength);
14480
- if (buf.length === item.byteLength) {
14481
- item = buf;
14482
- } else {
14483
- item = buf.slice(item.byteOffset, item.byteOffset + item.byteLength);
14484
- }
14497
+ item = Buffer.from(item.buffer, item.byteOffset, item.byteLength);
14485
14498
  }
14486
14499
  result += "\\\\x" + item.toString("hex");
14487
14500
  } else {
14488
- result += escapeElement(prepareValue(val[i]));
14501
+ result += escapeElement(prepareValue(item));
14489
14502
  }
14490
14503
  }
14491
- result = result + "}";
14504
+ result += "}";
14492
14505
  return result;
14493
14506
  }
14494
14507
  var prepareValue = function(val, seen) {
@@ -14500,11 +14513,7 @@ var require_utils = __commonJS({
14500
14513
  return val;
14501
14514
  }
14502
14515
  if (ArrayBuffer.isView(val)) {
14503
- const buf = Buffer.from(val.buffer, val.byteOffset, val.byteLength);
14504
- if (buf.length === val.byteLength) {
14505
- return buf;
14506
- }
14507
- return buf.slice(val.byteOffset, val.byteOffset + val.byteLength);
14516
+ return Buffer.from(val.buffer, val.byteOffset, val.byteLength);
14508
14517
  }
14509
14518
  if (isDate(val)) {
14510
14519
  if (defaults2.parseInputDatesAsUTC) {
@@ -14610,47 +14619,9 @@ var require_utils = __commonJS({
14610
14619
  }
14611
14620
  });
14612
14621
 
14613
- // ../../node_modules/pg/lib/crypto/utils-legacy.js
14614
- var require_utils_legacy = __commonJS({
14615
- "../../node_modules/pg/lib/crypto/utils-legacy.js"(exports2, module2) {
14616
- "use strict";
14617
- var nodeCrypto = require("crypto");
14618
- function md5(string) {
14619
- return nodeCrypto.createHash("md5").update(string, "utf-8").digest("hex");
14620
- }
14621
- function postgresMd5PasswordHash(user, password, salt) {
14622
- const inner = md5(password + user);
14623
- const outer = md5(Buffer.concat([Buffer.from(inner), salt]));
14624
- return "md5" + outer;
14625
- }
14626
- function sha256(text) {
14627
- return nodeCrypto.createHash("sha256").update(text).digest();
14628
- }
14629
- function hashByName(hashName, text) {
14630
- hashName = hashName.replace(/(\D)-/, "$1");
14631
- return nodeCrypto.createHash(hashName).update(text).digest();
14632
- }
14633
- function hmacSha256(key, msg) {
14634
- return nodeCrypto.createHmac("sha256", key).update(msg).digest();
14635
- }
14636
- async function deriveKey(password, salt, iterations) {
14637
- return nodeCrypto.pbkdf2Sync(password, salt, iterations, 32, "sha256");
14638
- }
14639
- module2.exports = {
14640
- postgresMd5PasswordHash,
14641
- randomBytes: nodeCrypto.randomBytes,
14642
- deriveKey,
14643
- sha256,
14644
- hashByName,
14645
- hmacSha256,
14646
- md5
14647
- };
14648
- }
14649
- });
14650
-
14651
- // ../../node_modules/pg/lib/crypto/utils-webcrypto.js
14652
- var require_utils_webcrypto = __commonJS({
14653
- "../../node_modules/pg/lib/crypto/utils-webcrypto.js"(exports2, module2) {
14622
+ // ../../node_modules/pg/lib/crypto/utils.js
14623
+ var require_utils2 = __commonJS({
14624
+ "../../node_modules/pg/lib/crypto/utils.js"(exports2, module2) {
14654
14625
  "use strict";
14655
14626
  var nodeCrypto = require("crypto");
14656
14627
  module2.exports = {
@@ -14700,19 +14671,6 @@ var require_utils_webcrypto = __commonJS({
14700
14671
  }
14701
14672
  });
14702
14673
 
14703
- // ../../node_modules/pg/lib/crypto/utils.js
14704
- var require_utils2 = __commonJS({
14705
- "../../node_modules/pg/lib/crypto/utils.js"(exports2, module2) {
14706
- "use strict";
14707
- var useLegacyCrypto = parseInt(process.versions && process.versions.node && process.versions.node.split(".")[0]) < 15;
14708
- if (useLegacyCrypto) {
14709
- module2.exports = require_utils_legacy();
14710
- } else {
14711
- module2.exports = require_utils_webcrypto();
14712
- }
14713
- }
14714
- });
14715
-
14716
14674
  // ../../node_modules/pg/lib/crypto/cert-signatures.js
14717
14675
  var require_cert_signatures = __commonJS({
14718
14676
  "../../node_modules/pg/lib/crypto/cert-signatures.js"(exports2, module2) {
@@ -14833,7 +14791,13 @@ var require_sasl = __commonJS({
14833
14791
  "use strict";
14834
14792
  var crypto = require_utils2();
14835
14793
  var { signatureAlgorithmHashFromCertificate } = require_cert_signatures();
14836
- function startSession(mechanisms, stream) {
14794
+ function saslprep(password) {
14795
+ const nonAsciiSpace = /[\u00A0\u1680\u2000-\u200B\u202F\u205F\u3000]/g;
14796
+ const mappedToNothing = /[\u00AD\u034F\u1806\u180B\u180C\u180D\u200C\u200D\u2060\uFE00-\uFE0F\uFEFF]/g;
14797
+ return password.replace(nonAsciiSpace, " ").replace(mappedToNothing, "").normalize("NFKC");
14798
+ }
14799
+ var DEFAULT_MAX_SCRAM_ITERATIONS = 1e5;
14800
+ function startSession(mechanisms, stream, scramMaxIterations = DEFAULT_MAX_SCRAM_ITERATIONS) {
14837
14801
  const candidates = ["SCRAM-SHA-256"];
14838
14802
  if (stream) candidates.unshift("SCRAM-SHA-256-PLUS");
14839
14803
  const mechanism = candidates.find((candidate) => mechanisms.includes(candidate));
@@ -14849,7 +14813,8 @@ var require_sasl = __commonJS({
14849
14813
  mechanism,
14850
14814
  clientNonce,
14851
14815
  response: gs2Header + ",,n=*,r=" + clientNonce,
14852
- message: "SASLInitialResponse"
14816
+ message: "SASLInitialResponse",
14817
+ scramMaxIterations
14853
14818
  };
14854
14819
  }
14855
14820
  async function continueSession(session, password, serverData, stream) {
@@ -14871,6 +14836,12 @@ var require_sasl = __commonJS({
14871
14836
  } else if (sv.nonce.length === session.clientNonce.length) {
14872
14837
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce is too short");
14873
14838
  }
14839
+ const scramMaxIterations = typeof session.scramMaxIterations === "number" ? session.scramMaxIterations : DEFAULT_MAX_SCRAM_ITERATIONS;
14840
+ if (scramMaxIterations !== 0 && sv.iteration > scramMaxIterations) {
14841
+ throw new Error(
14842
+ "SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration count " + sv.iteration + " exceeds scramMaxIterations of " + scramMaxIterations
14843
+ );
14844
+ }
14874
14845
  const clientFirstMessageBare = "n=*,r=" + session.clientNonce;
14875
14846
  const serverFirstMessage = "r=" + sv.nonce + ",s=" + sv.salt + ",i=" + sv.iteration;
14876
14847
  let channelBinding = stream ? "eSws" : "biws";
@@ -14885,7 +14856,7 @@ var require_sasl = __commonJS({
14885
14856
  const clientFinalMessageWithoutProof = "c=" + channelBinding + ",r=" + sv.nonce;
14886
14857
  const authMessage = clientFirstMessageBare + "," + serverFirstMessage + "," + clientFinalMessageWithoutProof;
14887
14858
  const saltBytes = Buffer.from(sv.salt, "base64");
14888
- const saltedPassword = await crypto.deriveKey(password, saltBytes, sv.iteration);
14859
+ const saltedPassword = await crypto.deriveKey(saslprep(password), saltBytes, sv.iteration);
14889
14860
  const clientKey = await crypto.hmacSha256(saltedPassword, "Client Key");
14890
14861
  const storedKey = await crypto.sha256(clientKey);
14891
14862
  const clientSignature = await crypto.hmacSha256(storedKey, authMessage);
@@ -14961,7 +14932,11 @@ var require_sasl = __commonJS({
14961
14932
  }
14962
14933
  function parseServerFinalMessage(serverData) {
14963
14934
  const attrPairs = parseAttributePairs(serverData);
14935
+ const error = attrPairs.get("e");
14964
14936
  const serverSignature = attrPairs.get("v");
14937
+ if (error) {
14938
+ throw new Error(`SASL: SCRAM-SERVER-FINAL-MESSAGE: server returned error: "${error}"`);
14939
+ }
14965
14940
  if (!serverSignature) {
14966
14941
  throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature is missing");
14967
14942
  } else if (!isBase64(serverSignature)) {
@@ -14989,7 +14964,8 @@ var require_sasl = __commonJS({
14989
14964
  module2.exports = {
14990
14965
  startSession,
14991
14966
  continueSession,
14992
- finalizeSession
14967
+ finalizeSession,
14968
+ DEFAULT_MAX_SCRAM_ITERATIONS
14993
14969
  };
14994
14970
  }
14995
14971
  });
@@ -15038,7 +15014,7 @@ var require_pg_connection_string = __commonJS({
15038
15014
  const config2 = str.split(" ");
15039
15015
  return { host: config2[0], database: config2[1] };
15040
15016
  }
15041
- const config = {};
15017
+ const config = /* @__PURE__ */ Object.create(null);
15042
15018
  let result;
15043
15019
  let dummyHost = false;
15044
15020
  if (/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {
@@ -15053,6 +15029,7 @@ var require_pg_connection_string = __commonJS({
15053
15029
  }
15054
15030
  } catch (err) {
15055
15031
  err.input && (err.input = "*****REDACTED*****");
15032
+ throw err;
15056
15033
  }
15057
15034
  for (const entry of result.searchParams.entries()) {
15058
15035
  config[entry[0]] = entry[1];
@@ -15085,6 +15062,9 @@ var require_pg_connection_string = __commonJS({
15085
15062
  if (config.sslcert || config.sslkey || config.sslrootcert || config.sslmode) {
15086
15063
  config.ssl = {};
15087
15064
  }
15065
+ if (config.sslnegotiation === "direct" && config.ssl === void 0) {
15066
+ config.ssl = true;
15067
+ }
15088
15068
  const fs17 = config.sslcert || config.sslkey || config.sslrootcert ? require("fs") : null;
15089
15069
  if (config.sslcert) {
15090
15070
  config.ssl.cert = fs17.readFileSync(config.sslcert).toString();
@@ -15141,6 +15121,9 @@ var require_pg_connection_string = __commonJS({
15141
15121
  case "require":
15142
15122
  case "verify-ca":
15143
15123
  case "verify-full": {
15124
+ if (config.sslmode !== "verify-full") {
15125
+ deprecatedSslModeWarning(config.sslmode);
15126
+ }
15144
15127
  break;
15145
15128
  }
15146
15129
  case "no-verify": {
@@ -15157,7 +15140,7 @@ var require_pg_connection_string = __commonJS({
15157
15140
  c[key] = value;
15158
15141
  }
15159
15142
  return c;
15160
- }, {});
15143
+ }, /* @__PURE__ */ Object.create(null));
15161
15144
  return connectionOptions;
15162
15145
  }
15163
15146
  function toClientConfig(config) {
@@ -15184,12 +15167,25 @@ var require_pg_connection_string = __commonJS({
15184
15167
  }
15185
15168
  }
15186
15169
  return c;
15187
- }, {});
15170
+ }, /* @__PURE__ */ Object.create(null));
15188
15171
  return poolConfig;
15189
15172
  }
15190
15173
  function parseIntoClientConfig(str) {
15191
15174
  return toClientConfig(parse(str));
15192
15175
  }
15176
+ function deprecatedSslModeWarning(sslmode) {
15177
+ if (!deprecatedSslModeWarning.warned && typeof process !== "undefined" && process.emitWarning) {
15178
+ deprecatedSslModeWarning.warned = true;
15179
+ process.emitWarning(`SECURITY WARNING: The SSL modes 'prefer', 'require', and 'verify-ca' are treated as aliases for 'verify-full'.
15180
+ In the next major version (pg-connection-string v3.0.0 and pg v9.0.0), these modes will adopt standard libpq semantics, which have weaker security guarantees.
15181
+
15182
+ To prepare for this change:
15183
+ - If you want the current behavior, explicitly use 'sslmode=verify-full'
15184
+ - If you want libpq compatibility now, use 'uselibpqcompat=true&sslmode=${sslmode}'
15185
+
15186
+ See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode definitions.`);
15187
+ }
15188
+ }
15193
15189
  module2.exports = parse;
15194
15190
  parse.parse = parse;
15195
15191
  parse.toClientConfig = toClientConfig;
@@ -15205,13 +15201,16 @@ var require_connection_parameters = __commonJS({
15205
15201
  var defaults2 = require_defaults();
15206
15202
  var parse = require_pg_connection_string().parse;
15207
15203
  var val = function(key, config, envVar) {
15204
+ if (config[key]) {
15205
+ return config[key];
15206
+ }
15208
15207
  if (envVar === void 0) {
15209
15208
  envVar = process.env["PG" + key.toUpperCase()];
15210
15209
  } else if (envVar === false) {
15211
15210
  } else {
15212
15211
  envVar = process.env[envVar];
15213
15212
  }
15214
- return config[key] || envVar || defaults2[key];
15213
+ return envVar || defaults2[key];
15215
15214
  };
15216
15215
  var readSSLConfigFromEnvironment = function() {
15217
15216
  switch (process.env.PGSSLMODE) {
@@ -15271,6 +15270,15 @@ var require_connection_parameters = __commonJS({
15271
15270
  enumerable: false
15272
15271
  });
15273
15272
  }
15273
+ this.sslnegotiation = val("sslnegotiation", config, "PGSSLNEGOTIATION");
15274
+ if (this.sslnegotiation !== void 0 && this.sslnegotiation !== "postgres" && this.sslnegotiation !== "direct") {
15275
+ throw new Error(
15276
+ `Invalid sslnegotiation value: "${this.sslnegotiation}". Valid values are "postgres" and "direct".`
15277
+ );
15278
+ }
15279
+ if (this.sslnegotiation === "direct" && !this.ssl) {
15280
+ throw new Error("sslnegotiation=direct requires SSL to be enabled");
15281
+ }
15274
15282
  this.client_encoding = val("client_encoding", config);
15275
15283
  this.replication = val("replication", config);
15276
15284
  this.isDomainSocket = !(this.host || "").indexOf("/");
@@ -15309,6 +15317,7 @@ var require_connection_parameters = __commonJS({
15309
15317
  add(params, ssl, "sslkey");
15310
15318
  add(params, ssl, "sslcert");
15311
15319
  add(params, ssl, "sslrootcert");
15320
+ add(params, this, "sslnegotiation");
15312
15321
  if (this.database) {
15313
15322
  params.push("dbname=" + quoteParamValue(this.database));
15314
15323
  }
@@ -15409,7 +15418,7 @@ var require_result = __commonJS({
15409
15418
  if (this.fields.length) {
15410
15419
  this._parsers = new Array(fieldDescriptions.length);
15411
15420
  }
15412
- const row = {};
15421
+ const row = /* @__PURE__ */ Object.create(null);
15413
15422
  for (let i = 0; i < fieldDescriptions.length; i++) {
15414
15423
  const desc = fieldDescriptions[i];
15415
15424
  row[desc.name] = null;
@@ -15604,6 +15613,8 @@ var require_query = __commonJS({
15604
15613
  valueMapper: utils.prepareValue
15605
15614
  });
15606
15615
  } catch (err) {
15616
+ connection.close({ type: "S", name: this.name });
15617
+ connection.sync();
15607
15618
  this.handleError(err, connection);
15608
15619
  return;
15609
15620
  }
@@ -15623,9 +15634,9 @@ var require_query = __commonJS({
15623
15634
  }
15624
15635
  });
15625
15636
 
15626
- // ../../node_modules/pg-protocol/dist/messages.js
15637
+ // ../../node_modules/pg/node_modules/pg-protocol/dist/messages.js
15627
15638
  var require_messages = __commonJS({
15628
- "../../node_modules/pg-protocol/dist/messages.js"(exports2) {
15639
+ "../../node_modules/pg/node_modules/pg-protocol/dist/messages.js"(exports2) {
15629
15640
  "use strict";
15630
15641
  Object.defineProperty(exports2, "__esModule", { value: true });
15631
15642
  exports2.NoticeMessage = exports2.DataRowMessage = exports2.CommandCompleteMessage = exports2.ReadyForQueryMessage = exports2.NotificationResponseMessage = exports2.BackendKeyDataMessage = exports2.AuthenticationMD5Password = exports2.ParameterStatusMessage = exports2.ParameterDescriptionMessage = exports2.RowDescriptionMessage = exports2.Field = exports2.CopyResponse = exports2.CopyDataMessage = exports2.DatabaseError = exports2.copyDone = exports2.emptyQuery = exports2.replicationStart = exports2.portalSuspended = exports2.noData = exports2.closeComplete = exports2.bindComplete = exports2.parseComplete = void 0;
@@ -15788,9 +15799,9 @@ var require_messages = __commonJS({
15788
15799
  }
15789
15800
  });
15790
15801
 
15791
- // ../../node_modules/pg-protocol/dist/buffer-writer.js
15802
+ // ../../node_modules/pg/node_modules/pg-protocol/dist/buffer-writer.js
15792
15803
  var require_buffer_writer = __commonJS({
15793
- "../../node_modules/pg-protocol/dist/buffer-writer.js"(exports2) {
15804
+ "../../node_modules/pg/node_modules/pg-protocol/dist/buffer-writer.js"(exports2) {
15794
15805
  "use strict";
15795
15806
  Object.defineProperty(exports2, "__esModule", { value: true });
15796
15807
  exports2.Writer = void 0;
@@ -15843,6 +15854,25 @@ var require_buffer_writer = __commonJS({
15843
15854
  this.offset += len;
15844
15855
  return this;
15845
15856
  }
15857
+ // Write an Int32 byte-length prefix immediately followed by the string's UTF-8
15858
+ // bytes. Postgres' Bind wire format prefixes every parameter with its length,
15859
+ // and doing it in one method computes Buffer.byteLength ONCE — the previous
15860
+ // `addInt32(Buffer.byteLength(s)).addString(s)` pairing scanned the string
15861
+ // three times (byteLength for the prefix, byteLength again inside addString,
15862
+ // then the encode), which is costly for large text parameters.
15863
+ addInt32PrefixedString(string) {
15864
+ const len = Buffer.byteLength(string);
15865
+ this.ensure(4 + len);
15866
+ const buffer = this.buffer;
15867
+ let offset = this.offset;
15868
+ buffer[offset++] = len >>> 24 & 255;
15869
+ buffer[offset++] = len >>> 16 & 255;
15870
+ buffer[offset++] = len >>> 8 & 255;
15871
+ buffer[offset++] = len >>> 0 & 255;
15872
+ buffer.write(string, offset, "utf-8");
15873
+ this.offset = offset + len;
15874
+ return this;
15875
+ }
15846
15876
  add(otherBuffer) {
15847
15877
  this.ensure(otherBuffer.length);
15848
15878
  otherBuffer.copy(this.buffer, this.offset);
@@ -15864,14 +15894,18 @@ var require_buffer_writer = __commonJS({
15864
15894
  this.buffer = Buffer.allocUnsafe(this.size);
15865
15895
  return result;
15866
15896
  }
15897
+ clear() {
15898
+ this.offset = 5;
15899
+ this.headerPosition = 0;
15900
+ }
15867
15901
  };
15868
15902
  exports2.Writer = Writer;
15869
15903
  }
15870
15904
  });
15871
15905
 
15872
- // ../../node_modules/pg-protocol/dist/serializer.js
15906
+ // ../../node_modules/pg/node_modules/pg-protocol/dist/serializer.js
15873
15907
  var require_serializer = __commonJS({
15874
- "../../node_modules/pg-protocol/dist/serializer.js"(exports2) {
15908
+ "../../node_modules/pg/node_modules/pg-protocol/dist/serializer.js"(exports2) {
15875
15909
  "use strict";
15876
15910
  Object.defineProperty(exports2, "__esModule", { value: true });
15877
15911
  exports2.serialize = void 0;
@@ -15900,7 +15934,7 @@ var require_serializer = __commonJS({
15900
15934
  );
15901
15935
  };
15902
15936
  var sendSASLInitialResponseMessage = function(mechanism, initialResponse) {
15903
- writer.addCString(mechanism).addInt32(Buffer.byteLength(initialResponse)).addString(initialResponse);
15937
+ writer.addCString(mechanism).addInt32PrefixedString(initialResponse);
15904
15938
  return writer.flush(
15905
15939
  112
15906
15940
  /* code.startup */
@@ -15959,8 +15993,7 @@ var require_serializer = __commonJS({
15959
15993
  0
15960
15994
  /* ParamType.STRING */
15961
15995
  );
15962
- paramWriter.addInt32(Buffer.byteLength(mappedVal));
15963
- paramWriter.addString(mappedVal);
15996
+ paramWriter.addInt32PrefixedString(mappedVal);
15964
15997
  }
15965
15998
  }
15966
15999
  };
@@ -15972,7 +16005,13 @@ var require_serializer = __commonJS({
15972
16005
  const len = values.length;
15973
16006
  writer.addCString(portal).addCString(statement);
15974
16007
  writer.addInt16(len);
15975
- writeValues(values, config.valueMapper);
16008
+ try {
16009
+ writeValues(values, config.valueMapper);
16010
+ } catch (err) {
16011
+ writer.clear();
16012
+ paramWriter.clear();
16013
+ throw err;
16014
+ }
15976
16015
  writer.addInt16(len);
15977
16016
  writer.add(paramWriter.flush());
15978
16017
  writer.addInt16(1);
@@ -16086,17 +16125,16 @@ var require_serializer = __commonJS({
16086
16125
  }
16087
16126
  });
16088
16127
 
16089
- // ../../node_modules/pg-protocol/dist/buffer-reader.js
16128
+ // ../../node_modules/pg/node_modules/pg-protocol/dist/buffer-reader.js
16090
16129
  var require_buffer_reader = __commonJS({
16091
- "../../node_modules/pg-protocol/dist/buffer-reader.js"(exports2) {
16130
+ "../../node_modules/pg/node_modules/pg-protocol/dist/buffer-reader.js"(exports2) {
16092
16131
  "use strict";
16093
16132
  Object.defineProperty(exports2, "__esModule", { value: true });
16094
16133
  exports2.BufferReader = void 0;
16095
- var emptyBuffer = Buffer.allocUnsafe(0);
16096
16134
  var BufferReader = class {
16097
16135
  constructor(offset = 0) {
16098
16136
  this.offset = offset;
16099
- this.buffer = emptyBuffer;
16137
+ this.buffer = Buffer.allocUnsafe(0);
16100
16138
  this.encoding = "utf-8";
16101
16139
  }
16102
16140
  setBuffer(offset, buffer) {
@@ -16131,7 +16169,7 @@ var require_buffer_reader = __commonJS({
16131
16169
  cstring() {
16132
16170
  const start = this.offset;
16133
16171
  let end = start;
16134
- while (this.buffer[end++] !== 0) {
16172
+ while (this.buffer[end++]) {
16135
16173
  }
16136
16174
  this.offset = end;
16137
16175
  return this.buffer.toString(this.encoding, start, end - 1);
@@ -16146,9 +16184,9 @@ var require_buffer_reader = __commonJS({
16146
16184
  }
16147
16185
  });
16148
16186
 
16149
- // ../../node_modules/pg-protocol/dist/parser.js
16187
+ // ../../node_modules/pg/node_modules/pg-protocol/dist/parser.js
16150
16188
  var require_parser = __commonJS({
16151
- "../../node_modules/pg-protocol/dist/parser.js"(exports2) {
16189
+ "../../node_modules/pg/node_modules/pg-protocol/dist/parser.js"(exports2) {
16152
16190
  "use strict";
16153
16191
  Object.defineProperty(exports2, "__esModule", { value: true });
16154
16192
  exports2.Parser = void 0;
@@ -16157,6 +16195,7 @@ var require_parser = __commonJS({
16157
16195
  var CODE_LENGTH = 1;
16158
16196
  var LEN_LENGTH = 4;
16159
16197
  var HEADER_LENGTH = CODE_LENGTH + LEN_LENGTH;
16198
+ var LATEINIT_LENGTH = -1;
16160
16199
  var emptyBuffer = Buffer.allocUnsafe(0);
16161
16200
  var Parser = class {
16162
16201
  constructor(opts) {
@@ -16222,229 +16261,243 @@ var require_parser = __commonJS({
16222
16261
  }
16223
16262
  }
16224
16263
  handlePacket(offset, code, length, bytes) {
16264
+ const { reader } = this;
16265
+ reader.setBuffer(offset, bytes);
16266
+ let message;
16225
16267
  switch (code) {
16226
16268
  case 50:
16227
- return messages_1.bindComplete;
16269
+ message = messages_1.bindComplete;
16270
+ break;
16228
16271
  case 49:
16229
- return messages_1.parseComplete;
16272
+ message = messages_1.parseComplete;
16273
+ break;
16230
16274
  case 51:
16231
- return messages_1.closeComplete;
16275
+ message = messages_1.closeComplete;
16276
+ break;
16232
16277
  case 110:
16233
- return messages_1.noData;
16278
+ message = messages_1.noData;
16279
+ break;
16234
16280
  case 115:
16235
- return messages_1.portalSuspended;
16281
+ message = messages_1.portalSuspended;
16282
+ break;
16236
16283
  case 99:
16237
- return messages_1.copyDone;
16284
+ message = messages_1.copyDone;
16285
+ break;
16238
16286
  case 87:
16239
- return messages_1.replicationStart;
16287
+ message = messages_1.replicationStart;
16288
+ break;
16240
16289
  case 73:
16241
- return messages_1.emptyQuery;
16290
+ message = messages_1.emptyQuery;
16291
+ break;
16242
16292
  case 68:
16243
- return this.parseDataRowMessage(offset, length, bytes);
16293
+ message = parseDataRowMessage(reader);
16294
+ break;
16244
16295
  case 67:
16245
- return this.parseCommandCompleteMessage(offset, length, bytes);
16296
+ message = parseCommandCompleteMessage(reader);
16297
+ break;
16246
16298
  case 90:
16247
- return this.parseReadyForQueryMessage(offset, length, bytes);
16299
+ message = parseReadyForQueryMessage(reader);
16300
+ break;
16248
16301
  case 65:
16249
- return this.parseNotificationMessage(offset, length, bytes);
16302
+ message = parseNotificationMessage(reader);
16303
+ break;
16250
16304
  case 82:
16251
- return this.parseAuthenticationResponse(offset, length, bytes);
16305
+ message = parseAuthenticationResponse(reader, length);
16306
+ break;
16252
16307
  case 83:
16253
- return this.parseParameterStatusMessage(offset, length, bytes);
16308
+ message = parseParameterStatusMessage(reader);
16309
+ break;
16254
16310
  case 75:
16255
- return this.parseBackendKeyData(offset, length, bytes);
16311
+ message = parseBackendKeyData(reader);
16312
+ break;
16256
16313
  case 69:
16257
- return this.parseErrorMessage(offset, length, bytes, "error");
16314
+ message = parseErrorMessage(reader, "error");
16315
+ break;
16258
16316
  case 78:
16259
- return this.parseErrorMessage(offset, length, bytes, "notice");
16260
- case 84:
16261
- return this.parseRowDescriptionMessage(offset, length, bytes);
16262
- case 116:
16263
- return this.parseParameterDescriptionMessage(offset, length, bytes);
16264
- case 71:
16265
- return this.parseCopyInMessage(offset, length, bytes);
16266
- case 72:
16267
- return this.parseCopyOutMessage(offset, length, bytes);
16268
- case 100:
16269
- return this.parseCopyData(offset, length, bytes);
16270
- default:
16271
- return new messages_1.DatabaseError("received invalid response: " + code.toString(16), length, "error");
16272
- }
16273
- }
16274
- parseReadyForQueryMessage(offset, length, bytes) {
16275
- this.reader.setBuffer(offset, bytes);
16276
- const status = this.reader.string(1);
16277
- return new messages_1.ReadyForQueryMessage(length, status);
16278
- }
16279
- parseCommandCompleteMessage(offset, length, bytes) {
16280
- this.reader.setBuffer(offset, bytes);
16281
- const text = this.reader.cstring();
16282
- return new messages_1.CommandCompleteMessage(length, text);
16283
- }
16284
- parseCopyData(offset, length, bytes) {
16285
- const chunk = bytes.slice(offset, offset + (length - 4));
16286
- return new messages_1.CopyDataMessage(length, chunk);
16287
- }
16288
- parseCopyInMessage(offset, length, bytes) {
16289
- return this.parseCopyMessage(offset, length, bytes, "copyInResponse");
16290
- }
16291
- parseCopyOutMessage(offset, length, bytes) {
16292
- return this.parseCopyMessage(offset, length, bytes, "copyOutResponse");
16293
- }
16294
- parseCopyMessage(offset, length, bytes, messageName) {
16295
- this.reader.setBuffer(offset, bytes);
16296
- const isBinary = this.reader.byte() !== 0;
16297
- const columnCount = this.reader.int16();
16298
- const message = new messages_1.CopyResponse(length, messageName, isBinary, columnCount);
16299
- for (let i = 0; i < columnCount; i++) {
16300
- message.columnTypes[i] = this.reader.int16();
16301
- }
16302
- return message;
16303
- }
16304
- parseNotificationMessage(offset, length, bytes) {
16305
- this.reader.setBuffer(offset, bytes);
16306
- const processId = this.reader.int32();
16307
- const channel = this.reader.cstring();
16308
- const payload = this.reader.cstring();
16309
- return new messages_1.NotificationResponseMessage(length, processId, channel, payload);
16310
- }
16311
- parseRowDescriptionMessage(offset, length, bytes) {
16312
- this.reader.setBuffer(offset, bytes);
16313
- const fieldCount = this.reader.int16();
16314
- const message = new messages_1.RowDescriptionMessage(length, fieldCount);
16315
- for (let i = 0; i < fieldCount; i++) {
16316
- message.fields[i] = this.parseField();
16317
- }
16318
- return message;
16319
- }
16320
- parseField() {
16321
- const name = this.reader.cstring();
16322
- const tableID = this.reader.uint32();
16323
- const columnID = this.reader.int16();
16324
- const dataTypeID = this.reader.uint32();
16325
- const dataTypeSize = this.reader.int16();
16326
- const dataTypeModifier = this.reader.int32();
16327
- const mode = this.reader.int16() === 0 ? "text" : "binary";
16328
- return new messages_1.Field(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, mode);
16329
- }
16330
- parseParameterDescriptionMessage(offset, length, bytes) {
16331
- this.reader.setBuffer(offset, bytes);
16332
- const parameterCount = this.reader.int16();
16333
- const message = new messages_1.ParameterDescriptionMessage(length, parameterCount);
16334
- for (let i = 0; i < parameterCount; i++) {
16335
- message.dataTypeIDs[i] = this.reader.int32();
16336
- }
16337
- return message;
16338
- }
16339
- parseDataRowMessage(offset, length, bytes) {
16340
- this.reader.setBuffer(offset, bytes);
16341
- const fieldCount = this.reader.int16();
16342
- const fields = new Array(fieldCount);
16343
- for (let i = 0; i < fieldCount; i++) {
16344
- const len = this.reader.int32();
16345
- fields[i] = len === -1 ? null : this.reader.string(len);
16346
- }
16347
- return new messages_1.DataRowMessage(length, fields);
16348
- }
16349
- parseParameterStatusMessage(offset, length, bytes) {
16350
- this.reader.setBuffer(offset, bytes);
16351
- const name = this.reader.cstring();
16352
- const value = this.reader.cstring();
16353
- return new messages_1.ParameterStatusMessage(length, name, value);
16354
- }
16355
- parseBackendKeyData(offset, length, bytes) {
16356
- this.reader.setBuffer(offset, bytes);
16357
- const processID = this.reader.int32();
16358
- const secretKey = this.reader.int32();
16359
- return new messages_1.BackendKeyDataMessage(length, processID, secretKey);
16360
- }
16361
- parseAuthenticationResponse(offset, length, bytes) {
16362
- this.reader.setBuffer(offset, bytes);
16363
- const code = this.reader.int32();
16364
- const message = {
16365
- name: "authenticationOk",
16366
- length
16367
- };
16368
- switch (code) {
16369
- case 0:
16317
+ message = parseErrorMessage(reader, "notice");
16370
16318
  break;
16371
- case 3:
16372
- if (message.length === 8) {
16373
- message.name = "authenticationCleartextPassword";
16374
- }
16319
+ case 84:
16320
+ message = parseRowDescriptionMessage(reader);
16375
16321
  break;
16376
- case 5:
16377
- if (message.length === 12) {
16378
- message.name = "authenticationMD5Password";
16379
- const salt = this.reader.bytes(4);
16380
- return new messages_1.AuthenticationMD5Password(length, salt);
16381
- }
16322
+ case 116:
16323
+ message = parseParameterDescriptionMessage(reader);
16382
16324
  break;
16383
- case 10:
16384
- {
16385
- message.name = "authenticationSASL";
16386
- message.mechanisms = [];
16387
- let mechanism;
16388
- do {
16389
- mechanism = this.reader.cstring();
16390
- if (mechanism) {
16391
- message.mechanisms.push(mechanism);
16392
- }
16393
- } while (mechanism);
16394
- }
16325
+ case 71:
16326
+ message = parseCopyInMessage(reader);
16395
16327
  break;
16396
- case 11:
16397
- message.name = "authenticationSASLContinue";
16398
- message.data = this.reader.string(length - 8);
16328
+ case 72:
16329
+ message = parseCopyOutMessage(reader);
16399
16330
  break;
16400
- case 12:
16401
- message.name = "authenticationSASLFinal";
16402
- message.data = this.reader.string(length - 8);
16331
+ case 100:
16332
+ message = parseCopyData(reader, length);
16403
16333
  break;
16404
16334
  default:
16405
- throw new Error("Unknown authenticationOk message type " + code);
16335
+ return new messages_1.DatabaseError("received invalid response: " + code.toString(16), length, "error");
16406
16336
  }
16407
- return message;
16408
- }
16409
- parseErrorMessage(offset, length, bytes, name) {
16410
- this.reader.setBuffer(offset, bytes);
16411
- const fields = {};
16412
- let fieldType = this.reader.string(1);
16413
- while (fieldType !== "\0") {
16414
- fields[fieldType] = this.reader.cstring();
16415
- fieldType = this.reader.string(1);
16416
- }
16417
- const messageValue = fields.M;
16418
- const message = name === "notice" ? new messages_1.NoticeMessage(length, messageValue) : new messages_1.DatabaseError(messageValue, length, name);
16419
- message.severity = fields.S;
16420
- message.code = fields.C;
16421
- message.detail = fields.D;
16422
- message.hint = fields.H;
16423
- message.position = fields.P;
16424
- message.internalPosition = fields.p;
16425
- message.internalQuery = fields.q;
16426
- message.where = fields.W;
16427
- message.schema = fields.s;
16428
- message.table = fields.t;
16429
- message.column = fields.c;
16430
- message.dataType = fields.d;
16431
- message.constraint = fields.n;
16432
- message.file = fields.F;
16433
- message.line = fields.L;
16434
- message.routine = fields.R;
16337
+ reader.setBuffer(0, emptyBuffer);
16338
+ message.length = length;
16435
16339
  return message;
16436
16340
  }
16437
16341
  };
16438
16342
  exports2.Parser = Parser;
16343
+ var parseReadyForQueryMessage = (reader) => {
16344
+ const status = reader.string(1);
16345
+ return new messages_1.ReadyForQueryMessage(LATEINIT_LENGTH, status);
16346
+ };
16347
+ var parseCommandCompleteMessage = (reader) => {
16348
+ const text = reader.cstring();
16349
+ return new messages_1.CommandCompleteMessage(LATEINIT_LENGTH, text);
16350
+ };
16351
+ var parseCopyData = (reader, length) => {
16352
+ const chunk = reader.bytes(length - 4);
16353
+ return new messages_1.CopyDataMessage(LATEINIT_LENGTH, chunk);
16354
+ };
16355
+ var parseCopyInMessage = (reader) => parseCopyMessage(reader, "copyInResponse");
16356
+ var parseCopyOutMessage = (reader) => parseCopyMessage(reader, "copyOutResponse");
16357
+ var parseCopyMessage = (reader, messageName) => {
16358
+ const isBinary = reader.byte() !== 0;
16359
+ const columnCount = reader.int16();
16360
+ const message = new messages_1.CopyResponse(LATEINIT_LENGTH, messageName, isBinary, columnCount);
16361
+ for (let i = 0; i < columnCount; i++) {
16362
+ message.columnTypes[i] = reader.int16();
16363
+ }
16364
+ return message;
16365
+ };
16366
+ var parseNotificationMessage = (reader) => {
16367
+ const processId = reader.int32();
16368
+ const channel = reader.cstring();
16369
+ const payload = reader.cstring();
16370
+ return new messages_1.NotificationResponseMessage(LATEINIT_LENGTH, processId, channel, payload);
16371
+ };
16372
+ var parseRowDescriptionMessage = (reader) => {
16373
+ const fieldCount = reader.int16();
16374
+ const message = new messages_1.RowDescriptionMessage(LATEINIT_LENGTH, fieldCount);
16375
+ for (let i = 0; i < fieldCount; i++) {
16376
+ message.fields[i] = parseField(reader);
16377
+ }
16378
+ return message;
16379
+ };
16380
+ var parseField = (reader) => {
16381
+ const name = reader.cstring();
16382
+ const tableID = reader.uint32();
16383
+ const columnID = reader.int16();
16384
+ const dataTypeID = reader.uint32();
16385
+ const dataTypeSize = reader.int16();
16386
+ const dataTypeModifier = reader.int32();
16387
+ const mode = reader.int16() === 0 ? "text" : "binary";
16388
+ return new messages_1.Field(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, mode);
16389
+ };
16390
+ var parseParameterDescriptionMessage = (reader) => {
16391
+ const parameterCount = reader.int16();
16392
+ const message = new messages_1.ParameterDescriptionMessage(LATEINIT_LENGTH, parameterCount);
16393
+ for (let i = 0; i < parameterCount; i++) {
16394
+ message.dataTypeIDs[i] = reader.int32();
16395
+ }
16396
+ return message;
16397
+ };
16398
+ var parseDataRowMessage = (reader) => {
16399
+ const fieldCount = reader.int16();
16400
+ const fields = new Array(fieldCount);
16401
+ for (let i = 0; i < fieldCount; i++) {
16402
+ const len = reader.int32();
16403
+ fields[i] = len === -1 ? null : reader.string(len);
16404
+ }
16405
+ return new messages_1.DataRowMessage(LATEINIT_LENGTH, fields);
16406
+ };
16407
+ var parseParameterStatusMessage = (reader) => {
16408
+ const name = reader.cstring();
16409
+ const value = reader.cstring();
16410
+ return new messages_1.ParameterStatusMessage(LATEINIT_LENGTH, name, value);
16411
+ };
16412
+ var parseBackendKeyData = (reader) => {
16413
+ const processID = reader.int32();
16414
+ const secretKey = reader.int32();
16415
+ return new messages_1.BackendKeyDataMessage(LATEINIT_LENGTH, processID, secretKey);
16416
+ };
16417
+ var parseAuthenticationResponse = (reader, length) => {
16418
+ const code = reader.int32();
16419
+ const message = {
16420
+ name: "authenticationOk",
16421
+ length
16422
+ };
16423
+ switch (code) {
16424
+ case 0:
16425
+ break;
16426
+ case 3:
16427
+ if (message.length === 8) {
16428
+ message.name = "authenticationCleartextPassword";
16429
+ }
16430
+ break;
16431
+ case 5:
16432
+ if (message.length === 12) {
16433
+ message.name = "authenticationMD5Password";
16434
+ const salt = reader.bytes(4);
16435
+ return new messages_1.AuthenticationMD5Password(LATEINIT_LENGTH, salt);
16436
+ }
16437
+ break;
16438
+ case 10:
16439
+ {
16440
+ message.name = "authenticationSASL";
16441
+ message.mechanisms = [];
16442
+ let mechanism;
16443
+ do {
16444
+ mechanism = reader.cstring();
16445
+ if (mechanism) {
16446
+ message.mechanisms.push(mechanism);
16447
+ }
16448
+ } while (mechanism);
16449
+ }
16450
+ break;
16451
+ case 11:
16452
+ message.name = "authenticationSASLContinue";
16453
+ message.data = reader.string(length - 8);
16454
+ break;
16455
+ case 12:
16456
+ message.name = "authenticationSASLFinal";
16457
+ message.data = reader.string(length - 8);
16458
+ break;
16459
+ default:
16460
+ throw new Error("Unknown authenticationOk message type " + code);
16461
+ }
16462
+ return message;
16463
+ };
16464
+ var parseErrorMessage = (reader, name) => {
16465
+ const fields = {};
16466
+ let fieldType = reader.string(1);
16467
+ while (fieldType !== "\0") {
16468
+ fields[fieldType] = reader.cstring();
16469
+ fieldType = reader.string(1);
16470
+ }
16471
+ const messageValue = fields.M;
16472
+ const message = name === "notice" ? new messages_1.NoticeMessage(LATEINIT_LENGTH, messageValue) : new messages_1.DatabaseError(messageValue, LATEINIT_LENGTH, name);
16473
+ message.severity = fields.S;
16474
+ message.code = fields.C;
16475
+ message.detail = fields.D;
16476
+ message.hint = fields.H;
16477
+ message.position = fields.P;
16478
+ message.internalPosition = fields.p;
16479
+ message.internalQuery = fields.q;
16480
+ message.where = fields.W;
16481
+ message.schema = fields.s;
16482
+ message.table = fields.t;
16483
+ message.column = fields.c;
16484
+ message.dataType = fields.d;
16485
+ message.constraint = fields.n;
16486
+ message.file = fields.F;
16487
+ message.line = fields.L;
16488
+ message.routine = fields.R;
16489
+ return message;
16490
+ };
16439
16491
  }
16440
16492
  });
16441
16493
 
16442
- // ../../node_modules/pg-protocol/dist/index.js
16494
+ // ../../node_modules/pg/node_modules/pg-protocol/dist/index.js
16443
16495
  var require_dist2 = __commonJS({
16444
- "../../node_modules/pg-protocol/dist/index.js"(exports2) {
16496
+ "../../node_modules/pg/node_modules/pg-protocol/dist/index.js"(exports2) {
16445
16497
  "use strict";
16446
16498
  Object.defineProperty(exports2, "__esModule", { value: true });
16447
- exports2.DatabaseError = exports2.serialize = exports2.parse = void 0;
16499
+ exports2.DatabaseError = exports2.serialize = void 0;
16500
+ exports2.parse = parse;
16448
16501
  var messages_1 = require_messages();
16449
16502
  Object.defineProperty(exports2, "DatabaseError", { enumerable: true, get: function() {
16450
16503
  return messages_1.DatabaseError;
@@ -16459,7 +16512,6 @@ var require_dist2 = __commonJS({
16459
16512
  stream.on("data", (buffer) => parser.parse(buffer, callback));
16460
16513
  return new Promise((resolve) => stream.on("end", () => resolve()));
16461
16514
  }
16462
- exports2.parse = parse;
16463
16515
  }
16464
16516
  });
16465
16517
 
@@ -16545,7 +16597,8 @@ var require_connection = __commonJS({
16545
16597
  "use strict";
16546
16598
  var EventEmitter = require("events").EventEmitter;
16547
16599
  var { parse, serialize } = require_dist2();
16548
- var { getStream, getSecureStream } = require_stream();
16600
+ var stream = require_stream();
16601
+ var { getStream } = stream;
16549
16602
  var flushBuffer = serialize.flush();
16550
16603
  var syncBuffer = serialize.sync();
16551
16604
  var endBuffer = serialize.end();
@@ -16559,9 +16612,9 @@ var require_connection = __commonJS({
16559
16612
  }
16560
16613
  this._keepAlive = config.keepAlive;
16561
16614
  this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis;
16562
- this.lastBuffer = false;
16563
16615
  this.parsedStatements = {};
16564
16616
  this.ssl = config.ssl || false;
16617
+ this.sslNegotiation = config.sslNegotiation || "postgres";
16565
16618
  this._ending = false;
16566
16619
  this._emitMessage = false;
16567
16620
  const self = this;
@@ -16595,6 +16648,11 @@ var require_connection = __commonJS({
16595
16648
  if (!this.ssl) {
16596
16649
  return this.attachListeners(this.stream);
16597
16650
  }
16651
+ if (this.sslNegotiation === "direct") {
16652
+ return this.stream.once("connect", function() {
16653
+ self.upgradeToSSL(host, reportStreamError);
16654
+ });
16655
+ }
16598
16656
  this.stream.once("data", function(buffer) {
16599
16657
  const responseCode = buffer.toString("utf8");
16600
16658
  switch (responseCode) {
@@ -16607,31 +16665,38 @@ var require_connection = __commonJS({
16607
16665
  self.stream.end();
16608
16666
  return self.emit("error", new Error("There was an error establishing an SSL connection"));
16609
16667
  }
16610
- const options = {
16611
- socket: self.stream
16612
- };
16613
- if (self.ssl !== true) {
16614
- Object.assign(options, self.ssl);
16615
- if ("key" in self.ssl) {
16616
- options.key = self.ssl.key;
16617
- }
16618
- }
16619
- const net2 = require("net");
16620
- if (net2.isIP && net2.isIP(host) === 0) {
16621
- options.servername = host;
16622
- }
16623
- try {
16624
- self.stream = getSecureStream(options);
16625
- } catch (err) {
16626
- return self.emit("error", err);
16627
- }
16628
- self.attachListeners(self.stream);
16629
- self.stream.on("error", reportStreamError);
16630
- self.emit("sslconnect");
16668
+ self.upgradeToSSL(host, reportStreamError);
16631
16669
  });
16632
16670
  }
16633
- attachListeners(stream) {
16634
- parse(stream, (msg) => {
16671
+ upgradeToSSL(host, reportStreamError) {
16672
+ const self = this;
16673
+ const options = {
16674
+ socket: self.stream
16675
+ };
16676
+ if (self.ssl !== true) {
16677
+ Object.assign(options, self.ssl);
16678
+ if ("key" in self.ssl) {
16679
+ options.key = self.ssl.key;
16680
+ }
16681
+ }
16682
+ if (self.sslNegotiation === "direct") {
16683
+ options.ALPNProtocols = ["postgresql"];
16684
+ }
16685
+ const net2 = require("net");
16686
+ if (net2.isIP && net2.isIP(host) === 0) {
16687
+ options.servername = host;
16688
+ }
16689
+ try {
16690
+ self.stream = stream.getSecureStream(options);
16691
+ } catch (err) {
16692
+ return self.emit("error", err);
16693
+ }
16694
+ self.attachListeners(self.stream);
16695
+ self.stream.on("error", reportStreamError);
16696
+ self.emit("sslconnect");
16697
+ }
16698
+ attachListeners(stream2) {
16699
+ parse(stream2, (msg) => {
16635
16700
  const eventName = msg.name === "error" ? "errorMessage" : msg.name;
16636
16701
  if (this._emitMessage) {
16637
16702
  this.emit("message", msg);
@@ -17022,6 +17087,7 @@ var require_client = __commonJS({
17022
17087
  "use strict";
17023
17088
  var EventEmitter = require("events").EventEmitter;
17024
17089
  var utils = require_utils();
17090
+ var nodeUtils = require("util");
17025
17091
  var sasl = require_sasl();
17026
17092
  var TypeOverrides2 = require_type_overrides();
17027
17093
  var ConnectionParameters = require_connection_parameters();
@@ -17029,6 +17095,41 @@ var require_client = __commonJS({
17029
17095
  var defaults2 = require_defaults();
17030
17096
  var Connection2 = require_connection();
17031
17097
  var crypto = require_utils2();
17098
+ var activeQueryDeprecationNotice = nodeUtils.deprecate(
17099
+ () => {
17100
+ },
17101
+ "Client.activeQuery is deprecated and will be removed in pg@9.0"
17102
+ );
17103
+ var queryQueueDeprecationNotice = nodeUtils.deprecate(
17104
+ () => {
17105
+ },
17106
+ "Client.queryQueue is deprecated and will be removed in pg@9.0."
17107
+ );
17108
+ var pgPassDeprecationNotice = nodeUtils.deprecate(
17109
+ () => {
17110
+ },
17111
+ "pgpass support is deprecated and will be removed in pg@9.0. You can provide an async function as the password property to the Client/Pool constructor that returns a password instead. Within this function you can call the pgpass module in your own code."
17112
+ );
17113
+ var byoPromiseDeprecationNotice = nodeUtils.deprecate(
17114
+ () => {
17115
+ },
17116
+ "Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in pg@9.0."
17117
+ );
17118
+ var queryQueueLengthDeprecationNotice = nodeUtils.deprecate(
17119
+ () => {
17120
+ },
17121
+ "Calling client.query() when the client is already executing a query is deprecated and will be removed in pg@9.0. Use async/await or an external async flow control mechanism instead."
17122
+ );
17123
+ function coerceNumberOrDefault(value, defaultValue) {
17124
+ if (typeof value === "number") {
17125
+ return Number.isFinite(value) ? value : defaultValue;
17126
+ }
17127
+ if (typeof value === "string" && value.trim() !== "") {
17128
+ const n = Number(value);
17129
+ return Number.isFinite(n) ? n : defaultValue;
17130
+ }
17131
+ return defaultValue;
17132
+ }
17032
17133
  var Client2 = class extends EventEmitter {
17033
17134
  constructor(config) {
17034
17135
  super();
@@ -17045,6 +17146,9 @@ var require_client = __commonJS({
17045
17146
  });
17046
17147
  this.replication = this.connectionParameters.replication;
17047
17148
  const c = config || {};
17149
+ if (c.Promise) {
17150
+ byoPromiseDeprecationNotice();
17151
+ }
17048
17152
  this._Promise = c.Promise || global.Promise;
17049
17153
  this._types = new TypeOverrides2(c.types);
17050
17154
  this._ending = false;
@@ -17053,19 +17157,24 @@ var require_client = __commonJS({
17053
17157
  this._connected = false;
17054
17158
  this._connectionError = false;
17055
17159
  this._queryable = true;
17160
+ this._activeQuery = null;
17161
+ this._txStatus = null;
17056
17162
  this.enableChannelBinding = Boolean(c.enableChannelBinding);
17163
+ this.scramMaxIterations = coerceNumberOrDefault(c.scramMaxIterations, sasl.DEFAULT_MAX_SCRAM_ITERATIONS);
17057
17164
  this.connection = c.connection || new Connection2({
17058
17165
  stream: c.stream,
17059
17166
  ssl: this.connectionParameters.ssl,
17167
+ sslNegotiation: this.connectionParameters.sslnegotiation,
17060
17168
  keepAlive: c.keepAlive || false,
17061
17169
  keepAliveInitialDelayMillis: c.keepAliveInitialDelayMillis || 0,
17062
17170
  encoding: this.connectionParameters.client_encoding || "utf8"
17063
17171
  });
17064
- this.queryQueue = [];
17172
+ this._queryQueue = [];
17065
17173
  this.binary = c.binary || defaults2.binary;
17066
17174
  this.processID = null;
17067
17175
  this.secretKey = null;
17068
17176
  this.ssl = this.connectionParameters.ssl || false;
17177
+ this.sslNegotiation = this.connectionParameters.sslnegotiation || "postgres";
17069
17178
  if (this.ssl && this.ssl.key) {
17070
17179
  Object.defineProperty(this.ssl, "key", {
17071
17180
  enumerable: false
@@ -17073,18 +17182,30 @@ var require_client = __commonJS({
17073
17182
  }
17074
17183
  this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0;
17075
17184
  }
17185
+ get activeQuery() {
17186
+ activeQueryDeprecationNotice();
17187
+ return this._activeQuery;
17188
+ }
17189
+ set activeQuery(val) {
17190
+ activeQueryDeprecationNotice();
17191
+ this._activeQuery = val;
17192
+ }
17193
+ _getActiveQuery() {
17194
+ return this._activeQuery;
17195
+ }
17076
17196
  _errorAllQueries(err) {
17077
17197
  const enqueueError = (query) => {
17078
17198
  process.nextTick(() => {
17079
17199
  query.handleError(err, this.connection);
17080
17200
  });
17081
17201
  };
17082
- if (this.activeQuery) {
17083
- enqueueError(this.activeQuery);
17084
- this.activeQuery = null;
17202
+ const activeQuery = this._getActiveQuery();
17203
+ if (activeQuery) {
17204
+ enqueueError(activeQuery);
17205
+ this._activeQuery = null;
17085
17206
  }
17086
- this.queryQueue.forEach(enqueueError);
17087
- this.queryQueue.length = 0;
17207
+ this._queryQueue.forEach(enqueueError);
17208
+ this._queryQueue.length = 0;
17088
17209
  }
17089
17210
  _connect(callback) {
17090
17211
  const self = this;
@@ -17114,7 +17235,9 @@ var require_client = __commonJS({
17114
17235
  }
17115
17236
  con.on("connect", function() {
17116
17237
  if (self.ssl) {
17117
- con.requestSsl();
17238
+ if (self.sslNegotiation !== "direct") {
17239
+ con.requestSsl();
17240
+ }
17118
17241
  } else {
17119
17242
  con.startup(self.getStartupConf());
17120
17243
  }
@@ -17154,7 +17277,7 @@ var require_client = __commonJS({
17154
17277
  if (error) {
17155
17278
  reject(error);
17156
17279
  } else {
17157
- resolve();
17280
+ resolve(this);
17158
17281
  }
17159
17282
  });
17160
17283
  });
@@ -17180,12 +17303,10 @@ var require_client = __commonJS({
17180
17303
  con.on("copyData", this._handleCopyData.bind(this));
17181
17304
  con.on("notification", this._handleNotification.bind(this));
17182
17305
  }
17183
- // TODO(bmc): deprecate pgpass "built in" integration since this.password can be a function
17184
- // it can be supplied by the user if required - this is a breaking change!
17185
- _checkPgPass(cb) {
17306
+ _getPassword(cb) {
17186
17307
  const con = this.connection;
17187
17308
  if (typeof this.password === "function") {
17188
- this._Promise.resolve().then(() => this.password()).then((pass) => {
17309
+ this._Promise.resolve().then(() => this.password(this.connectionParameters)).then((pass) => {
17189
17310
  if (pass !== void 0) {
17190
17311
  if (typeof pass !== "string") {
17191
17312
  con.emit("error", new TypeError("Password must be a string"));
@@ -17206,6 +17327,7 @@ var require_client = __commonJS({
17206
17327
  const pgPass = require_lib();
17207
17328
  pgPass(this.connectionParameters, (pass) => {
17208
17329
  if (void 0 !== pass) {
17330
+ pgPassDeprecationNotice();
17209
17331
  this.connectionParameters.password = this.password = pass;
17210
17332
  }
17211
17333
  cb();
@@ -17216,12 +17338,12 @@ var require_client = __commonJS({
17216
17338
  }
17217
17339
  }
17218
17340
  _handleAuthCleartextPassword(msg) {
17219
- this._checkPgPass(() => {
17341
+ this._getPassword(() => {
17220
17342
  this.connection.password(this.password);
17221
17343
  });
17222
17344
  }
17223
17345
  _handleAuthMD5Password(msg) {
17224
- this._checkPgPass(async () => {
17346
+ this._getPassword(async () => {
17225
17347
  try {
17226
17348
  const hashedPassword = await crypto.postgresMd5PasswordHash(this.user, this.password, msg.salt);
17227
17349
  this.connection.password(hashedPassword);
@@ -17231,9 +17353,13 @@ var require_client = __commonJS({
17231
17353
  });
17232
17354
  }
17233
17355
  _handleAuthSASL(msg) {
17234
- this._checkPgPass(() => {
17356
+ this._getPassword(() => {
17235
17357
  try {
17236
- this.saslSession = sasl.startSession(msg.mechanisms, this.enableChannelBinding && this.connection.stream);
17358
+ this.saslSession = sasl.startSession(
17359
+ msg.mechanisms,
17360
+ this.enableChannelBinding && this.connection.stream,
17361
+ this.scramMaxIterations
17362
+ );
17237
17363
  this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
17238
17364
  } catch (err) {
17239
17365
  this.connection.emit("error", err);
@@ -17276,8 +17402,9 @@ var require_client = __commonJS({
17276
17402
  }
17277
17403
  this.emit("connect");
17278
17404
  }
17279
- const { activeQuery } = this;
17280
- this.activeQuery = null;
17405
+ const activeQuery = this._getActiveQuery();
17406
+ this._activeQuery = null;
17407
+ this._txStatus = msg?.status ?? null;
17281
17408
  this.readyForQuery = true;
17282
17409
  if (activeQuery) {
17283
17410
  activeQuery.handleReadyForQuery(this.connection);
@@ -17313,49 +17440,87 @@ var require_client = __commonJS({
17313
17440
  if (this._connecting) {
17314
17441
  return this._handleErrorWhileConnecting(msg);
17315
17442
  }
17316
- const activeQuery = this.activeQuery;
17443
+ const activeQuery = this._getActiveQuery();
17317
17444
  if (!activeQuery) {
17318
17445
  this._handleErrorEvent(msg);
17319
17446
  return;
17320
17447
  }
17321
- this.activeQuery = null;
17448
+ this._activeQuery = null;
17322
17449
  activeQuery.handleError(msg, this.connection);
17323
17450
  }
17324
17451
  _handleRowDescription(msg) {
17325
- this.activeQuery.handleRowDescription(msg);
17452
+ const activeQuery = this._getActiveQuery();
17453
+ if (activeQuery == null) {
17454
+ const error = new Error("Received unexpected rowDescription message from backend.");
17455
+ this._handleErrorEvent(error);
17456
+ return;
17457
+ }
17458
+ activeQuery.handleRowDescription(msg);
17326
17459
  }
17327
17460
  _handleDataRow(msg) {
17328
- this.activeQuery.handleDataRow(msg);
17461
+ const activeQuery = this._getActiveQuery();
17462
+ if (activeQuery == null) {
17463
+ const error = new Error("Received unexpected dataRow message from backend.");
17464
+ this._handleErrorEvent(error);
17465
+ return;
17466
+ }
17467
+ activeQuery.handleDataRow(msg);
17329
17468
  }
17330
17469
  _handlePortalSuspended(msg) {
17331
- this.activeQuery.handlePortalSuspended(this.connection);
17470
+ const activeQuery = this._getActiveQuery();
17471
+ if (activeQuery == null) {
17472
+ const error = new Error("Received unexpected portalSuspended message from backend.");
17473
+ this._handleErrorEvent(error);
17474
+ return;
17475
+ }
17476
+ activeQuery.handlePortalSuspended(this.connection);
17332
17477
  }
17333
17478
  _handleEmptyQuery(msg) {
17334
- this.activeQuery.handleEmptyQuery(this.connection);
17479
+ const activeQuery = this._getActiveQuery();
17480
+ if (activeQuery == null) {
17481
+ const error = new Error("Received unexpected emptyQuery message from backend.");
17482
+ this._handleErrorEvent(error);
17483
+ return;
17484
+ }
17485
+ activeQuery.handleEmptyQuery(this.connection);
17335
17486
  }
17336
17487
  _handleCommandComplete(msg) {
17337
- if (this.activeQuery == null) {
17488
+ const activeQuery = this._getActiveQuery();
17489
+ if (activeQuery == null) {
17338
17490
  const error = new Error("Received unexpected commandComplete message from backend.");
17339
17491
  this._handleErrorEvent(error);
17340
17492
  return;
17341
17493
  }
17342
- this.activeQuery.handleCommandComplete(msg, this.connection);
17494
+ activeQuery.handleCommandComplete(msg, this.connection);
17343
17495
  }
17344
17496
  _handleParseComplete() {
17345
- if (this.activeQuery == null) {
17497
+ const activeQuery = this._getActiveQuery();
17498
+ if (activeQuery == null) {
17346
17499
  const error = new Error("Received unexpected parseComplete message from backend.");
17347
17500
  this._handleErrorEvent(error);
17348
17501
  return;
17349
17502
  }
17350
- if (this.activeQuery.name) {
17351
- this.connection.parsedStatements[this.activeQuery.name] = this.activeQuery.text;
17503
+ if (activeQuery.name) {
17504
+ this.connection.parsedStatements[activeQuery.name] = activeQuery.text;
17352
17505
  }
17353
17506
  }
17354
17507
  _handleCopyInResponse(msg) {
17355
- this.activeQuery.handleCopyInResponse(this.connection);
17508
+ const activeQuery = this._getActiveQuery();
17509
+ if (activeQuery == null) {
17510
+ const error = new Error("Received unexpected copyInResponse message from backend.");
17511
+ this._handleErrorEvent(error);
17512
+ return;
17513
+ }
17514
+ activeQuery.handleCopyInResponse(this.connection);
17356
17515
  }
17357
17516
  _handleCopyData(msg) {
17358
- this.activeQuery.handleCopyData(msg, this.connection);
17517
+ const activeQuery = this._getActiveQuery();
17518
+ if (activeQuery == null) {
17519
+ const error = new Error("Received unexpected copyData message from backend.");
17520
+ this._handleErrorEvent(error);
17521
+ return;
17522
+ }
17523
+ activeQuery.handleCopyData(msg, this.connection);
17359
17524
  }
17360
17525
  _handleNotification(msg) {
17361
17526
  this.emit("notification", msg);
@@ -17401,8 +17566,8 @@ var require_client = __commonJS({
17401
17566
  con.on("connect", function() {
17402
17567
  con.cancel(client.processID, client.secretKey);
17403
17568
  });
17404
- } else if (client.queryQueue.indexOf(query) !== -1) {
17405
- client.queryQueue.splice(client.queryQueue.indexOf(query), 1);
17569
+ } else if (client._queryQueue.indexOf(query) !== -1) {
17570
+ client._queryQueue.splice(client._queryQueue.indexOf(query), 1);
17406
17571
  }
17407
17572
  }
17408
17573
  setTypeParser(oid, format2, parseFn) {
@@ -17422,20 +17587,21 @@ var require_client = __commonJS({
17422
17587
  }
17423
17588
  _pulseQueryQueue() {
17424
17589
  if (this.readyForQuery === true) {
17425
- this.activeQuery = this.queryQueue.shift();
17426
- if (this.activeQuery) {
17590
+ this._activeQuery = this._queryQueue.shift();
17591
+ const activeQuery = this._getActiveQuery();
17592
+ if (activeQuery) {
17427
17593
  this.readyForQuery = false;
17428
17594
  this.hasExecuted = true;
17429
- const queryError = this.activeQuery.submit(this.connection);
17595
+ const queryError = activeQuery.submit(this.connection);
17430
17596
  if (queryError) {
17431
17597
  process.nextTick(() => {
17432
- this.activeQuery.handleError(queryError, this.connection);
17598
+ activeQuery.handleError(queryError, this.connection);
17433
17599
  this.readyForQuery = true;
17434
17600
  this._pulseQueryQueue();
17435
17601
  });
17436
17602
  }
17437
17603
  } else if (this.hasExecuted) {
17438
- this.activeQuery = null;
17604
+ this._activeQuery = null;
17439
17605
  this.emit("drain");
17440
17606
  }
17441
17607
  }
@@ -17443,19 +17609,19 @@ var require_client = __commonJS({
17443
17609
  query(config, values, callback) {
17444
17610
  let query;
17445
17611
  let result;
17446
- let readTimeout;
17447
- let readTimeoutTimer;
17448
- let queryCallback;
17449
- if (config === null || config === void 0) {
17612
+ if (config == null) {
17450
17613
  throw new TypeError("Client was passed a null or undefined query");
17451
- } else if (typeof config.submit === "function") {
17452
- readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
17614
+ }
17615
+ if (typeof config.submit === "function") {
17453
17616
  result = query = config;
17454
- if (typeof values === "function") {
17455
- query.callback = query.callback || values;
17617
+ if (!query.callback) {
17618
+ if (typeof values === "function") {
17619
+ query.callback = values;
17620
+ } else if (callback) {
17621
+ query.callback = callback;
17622
+ }
17456
17623
  }
17457
17624
  } else {
17458
- readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
17459
17625
  query = new Query2(config, values, callback);
17460
17626
  if (!query.callback) {
17461
17627
  result = new this._Promise((resolve, reject) => {
@@ -17464,11 +17630,15 @@ var require_client = __commonJS({
17464
17630
  Error.captureStackTrace(err);
17465
17631
  throw err;
17466
17632
  });
17633
+ } else if (typeof query.callback !== "function") {
17634
+ throw new TypeError("callback is not a function");
17467
17635
  }
17468
17636
  }
17637
+ const readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
17469
17638
  if (readTimeout) {
17470
- queryCallback = query.callback;
17471
- readTimeoutTimer = setTimeout(() => {
17639
+ const queryCallback = query.callback || (() => {
17640
+ });
17641
+ const readTimeoutTimer = setTimeout(() => {
17472
17642
  const error = new Error("Query read timeout");
17473
17643
  process.nextTick(() => {
17474
17644
  query.handleError(error, this.connection);
@@ -17476,9 +17646,9 @@ var require_client = __commonJS({
17476
17646
  queryCallback(error);
17477
17647
  query.callback = () => {
17478
17648
  };
17479
- const index = this.queryQueue.indexOf(query);
17649
+ const index = this._queryQueue.indexOf(query);
17480
17650
  if (index > -1) {
17481
- this.queryQueue.splice(index, 1);
17651
+ this._queryQueue.splice(index, 1);
17482
17652
  }
17483
17653
  this._pulseQueryQueue();
17484
17654
  }, readTimeout);
@@ -17505,7 +17675,10 @@ var require_client = __commonJS({
17505
17675
  });
17506
17676
  return result;
17507
17677
  }
17508
- this.queryQueue.push(query);
17678
+ if (this._queryQueue.length > 0) {
17679
+ queryQueueLengthDeprecationNotice();
17680
+ }
17681
+ this._queryQueue.push(query);
17509
17682
  this._pulseQueryQueue();
17510
17683
  return result;
17511
17684
  }
@@ -17515,16 +17688,20 @@ var require_client = __commonJS({
17515
17688
  unref() {
17516
17689
  this.connection.unref();
17517
17690
  }
17691
+ getTransactionStatus() {
17692
+ return this._txStatus;
17693
+ }
17518
17694
  end(cb) {
17519
17695
  this._ending = true;
17520
17696
  if (!this.connection._connecting || this._ended) {
17521
17697
  if (cb) {
17522
17698
  cb();
17699
+ return;
17523
17700
  } else {
17524
17701
  return this._Promise.resolve();
17525
17702
  }
17526
17703
  }
17527
- if (this.activeQuery || !this._queryable) {
17704
+ if (this._getActiveQuery() || !this._queryable) {
17528
17705
  this.connection.stream.destroy();
17529
17706
  } else {
17530
17707
  this.connection.end();
@@ -17537,6 +17714,10 @@ var require_client = __commonJS({
17537
17714
  });
17538
17715
  }
17539
17716
  }
17717
+ get queryQueue() {
17718
+ queryQueueDeprecationNotice();
17719
+ return this._queryQueue;
17720
+ }
17540
17721
  };
17541
17722
  Client2.Query = Query2;
17542
17723
  module2.exports = Client2;
@@ -17635,6 +17816,13 @@ var require_pg_pool = __commonJS({
17635
17816
  this.ending = false;
17636
17817
  this.ended = false;
17637
17818
  }
17819
+ _promiseTry(f) {
17820
+ const Promise2 = this.Promise;
17821
+ if (typeof Promise2.try === "function") {
17822
+ return Promise2.try(f);
17823
+ }
17824
+ return new Promise2((resolve) => resolve(f()));
17825
+ }
17638
17826
  _isFull() {
17639
17827
  return this._clients.length >= this.options.max;
17640
17828
  }
@@ -17738,9 +17926,15 @@ var require_pg_pool = __commonJS({
17738
17926
  let timeoutHit = false;
17739
17927
  if (this.options.connectionTimeoutMillis) {
17740
17928
  tid = setTimeout(() => {
17741
- this.log("ending client due to timeout");
17742
- timeoutHit = true;
17743
- client.connection ? client.connection.stream.destroy() : client.end();
17929
+ if (client.connection) {
17930
+ this.log("ending client due to timeout");
17931
+ timeoutHit = true;
17932
+ client.connection.stream.destroy();
17933
+ } else if (!client.isConnected()) {
17934
+ this.log("ending client due to timeout");
17935
+ timeoutHit = true;
17936
+ client.end();
17937
+ }
17744
17938
  }, this.options.connectionTimeoutMillis);
17745
17939
  }
17746
17940
  this.log("connecting new client");
@@ -17761,27 +17955,47 @@ var require_pg_pool = __commonJS({
17761
17955
  }
17762
17956
  } else {
17763
17957
  this.log("new client connected");
17764
- if (this.options.maxLifetimeSeconds !== 0) {
17765
- const maxLifetimeTimeout = setTimeout(() => {
17766
- this.log("ending client due to expired lifetime");
17767
- this._expired.add(client);
17768
- const idleIndex = this._idle.findIndex((idleItem) => idleItem.client === client);
17769
- if (idleIndex !== -1) {
17770
- this._acquireClient(
17771
- client,
17772
- new PendingItem((err2, client2, clientRelease) => clientRelease()),
17773
- idleListener,
17774
- false
17775
- );
17958
+ if (this.options.onConnect) {
17959
+ this._promiseTry(() => this.options.onConnect(client)).then(
17960
+ () => {
17961
+ this._afterConnect(client, pendingItem, idleListener);
17962
+ },
17963
+ (hookErr) => {
17964
+ this._clients = this._clients.filter((c) => c !== client);
17965
+ client.end(() => {
17966
+ this._pulseQueue();
17967
+ if (!pendingItem.timedOut) {
17968
+ pendingItem.callback(hookErr, void 0, NOOP);
17969
+ }
17970
+ });
17776
17971
  }
17777
- }, this.options.maxLifetimeSeconds * 1e3);
17778
- maxLifetimeTimeout.unref();
17779
- client.once("end", () => clearTimeout(maxLifetimeTimeout));
17972
+ );
17973
+ return;
17780
17974
  }
17781
- return this._acquireClient(client, pendingItem, idleListener, true);
17975
+ return this._afterConnect(client, pendingItem, idleListener);
17782
17976
  }
17783
17977
  });
17784
17978
  }
17979
+ _afterConnect(client, pendingItem, idleListener) {
17980
+ if (this.options.maxLifetimeSeconds !== 0) {
17981
+ const maxLifetimeTimeout = setTimeout(() => {
17982
+ this.log("ending client due to expired lifetime");
17983
+ this._expired.add(client);
17984
+ const idleIndex = this._idle.findIndex((idleItem) => idleItem.client === client);
17985
+ if (idleIndex !== -1) {
17986
+ this._acquireClient(
17987
+ client,
17988
+ new PendingItem((err, client2, clientRelease) => clientRelease()),
17989
+ idleListener,
17990
+ false
17991
+ );
17992
+ }
17993
+ }, this.options.maxLifetimeSeconds * 1e3);
17994
+ maxLifetimeTimeout.unref();
17995
+ client.once("end", () => clearTimeout(maxLifetimeTimeout));
17996
+ }
17997
+ return this._acquireClient(client, pendingItem, idleListener, true);
17998
+ }
17785
17999
  // acquire a client for a pending work item
17786
18000
  _acquireClient(client, pendingItem, idleListener, isNew) {
17787
18001
  if (isNew) {
@@ -17842,8 +18056,10 @@ var require_pg_pool = __commonJS({
17842
18056
  let tid;
17843
18057
  if (this.options.idleTimeoutMillis && this._isAboveMin()) {
17844
18058
  tid = setTimeout(() => {
17845
- this.log("remove idle client");
17846
- this._remove(client, this._pulseQueue.bind(this));
18059
+ if (this._isAboveMin()) {
18060
+ this.log("remove idle client");
18061
+ this._remove(client, this._pulseQueue.bind(this));
18062
+ }
17847
18063
  }, this.options.idleTimeoutMillis);
17848
18064
  if (this.options.allowExitOnIdle) {
17849
18065
  tid.unref();
@@ -18079,6 +18295,7 @@ var require_query2 = __commonJS({
18079
18295
  var require_client2 = __commonJS({
18080
18296
  "../../node_modules/pg/lib/native/client.js"(exports2, module2) {
18081
18297
  "use strict";
18298
+ var nodeUtils = require("util");
18082
18299
  var Native;
18083
18300
  try {
18084
18301
  Native = require("pg-native");
@@ -18090,6 +18307,11 @@ var require_client2 = __commonJS({
18090
18307
  var util = require("util");
18091
18308
  var ConnectionParameters = require_connection_parameters();
18092
18309
  var NativeQuery = require_query2();
18310
+ var queryQueueLengthDeprecationNotice = nodeUtils.deprecate(
18311
+ () => {
18312
+ },
18313
+ "Calling client.query() when the client is already executing a query is deprecated and will be removed in pg@9.0. Use async/await or an external async flow control mechanism instead."
18314
+ );
18093
18315
  var Client2 = module2.exports = function(config) {
18094
18316
  EventEmitter.call(this);
18095
18317
  config = config || {};
@@ -18162,7 +18384,7 @@ var require_client2 = __commonJS({
18162
18384
  });
18163
18385
  self.emit("connect");
18164
18386
  self._pulseQueryQueue(true);
18165
- cb();
18387
+ cb(null, this);
18166
18388
  });
18167
18389
  });
18168
18390
  };
@@ -18176,7 +18398,7 @@ var require_client2 = __commonJS({
18176
18398
  if (error) {
18177
18399
  reject(error);
18178
18400
  } else {
18179
- resolve();
18401
+ resolve(this);
18180
18402
  }
18181
18403
  });
18182
18404
  });
@@ -18211,7 +18433,8 @@ var require_client2 = __commonJS({
18211
18433
  }
18212
18434
  }
18213
18435
  if (readTimeout) {
18214
- queryCallback = query.callback;
18436
+ queryCallback = query.callback || (() => {
18437
+ });
18215
18438
  readTimeoutTimer = setTimeout(() => {
18216
18439
  const error = new Error("Query read timeout");
18217
18440
  process.nextTick(() => {
@@ -18245,6 +18468,9 @@ var require_client2 = __commonJS({
18245
18468
  });
18246
18469
  return result;
18247
18470
  }
18471
+ if (this._queryQueue.length > 0) {
18472
+ queryQueueLengthDeprecationNotice();
18473
+ }
18248
18474
  this._queryQueue.push(query);
18249
18475
  this._pulseQueryQueue();
18250
18476
  return result;
@@ -18252,8 +18478,11 @@ var require_client2 = __commonJS({
18252
18478
  Client2.prototype.end = function(cb) {
18253
18479
  const self = this;
18254
18480
  this._ending = true;
18255
- if (!this._connected) {
18256
- this.once("connect", this.end.bind(this, cb));
18481
+ if (this._connecting && !this._connected) {
18482
+ this.once("connect", () => {
18483
+ this.end(() => {
18484
+ });
18485
+ });
18257
18486
  }
18258
18487
  let result;
18259
18488
  if (!cb) {
@@ -18262,6 +18491,7 @@ var require_client2 = __commonJS({
18262
18491
  });
18263
18492
  }
18264
18493
  this.native.end(function() {
18494
+ self._connected = false;
18265
18495
  self._errorAllQueries(new Error("Connection terminated"));
18266
18496
  process.nextTick(() => {
18267
18497
  self.emit("end");
@@ -18312,6 +18542,12 @@ var require_client2 = __commonJS({
18312
18542
  Client2.prototype.getTypeParser = function(oid, format2) {
18313
18543
  return this._types.getTypeParser(oid, format2);
18314
18544
  };
18545
+ Client2.prototype.isConnected = function() {
18546
+ return this._connected;
18547
+ };
18548
+ Client2.prototype.getTransactionStatus = function() {
18549
+ return this.native.getTransactionStatus();
18550
+ };
18315
18551
  }
18316
18552
  });
18317
18553
 
@@ -18343,9 +18579,9 @@ var require_lib2 = __commonJS({
18343
18579
  }
18344
18580
  };
18345
18581
  };
18346
- var PG = function(clientConstructor) {
18582
+ var PG = function(clientConstructor2) {
18347
18583
  this.defaults = defaults2;
18348
- this.Client = clientConstructor;
18584
+ this.Client = clientConstructor2;
18349
18585
  this.Query = this.Client.Query;
18350
18586
  this.Pool = poolFactory(this.Client);
18351
18587
  this._pools = [];
@@ -18358,29 +18594,34 @@ var require_lib2 = __commonJS({
18358
18594
  this.Result = Result2;
18359
18595
  this.utils = utils;
18360
18596
  };
18361
- if (typeof process.env.NODE_PG_FORCE_NATIVE !== "undefined") {
18362
- module2.exports = new PG(require_native());
18363
- } else {
18364
- module2.exports = new PG(Client2);
18365
- Object.defineProperty(module2.exports, "native", {
18366
- configurable: true,
18367
- enumerable: false,
18368
- get() {
18369
- let native = null;
18370
- try {
18371
- native = new PG(require_native());
18372
- } catch (err) {
18373
- if (err.code !== "MODULE_NOT_FOUND") {
18374
- throw err;
18375
- }
18597
+ var clientConstructor = Client2;
18598
+ var forceNative = false;
18599
+ try {
18600
+ forceNative = !!process.env.NODE_PG_FORCE_NATIVE;
18601
+ } catch {
18602
+ }
18603
+ if (forceNative) {
18604
+ clientConstructor = require_native();
18605
+ }
18606
+ module2.exports = new PG(clientConstructor);
18607
+ Object.defineProperty(module2.exports, "native", {
18608
+ configurable: true,
18609
+ enumerable: false,
18610
+ get() {
18611
+ let native = null;
18612
+ try {
18613
+ native = new PG(require_native());
18614
+ } catch (err) {
18615
+ if (err.code !== "MODULE_NOT_FOUND") {
18616
+ throw err;
18376
18617
  }
18377
- Object.defineProperty(module2.exports, "native", {
18378
- value: native
18379
- });
18380
- return native;
18381
18618
  }
18382
- });
18383
- }
18619
+ Object.defineProperty(module2.exports, "native", {
18620
+ value: native
18621
+ });
18622
+ return native;
18623
+ }
18624
+ });
18384
18625
  }
18385
18626
  });
18386
18627