logixia 1.0.3 → 1.1.2

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.
Files changed (37) hide show
  1. package/README.md +523 -2852
  2. package/dist/{build-C67p8wVr.js → build-DIEB3doa.js} +7 -2
  3. package/dist/build-DIEB3doa.js.map +1 -0
  4. package/dist/{build-MpmEusc_.mjs → build-MmD3T4bV.mjs} +8 -3
  5. package/dist/build-MmD3T4bV.mjs.map +1 -0
  6. package/dist/{chunk-C41Io3cc.mjs → chunk-uEZWKkIX.mjs} +1 -1
  7. package/dist/{esm-BYmTa3gi.mjs → esm-BRY8ugtK.mjs} +438 -276
  8. package/dist/esm-BRY8ugtK.mjs.map +1 -0
  9. package/dist/{esm-BTpcNBX_.js → esm-CzjF801-.js} +437 -275
  10. package/dist/esm-CzjF801-.js.map +1 -0
  11. package/dist/index.d.mts +1012 -95
  12. package/dist/index.d.mts.map +1 -1
  13. package/dist/index.d.ts +1012 -95
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +3558 -1435
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +3517 -1408
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{lib-DvMm_tAr.mjs → lib-BNWFXK2z.mjs} +2211 -786
  20. package/dist/lib-BNWFXK2z.mjs.map +1 -0
  21. package/dist/{lib-xHiD5O-N.js → lib-Bb_wxP5g.js} +2210 -785
  22. package/dist/lib-Bb_wxP5g.js.map +1 -0
  23. package/dist/{promise-CnIyndHL.mjs → promise-BAWXE7C8.mjs} +820 -1449
  24. package/dist/promise-BAWXE7C8.mjs.map +1 -0
  25. package/dist/{promise-C7YeyZbJ.js → promise-Tbon3Kaq.js} +819 -1448
  26. package/dist/promise-Tbon3Kaq.js.map +1 -0
  27. package/dist/{sqlite3--ZdiJYT3.mjs → sqlite3-BUpkBlte.mjs} +2 -2
  28. package/dist/{sqlite3--ZdiJYT3.mjs.map → sqlite3-BUpkBlte.mjs.map} +1 -1
  29. package/package.json +124 -53
  30. package/dist/build-C67p8wVr.js.map +0 -1
  31. package/dist/build-MpmEusc_.mjs.map +0 -1
  32. package/dist/esm-BTpcNBX_.js.map +0 -1
  33. package/dist/esm-BYmTa3gi.mjs.map +0 -1
  34. package/dist/lib-DvMm_tAr.mjs.map +0 -1
  35. package/dist/lib-xHiD5O-N.js.map +0 -1
  36. package/dist/promise-C7YeyZbJ.js.map +0 -1
  37. package/dist/promise-CnIyndHL.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { __commonJS, __require, __toESM } from "./chunk-C41Io3cc.mjs";
1
+ import { a as __toESM, r as __require, t as __commonJS } from "./chunk-uEZWKkIX.mjs";
2
2
 
3
3
  //#region node_modules/postgres-array/index.js
4
4
  var require_postgres_array = /* @__PURE__ */ __commonJS({ "node_modules/postgres-array/index.js": ((exports) => {
@@ -256,8 +256,7 @@ var require_postgres_interval = /* @__PURE__ */ __commonJS({ "node_modules/postg
256
256
  var matches = INTERVAL.exec(interval);
257
257
  var isNegative = matches[8] === "-";
258
258
  return Object.keys(positions).reduce(function(parsed, property) {
259
- var position = positions[property];
260
- var value = matches[position];
259
+ var value = matches[positions[property]];
261
260
  if (!value) return parsed;
262
261
  value = property === "milliseconds" ? parseMilliseconds(value) : parseInt(value, 10);
263
262
  if (!value) return parsed;
@@ -271,8 +270,9 @@ var require_postgres_interval = /* @__PURE__ */ __commonJS({ "node_modules/postg
271
270
  //#endregion
272
271
  //#region node_modules/postgres-bytea/index.js
273
272
  var require_postgres_bytea = /* @__PURE__ */ __commonJS({ "node_modules/postgres-bytea/index.js": ((exports, module) => {
273
+ var bufferFrom = Buffer.from || Buffer;
274
274
  module.exports = function parseBytea(input) {
275
- if (/^\\x/.test(input)) return new Buffer(input.substr(2), "hex");
275
+ if (/^\\x/.test(input)) return bufferFrom(input.substr(2), "hex");
276
276
  var output = "";
277
277
  var i = 0;
278
278
  while (i < input.length) if (input[i] !== "\\") {
@@ -287,7 +287,7 @@ var require_postgres_bytea = /* @__PURE__ */ __commonJS({ "node_modules/postgres
287
287
  for (var k = 0; k < Math.floor(backslashes / 2); ++k) output += "\\";
288
288
  i += Math.floor(backslashes / 2) * 2;
289
289
  }
290
- return new Buffer(output, "binary");
290
+ return bufferFrom(output, "binary");
291
291
  };
292
292
  }) });
293
293
 
@@ -785,9 +785,13 @@ var require_pg_types = /* @__PURE__ */ __commonJS({ "node_modules/pg-types/index
785
785
  //#endregion
786
786
  //#region node_modules/pg/lib/defaults.js
787
787
  var require_defaults = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/defaults.js": ((exports, module) => {
788
+ let user;
789
+ try {
790
+ user = process.platform === "win32" ? process.env.USERNAME : process.env.USER;
791
+ } catch {}
788
792
  module.exports = {
789
793
  host: "localhost",
790
- user: process.platform === "win32" ? process.env.USERNAME : process.env.USER,
794
+ user,
791
795
  database: void 0,
792
796
  password: null,
793
797
  connectionString: void 0,
@@ -939,8 +943,8 @@ var require_utils_legacy = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/cry
939
943
  function md5$1(string) {
940
944
  return nodeCrypto$1.createHash("md5").update(string, "utf-8").digest("hex");
941
945
  }
942
- function postgresMd5PasswordHash$1(user, password$1, salt) {
943
- const inner = md5$1(password$1 + user);
946
+ function postgresMd5PasswordHash$1(user$1, password$1, salt) {
947
+ const inner = md5$1(password$1 + user$1);
944
948
  return "md5" + md5$1(Buffer.concat([Buffer.from(inner), salt]));
945
949
  }
946
950
  function sha256$1(text) {
@@ -1008,8 +1012,8 @@ var require_utils_webcrypto = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/
1008
1012
  return Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("");
1009
1013
  }
1010
1014
  }
1011
- async function postgresMd5PasswordHash(user, password$1, salt) {
1012
- const inner = await md5(password$1 + user);
1015
+ async function postgresMd5PasswordHash(user$1, password$1, salt) {
1016
+ const inner = await md5(password$1 + user$1);
1013
1017
  return "md5" + await md5(Buffer.concat([Buffer.from(inner), salt]));
1014
1018
  }
1015
1019
  /**
@@ -1237,9 +1241,7 @@ var require_sasl = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/crypto/sasl
1237
1241
  if (typeof text !== "string") throw new TypeError("SASL: attribute pairs text must be a string");
1238
1242
  return new Map(text.split(",").map((attrValue) => {
1239
1243
  if (!/^.=/.test(attrValue)) throw new Error("SASL: Invalid attribute pair entry");
1240
- const name = attrValue[0];
1241
- const value = attrValue.substring(2);
1242
- return [name, value];
1244
+ return [attrValue[0], attrValue.substring(2)];
1243
1245
  }));
1244
1246
  }
1245
1247
  function parseServerFirstMessage(data) {
@@ -1333,6 +1335,7 @@ var require_pg_connection_string = /* @__PURE__ */ __commonJS({ "node_modules/pg
1333
1335
  }
1334
1336
  } catch (err) {
1335
1337
  err.input && (err.input = "*****REDACTED*****");
1338
+ throw err;
1336
1339
  }
1337
1340
  for (const entry of result.searchParams.entries()) config[entry[0]] = entry[1];
1338
1341
  config.user = config.user || decodeURIComponent(result.username);
@@ -1381,7 +1384,9 @@ var require_pg_connection_string = /* @__PURE__ */ __commonJS({ "node_modules/pg
1381
1384
  case "prefer":
1382
1385
  case "require":
1383
1386
  case "verify-ca":
1384
- case "verify-full": break;
1387
+ case "verify-full":
1388
+ if (config.sslmode !== "verify-full") deprecatedSslModeWarning(config.sslmode);
1389
+ break;
1385
1390
  case "no-verify":
1386
1391
  config.ssl.rejectUnauthorized = false;
1387
1392
  break;
@@ -1413,6 +1418,19 @@ var require_pg_connection_string = /* @__PURE__ */ __commonJS({ "node_modules/pg
1413
1418
  function parseIntoClientConfig(str) {
1414
1419
  return toClientConfig(parse$4(str));
1415
1420
  }
1421
+ function deprecatedSslModeWarning(sslmode) {
1422
+ if (!deprecatedSslModeWarning.warned && typeof process !== "undefined" && process.emitWarning) {
1423
+ deprecatedSslModeWarning.warned = true;
1424
+ process.emitWarning(`SECURITY WARNING: The SSL modes 'prefer', 'require', and 'verify-ca' are treated as aliases for 'verify-full'.
1425
+ 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.
1426
+
1427
+ To prepare for this change:
1428
+ - If you want the current behavior, explicitly use 'sslmode=verify-full'
1429
+ - If you want libpq compatibility now, use 'uselibpqcompat=true&sslmode=${sslmode}'
1430
+
1431
+ See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode definitions.`);
1432
+ }
1433
+ }
1416
1434
  module.exports = parse$4;
1417
1435
  parse$4.parse = parse$4;
1418
1436
  parse$4.toClientConfig = toClientConfig;
@@ -1426,9 +1444,10 @@ var require_connection_parameters = /* @__PURE__ */ __commonJS({ "node_modules/p
1426
1444
  const defaults$3 = require_defaults();
1427
1445
  const parse$3 = require_pg_connection_string().parse;
1428
1446
  const val = function(key, config, envVar) {
1447
+ if (config[key]) return config[key];
1429
1448
  if (envVar === void 0) envVar = process.env["PG" + key.toUpperCase()];
1430
1449
  else if (envVar === false) {} else envVar = process.env[envVar];
1431
- return config[key] || envVar || defaults$3[key];
1450
+ return envVar || defaults$3[key];
1432
1451
  };
1433
1452
  const readSSLConfigFromEnvironment = function() {
1434
1453
  switch (process.env.PGSSLMODE) {
@@ -1736,6 +1755,7 @@ var require_query$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/query.js
1736
1755
  //#region node_modules/pg-protocol/dist/messages.js
1737
1756
  var require_messages = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/dist/messages.js": ((exports) => {
1738
1757
  Object.defineProperty(exports, "__esModule", { value: true });
1758
+ exports.NoticeMessage = exports.DataRowMessage = exports.CommandCompleteMessage = exports.ReadyForQueryMessage = exports.NotificationResponseMessage = exports.BackendKeyDataMessage = exports.AuthenticationMD5Password = exports.ParameterStatusMessage = exports.ParameterDescriptionMessage = exports.RowDescriptionMessage = exports.Field = exports.CopyResponse = exports.CopyDataMessage = exports.DatabaseError = exports.copyDone = exports.emptyQuery = exports.replicationStart = exports.portalSuspended = exports.noData = exports.closeComplete = exports.bindComplete = exports.parseComplete = void 0;
1739
1759
  exports.parseComplete = {
1740
1760
  name: "parseComplete",
1741
1761
  length: 5
@@ -1898,6 +1918,7 @@ var require_messages = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/di
1898
1918
  //#region node_modules/pg-protocol/dist/buffer-writer.js
1899
1919
  var require_buffer_writer = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/dist/buffer-writer.js": ((exports) => {
1900
1920
  Object.defineProperty(exports, "__esModule", { value: true });
1921
+ exports.Writer = void 0;
1901
1922
  var Writer = class {
1902
1923
  constructor(size = 256) {
1903
1924
  this.size = size;
@@ -1974,6 +1995,7 @@ var require_buffer_writer = /* @__PURE__ */ __commonJS({ "node_modules/pg-protoc
1974
1995
  //#region node_modules/pg-protocol/dist/serializer.js
1975
1996
  var require_serializer = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/dist/serializer.js": ((exports) => {
1976
1997
  Object.defineProperty(exports, "__esModule", { value: true });
1998
+ exports.serialize = void 0;
1977
1999
  const buffer_writer_1 = require_buffer_writer();
1978
2000
  const writer = new buffer_writer_1.Writer();
1979
2001
  const startup = (opts) => {
@@ -2100,8 +2122,7 @@ var require_serializer = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/
2100
2122
  return msg.name ? cstringMessage(68, `${msg.type}${msg.name || ""}`) : msg.type === "P" ? emptyDescribePortal : emptyDescribeStatement;
2101
2123
  };
2102
2124
  const close = (msg) => {
2103
- const text = `${msg.type}${msg.name || ""}`;
2104
- return cstringMessage(67, text);
2125
+ return cstringMessage(67, `${msg.type}${msg.name || ""}`);
2105
2126
  };
2106
2127
  const copyData = (chunk) => {
2107
2128
  return writer.add(chunk).flush(100);
@@ -2147,11 +2168,11 @@ var require_serializer = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/
2147
2168
  //#region node_modules/pg-protocol/dist/buffer-reader.js
2148
2169
  var require_buffer_reader = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/dist/buffer-reader.js": ((exports) => {
2149
2170
  Object.defineProperty(exports, "__esModule", { value: true });
2150
- const emptyBuffer$1 = Buffer.allocUnsafe(0);
2171
+ exports.BufferReader = void 0;
2151
2172
  var BufferReader = class {
2152
2173
  constructor(offset = 0) {
2153
2174
  this.offset = offset;
2154
- this.buffer = emptyBuffer$1;
2175
+ this.buffer = Buffer.allocUnsafe(0);
2155
2176
  this.encoding = "utf-8";
2156
2177
  }
2157
2178
  setBuffer(offset, buffer) {
@@ -2203,10 +2224,12 @@ var require_buffer_reader = /* @__PURE__ */ __commonJS({ "node_modules/pg-protoc
2203
2224
  //#region node_modules/pg-protocol/dist/parser.js
2204
2225
  var require_parser = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/dist/parser.js": ((exports) => {
2205
2226
  Object.defineProperty(exports, "__esModule", { value: true });
2227
+ exports.Parser = void 0;
2206
2228
  const messages_1$1 = require_messages();
2207
2229
  const buffer_reader_1 = require_buffer_reader();
2208
2230
  const CODE_LENGTH = 1;
2209
2231
  const HEADER_LENGTH = CODE_LENGTH + 4;
2232
+ const LATEINIT_LENGTH = -1;
2210
2233
  const emptyBuffer = Buffer.allocUnsafe(0);
2211
2234
  var Parser = class {
2212
2235
  constructor(opts) {
@@ -2226,8 +2249,7 @@ var require_parser = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/dist
2226
2249
  const length = this.buffer.readUInt32BE(offset + CODE_LENGTH);
2227
2250
  const fullMessageLength = CODE_LENGTH + length;
2228
2251
  if (fullMessageLength + offset <= bufferFullLength) {
2229
- const message = this.handlePacket(offset + HEADER_LENGTH, code, length, this.buffer);
2230
- callback(message);
2252
+ callback(this.handlePacket(offset + HEADER_LENGTH, code, length, this.buffer));
2231
2253
  offset += fullMessageLength;
2232
2254
  } else break;
2233
2255
  }
@@ -2264,185 +2286,220 @@ var require_parser = /* @__PURE__ */ __commonJS({ "node_modules/pg-protocol/dist
2264
2286
  }
2265
2287
  }
2266
2288
  handlePacket(offset, code, length, bytes) {
2289
+ const { reader } = this;
2290
+ reader.setBuffer(offset, bytes);
2291
+ let message;
2267
2292
  switch (code) {
2268
- case 50: return messages_1$1.bindComplete;
2269
- case 49: return messages_1$1.parseComplete;
2270
- case 51: return messages_1$1.closeComplete;
2271
- case 110: return messages_1$1.noData;
2272
- case 115: return messages_1$1.portalSuspended;
2273
- case 99: return messages_1$1.copyDone;
2274
- case 87: return messages_1$1.replicationStart;
2275
- case 73: return messages_1$1.emptyQuery;
2276
- case 68: return this.parseDataRowMessage(offset, length, bytes);
2277
- case 67: return this.parseCommandCompleteMessage(offset, length, bytes);
2278
- case 90: return this.parseReadyForQueryMessage(offset, length, bytes);
2279
- case 65: return this.parseNotificationMessage(offset, length, bytes);
2280
- case 82: return this.parseAuthenticationResponse(offset, length, bytes);
2281
- case 83: return this.parseParameterStatusMessage(offset, length, bytes);
2282
- case 75: return this.parseBackendKeyData(offset, length, bytes);
2283
- case 69: return this.parseErrorMessage(offset, length, bytes, "error");
2284
- case 78: return this.parseErrorMessage(offset, length, bytes, "notice");
2285
- case 84: return this.parseRowDescriptionMessage(offset, length, bytes);
2286
- case 116: return this.parseParameterDescriptionMessage(offset, length, bytes);
2287
- case 71: return this.parseCopyInMessage(offset, length, bytes);
2288
- case 72: return this.parseCopyOutMessage(offset, length, bytes);
2289
- case 100: return this.parseCopyData(offset, length, bytes);
2290
- default: return new messages_1$1.DatabaseError("received invalid response: " + code.toString(16), length, "error");
2291
- }
2292
- }
2293
- parseReadyForQueryMessage(offset, length, bytes) {
2294
- this.reader.setBuffer(offset, bytes);
2295
- const status = this.reader.string(1);
2296
- return new messages_1$1.ReadyForQueryMessage(length, status);
2297
- }
2298
- parseCommandCompleteMessage(offset, length, bytes) {
2299
- this.reader.setBuffer(offset, bytes);
2300
- const text = this.reader.cstring();
2301
- return new messages_1$1.CommandCompleteMessage(length, text);
2302
- }
2303
- parseCopyData(offset, length, bytes) {
2304
- const chunk = bytes.slice(offset, offset + (length - 4));
2305
- return new messages_1$1.CopyDataMessage(length, chunk);
2306
- }
2307
- parseCopyInMessage(offset, length, bytes) {
2308
- return this.parseCopyMessage(offset, length, bytes, "copyInResponse");
2309
- }
2310
- parseCopyOutMessage(offset, length, bytes) {
2311
- return this.parseCopyMessage(offset, length, bytes, "copyOutResponse");
2312
- }
2313
- parseCopyMessage(offset, length, bytes, messageName) {
2314
- this.reader.setBuffer(offset, bytes);
2315
- const isBinary = this.reader.byte() !== 0;
2316
- const columnCount = this.reader.int16();
2317
- const message = new messages_1$1.CopyResponse(length, messageName, isBinary, columnCount);
2318
- for (let i = 0; i < columnCount; i++) message.columnTypes[i] = this.reader.int16();
2319
- return message;
2320
- }
2321
- parseNotificationMessage(offset, length, bytes) {
2322
- this.reader.setBuffer(offset, bytes);
2323
- const processId = this.reader.int32();
2324
- const channel = this.reader.cstring();
2325
- const payload = this.reader.cstring();
2326
- return new messages_1$1.NotificationResponseMessage(length, processId, channel, payload);
2327
- }
2328
- parseRowDescriptionMessage(offset, length, bytes) {
2329
- this.reader.setBuffer(offset, bytes);
2330
- const fieldCount = this.reader.int16();
2331
- const message = new messages_1$1.RowDescriptionMessage(length, fieldCount);
2332
- for (let i = 0; i < fieldCount; i++) message.fields[i] = this.parseField();
2333
- return message;
2334
- }
2335
- parseField() {
2336
- const name = this.reader.cstring();
2337
- const tableID = this.reader.uint32();
2338
- const columnID = this.reader.int16();
2339
- const dataTypeID = this.reader.uint32();
2340
- const dataTypeSize = this.reader.int16();
2341
- const dataTypeModifier = this.reader.int32();
2342
- const mode = this.reader.int16() === 0 ? "text" : "binary";
2343
- return new messages_1$1.Field(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, mode);
2344
- }
2345
- parseParameterDescriptionMessage(offset, length, bytes) {
2346
- this.reader.setBuffer(offset, bytes);
2347
- const parameterCount = this.reader.int16();
2348
- const message = new messages_1$1.ParameterDescriptionMessage(length, parameterCount);
2349
- for (let i = 0; i < parameterCount; i++) message.dataTypeIDs[i] = this.reader.int32();
2350
- return message;
2351
- }
2352
- parseDataRowMessage(offset, length, bytes) {
2353
- this.reader.setBuffer(offset, bytes);
2354
- const fieldCount = this.reader.int16();
2355
- const fields = new Array(fieldCount);
2356
- for (let i = 0; i < fieldCount; i++) {
2357
- const len = this.reader.int32();
2358
- fields[i] = len === -1 ? null : this.reader.string(len);
2359
- }
2360
- return new messages_1$1.DataRowMessage(length, fields);
2361
- }
2362
- parseParameterStatusMessage(offset, length, bytes) {
2363
- this.reader.setBuffer(offset, bytes);
2364
- const name = this.reader.cstring();
2365
- const value = this.reader.cstring();
2366
- return new messages_1$1.ParameterStatusMessage(length, name, value);
2367
- }
2368
- parseBackendKeyData(offset, length, bytes) {
2369
- this.reader.setBuffer(offset, bytes);
2370
- const processID = this.reader.int32();
2371
- const secretKey = this.reader.int32();
2372
- return new messages_1$1.BackendKeyDataMessage(length, processID, secretKey);
2373
- }
2374
- parseAuthenticationResponse(offset, length, bytes) {
2375
- this.reader.setBuffer(offset, bytes);
2376
- const code = this.reader.int32();
2377
- const message = {
2378
- name: "authenticationOk",
2379
- length
2380
- };
2381
- switch (code) {
2382
- case 0: break;
2383
- case 3:
2384
- if (message.length === 8) message.name = "authenticationCleartextPassword";
2293
+ case 50:
2294
+ message = messages_1$1.bindComplete;
2385
2295
  break;
2386
- case 5:
2387
- if (message.length === 12) {
2388
- message.name = "authenticationMD5Password";
2389
- const salt = this.reader.bytes(4);
2390
- return new messages_1$1.AuthenticationMD5Password(length, salt);
2391
- }
2296
+ case 49:
2297
+ message = messages_1$1.parseComplete;
2392
2298
  break;
2393
- case 10:
2394
- {
2395
- message.name = "authenticationSASL";
2396
- message.mechanisms = [];
2397
- let mechanism;
2398
- do {
2399
- mechanism = this.reader.cstring();
2400
- if (mechanism) message.mechanisms.push(mechanism);
2401
- } while (mechanism);
2402
- }
2299
+ case 51:
2300
+ message = messages_1$1.closeComplete;
2301
+ break;
2302
+ case 110:
2303
+ message = messages_1$1.noData;
2403
2304
  break;
2404
- case 11:
2405
- message.name = "authenticationSASLContinue";
2406
- message.data = this.reader.string(length - 8);
2305
+ case 115:
2306
+ message = messages_1$1.portalSuspended;
2407
2307
  break;
2408
- case 12:
2409
- message.name = "authenticationSASLFinal";
2410
- message.data = this.reader.string(length - 8);
2308
+ case 99:
2309
+ message = messages_1$1.copyDone;
2411
2310
  break;
2412
- default: throw new Error("Unknown authenticationOk message type " + code);
2311
+ case 87:
2312
+ message = messages_1$1.replicationStart;
2313
+ break;
2314
+ case 73:
2315
+ message = messages_1$1.emptyQuery;
2316
+ break;
2317
+ case 68:
2318
+ message = parseDataRowMessage(reader);
2319
+ break;
2320
+ case 67:
2321
+ message = parseCommandCompleteMessage(reader);
2322
+ break;
2323
+ case 90:
2324
+ message = parseReadyForQueryMessage(reader);
2325
+ break;
2326
+ case 65:
2327
+ message = parseNotificationMessage(reader);
2328
+ break;
2329
+ case 82:
2330
+ message = parseAuthenticationResponse(reader, length);
2331
+ break;
2332
+ case 83:
2333
+ message = parseParameterStatusMessage(reader);
2334
+ break;
2335
+ case 75:
2336
+ message = parseBackendKeyData(reader);
2337
+ break;
2338
+ case 69:
2339
+ message = parseErrorMessage(reader, "error");
2340
+ break;
2341
+ case 78:
2342
+ message = parseErrorMessage(reader, "notice");
2343
+ break;
2344
+ case 84:
2345
+ message = parseRowDescriptionMessage(reader);
2346
+ break;
2347
+ case 116:
2348
+ message = parseParameterDescriptionMessage(reader);
2349
+ break;
2350
+ case 71:
2351
+ message = parseCopyInMessage(reader);
2352
+ break;
2353
+ case 72:
2354
+ message = parseCopyOutMessage(reader);
2355
+ break;
2356
+ case 100:
2357
+ message = parseCopyData(reader, length);
2358
+ break;
2359
+ default: return new messages_1$1.DatabaseError("received invalid response: " + code.toString(16), length, "error");
2413
2360
  }
2414
- return message;
2415
- }
2416
- parseErrorMessage(offset, length, bytes, name) {
2417
- this.reader.setBuffer(offset, bytes);
2418
- const fields = {};
2419
- let fieldType = this.reader.string(1);
2420
- while (fieldType !== "\0") {
2421
- fields[fieldType] = this.reader.cstring();
2422
- fieldType = this.reader.string(1);
2423
- }
2424
- const messageValue = fields.M;
2425
- const message = name === "notice" ? new messages_1$1.NoticeMessage(length, messageValue) : new messages_1$1.DatabaseError(messageValue, length, name);
2426
- message.severity = fields.S;
2427
- message.code = fields.C;
2428
- message.detail = fields.D;
2429
- message.hint = fields.H;
2430
- message.position = fields.P;
2431
- message.internalPosition = fields.p;
2432
- message.internalQuery = fields.q;
2433
- message.where = fields.W;
2434
- message.schema = fields.s;
2435
- message.table = fields.t;
2436
- message.column = fields.c;
2437
- message.dataType = fields.d;
2438
- message.constraint = fields.n;
2439
- message.file = fields.F;
2440
- message.line = fields.L;
2441
- message.routine = fields.R;
2361
+ reader.setBuffer(0, emptyBuffer);
2362
+ message.length = length;
2442
2363
  return message;
2443
2364
  }
2444
2365
  };
2445
2366
  exports.Parser = Parser;
2367
+ const parseReadyForQueryMessage = (reader) => {
2368
+ const status = reader.string(1);
2369
+ return new messages_1$1.ReadyForQueryMessage(LATEINIT_LENGTH, status);
2370
+ };
2371
+ const parseCommandCompleteMessage = (reader) => {
2372
+ const text = reader.cstring();
2373
+ return new messages_1$1.CommandCompleteMessage(LATEINIT_LENGTH, text);
2374
+ };
2375
+ const parseCopyData = (reader, length) => {
2376
+ const chunk = reader.bytes(length - 4);
2377
+ return new messages_1$1.CopyDataMessage(LATEINIT_LENGTH, chunk);
2378
+ };
2379
+ const parseCopyInMessage = (reader) => parseCopyMessage(reader, "copyInResponse");
2380
+ const parseCopyOutMessage = (reader) => parseCopyMessage(reader, "copyOutResponse");
2381
+ const parseCopyMessage = (reader, messageName) => {
2382
+ const isBinary = reader.byte() !== 0;
2383
+ const columnCount = reader.int16();
2384
+ const message = new messages_1$1.CopyResponse(LATEINIT_LENGTH, messageName, isBinary, columnCount);
2385
+ for (let i = 0; i < columnCount; i++) message.columnTypes[i] = reader.int16();
2386
+ return message;
2387
+ };
2388
+ const parseNotificationMessage = (reader) => {
2389
+ const processId = reader.int32();
2390
+ const channel = reader.cstring();
2391
+ const payload = reader.cstring();
2392
+ return new messages_1$1.NotificationResponseMessage(LATEINIT_LENGTH, processId, channel, payload);
2393
+ };
2394
+ const parseRowDescriptionMessage = (reader) => {
2395
+ const fieldCount = reader.int16();
2396
+ const message = new messages_1$1.RowDescriptionMessage(LATEINIT_LENGTH, fieldCount);
2397
+ for (let i = 0; i < fieldCount; i++) message.fields[i] = parseField(reader);
2398
+ return message;
2399
+ };
2400
+ const parseField = (reader) => {
2401
+ const name = reader.cstring();
2402
+ const tableID = reader.uint32();
2403
+ const columnID = reader.int16();
2404
+ const dataTypeID = reader.uint32();
2405
+ const dataTypeSize = reader.int16();
2406
+ const dataTypeModifier = reader.int32();
2407
+ const mode = reader.int16() === 0 ? "text" : "binary";
2408
+ return new messages_1$1.Field(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, mode);
2409
+ };
2410
+ const parseParameterDescriptionMessage = (reader) => {
2411
+ const parameterCount = reader.int16();
2412
+ const message = new messages_1$1.ParameterDescriptionMessage(LATEINIT_LENGTH, parameterCount);
2413
+ for (let i = 0; i < parameterCount; i++) message.dataTypeIDs[i] = reader.int32();
2414
+ return message;
2415
+ };
2416
+ const parseDataRowMessage = (reader) => {
2417
+ const fieldCount = reader.int16();
2418
+ const fields = new Array(fieldCount);
2419
+ for (let i = 0; i < fieldCount; i++) {
2420
+ const len = reader.int32();
2421
+ fields[i] = len === -1 ? null : reader.string(len);
2422
+ }
2423
+ return new messages_1$1.DataRowMessage(LATEINIT_LENGTH, fields);
2424
+ };
2425
+ const parseParameterStatusMessage = (reader) => {
2426
+ const name = reader.cstring();
2427
+ const value = reader.cstring();
2428
+ return new messages_1$1.ParameterStatusMessage(LATEINIT_LENGTH, name, value);
2429
+ };
2430
+ const parseBackendKeyData = (reader) => {
2431
+ const processID = reader.int32();
2432
+ const secretKey = reader.int32();
2433
+ return new messages_1$1.BackendKeyDataMessage(LATEINIT_LENGTH, processID, secretKey);
2434
+ };
2435
+ const parseAuthenticationResponse = (reader, length) => {
2436
+ const code = reader.int32();
2437
+ const message = {
2438
+ name: "authenticationOk",
2439
+ length
2440
+ };
2441
+ switch (code) {
2442
+ case 0: break;
2443
+ case 3:
2444
+ if (message.length === 8) message.name = "authenticationCleartextPassword";
2445
+ break;
2446
+ case 5:
2447
+ if (message.length === 12) {
2448
+ message.name = "authenticationMD5Password";
2449
+ const salt = reader.bytes(4);
2450
+ return new messages_1$1.AuthenticationMD5Password(LATEINIT_LENGTH, salt);
2451
+ }
2452
+ break;
2453
+ case 10:
2454
+ {
2455
+ message.name = "authenticationSASL";
2456
+ message.mechanisms = [];
2457
+ let mechanism;
2458
+ do {
2459
+ mechanism = reader.cstring();
2460
+ if (mechanism) message.mechanisms.push(mechanism);
2461
+ } while (mechanism);
2462
+ }
2463
+ break;
2464
+ case 11:
2465
+ message.name = "authenticationSASLContinue";
2466
+ message.data = reader.string(length - 8);
2467
+ break;
2468
+ case 12:
2469
+ message.name = "authenticationSASLFinal";
2470
+ message.data = reader.string(length - 8);
2471
+ break;
2472
+ default: throw new Error("Unknown authenticationOk message type " + code);
2473
+ }
2474
+ return message;
2475
+ };
2476
+ const parseErrorMessage = (reader, name) => {
2477
+ const fields = {};
2478
+ let fieldType = reader.string(1);
2479
+ while (fieldType !== "\0") {
2480
+ fields[fieldType] = reader.cstring();
2481
+ fieldType = reader.string(1);
2482
+ }
2483
+ const messageValue = fields.M;
2484
+ const message = name === "notice" ? new messages_1$1.NoticeMessage(LATEINIT_LENGTH, messageValue) : new messages_1$1.DatabaseError(messageValue, LATEINIT_LENGTH, name);
2485
+ message.severity = fields.S;
2486
+ message.code = fields.C;
2487
+ message.detail = fields.D;
2488
+ message.hint = fields.H;
2489
+ message.position = fields.P;
2490
+ message.internalPosition = fields.p;
2491
+ message.internalQuery = fields.q;
2492
+ message.where = fields.W;
2493
+ message.schema = fields.s;
2494
+ message.table = fields.t;
2495
+ message.column = fields.c;
2496
+ message.dataType = fields.d;
2497
+ message.constraint = fields.n;
2498
+ message.file = fields.F;
2499
+ message.line = fields.L;
2500
+ message.routine = fields.R;
2501
+ return message;
2502
+ };
2446
2503
  }) });
2447
2504
 
2448
2505
  //#endregion
@@ -2556,7 +2613,6 @@ var require_connection = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/conne
2556
2613
  if (typeof this.stream === "function") this.stream = this.stream(config);
2557
2614
  this._keepAlive = config.keepAlive;
2558
2615
  this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis;
2559
- this.lastBuffer = false;
2560
2616
  this.parsedStatements = {};
2561
2617
  this.ssl = config.ssl || false;
2562
2618
  this._ending = false;
@@ -2921,8 +2977,7 @@ var require_helper = /* @__PURE__ */ __commonJS({ "node_modules/pgpass/lib/helpe
2921
2977
  };
2922
2978
  for (var idx = 0; idx < fieldNames.length; idx += 1) {
2923
2979
  var rule = rules[idx];
2924
- var value = entry[fieldNames[idx]] || "";
2925
- if (!rule(value)) return false;
2980
+ if (!rule(entry[fieldNames[idx]] || "")) return false;
2926
2981
  }
2927
2982
  return true;
2928
2983
  };
@@ -2949,6 +3004,7 @@ var require_lib$1 = /* @__PURE__ */ __commonJS({ "node_modules/pgpass/lib/index.
2949
3004
  var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.js": ((exports, module) => {
2950
3005
  const EventEmitter$3 = __require("events").EventEmitter;
2951
3006
  const utils$2 = require_utils$1();
3007
+ const nodeUtils$1 = __require("util");
2952
3008
  const sasl = require_sasl();
2953
3009
  const TypeOverrides$3 = require_type_overrides();
2954
3010
  const ConnectionParameters$1 = require_connection_parameters();
@@ -2956,6 +3012,11 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
2956
3012
  const defaults$2 = require_defaults();
2957
3013
  const Connection$2 = require_connection();
2958
3014
  const crypto = require_utils();
3015
+ const activeQueryDeprecationNotice = nodeUtils$1.deprecate(() => {}, "Client.activeQuery is deprecated and will be removed in pg@9.0");
3016
+ const queryQueueDeprecationNotice = nodeUtils$1.deprecate(() => {}, "Client.queryQueue is deprecated and will be removed in pg@9.0.");
3017
+ const pgPassDeprecationNotice = nodeUtils$1.deprecate(() => {}, "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.");
3018
+ const byoPromiseDeprecationNotice = nodeUtils$1.deprecate(() => {}, "Passing a custom Promise implementation to the Client/Pool constructor is deprecated and will be removed in pg@9.0.");
3019
+ const queryQueueLengthDeprecationNotice$1 = nodeUtils$1.deprecate(() => {}, "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.");
2959
3020
  var Client$3 = class extends EventEmitter$3 {
2960
3021
  constructor(config) {
2961
3022
  super();
@@ -2972,6 +3033,7 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
2972
3033
  });
2973
3034
  this.replication = this.connectionParameters.replication;
2974
3035
  const c = config || {};
3036
+ if (c.Promise) byoPromiseDeprecationNotice();
2975
3037
  this._Promise = c.Promise || global.Promise;
2976
3038
  this._types = new TypeOverrides$3(c.types);
2977
3039
  this._ending = false;
@@ -2980,6 +3042,7 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
2980
3042
  this._connected = false;
2981
3043
  this._connectionError = false;
2982
3044
  this._queryable = true;
3045
+ this._activeQuery = null;
2983
3046
  this.enableChannelBinding = Boolean(c.enableChannelBinding);
2984
3047
  this.connection = c.connection || new Connection$2({
2985
3048
  stream: c.stream,
@@ -2988,7 +3051,7 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
2988
3051
  keepAliveInitialDelayMillis: c.keepAliveInitialDelayMillis || 0,
2989
3052
  encoding: this.connectionParameters.client_encoding || "utf8"
2990
3053
  });
2991
- this.queryQueue = [];
3054
+ this._queryQueue = [];
2992
3055
  this.binary = c.binary || defaults$2.binary;
2993
3056
  this.processID = null;
2994
3057
  this.secretKey = null;
@@ -2996,18 +3059,30 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
2996
3059
  if (this.ssl && this.ssl.key) Object.defineProperty(this.ssl, "key", { enumerable: false });
2997
3060
  this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0;
2998
3061
  }
3062
+ get activeQuery() {
3063
+ activeQueryDeprecationNotice();
3064
+ return this._activeQuery;
3065
+ }
3066
+ set activeQuery(val$1) {
3067
+ activeQueryDeprecationNotice();
3068
+ this._activeQuery = val$1;
3069
+ }
3070
+ _getActiveQuery() {
3071
+ return this._activeQuery;
3072
+ }
2999
3073
  _errorAllQueries(err) {
3000
3074
  const enqueueError = (query$1) => {
3001
3075
  process.nextTick(() => {
3002
3076
  query$1.handleError(err, this.connection);
3003
3077
  });
3004
3078
  };
3005
- if (this.activeQuery) {
3006
- enqueueError(this.activeQuery);
3007
- this.activeQuery = null;
3079
+ const activeQuery = this._getActiveQuery();
3080
+ if (activeQuery) {
3081
+ enqueueError(activeQuery);
3082
+ this._activeQuery = null;
3008
3083
  }
3009
- this.queryQueue.forEach(enqueueError);
3010
- this.queryQueue.length = 0;
3084
+ this._queryQueue.forEach(enqueueError);
3085
+ this._queryQueue.length = 0;
3011
3086
  }
3012
3087
  _connect(callback) {
3013
3088
  const self = this;
@@ -3061,7 +3136,7 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3061
3136
  return new this._Promise((resolve, reject) => {
3062
3137
  this._connect((error) => {
3063
3138
  if (error) reject(error);
3064
- else resolve();
3139
+ else resolve(this);
3065
3140
  });
3066
3141
  });
3067
3142
  }
@@ -3086,9 +3161,9 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3086
3161
  con.on("copyData", this._handleCopyData.bind(this));
3087
3162
  con.on("notification", this._handleNotification.bind(this));
3088
3163
  }
3089
- _checkPgPass(cb) {
3164
+ _getPassword(cb) {
3090
3165
  const con = this.connection;
3091
- if (typeof this.password === "function") this._Promise.resolve().then(() => this.password()).then((pass) => {
3166
+ if (typeof this.password === "function") this._Promise.resolve().then(() => this.password(this.connectionParameters)).then((pass) => {
3092
3167
  if (pass !== void 0) {
3093
3168
  if (typeof pass !== "string") {
3094
3169
  con.emit("error", /* @__PURE__ */ new TypeError("Password must be a string"));
@@ -3103,7 +3178,10 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3103
3178
  else if (this.password !== null) cb();
3104
3179
  else try {
3105
3180
  require_lib$1()(this.connectionParameters, (pass) => {
3106
- if (void 0 !== pass) this.connectionParameters.password = this.password = pass;
3181
+ if (void 0 !== pass) {
3182
+ pgPassDeprecationNotice();
3183
+ this.connectionParameters.password = this.password = pass;
3184
+ }
3107
3185
  cb();
3108
3186
  });
3109
3187
  } catch (e) {
@@ -3111,12 +3189,12 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3111
3189
  }
3112
3190
  }
3113
3191
  _handleAuthCleartextPassword(msg) {
3114
- this._checkPgPass(() => {
3192
+ this._getPassword(() => {
3115
3193
  this.connection.password(this.password);
3116
3194
  });
3117
3195
  }
3118
3196
  _handleAuthMD5Password(msg) {
3119
- this._checkPgPass(async () => {
3197
+ this._getPassword(async () => {
3120
3198
  try {
3121
3199
  const hashedPassword = await crypto.postgresMd5PasswordHash(this.user, this.password, msg.salt);
3122
3200
  this.connection.password(hashedPassword);
@@ -3126,7 +3204,7 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3126
3204
  });
3127
3205
  }
3128
3206
  _handleAuthSASL(msg) {
3129
- this._checkPgPass(() => {
3207
+ this._getPassword(() => {
3130
3208
  try {
3131
3209
  this.saslSession = sasl.startSession(msg.mechanisms, this.enableChannelBinding && this.connection.stream);
3132
3210
  this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
@@ -3166,8 +3244,8 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3166
3244
  }
3167
3245
  this.emit("connect");
3168
3246
  }
3169
- const { activeQuery } = this;
3170
- this.activeQuery = null;
3247
+ const activeQuery = this._getActiveQuery();
3248
+ this._activeQuery = null;
3171
3249
  this.readyForQuery = true;
3172
3250
  if (activeQuery) activeQuery.handleReadyForQuery(this.connection);
3173
3251
  this._pulseQueryQueue();
@@ -3187,47 +3265,85 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3187
3265
  }
3188
3266
  _handleErrorMessage(msg) {
3189
3267
  if (this._connecting) return this._handleErrorWhileConnecting(msg);
3190
- const activeQuery = this.activeQuery;
3268
+ const activeQuery = this._getActiveQuery();
3191
3269
  if (!activeQuery) {
3192
3270
  this._handleErrorEvent(msg);
3193
3271
  return;
3194
3272
  }
3195
- this.activeQuery = null;
3273
+ this._activeQuery = null;
3196
3274
  activeQuery.handleError(msg, this.connection);
3197
3275
  }
3198
3276
  _handleRowDescription(msg) {
3199
- this.activeQuery.handleRowDescription(msg);
3277
+ const activeQuery = this._getActiveQuery();
3278
+ if (activeQuery == null) {
3279
+ const error = /* @__PURE__ */ new Error("Received unexpected rowDescription message from backend.");
3280
+ this._handleErrorEvent(error);
3281
+ return;
3282
+ }
3283
+ activeQuery.handleRowDescription(msg);
3200
3284
  }
3201
3285
  _handleDataRow(msg) {
3202
- this.activeQuery.handleDataRow(msg);
3286
+ const activeQuery = this._getActiveQuery();
3287
+ if (activeQuery == null) {
3288
+ const error = /* @__PURE__ */ new Error("Received unexpected dataRow message from backend.");
3289
+ this._handleErrorEvent(error);
3290
+ return;
3291
+ }
3292
+ activeQuery.handleDataRow(msg);
3203
3293
  }
3204
3294
  _handlePortalSuspended(msg) {
3205
- this.activeQuery.handlePortalSuspended(this.connection);
3295
+ const activeQuery = this._getActiveQuery();
3296
+ if (activeQuery == null) {
3297
+ const error = /* @__PURE__ */ new Error("Received unexpected portalSuspended message from backend.");
3298
+ this._handleErrorEvent(error);
3299
+ return;
3300
+ }
3301
+ activeQuery.handlePortalSuspended(this.connection);
3206
3302
  }
3207
3303
  _handleEmptyQuery(msg) {
3208
- this.activeQuery.handleEmptyQuery(this.connection);
3304
+ const activeQuery = this._getActiveQuery();
3305
+ if (activeQuery == null) {
3306
+ const error = /* @__PURE__ */ new Error("Received unexpected emptyQuery message from backend.");
3307
+ this._handleErrorEvent(error);
3308
+ return;
3309
+ }
3310
+ activeQuery.handleEmptyQuery(this.connection);
3209
3311
  }
3210
3312
  _handleCommandComplete(msg) {
3211
- if (this.activeQuery == null) {
3313
+ const activeQuery = this._getActiveQuery();
3314
+ if (activeQuery == null) {
3212
3315
  const error = /* @__PURE__ */ new Error("Received unexpected commandComplete message from backend.");
3213
3316
  this._handleErrorEvent(error);
3214
3317
  return;
3215
3318
  }
3216
- this.activeQuery.handleCommandComplete(msg, this.connection);
3319
+ activeQuery.handleCommandComplete(msg, this.connection);
3217
3320
  }
3218
3321
  _handleParseComplete() {
3219
- if (this.activeQuery == null) {
3322
+ const activeQuery = this._getActiveQuery();
3323
+ if (activeQuery == null) {
3220
3324
  const error = /* @__PURE__ */ new Error("Received unexpected parseComplete message from backend.");
3221
3325
  this._handleErrorEvent(error);
3222
3326
  return;
3223
3327
  }
3224
- if (this.activeQuery.name) this.connection.parsedStatements[this.activeQuery.name] = this.activeQuery.text;
3328
+ if (activeQuery.name) this.connection.parsedStatements[activeQuery.name] = activeQuery.text;
3225
3329
  }
3226
3330
  _handleCopyInResponse(msg) {
3227
- this.activeQuery.handleCopyInResponse(this.connection);
3331
+ const activeQuery = this._getActiveQuery();
3332
+ if (activeQuery == null) {
3333
+ const error = /* @__PURE__ */ new Error("Received unexpected copyInResponse message from backend.");
3334
+ this._handleErrorEvent(error);
3335
+ return;
3336
+ }
3337
+ activeQuery.handleCopyInResponse(this.connection);
3228
3338
  }
3229
3339
  _handleCopyData(msg) {
3230
- this.activeQuery.handleCopyData(msg, this.connection);
3340
+ const activeQuery = this._getActiveQuery();
3341
+ if (activeQuery == null) {
3342
+ const error = /* @__PURE__ */ new Error("Received unexpected copyData message from backend.");
3343
+ this._handleErrorEvent(error);
3344
+ return;
3345
+ }
3346
+ activeQuery.handleCopyData(msg, this.connection);
3231
3347
  }
3232
3348
  _handleNotification(msg) {
3233
3349
  this.emit("notification", msg);
@@ -3258,7 +3374,7 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3258
3374
  con.on("connect", function() {
3259
3375
  con.cancel(client.processID, client.secretKey);
3260
3376
  });
3261
- } else if (client.queryQueue.indexOf(query$1) !== -1) client.queryQueue.splice(client.queryQueue.indexOf(query$1), 1);
3377
+ } else if (client._queryQueue.indexOf(query$1) !== -1) client._queryQueue.splice(client._queryQueue.indexOf(query$1), 1);
3262
3378
  }
3263
3379
  setTypeParser(oid, format, parseFn) {
3264
3380
  return this._types.setTypeParser(oid, format, parseFn);
@@ -3274,18 +3390,19 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3274
3390
  }
3275
3391
  _pulseQueryQueue() {
3276
3392
  if (this.readyForQuery === true) {
3277
- this.activeQuery = this.queryQueue.shift();
3278
- if (this.activeQuery) {
3393
+ this._activeQuery = this._queryQueue.shift();
3394
+ const activeQuery = this._getActiveQuery();
3395
+ if (activeQuery) {
3279
3396
  this.readyForQuery = false;
3280
3397
  this.hasExecuted = true;
3281
- const queryError = this.activeQuery.submit(this.connection);
3398
+ const queryError = activeQuery.submit(this.connection);
3282
3399
  if (queryError) process.nextTick(() => {
3283
- this.activeQuery.handleError(queryError, this.connection);
3400
+ activeQuery.handleError(queryError, this.connection);
3284
3401
  this.readyForQuery = true;
3285
3402
  this._pulseQueryQueue();
3286
3403
  });
3287
3404
  } else if (this.hasExecuted) {
3288
- this.activeQuery = null;
3405
+ this._activeQuery = null;
3289
3406
  this.emit("drain");
3290
3407
  }
3291
3408
  }
@@ -3300,7 +3417,10 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3300
3417
  else if (typeof config.submit === "function") {
3301
3418
  readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
3302
3419
  result = query$1 = config;
3303
- if (typeof values === "function") query$1.callback = query$1.callback || values;
3420
+ if (!query$1.callback) {
3421
+ if (typeof values === "function") query$1.callback = values;
3422
+ else if (callback) query$1.callback = callback;
3423
+ }
3304
3424
  } else {
3305
3425
  readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
3306
3426
  query$1 = new Query$1(config, values, callback);
@@ -3312,7 +3432,7 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3312
3432
  });
3313
3433
  }
3314
3434
  if (readTimeout) {
3315
- queryCallback = query$1.callback;
3435
+ queryCallback = query$1.callback || (() => {});
3316
3436
  readTimeoutTimer = setTimeout(() => {
3317
3437
  const error = /* @__PURE__ */ new Error("Query read timeout");
3318
3438
  process.nextTick(() => {
@@ -3320,8 +3440,8 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3320
3440
  });
3321
3441
  queryCallback(error);
3322
3442
  query$1.callback = () => {};
3323
- const index = this.queryQueue.indexOf(query$1);
3324
- if (index > -1) this.queryQueue.splice(index, 1);
3443
+ const index = this._queryQueue.indexOf(query$1);
3444
+ if (index > -1) this._queryQueue.splice(index, 1);
3325
3445
  this._pulseQueryQueue();
3326
3446
  }, readTimeout);
3327
3447
  query$1.callback = (err, res) => {
@@ -3343,7 +3463,8 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3343
3463
  });
3344
3464
  return result;
3345
3465
  }
3346
- this.queryQueue.push(query$1);
3466
+ if (this._queryQueue.length > 0) queryQueueLengthDeprecationNotice$1();
3467
+ this._queryQueue.push(query$1);
3347
3468
  this._pulseQueryQueue();
3348
3469
  return result;
3349
3470
  }
@@ -3357,13 +3478,17 @@ var require_client$1 = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/client.
3357
3478
  this._ending = true;
3358
3479
  if (!this.connection._connecting || this._ended) if (cb) cb();
3359
3480
  else return this._Promise.resolve();
3360
- if (this.activeQuery || !this._queryable) this.connection.stream.destroy();
3481
+ if (this._getActiveQuery() || !this._queryable) this.connection.stream.destroy();
3361
3482
  else this.connection.end();
3362
3483
  if (cb) this.connection.once("end", cb);
3363
3484
  else return new this._Promise((resolve) => {
3364
3485
  this.connection.once("end", resolve);
3365
3486
  });
3366
3487
  }
3488
+ get queryQueue() {
3489
+ queryQueueDeprecationNotice();
3490
+ return this._queryQueue;
3491
+ }
3367
3492
  };
3368
3493
  Client$3.Query = Query$1;
3369
3494
  module.exports = Client$3;
@@ -3403,16 +3528,15 @@ var require_pg_pool = /* @__PURE__ */ __commonJS({ "node_modules/pg-pool/index.j
3403
3528
  const cb = function(err, client) {
3404
3529
  err ? rej(err) : res(client);
3405
3530
  };
3406
- const result = new Promise$1(function(resolve, reject) {
3407
- res = resolve;
3408
- rej = reject;
3409
- }).catch((err) => {
3410
- Error.captureStackTrace(err);
3411
- throw err;
3412
- });
3413
3531
  return {
3414
3532
  callback: cb,
3415
- result
3533
+ result: new Promise$1(function(resolve, reject) {
3534
+ res = resolve;
3535
+ rej = reject;
3536
+ }).catch((err) => {
3537
+ Error.captureStackTrace(err);
3538
+ throw err;
3539
+ })
3416
3540
  };
3417
3541
  }
3418
3542
  function makeIdleListener(pool, client) {
@@ -3454,6 +3578,11 @@ var require_pg_pool = /* @__PURE__ */ __commonJS({ "node_modules/pg-pool/index.j
3454
3578
  this.ending = false;
3455
3579
  this.ended = false;
3456
3580
  }
3581
+ _promiseTry(f) {
3582
+ const Promise$1 = this.Promise;
3583
+ if (typeof Promise$1.try === "function") return Promise$1.try(f);
3584
+ return new Promise$1((resolve) => resolve(f()));
3585
+ }
3457
3586
  _isFull() {
3458
3587
  return this._clients.length >= this.options.max;
3459
3588
  }
@@ -3542,9 +3671,15 @@ var require_pg_pool = /* @__PURE__ */ __commonJS({ "node_modules/pg-pool/index.j
3542
3671
  let tid;
3543
3672
  let timeoutHit = false;
3544
3673
  if (this.options.connectionTimeoutMillis) tid = setTimeout(() => {
3545
- this.log("ending client due to timeout");
3546
- timeoutHit = true;
3547
- client.connection ? client.connection.stream.destroy() : client.end();
3674
+ if (client.connection) {
3675
+ this.log("ending client due to timeout");
3676
+ timeoutHit = true;
3677
+ client.connection.stream.destroy();
3678
+ } else if (!client.isConnected()) {
3679
+ this.log("ending client due to timeout");
3680
+ timeoutHit = true;
3681
+ client.end();
3682
+ }
3548
3683
  }, this.options.connectionTimeoutMillis);
3549
3684
  this.log("connecting new client");
3550
3685
  client.connect((err) => {
@@ -3558,19 +3693,34 @@ var require_pg_pool = /* @__PURE__ */ __commonJS({ "node_modules/pg-pool/index.j
3558
3693
  if (!pendingItem.timedOut) pendingItem.callback(err, void 0, NOOP);
3559
3694
  } else {
3560
3695
  this.log("new client connected");
3561
- if (this.options.maxLifetimeSeconds !== 0) {
3562
- const maxLifetimeTimeout = setTimeout(() => {
3563
- this.log("ending client due to expired lifetime");
3564
- this._expired.add(client);
3565
- if (this._idle.findIndex((idleItem) => idleItem.client === client) !== -1) this._acquireClient(client, new PendingItem((err$1, client$1, clientRelease) => clientRelease()), idleListener, false);
3566
- }, this.options.maxLifetimeSeconds * 1e3);
3567
- maxLifetimeTimeout.unref();
3568
- client.once("end", () => clearTimeout(maxLifetimeTimeout));
3696
+ if (this.options.onConnect) {
3697
+ this._promiseTry(() => this.options.onConnect(client)).then(() => {
3698
+ this._afterConnect(client, pendingItem, idleListener);
3699
+ }, (hookErr) => {
3700
+ this._clients = this._clients.filter((c) => c !== client);
3701
+ client.end(() => {
3702
+ this._pulseQueue();
3703
+ if (!pendingItem.timedOut) pendingItem.callback(hookErr, void 0, NOOP);
3704
+ });
3705
+ });
3706
+ return;
3569
3707
  }
3570
- return this._acquireClient(client, pendingItem, idleListener, true);
3708
+ return this._afterConnect(client, pendingItem, idleListener);
3571
3709
  }
3572
3710
  });
3573
3711
  }
3712
+ _afterConnect(client, pendingItem, idleListener) {
3713
+ if (this.options.maxLifetimeSeconds !== 0) {
3714
+ const maxLifetimeTimeout = setTimeout(() => {
3715
+ this.log("ending client due to expired lifetime");
3716
+ this._expired.add(client);
3717
+ if (this._idle.findIndex((idleItem) => idleItem.client === client) !== -1) this._acquireClient(client, new PendingItem((err, client$1, clientRelease) => clientRelease()), idleListener, false);
3718
+ }, this.options.maxLifetimeSeconds * 1e3);
3719
+ maxLifetimeTimeout.unref();
3720
+ client.once("end", () => clearTimeout(maxLifetimeTimeout));
3721
+ }
3722
+ return this._acquireClient(client, pendingItem, idleListener, true);
3723
+ }
3574
3724
  _acquireClient(client, pendingItem, idleListener, isNew) {
3575
3725
  if (isNew) this.emit("connect", client);
3576
3726
  this.emit("acquire", client);
@@ -3611,8 +3761,10 @@ var require_pg_pool = /* @__PURE__ */ __commonJS({ "node_modules/pg-pool/index.j
3611
3761
  let tid;
3612
3762
  if (this.options.idleTimeoutMillis && this._isAboveMin()) {
3613
3763
  tid = setTimeout(() => {
3614
- this.log("remove idle client");
3615
- this._remove(client, this._pulseQueue.bind(this));
3764
+ if (this._isAboveMin()) {
3765
+ this.log("remove idle client");
3766
+ this._remove(client, this._pulseQueue.bind(this));
3767
+ }
3616
3768
  }, this.options.idleTimeoutMillis);
3617
3769
  if (this.options.allowExitOnIdle) tid.unref();
3618
3770
  }
@@ -3805,6 +3957,7 @@ var require_query = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/que
3805
3957
  //#endregion
3806
3958
  //#region node_modules/pg/lib/native/client.js
3807
3959
  var require_client = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/client.js": ((exports, module) => {
3960
+ const nodeUtils = __require("util");
3808
3961
  var Native;
3809
3962
  try {
3810
3963
  Native = __require("pg-native");
@@ -3816,6 +3969,7 @@ var require_client = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/cl
3816
3969
  const util = __require("util");
3817
3970
  const ConnectionParameters = require_connection_parameters();
3818
3971
  const NativeQuery = require_query();
3972
+ const queryQueueLengthDeprecationNotice = nodeUtils.deprecate(() => {}, "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.");
3819
3973
  const Client$2 = module.exports = function(config) {
3820
3974
  EventEmitter.call(this);
3821
3975
  config = config || {};
@@ -3886,7 +4040,7 @@ var require_client = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/cl
3886
4040
  });
3887
4041
  self.emit("connect");
3888
4042
  self._pulseQueryQueue(true);
3889
- cb();
4043
+ cb(null, this);
3890
4044
  });
3891
4045
  });
3892
4046
  };
@@ -3898,7 +4052,7 @@ var require_client = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/cl
3898
4052
  return new this._Promise((resolve, reject) => {
3899
4053
  this._connect((error) => {
3900
4054
  if (error) reject(error);
3901
- else resolve();
4055
+ else resolve(this);
3902
4056
  });
3903
4057
  });
3904
4058
  };
@@ -3929,7 +4083,7 @@ var require_client = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/cl
3929
4083
  }
3930
4084
  }
3931
4085
  if (readTimeout) {
3932
- queryCallback = query$1.callback;
4086
+ queryCallback = query$1.callback || (() => {});
3933
4087
  readTimeoutTimer = setTimeout(() => {
3934
4088
  const error = /* @__PURE__ */ new Error("Query read timeout");
3935
4089
  process.nextTick(() => {
@@ -3960,6 +4114,7 @@ var require_client = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/cl
3960
4114
  });
3961
4115
  return result;
3962
4116
  }
4117
+ if (this._queryQueue.length > 0) queryQueueLengthDeprecationNotice();
3963
4118
  this._queryQueue.push(query$1);
3964
4119
  this._pulseQueryQueue();
3965
4120
  return result;
@@ -3973,6 +4128,7 @@ var require_client = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/cl
3973
4128
  cb = (err) => err ? reject(err) : resolve();
3974
4129
  });
3975
4130
  this.native.end(function() {
4131
+ self._connected = false;
3976
4132
  self._errorAllQueries(/* @__PURE__ */ new Error("Connection terminated"));
3977
4133
  process.nextTick(() => {
3978
4134
  self.emit("end");
@@ -4011,6 +4167,9 @@ var require_client = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/native/cl
4011
4167
  Client$2.prototype.getTypeParser = function(oid, format) {
4012
4168
  return this._types.getTypeParser(oid, format);
4013
4169
  };
4170
+ Client$2.prototype.isConnected = function() {
4171
+ return this._connected;
4172
+ };
4014
4173
  }) });
4015
4174
 
4016
4175
  //#endregion
@@ -4038,9 +4197,9 @@ var require_lib = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/index.js": (
4038
4197
  }
4039
4198
  };
4040
4199
  };
4041
- const PG = function(clientConstructor) {
4200
+ const PG = function(clientConstructor$1) {
4042
4201
  this.defaults = defaults$1;
4043
- this.Client = clientConstructor;
4202
+ this.Client = clientConstructor$1;
4044
4203
  this.Query = this.Client.Query;
4045
4204
  this.Pool = poolFactory(this.Client);
4046
4205
  this._pools = [];
@@ -4053,24 +4212,27 @@ var require_lib = /* @__PURE__ */ __commonJS({ "node_modules/pg/lib/index.js": (
4053
4212
  this.Result = Result$1;
4054
4213
  this.utils = utils;
4055
4214
  };
4056
- if (typeof process.env.NODE_PG_FORCE_NATIVE !== "undefined") module.exports = new PG(require_native());
4057
- else {
4058
- module.exports = new PG(Client$1);
4059
- Object.defineProperty(module.exports, "native", {
4060
- configurable: true,
4061
- enumerable: false,
4062
- get() {
4063
- let native = null;
4064
- try {
4065
- native = new PG(require_native());
4066
- } catch (err) {
4067
- if (err.code !== "MODULE_NOT_FOUND") throw err;
4068
- }
4069
- Object.defineProperty(module.exports, "native", { value: native });
4070
- return native;
4215
+ let clientConstructor = Client$1;
4216
+ let forceNative = false;
4217
+ try {
4218
+ forceNative = !!process.env.NODE_PG_FORCE_NATIVE;
4219
+ } catch {}
4220
+ if (forceNative) clientConstructor = require_native();
4221
+ module.exports = new PG(clientConstructor);
4222
+ Object.defineProperty(module.exports, "native", {
4223
+ configurable: true,
4224
+ enumerable: false,
4225
+ get() {
4226
+ let native = null;
4227
+ try {
4228
+ native = new PG(require_native());
4229
+ } catch (err) {
4230
+ if (err.code !== "MODULE_NOT_FOUND") throw err;
4071
4231
  }
4072
- });
4073
- }
4232
+ Object.defineProperty(module.exports, "native", { value: native });
4233
+ return native;
4234
+ }
4235
+ });
4074
4236
  }) });
4075
4237
 
4076
4238
  //#endregion
@@ -4091,4 +4253,4 @@ var esm_default = import_lib.default;
4091
4253
 
4092
4254
  //#endregion
4093
4255
  export { Client, Connection, DatabaseError, Pool, Query, Result, TypeOverrides, esm_default as default, defaults, escapeIdentifier, escapeLiteral, types };
4094
- //# sourceMappingURL=esm-BYmTa3gi.mjs.map
4256
+ //# sourceMappingURL=esm-BRY8ugtK.mjs.map