@jterrazz/test 3.3.1 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +245 -73
- package/dist/index.cjs +240 -4357
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +137 -4276
- package/dist/index.js.map +1 -1
- package/package.json +12 -8
- package/dist/assets/cpufeatures-B-FC6C9Z.node +0 -0
- package/dist/assets/sshcrypto-D82met6T.node +0 -0
- package/dist/build.cjs +0 -122200
- package/dist/build.cjs.map +0 -1
- package/dist/build.js +0 -122193
- package/dist/build.js.map +0 -1
- package/dist/chunk.cjs +0 -64
- package/dist/chunk.js +0 -37
- package/dist/dist.cjs +0 -6587
- package/dist/dist.cjs.map +0 -1
- package/dist/dist.js +0 -6582
- package/dist/dist.js.map +0 -1
- package/dist/dist2.cjs +0 -20838
- package/dist/dist2.cjs.map +0 -1
- package/dist/dist2.js +0 -20834
- package/dist/dist2.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { i as __require, o as __toESM, t as __commonJSMin } from "./chunk.js";
|
|
2
|
-
import { t as require_dist$1 } from "./dist.js";
|
|
3
1
|
import MockDatePackage from "mockdate";
|
|
4
2
|
import { mockDeep } from "vitest-mock-extended";
|
|
5
3
|
import { cpSync, existsSync, mkdtempSync, readFileSync } from "node:fs";
|
|
6
4
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
7
|
-
import { execSync } from "node:child_process";
|
|
5
|
+
import { execSync, spawn } from "node:child_process";
|
|
6
|
+
import { parse } from "yaml";
|
|
7
|
+
import { Client } from "pg";
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
9
|
//#region src/mocking/mock-of-date.ts
|
|
10
10
|
const mockOfDate = MockDatePackage;
|
|
@@ -36,7 +36,7 @@ var ComposeStackAdapter = class {
|
|
|
36
36
|
}
|
|
37
37
|
async start() {
|
|
38
38
|
if (this.started) return;
|
|
39
|
-
this.run(`docker compose -f ${this.composeFile} up -d --wait
|
|
39
|
+
this.run(`docker compose -f ${this.composeFile} up -d --wait`);
|
|
40
40
|
this.started = true;
|
|
41
41
|
}
|
|
42
42
|
async stop() {
|
|
@@ -62,21 +62,24 @@ var TestcontainersAdapter = class {
|
|
|
62
62
|
image;
|
|
63
63
|
containerPort;
|
|
64
64
|
env;
|
|
65
|
+
reuse;
|
|
65
66
|
container = null;
|
|
66
67
|
constructor(options) {
|
|
67
68
|
this.image = options.image;
|
|
68
69
|
this.containerPort = options.port;
|
|
69
70
|
this.env = options.env ?? {};
|
|
71
|
+
this.reuse = options.reuse ?? false;
|
|
70
72
|
}
|
|
71
73
|
async start() {
|
|
72
|
-
const { GenericContainer, Wait } = await import("
|
|
74
|
+
const { GenericContainer, Wait } = await import("testcontainers");
|
|
73
75
|
let builder = new GenericContainer(this.image).withExposedPorts(this.containerPort);
|
|
74
76
|
for (const [key, value] of Object.entries(this.env)) builder = builder.withEnvironment({ [key]: value });
|
|
75
77
|
if (this.image.startsWith("postgres")) builder = builder.withWaitStrategy(Wait.forLogMessage(/database system is ready to accept connections/, 2));
|
|
78
|
+
if (this.reuse) builder = builder.withReuse();
|
|
76
79
|
this.container = await builder.start();
|
|
77
80
|
}
|
|
78
81
|
async stop() {
|
|
79
|
-
if (this.container) {
|
|
82
|
+
if (this.container && !this.reuse) {
|
|
80
83
|
await this.container.stop();
|
|
81
84
|
this.container = null;
|
|
82
85
|
}
|
|
@@ -111,7 +114,6 @@ var TestcontainersAdapter = class {
|
|
|
111
114
|
};
|
|
112
115
|
//#endregion
|
|
113
116
|
//#region src/infrastructure/compose-parser.ts
|
|
114
|
-
var import_dist = require_dist$1();
|
|
115
117
|
/**
|
|
116
118
|
* Detect the service type from the image name.
|
|
117
119
|
*/
|
|
@@ -140,7 +142,7 @@ function findComposeFile(projectRoot) {
|
|
|
140
142
|
* Parse a docker-compose file and extract service definitions.
|
|
141
143
|
*/
|
|
142
144
|
function parseComposeFile(filePath) {
|
|
143
|
-
const doc =
|
|
145
|
+
const doc = parse(readFileSync(filePath, "utf8"));
|
|
144
146
|
if (!doc?.services) return {
|
|
145
147
|
services: [],
|
|
146
148
|
appService: null,
|
|
@@ -350,4214 +352,6 @@ function normalizeOutput(str) {
|
|
|
350
352
|
return stripAnsi(str).replace(/localhost:\d+/g, "localhost:PORT").replace(/\d+ms/g, "Xms").replace(/\d+\.\d+s/g, "X.Xs").trim();
|
|
351
353
|
}
|
|
352
354
|
//#endregion
|
|
353
|
-
//#region node_modules/postgres-array/index.js
|
|
354
|
-
var require_postgres_array = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
355
|
-
exports.parse = function(source, transform) {
|
|
356
|
-
return new ArrayParser(source, transform).parse();
|
|
357
|
-
};
|
|
358
|
-
var ArrayParser = class ArrayParser {
|
|
359
|
-
constructor(source, transform) {
|
|
360
|
-
this.source = source;
|
|
361
|
-
this.transform = transform || identity;
|
|
362
|
-
this.position = 0;
|
|
363
|
-
this.entries = [];
|
|
364
|
-
this.recorded = [];
|
|
365
|
-
this.dimension = 0;
|
|
366
|
-
}
|
|
367
|
-
isEof() {
|
|
368
|
-
return this.position >= this.source.length;
|
|
369
|
-
}
|
|
370
|
-
nextCharacter() {
|
|
371
|
-
var character = this.source[this.position++];
|
|
372
|
-
if (character === "\\") return {
|
|
373
|
-
value: this.source[this.position++],
|
|
374
|
-
escaped: true
|
|
375
|
-
};
|
|
376
|
-
return {
|
|
377
|
-
value: character,
|
|
378
|
-
escaped: false
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
record(character) {
|
|
382
|
-
this.recorded.push(character);
|
|
383
|
-
}
|
|
384
|
-
newEntry(includeEmpty) {
|
|
385
|
-
var entry;
|
|
386
|
-
if (this.recorded.length > 0 || includeEmpty) {
|
|
387
|
-
entry = this.recorded.join("");
|
|
388
|
-
if (entry === "NULL" && !includeEmpty) entry = null;
|
|
389
|
-
if (entry !== null) entry = this.transform(entry);
|
|
390
|
-
this.entries.push(entry);
|
|
391
|
-
this.recorded = [];
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
consumeDimensions() {
|
|
395
|
-
if (this.source[0] === "[") {
|
|
396
|
-
while (!this.isEof()) if (this.nextCharacter().value === "=") break;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
parse(nested) {
|
|
400
|
-
var character, parser, quote;
|
|
401
|
-
this.consumeDimensions();
|
|
402
|
-
while (!this.isEof()) {
|
|
403
|
-
character = this.nextCharacter();
|
|
404
|
-
if (character.value === "{" && !quote) {
|
|
405
|
-
this.dimension++;
|
|
406
|
-
if (this.dimension > 1) {
|
|
407
|
-
parser = new ArrayParser(this.source.substr(this.position - 1), this.transform);
|
|
408
|
-
this.entries.push(parser.parse(true));
|
|
409
|
-
this.position += parser.position - 2;
|
|
410
|
-
}
|
|
411
|
-
} else if (character.value === "}" && !quote) {
|
|
412
|
-
this.dimension--;
|
|
413
|
-
if (!this.dimension) {
|
|
414
|
-
this.newEntry();
|
|
415
|
-
if (nested) return this.entries;
|
|
416
|
-
}
|
|
417
|
-
} else if (character.value === "\"" && !character.escaped) {
|
|
418
|
-
if (quote) this.newEntry(true);
|
|
419
|
-
quote = !quote;
|
|
420
|
-
} else if (character.value === "," && !quote) this.newEntry();
|
|
421
|
-
else this.record(character.value);
|
|
422
|
-
}
|
|
423
|
-
if (this.dimension !== 0) throw new Error("array dimension not balanced");
|
|
424
|
-
return this.entries;
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
function identity(value) {
|
|
428
|
-
return value;
|
|
429
|
-
}
|
|
430
|
-
}));
|
|
431
|
-
//#endregion
|
|
432
|
-
//#region node_modules/pg-types/lib/arrayParser.js
|
|
433
|
-
var require_arrayParser = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
434
|
-
var array = require_postgres_array();
|
|
435
|
-
module.exports = { create: function(source, transform) {
|
|
436
|
-
return { parse: function() {
|
|
437
|
-
return array.parse(source, transform);
|
|
438
|
-
} };
|
|
439
|
-
} };
|
|
440
|
-
}));
|
|
441
|
-
//#endregion
|
|
442
|
-
//#region node_modules/postgres-date/index.js
|
|
443
|
-
var require_postgres_date = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
444
|
-
var DATE_TIME = /(\d{1,})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?.*?( BC)?$/;
|
|
445
|
-
var DATE = /^(\d{1,})-(\d{2})-(\d{2})( BC)?$/;
|
|
446
|
-
var TIME_ZONE = /([Z+-])(\d{2})?:?(\d{2})?:?(\d{2})?/;
|
|
447
|
-
var INFINITY = /^-?infinity$/;
|
|
448
|
-
module.exports = function parseDate(isoDate) {
|
|
449
|
-
if (INFINITY.test(isoDate)) return Number(isoDate.replace("i", "I"));
|
|
450
|
-
var matches = DATE_TIME.exec(isoDate);
|
|
451
|
-
if (!matches) return getDate(isoDate) || null;
|
|
452
|
-
var isBC = !!matches[8];
|
|
453
|
-
var year = parseInt(matches[1], 10);
|
|
454
|
-
if (isBC) year = bcYearToNegativeYear(year);
|
|
455
|
-
var month = parseInt(matches[2], 10) - 1;
|
|
456
|
-
var day = matches[3];
|
|
457
|
-
var hour = parseInt(matches[4], 10);
|
|
458
|
-
var minute = parseInt(matches[5], 10);
|
|
459
|
-
var second = parseInt(matches[6], 10);
|
|
460
|
-
var ms = matches[7];
|
|
461
|
-
ms = ms ? 1e3 * parseFloat(ms) : 0;
|
|
462
|
-
var date;
|
|
463
|
-
var offset = timeZoneOffset(isoDate);
|
|
464
|
-
if (offset != null) {
|
|
465
|
-
date = new Date(Date.UTC(year, month, day, hour, minute, second, ms));
|
|
466
|
-
if (is0To99(year)) date.setUTCFullYear(year);
|
|
467
|
-
if (offset !== 0) date.setTime(date.getTime() - offset);
|
|
468
|
-
} else {
|
|
469
|
-
date = new Date(year, month, day, hour, minute, second, ms);
|
|
470
|
-
if (is0To99(year)) date.setFullYear(year);
|
|
471
|
-
}
|
|
472
|
-
return date;
|
|
473
|
-
};
|
|
474
|
-
function getDate(isoDate) {
|
|
475
|
-
var matches = DATE.exec(isoDate);
|
|
476
|
-
if (!matches) return;
|
|
477
|
-
var year = parseInt(matches[1], 10);
|
|
478
|
-
if (!!matches[4]) year = bcYearToNegativeYear(year);
|
|
479
|
-
var month = parseInt(matches[2], 10) - 1;
|
|
480
|
-
var day = matches[3];
|
|
481
|
-
var date = new Date(year, month, day);
|
|
482
|
-
if (is0To99(year)) date.setFullYear(year);
|
|
483
|
-
return date;
|
|
484
|
-
}
|
|
485
|
-
function timeZoneOffset(isoDate) {
|
|
486
|
-
if (isoDate.endsWith("+00")) return 0;
|
|
487
|
-
var zone = TIME_ZONE.exec(isoDate.split(" ")[1]);
|
|
488
|
-
if (!zone) return;
|
|
489
|
-
var type = zone[1];
|
|
490
|
-
if (type === "Z") return 0;
|
|
491
|
-
var sign = type === "-" ? -1 : 1;
|
|
492
|
-
return (parseInt(zone[2], 10) * 3600 + parseInt(zone[3] || 0, 10) * 60 + parseInt(zone[4] || 0, 10)) * sign * 1e3;
|
|
493
|
-
}
|
|
494
|
-
function bcYearToNegativeYear(year) {
|
|
495
|
-
return -(year - 1);
|
|
496
|
-
}
|
|
497
|
-
function is0To99(num) {
|
|
498
|
-
return num >= 0 && num < 100;
|
|
499
|
-
}
|
|
500
|
-
}));
|
|
501
|
-
//#endregion
|
|
502
|
-
//#region node_modules/xtend/mutable.js
|
|
503
|
-
var require_mutable = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
504
|
-
module.exports = extend;
|
|
505
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
506
|
-
function extend(target) {
|
|
507
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
508
|
-
var source = arguments[i];
|
|
509
|
-
for (var key in source) if (hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
510
|
-
}
|
|
511
|
-
return target;
|
|
512
|
-
}
|
|
513
|
-
}));
|
|
514
|
-
//#endregion
|
|
515
|
-
//#region node_modules/postgres-interval/index.js
|
|
516
|
-
var require_postgres_interval = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
517
|
-
var extend = require_mutable();
|
|
518
|
-
module.exports = PostgresInterval;
|
|
519
|
-
function PostgresInterval(raw) {
|
|
520
|
-
if (!(this instanceof PostgresInterval)) return new PostgresInterval(raw);
|
|
521
|
-
extend(this, parse(raw));
|
|
522
|
-
}
|
|
523
|
-
var properties = [
|
|
524
|
-
"seconds",
|
|
525
|
-
"minutes",
|
|
526
|
-
"hours",
|
|
527
|
-
"days",
|
|
528
|
-
"months",
|
|
529
|
-
"years"
|
|
530
|
-
];
|
|
531
|
-
PostgresInterval.prototype.toPostgres = function() {
|
|
532
|
-
var filtered = properties.filter(this.hasOwnProperty, this);
|
|
533
|
-
if (this.milliseconds && filtered.indexOf("seconds") < 0) filtered.push("seconds");
|
|
534
|
-
if (filtered.length === 0) return "0";
|
|
535
|
-
return filtered.map(function(property) {
|
|
536
|
-
var value = this[property] || 0;
|
|
537
|
-
if (property === "seconds" && this.milliseconds) value = (value + this.milliseconds / 1e3).toFixed(6).replace(/\.?0+$/, "");
|
|
538
|
-
return value + " " + property;
|
|
539
|
-
}, this).join(" ");
|
|
540
|
-
};
|
|
541
|
-
var propertiesISOEquivalent = {
|
|
542
|
-
years: "Y",
|
|
543
|
-
months: "M",
|
|
544
|
-
days: "D",
|
|
545
|
-
hours: "H",
|
|
546
|
-
minutes: "M",
|
|
547
|
-
seconds: "S"
|
|
548
|
-
};
|
|
549
|
-
var dateProperties = [
|
|
550
|
-
"years",
|
|
551
|
-
"months",
|
|
552
|
-
"days"
|
|
553
|
-
];
|
|
554
|
-
var timeProperties = [
|
|
555
|
-
"hours",
|
|
556
|
-
"minutes",
|
|
557
|
-
"seconds"
|
|
558
|
-
];
|
|
559
|
-
PostgresInterval.prototype.toISOString = PostgresInterval.prototype.toISO = function() {
|
|
560
|
-
var datePart = dateProperties.map(buildProperty, this).join("");
|
|
561
|
-
var timePart = timeProperties.map(buildProperty, this).join("");
|
|
562
|
-
return "P" + datePart + "T" + timePart;
|
|
563
|
-
function buildProperty(property) {
|
|
564
|
-
var value = this[property] || 0;
|
|
565
|
-
if (property === "seconds" && this.milliseconds) value = (value + this.milliseconds / 1e3).toFixed(6).replace(/0+$/, "");
|
|
566
|
-
return value + propertiesISOEquivalent[property];
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
var NUMBER = "([+-]?\\d+)";
|
|
570
|
-
var YEAR = NUMBER + "\\s+years?";
|
|
571
|
-
var MONTH = NUMBER + "\\s+mons?";
|
|
572
|
-
var DAY = NUMBER + "\\s+days?";
|
|
573
|
-
var INTERVAL = new RegExp([
|
|
574
|
-
YEAR,
|
|
575
|
-
MONTH,
|
|
576
|
-
DAY,
|
|
577
|
-
"([+-])?([\\d]*):(\\d\\d):(\\d\\d)\\.?(\\d{1,6})?"
|
|
578
|
-
].map(function(regexString) {
|
|
579
|
-
return "(" + regexString + ")?";
|
|
580
|
-
}).join("\\s*"));
|
|
581
|
-
var positions = {
|
|
582
|
-
years: 2,
|
|
583
|
-
months: 4,
|
|
584
|
-
days: 6,
|
|
585
|
-
hours: 9,
|
|
586
|
-
minutes: 10,
|
|
587
|
-
seconds: 11,
|
|
588
|
-
milliseconds: 12
|
|
589
|
-
};
|
|
590
|
-
var negatives = [
|
|
591
|
-
"hours",
|
|
592
|
-
"minutes",
|
|
593
|
-
"seconds",
|
|
594
|
-
"milliseconds"
|
|
595
|
-
];
|
|
596
|
-
function parseMilliseconds(fraction) {
|
|
597
|
-
var microseconds = fraction + "000000".slice(fraction.length);
|
|
598
|
-
return parseInt(microseconds, 10) / 1e3;
|
|
599
|
-
}
|
|
600
|
-
function parse(interval) {
|
|
601
|
-
if (!interval) return {};
|
|
602
|
-
var matches = INTERVAL.exec(interval);
|
|
603
|
-
var isNegative = matches[8] === "-";
|
|
604
|
-
return Object.keys(positions).reduce(function(parsed, property) {
|
|
605
|
-
var value = matches[positions[property]];
|
|
606
|
-
if (!value) return parsed;
|
|
607
|
-
value = property === "milliseconds" ? parseMilliseconds(value) : parseInt(value, 10);
|
|
608
|
-
if (!value) return parsed;
|
|
609
|
-
if (isNegative && ~negatives.indexOf(property)) value *= -1;
|
|
610
|
-
parsed[property] = value;
|
|
611
|
-
return parsed;
|
|
612
|
-
}, {});
|
|
613
|
-
}
|
|
614
|
-
}));
|
|
615
|
-
//#endregion
|
|
616
|
-
//#region node_modules/postgres-bytea/index.js
|
|
617
|
-
var require_postgres_bytea = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
618
|
-
var bufferFrom = Buffer.from || Buffer;
|
|
619
|
-
module.exports = function parseBytea(input) {
|
|
620
|
-
if (/^\\x/.test(input)) return bufferFrom(input.substr(2), "hex");
|
|
621
|
-
var output = "";
|
|
622
|
-
var i = 0;
|
|
623
|
-
while (i < input.length) if (input[i] !== "\\") {
|
|
624
|
-
output += input[i];
|
|
625
|
-
++i;
|
|
626
|
-
} else if (/[0-7]{3}/.test(input.substr(i + 1, 3))) {
|
|
627
|
-
output += String.fromCharCode(parseInt(input.substr(i + 1, 3), 8));
|
|
628
|
-
i += 4;
|
|
629
|
-
} else {
|
|
630
|
-
var backslashes = 1;
|
|
631
|
-
while (i + backslashes < input.length && input[i + backslashes] === "\\") backslashes++;
|
|
632
|
-
for (var k = 0; k < Math.floor(backslashes / 2); ++k) output += "\\";
|
|
633
|
-
i += Math.floor(backslashes / 2) * 2;
|
|
634
|
-
}
|
|
635
|
-
return bufferFrom(output, "binary");
|
|
636
|
-
};
|
|
637
|
-
}));
|
|
638
|
-
//#endregion
|
|
639
|
-
//#region node_modules/pg-types/lib/textParsers.js
|
|
640
|
-
var require_textParsers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
641
|
-
var array = require_postgres_array();
|
|
642
|
-
var arrayParser = require_arrayParser();
|
|
643
|
-
var parseDate = require_postgres_date();
|
|
644
|
-
var parseInterval = require_postgres_interval();
|
|
645
|
-
var parseByteA = require_postgres_bytea();
|
|
646
|
-
function allowNull(fn) {
|
|
647
|
-
return function nullAllowed(value) {
|
|
648
|
-
if (value === null) return value;
|
|
649
|
-
return fn(value);
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
function parseBool(value) {
|
|
653
|
-
if (value === null) return value;
|
|
654
|
-
return value === "TRUE" || value === "t" || value === "true" || value === "y" || value === "yes" || value === "on" || value === "1";
|
|
655
|
-
}
|
|
656
|
-
function parseBoolArray(value) {
|
|
657
|
-
if (!value) return null;
|
|
658
|
-
return array.parse(value, parseBool);
|
|
659
|
-
}
|
|
660
|
-
function parseBaseTenInt(string) {
|
|
661
|
-
return parseInt(string, 10);
|
|
662
|
-
}
|
|
663
|
-
function parseIntegerArray(value) {
|
|
664
|
-
if (!value) return null;
|
|
665
|
-
return array.parse(value, allowNull(parseBaseTenInt));
|
|
666
|
-
}
|
|
667
|
-
function parseBigIntegerArray(value) {
|
|
668
|
-
if (!value) return null;
|
|
669
|
-
return array.parse(value, allowNull(function(entry) {
|
|
670
|
-
return parseBigInteger(entry).trim();
|
|
671
|
-
}));
|
|
672
|
-
}
|
|
673
|
-
var parsePointArray = function(value) {
|
|
674
|
-
if (!value) return null;
|
|
675
|
-
return arrayParser.create(value, function(entry) {
|
|
676
|
-
if (entry !== null) entry = parsePoint(entry);
|
|
677
|
-
return entry;
|
|
678
|
-
}).parse();
|
|
679
|
-
};
|
|
680
|
-
var parseFloatArray = function(value) {
|
|
681
|
-
if (!value) return null;
|
|
682
|
-
return arrayParser.create(value, function(entry) {
|
|
683
|
-
if (entry !== null) entry = parseFloat(entry);
|
|
684
|
-
return entry;
|
|
685
|
-
}).parse();
|
|
686
|
-
};
|
|
687
|
-
var parseStringArray = function(value) {
|
|
688
|
-
if (!value) return null;
|
|
689
|
-
return arrayParser.create(value).parse();
|
|
690
|
-
};
|
|
691
|
-
var parseDateArray = function(value) {
|
|
692
|
-
if (!value) return null;
|
|
693
|
-
return arrayParser.create(value, function(entry) {
|
|
694
|
-
if (entry !== null) entry = parseDate(entry);
|
|
695
|
-
return entry;
|
|
696
|
-
}).parse();
|
|
697
|
-
};
|
|
698
|
-
var parseIntervalArray = function(value) {
|
|
699
|
-
if (!value) return null;
|
|
700
|
-
return arrayParser.create(value, function(entry) {
|
|
701
|
-
if (entry !== null) entry = parseInterval(entry);
|
|
702
|
-
return entry;
|
|
703
|
-
}).parse();
|
|
704
|
-
};
|
|
705
|
-
var parseByteAArray = function(value) {
|
|
706
|
-
if (!value) return null;
|
|
707
|
-
return array.parse(value, allowNull(parseByteA));
|
|
708
|
-
};
|
|
709
|
-
var parseInteger = function(value) {
|
|
710
|
-
return parseInt(value, 10);
|
|
711
|
-
};
|
|
712
|
-
var parseBigInteger = function(value) {
|
|
713
|
-
var valStr = String(value);
|
|
714
|
-
if (/^\d+$/.test(valStr)) return valStr;
|
|
715
|
-
return value;
|
|
716
|
-
};
|
|
717
|
-
var parseJsonArray = function(value) {
|
|
718
|
-
if (!value) return null;
|
|
719
|
-
return array.parse(value, allowNull(JSON.parse));
|
|
720
|
-
};
|
|
721
|
-
var parsePoint = function(value) {
|
|
722
|
-
if (value[0] !== "(") return null;
|
|
723
|
-
value = value.substring(1, value.length - 1).split(",");
|
|
724
|
-
return {
|
|
725
|
-
x: parseFloat(value[0]),
|
|
726
|
-
y: parseFloat(value[1])
|
|
727
|
-
};
|
|
728
|
-
};
|
|
729
|
-
var parseCircle = function(value) {
|
|
730
|
-
if (value[0] !== "<" && value[1] !== "(") return null;
|
|
731
|
-
var point = "(";
|
|
732
|
-
var radius = "";
|
|
733
|
-
var pointParsed = false;
|
|
734
|
-
for (var i = 2; i < value.length - 1; i++) {
|
|
735
|
-
if (!pointParsed) point += value[i];
|
|
736
|
-
if (value[i] === ")") {
|
|
737
|
-
pointParsed = true;
|
|
738
|
-
continue;
|
|
739
|
-
} else if (!pointParsed) continue;
|
|
740
|
-
if (value[i] === ",") continue;
|
|
741
|
-
radius += value[i];
|
|
742
|
-
}
|
|
743
|
-
var result = parsePoint(point);
|
|
744
|
-
result.radius = parseFloat(radius);
|
|
745
|
-
return result;
|
|
746
|
-
};
|
|
747
|
-
var init = function(register) {
|
|
748
|
-
register(20, parseBigInteger);
|
|
749
|
-
register(21, parseInteger);
|
|
750
|
-
register(23, parseInteger);
|
|
751
|
-
register(26, parseInteger);
|
|
752
|
-
register(700, parseFloat);
|
|
753
|
-
register(701, parseFloat);
|
|
754
|
-
register(16, parseBool);
|
|
755
|
-
register(1082, parseDate);
|
|
756
|
-
register(1114, parseDate);
|
|
757
|
-
register(1184, parseDate);
|
|
758
|
-
register(600, parsePoint);
|
|
759
|
-
register(651, parseStringArray);
|
|
760
|
-
register(718, parseCircle);
|
|
761
|
-
register(1e3, parseBoolArray);
|
|
762
|
-
register(1001, parseByteAArray);
|
|
763
|
-
register(1005, parseIntegerArray);
|
|
764
|
-
register(1007, parseIntegerArray);
|
|
765
|
-
register(1028, parseIntegerArray);
|
|
766
|
-
register(1016, parseBigIntegerArray);
|
|
767
|
-
register(1017, parsePointArray);
|
|
768
|
-
register(1021, parseFloatArray);
|
|
769
|
-
register(1022, parseFloatArray);
|
|
770
|
-
register(1231, parseFloatArray);
|
|
771
|
-
register(1014, parseStringArray);
|
|
772
|
-
register(1015, parseStringArray);
|
|
773
|
-
register(1008, parseStringArray);
|
|
774
|
-
register(1009, parseStringArray);
|
|
775
|
-
register(1040, parseStringArray);
|
|
776
|
-
register(1041, parseStringArray);
|
|
777
|
-
register(1115, parseDateArray);
|
|
778
|
-
register(1182, parseDateArray);
|
|
779
|
-
register(1185, parseDateArray);
|
|
780
|
-
register(1186, parseInterval);
|
|
781
|
-
register(1187, parseIntervalArray);
|
|
782
|
-
register(17, parseByteA);
|
|
783
|
-
register(114, JSON.parse.bind(JSON));
|
|
784
|
-
register(3802, JSON.parse.bind(JSON));
|
|
785
|
-
register(199, parseJsonArray);
|
|
786
|
-
register(3807, parseJsonArray);
|
|
787
|
-
register(3907, parseStringArray);
|
|
788
|
-
register(2951, parseStringArray);
|
|
789
|
-
register(791, parseStringArray);
|
|
790
|
-
register(1183, parseStringArray);
|
|
791
|
-
register(1270, parseStringArray);
|
|
792
|
-
};
|
|
793
|
-
module.exports = { init };
|
|
794
|
-
}));
|
|
795
|
-
//#endregion
|
|
796
|
-
//#region node_modules/pg-int8/index.js
|
|
797
|
-
var require_pg_int8 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
798
|
-
var BASE = 1e6;
|
|
799
|
-
function readInt8(buffer) {
|
|
800
|
-
var high = buffer.readInt32BE(0);
|
|
801
|
-
var low = buffer.readUInt32BE(4);
|
|
802
|
-
var sign = "";
|
|
803
|
-
if (high < 0) {
|
|
804
|
-
high = ~high + (low === 0);
|
|
805
|
-
low = ~low + 1 >>> 0;
|
|
806
|
-
sign = "-";
|
|
807
|
-
}
|
|
808
|
-
var result = "";
|
|
809
|
-
var carry;
|
|
810
|
-
var t;
|
|
811
|
-
var digits;
|
|
812
|
-
var pad;
|
|
813
|
-
var l;
|
|
814
|
-
var i;
|
|
815
|
-
carry = high % BASE;
|
|
816
|
-
high = high / BASE >>> 0;
|
|
817
|
-
t = 4294967296 * carry + low;
|
|
818
|
-
low = t / BASE >>> 0;
|
|
819
|
-
digits = "" + (t - BASE * low);
|
|
820
|
-
if (low === 0 && high === 0) return sign + digits + result;
|
|
821
|
-
pad = "";
|
|
822
|
-
l = 6 - digits.length;
|
|
823
|
-
for (i = 0; i < l; i++) pad += "0";
|
|
824
|
-
result = pad + digits + result;
|
|
825
|
-
carry = high % BASE;
|
|
826
|
-
high = high / BASE >>> 0;
|
|
827
|
-
t = 4294967296 * carry + low;
|
|
828
|
-
low = t / BASE >>> 0;
|
|
829
|
-
digits = "" + (t - BASE * low);
|
|
830
|
-
if (low === 0 && high === 0) return sign + digits + result;
|
|
831
|
-
pad = "";
|
|
832
|
-
l = 6 - digits.length;
|
|
833
|
-
for (i = 0; i < l; i++) pad += "0";
|
|
834
|
-
result = pad + digits + result;
|
|
835
|
-
carry = high % BASE;
|
|
836
|
-
high = high / BASE >>> 0;
|
|
837
|
-
t = 4294967296 * carry + low;
|
|
838
|
-
low = t / BASE >>> 0;
|
|
839
|
-
digits = "" + (t - BASE * low);
|
|
840
|
-
if (low === 0 && high === 0) return sign + digits + result;
|
|
841
|
-
pad = "";
|
|
842
|
-
l = 6 - digits.length;
|
|
843
|
-
for (i = 0; i < l; i++) pad += "0";
|
|
844
|
-
result = pad + digits + result;
|
|
845
|
-
carry = high % BASE;
|
|
846
|
-
t = 4294967296 * carry + low;
|
|
847
|
-
digits = "" + t % BASE;
|
|
848
|
-
return sign + digits + result;
|
|
849
|
-
}
|
|
850
|
-
module.exports = readInt8;
|
|
851
|
-
}));
|
|
852
|
-
//#endregion
|
|
853
|
-
//#region node_modules/pg-types/lib/binaryParsers.js
|
|
854
|
-
var require_binaryParsers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
855
|
-
var parseInt64 = require_pg_int8();
|
|
856
|
-
var parseBits = function(data, bits, offset, invert, callback) {
|
|
857
|
-
offset = offset || 0;
|
|
858
|
-
invert = invert || false;
|
|
859
|
-
callback = callback || function(lastValue, newValue, bits) {
|
|
860
|
-
return lastValue * Math.pow(2, bits) + newValue;
|
|
861
|
-
};
|
|
862
|
-
var offsetBytes = offset >> 3;
|
|
863
|
-
var inv = function(value) {
|
|
864
|
-
if (invert) return ~value & 255;
|
|
865
|
-
return value;
|
|
866
|
-
};
|
|
867
|
-
var mask = 255;
|
|
868
|
-
var firstBits = 8 - offset % 8;
|
|
869
|
-
if (bits < firstBits) {
|
|
870
|
-
mask = 255 << 8 - bits & 255;
|
|
871
|
-
firstBits = bits;
|
|
872
|
-
}
|
|
873
|
-
if (offset) mask = mask >> offset % 8;
|
|
874
|
-
var result = 0;
|
|
875
|
-
if (offset % 8 + bits >= 8) result = callback(0, inv(data[offsetBytes]) & mask, firstBits);
|
|
876
|
-
var bytes = bits + offset >> 3;
|
|
877
|
-
for (var i = offsetBytes + 1; i < bytes; i++) result = callback(result, inv(data[i]), 8);
|
|
878
|
-
var lastBits = (bits + offset) % 8;
|
|
879
|
-
if (lastBits > 0) result = callback(result, inv(data[bytes]) >> 8 - lastBits, lastBits);
|
|
880
|
-
return result;
|
|
881
|
-
};
|
|
882
|
-
var parseFloatFromBits = function(data, precisionBits, exponentBits) {
|
|
883
|
-
var bias = Math.pow(2, exponentBits - 1) - 1;
|
|
884
|
-
var sign = parseBits(data, 1);
|
|
885
|
-
var exponent = parseBits(data, exponentBits, 1);
|
|
886
|
-
if (exponent === 0) return 0;
|
|
887
|
-
var precisionBitsCounter = 1;
|
|
888
|
-
var parsePrecisionBits = function(lastValue, newValue, bits) {
|
|
889
|
-
if (lastValue === 0) lastValue = 1;
|
|
890
|
-
for (var i = 1; i <= bits; i++) {
|
|
891
|
-
precisionBitsCounter /= 2;
|
|
892
|
-
if ((newValue & 1 << bits - i) > 0) lastValue += precisionBitsCounter;
|
|
893
|
-
}
|
|
894
|
-
return lastValue;
|
|
895
|
-
};
|
|
896
|
-
var mantissa = parseBits(data, precisionBits, exponentBits + 1, false, parsePrecisionBits);
|
|
897
|
-
if (exponent == Math.pow(2, exponentBits + 1) - 1) {
|
|
898
|
-
if (mantissa === 0) return sign === 0 ? Infinity : -Infinity;
|
|
899
|
-
return NaN;
|
|
900
|
-
}
|
|
901
|
-
return (sign === 0 ? 1 : -1) * Math.pow(2, exponent - bias) * mantissa;
|
|
902
|
-
};
|
|
903
|
-
var parseInt16 = function(value) {
|
|
904
|
-
if (parseBits(value, 1) == 1) return -1 * (parseBits(value, 15, 1, true) + 1);
|
|
905
|
-
return parseBits(value, 15, 1);
|
|
906
|
-
};
|
|
907
|
-
var parseInt32 = function(value) {
|
|
908
|
-
if (parseBits(value, 1) == 1) return -1 * (parseBits(value, 31, 1, true) + 1);
|
|
909
|
-
return parseBits(value, 31, 1);
|
|
910
|
-
};
|
|
911
|
-
var parseFloat32 = function(value) {
|
|
912
|
-
return parseFloatFromBits(value, 23, 8);
|
|
913
|
-
};
|
|
914
|
-
var parseFloat64 = function(value) {
|
|
915
|
-
return parseFloatFromBits(value, 52, 11);
|
|
916
|
-
};
|
|
917
|
-
var parseNumeric = function(value) {
|
|
918
|
-
var sign = parseBits(value, 16, 32);
|
|
919
|
-
if (sign == 49152) return NaN;
|
|
920
|
-
var weight = Math.pow(1e4, parseBits(value, 16, 16));
|
|
921
|
-
var result = 0;
|
|
922
|
-
var ndigits = parseBits(value, 16);
|
|
923
|
-
for (var i = 0; i < ndigits; i++) {
|
|
924
|
-
result += parseBits(value, 16, 64 + 16 * i) * weight;
|
|
925
|
-
weight /= 1e4;
|
|
926
|
-
}
|
|
927
|
-
var scale = Math.pow(10, parseBits(value, 16, 48));
|
|
928
|
-
return (sign === 0 ? 1 : -1) * Math.round(result * scale) / scale;
|
|
929
|
-
};
|
|
930
|
-
var parseDate = function(isUTC, value) {
|
|
931
|
-
var sign = parseBits(value, 1);
|
|
932
|
-
var rawValue = parseBits(value, 63, 1);
|
|
933
|
-
var result = /* @__PURE__ */ new Date((sign === 0 ? 1 : -1) * rawValue / 1e3 + 9466848e5);
|
|
934
|
-
if (!isUTC) result.setTime(result.getTime() + result.getTimezoneOffset() * 6e4);
|
|
935
|
-
result.usec = rawValue % 1e3;
|
|
936
|
-
result.getMicroSeconds = function() {
|
|
937
|
-
return this.usec;
|
|
938
|
-
};
|
|
939
|
-
result.setMicroSeconds = function(value) {
|
|
940
|
-
this.usec = value;
|
|
941
|
-
};
|
|
942
|
-
result.getUTCMicroSeconds = function() {
|
|
943
|
-
return this.usec;
|
|
944
|
-
};
|
|
945
|
-
return result;
|
|
946
|
-
};
|
|
947
|
-
var parseArray = function(value) {
|
|
948
|
-
var dim = parseBits(value, 32);
|
|
949
|
-
parseBits(value, 32, 32);
|
|
950
|
-
var elementType = parseBits(value, 32, 64);
|
|
951
|
-
var offset = 96;
|
|
952
|
-
var dims = [];
|
|
953
|
-
for (var i = 0; i < dim; i++) {
|
|
954
|
-
dims[i] = parseBits(value, 32, offset);
|
|
955
|
-
offset += 32;
|
|
956
|
-
offset += 32;
|
|
957
|
-
}
|
|
958
|
-
var parseElement = function(elementType) {
|
|
959
|
-
var length = parseBits(value, 32, offset);
|
|
960
|
-
offset += 32;
|
|
961
|
-
if (length == 4294967295) return null;
|
|
962
|
-
var result;
|
|
963
|
-
if (elementType == 23 || elementType == 20) {
|
|
964
|
-
result = parseBits(value, length * 8, offset);
|
|
965
|
-
offset += length * 8;
|
|
966
|
-
return result;
|
|
967
|
-
} else if (elementType == 25) {
|
|
968
|
-
result = value.toString(this.encoding, offset >> 3, (offset += length << 3) >> 3);
|
|
969
|
-
return result;
|
|
970
|
-
} else console.log("ERROR: ElementType not implemented: " + elementType);
|
|
971
|
-
};
|
|
972
|
-
var parse = function(dimension, elementType) {
|
|
973
|
-
var array = [];
|
|
974
|
-
var i;
|
|
975
|
-
if (dimension.length > 1) {
|
|
976
|
-
var count = dimension.shift();
|
|
977
|
-
for (i = 0; i < count; i++) array[i] = parse(dimension, elementType);
|
|
978
|
-
dimension.unshift(count);
|
|
979
|
-
} else for (i = 0; i < dimension[0]; i++) array[i] = parseElement(elementType);
|
|
980
|
-
return array;
|
|
981
|
-
};
|
|
982
|
-
return parse(dims, elementType);
|
|
983
|
-
};
|
|
984
|
-
var parseText = function(value) {
|
|
985
|
-
return value.toString("utf8");
|
|
986
|
-
};
|
|
987
|
-
var parseBool = function(value) {
|
|
988
|
-
if (value === null) return null;
|
|
989
|
-
return parseBits(value, 8) > 0;
|
|
990
|
-
};
|
|
991
|
-
var init = function(register) {
|
|
992
|
-
register(20, parseInt64);
|
|
993
|
-
register(21, parseInt16);
|
|
994
|
-
register(23, parseInt32);
|
|
995
|
-
register(26, parseInt32);
|
|
996
|
-
register(1700, parseNumeric);
|
|
997
|
-
register(700, parseFloat32);
|
|
998
|
-
register(701, parseFloat64);
|
|
999
|
-
register(16, parseBool);
|
|
1000
|
-
register(1114, parseDate.bind(null, false));
|
|
1001
|
-
register(1184, parseDate.bind(null, true));
|
|
1002
|
-
register(1e3, parseArray);
|
|
1003
|
-
register(1007, parseArray);
|
|
1004
|
-
register(1016, parseArray);
|
|
1005
|
-
register(1008, parseArray);
|
|
1006
|
-
register(1009, parseArray);
|
|
1007
|
-
register(25, parseText);
|
|
1008
|
-
};
|
|
1009
|
-
module.exports = { init };
|
|
1010
|
-
}));
|
|
1011
|
-
//#endregion
|
|
1012
|
-
//#region node_modules/pg-types/lib/builtins.js
|
|
1013
|
-
var require_builtins = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1014
|
-
/**
|
|
1015
|
-
* Following query was used to generate this file:
|
|
1016
|
-
|
|
1017
|
-
SELECT json_object_agg(UPPER(PT.typname), PT.oid::int4 ORDER BY pt.oid)
|
|
1018
|
-
FROM pg_type PT
|
|
1019
|
-
WHERE typnamespace = (SELECT pgn.oid FROM pg_namespace pgn WHERE nspname = 'pg_catalog') -- Take only builting Postgres types with stable OID (extension types are not guaranted to be stable)
|
|
1020
|
-
AND typtype = 'b' -- Only basic types
|
|
1021
|
-
AND typelem = 0 -- Ignore aliases
|
|
1022
|
-
AND typisdefined -- Ignore undefined types
|
|
1023
|
-
*/
|
|
1024
|
-
module.exports = {
|
|
1025
|
-
BOOL: 16,
|
|
1026
|
-
BYTEA: 17,
|
|
1027
|
-
CHAR: 18,
|
|
1028
|
-
INT8: 20,
|
|
1029
|
-
INT2: 21,
|
|
1030
|
-
INT4: 23,
|
|
1031
|
-
REGPROC: 24,
|
|
1032
|
-
TEXT: 25,
|
|
1033
|
-
OID: 26,
|
|
1034
|
-
TID: 27,
|
|
1035
|
-
XID: 28,
|
|
1036
|
-
CID: 29,
|
|
1037
|
-
JSON: 114,
|
|
1038
|
-
XML: 142,
|
|
1039
|
-
PG_NODE_TREE: 194,
|
|
1040
|
-
SMGR: 210,
|
|
1041
|
-
PATH: 602,
|
|
1042
|
-
POLYGON: 604,
|
|
1043
|
-
CIDR: 650,
|
|
1044
|
-
FLOAT4: 700,
|
|
1045
|
-
FLOAT8: 701,
|
|
1046
|
-
ABSTIME: 702,
|
|
1047
|
-
RELTIME: 703,
|
|
1048
|
-
TINTERVAL: 704,
|
|
1049
|
-
CIRCLE: 718,
|
|
1050
|
-
MACADDR8: 774,
|
|
1051
|
-
MONEY: 790,
|
|
1052
|
-
MACADDR: 829,
|
|
1053
|
-
INET: 869,
|
|
1054
|
-
ACLITEM: 1033,
|
|
1055
|
-
BPCHAR: 1042,
|
|
1056
|
-
VARCHAR: 1043,
|
|
1057
|
-
DATE: 1082,
|
|
1058
|
-
TIME: 1083,
|
|
1059
|
-
TIMESTAMP: 1114,
|
|
1060
|
-
TIMESTAMPTZ: 1184,
|
|
1061
|
-
INTERVAL: 1186,
|
|
1062
|
-
TIMETZ: 1266,
|
|
1063
|
-
BIT: 1560,
|
|
1064
|
-
VARBIT: 1562,
|
|
1065
|
-
NUMERIC: 1700,
|
|
1066
|
-
REFCURSOR: 1790,
|
|
1067
|
-
REGPROCEDURE: 2202,
|
|
1068
|
-
REGOPER: 2203,
|
|
1069
|
-
REGOPERATOR: 2204,
|
|
1070
|
-
REGCLASS: 2205,
|
|
1071
|
-
REGTYPE: 2206,
|
|
1072
|
-
UUID: 2950,
|
|
1073
|
-
TXID_SNAPSHOT: 2970,
|
|
1074
|
-
PG_LSN: 3220,
|
|
1075
|
-
PG_NDISTINCT: 3361,
|
|
1076
|
-
PG_DEPENDENCIES: 3402,
|
|
1077
|
-
TSVECTOR: 3614,
|
|
1078
|
-
TSQUERY: 3615,
|
|
1079
|
-
GTSVECTOR: 3642,
|
|
1080
|
-
REGCONFIG: 3734,
|
|
1081
|
-
REGDICTIONARY: 3769,
|
|
1082
|
-
JSONB: 3802,
|
|
1083
|
-
REGNAMESPACE: 4089,
|
|
1084
|
-
REGROLE: 4096
|
|
1085
|
-
};
|
|
1086
|
-
}));
|
|
1087
|
-
//#endregion
|
|
1088
|
-
//#region node_modules/pg-types/index.js
|
|
1089
|
-
var require_pg_types = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1090
|
-
var textParsers = require_textParsers();
|
|
1091
|
-
var binaryParsers = require_binaryParsers();
|
|
1092
|
-
var arrayParser = require_arrayParser();
|
|
1093
|
-
var builtinTypes = require_builtins();
|
|
1094
|
-
exports.getTypeParser = getTypeParser;
|
|
1095
|
-
exports.setTypeParser = setTypeParser;
|
|
1096
|
-
exports.arrayParser = arrayParser;
|
|
1097
|
-
exports.builtins = builtinTypes;
|
|
1098
|
-
var typeParsers = {
|
|
1099
|
-
text: {},
|
|
1100
|
-
binary: {}
|
|
1101
|
-
};
|
|
1102
|
-
function noParse(val) {
|
|
1103
|
-
return String(val);
|
|
1104
|
-
}
|
|
1105
|
-
function getTypeParser(oid, format) {
|
|
1106
|
-
format = format || "text";
|
|
1107
|
-
if (!typeParsers[format]) return noParse;
|
|
1108
|
-
return typeParsers[format][oid] || noParse;
|
|
1109
|
-
}
|
|
1110
|
-
function setTypeParser(oid, format, parseFn) {
|
|
1111
|
-
if (typeof format == "function") {
|
|
1112
|
-
parseFn = format;
|
|
1113
|
-
format = "text";
|
|
1114
|
-
}
|
|
1115
|
-
typeParsers[format][oid] = parseFn;
|
|
1116
|
-
}
|
|
1117
|
-
textParsers.init(function(oid, converter) {
|
|
1118
|
-
typeParsers.text[oid] = converter;
|
|
1119
|
-
});
|
|
1120
|
-
binaryParsers.init(function(oid, converter) {
|
|
1121
|
-
typeParsers.binary[oid] = converter;
|
|
1122
|
-
});
|
|
1123
|
-
}));
|
|
1124
|
-
//#endregion
|
|
1125
|
-
//#region node_modules/pg/lib/defaults.js
|
|
1126
|
-
var require_defaults = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1127
|
-
let user;
|
|
1128
|
-
try {
|
|
1129
|
-
user = process.platform === "win32" ? process.env.USERNAME : process.env.USER;
|
|
1130
|
-
} catch {}
|
|
1131
|
-
module.exports = {
|
|
1132
|
-
host: "localhost",
|
|
1133
|
-
user,
|
|
1134
|
-
database: void 0,
|
|
1135
|
-
password: null,
|
|
1136
|
-
connectionString: void 0,
|
|
1137
|
-
port: 5432,
|
|
1138
|
-
rows: 0,
|
|
1139
|
-
binary: false,
|
|
1140
|
-
max: 10,
|
|
1141
|
-
idleTimeoutMillis: 3e4,
|
|
1142
|
-
client_encoding: "",
|
|
1143
|
-
ssl: false,
|
|
1144
|
-
application_name: void 0,
|
|
1145
|
-
fallback_application_name: void 0,
|
|
1146
|
-
options: void 0,
|
|
1147
|
-
parseInputDatesAsUTC: false,
|
|
1148
|
-
statement_timeout: false,
|
|
1149
|
-
lock_timeout: false,
|
|
1150
|
-
idle_in_transaction_session_timeout: false,
|
|
1151
|
-
query_timeout: false,
|
|
1152
|
-
connect_timeout: 0,
|
|
1153
|
-
keepalives: 1,
|
|
1154
|
-
keepalives_idle: 0
|
|
1155
|
-
};
|
|
1156
|
-
const pgTypes = require_pg_types();
|
|
1157
|
-
const parseBigInteger = pgTypes.getTypeParser(20, "text");
|
|
1158
|
-
const parseBigIntegerArray = pgTypes.getTypeParser(1016, "text");
|
|
1159
|
-
module.exports.__defineSetter__("parseInt8", function(val) {
|
|
1160
|
-
pgTypes.setTypeParser(20, "text", val ? pgTypes.getTypeParser(23, "text") : parseBigInteger);
|
|
1161
|
-
pgTypes.setTypeParser(1016, "text", val ? pgTypes.getTypeParser(1007, "text") : parseBigIntegerArray);
|
|
1162
|
-
});
|
|
1163
|
-
}));
|
|
1164
|
-
//#endregion
|
|
1165
|
-
//#region node_modules/pg/lib/utils.js
|
|
1166
|
-
var require_utils$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1167
|
-
const defaults = require_defaults();
|
|
1168
|
-
const util$3 = __require("util");
|
|
1169
|
-
const { isDate } = util$3.types || util$3;
|
|
1170
|
-
function escapeElement(elementRepresentation) {
|
|
1171
|
-
return "\"" + elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"";
|
|
1172
|
-
}
|
|
1173
|
-
function arrayString(val) {
|
|
1174
|
-
let result = "{";
|
|
1175
|
-
for (let i = 0; i < val.length; i++) {
|
|
1176
|
-
if (i > 0) result = result + ",";
|
|
1177
|
-
if (val[i] === null || typeof val[i] === "undefined") result = result + "NULL";
|
|
1178
|
-
else if (Array.isArray(val[i])) result = result + arrayString(val[i]);
|
|
1179
|
-
else if (ArrayBuffer.isView(val[i])) {
|
|
1180
|
-
let item = val[i];
|
|
1181
|
-
if (!(item instanceof Buffer)) {
|
|
1182
|
-
const buf = Buffer.from(item.buffer, item.byteOffset, item.byteLength);
|
|
1183
|
-
if (buf.length === item.byteLength) item = buf;
|
|
1184
|
-
else item = buf.slice(item.byteOffset, item.byteOffset + item.byteLength);
|
|
1185
|
-
}
|
|
1186
|
-
result += "\\\\x" + item.toString("hex");
|
|
1187
|
-
} else result += escapeElement(prepareValue(val[i]));
|
|
1188
|
-
}
|
|
1189
|
-
result = result + "}";
|
|
1190
|
-
return result;
|
|
1191
|
-
}
|
|
1192
|
-
const prepareValue = function(val, seen) {
|
|
1193
|
-
if (val == null) return null;
|
|
1194
|
-
if (typeof val === "object") {
|
|
1195
|
-
if (val instanceof Buffer) return val;
|
|
1196
|
-
if (ArrayBuffer.isView(val)) {
|
|
1197
|
-
const buf = Buffer.from(val.buffer, val.byteOffset, val.byteLength);
|
|
1198
|
-
if (buf.length === val.byteLength) return buf;
|
|
1199
|
-
return buf.slice(val.byteOffset, val.byteOffset + val.byteLength);
|
|
1200
|
-
}
|
|
1201
|
-
if (isDate(val)) if (defaults.parseInputDatesAsUTC) return dateToStringUTC(val);
|
|
1202
|
-
else return dateToString(val);
|
|
1203
|
-
if (Array.isArray(val)) return arrayString(val);
|
|
1204
|
-
return prepareObject(val, seen);
|
|
1205
|
-
}
|
|
1206
|
-
return val.toString();
|
|
1207
|
-
};
|
|
1208
|
-
function prepareObject(val, seen) {
|
|
1209
|
-
if (val && typeof val.toPostgres === "function") {
|
|
1210
|
-
seen = seen || [];
|
|
1211
|
-
if (seen.indexOf(val) !== -1) throw new Error("circular reference detected while preparing \"" + val + "\" for query");
|
|
1212
|
-
seen.push(val);
|
|
1213
|
-
return prepareValue(val.toPostgres(prepareValue), seen);
|
|
1214
|
-
}
|
|
1215
|
-
return JSON.stringify(val);
|
|
1216
|
-
}
|
|
1217
|
-
function dateToString(date) {
|
|
1218
|
-
let offset = -date.getTimezoneOffset();
|
|
1219
|
-
let year = date.getFullYear();
|
|
1220
|
-
const isBCYear = year < 1;
|
|
1221
|
-
if (isBCYear) year = Math.abs(year) + 1;
|
|
1222
|
-
let ret = String(year).padStart(4, "0") + "-" + String(date.getMonth() + 1).padStart(2, "0") + "-" + String(date.getDate()).padStart(2, "0") + "T" + String(date.getHours()).padStart(2, "0") + ":" + String(date.getMinutes()).padStart(2, "0") + ":" + String(date.getSeconds()).padStart(2, "0") + "." + String(date.getMilliseconds()).padStart(3, "0");
|
|
1223
|
-
if (offset < 0) {
|
|
1224
|
-
ret += "-";
|
|
1225
|
-
offset *= -1;
|
|
1226
|
-
} else ret += "+";
|
|
1227
|
-
ret += String(Math.floor(offset / 60)).padStart(2, "0") + ":" + String(offset % 60).padStart(2, "0");
|
|
1228
|
-
if (isBCYear) ret += " BC";
|
|
1229
|
-
return ret;
|
|
1230
|
-
}
|
|
1231
|
-
function dateToStringUTC(date) {
|
|
1232
|
-
let year = date.getUTCFullYear();
|
|
1233
|
-
const isBCYear = year < 1;
|
|
1234
|
-
if (isBCYear) year = Math.abs(year) + 1;
|
|
1235
|
-
let ret = String(year).padStart(4, "0") + "-" + String(date.getUTCMonth() + 1).padStart(2, "0") + "-" + String(date.getUTCDate()).padStart(2, "0") + "T" + String(date.getUTCHours()).padStart(2, "0") + ":" + String(date.getUTCMinutes()).padStart(2, "0") + ":" + String(date.getUTCSeconds()).padStart(2, "0") + "." + String(date.getUTCMilliseconds()).padStart(3, "0");
|
|
1236
|
-
ret += "+00:00";
|
|
1237
|
-
if (isBCYear) ret += " BC";
|
|
1238
|
-
return ret;
|
|
1239
|
-
}
|
|
1240
|
-
function normalizeQueryConfig(config, values, callback) {
|
|
1241
|
-
config = typeof config === "string" ? { text: config } : config;
|
|
1242
|
-
if (values) if (typeof values === "function") config.callback = values;
|
|
1243
|
-
else config.values = values;
|
|
1244
|
-
if (callback) config.callback = callback;
|
|
1245
|
-
return config;
|
|
1246
|
-
}
|
|
1247
|
-
const escapeIdentifier = function(str) {
|
|
1248
|
-
return "\"" + str.replace(/"/g, "\"\"") + "\"";
|
|
1249
|
-
};
|
|
1250
|
-
const escapeLiteral = function(str) {
|
|
1251
|
-
let hasBackslash = false;
|
|
1252
|
-
let escaped = "'";
|
|
1253
|
-
if (str == null) return "''";
|
|
1254
|
-
if (typeof str !== "string") return "''";
|
|
1255
|
-
for (let i = 0; i < str.length; i++) {
|
|
1256
|
-
const c = str[i];
|
|
1257
|
-
if (c === "'") escaped += c + c;
|
|
1258
|
-
else if (c === "\\") {
|
|
1259
|
-
escaped += c + c;
|
|
1260
|
-
hasBackslash = true;
|
|
1261
|
-
} else escaped += c;
|
|
1262
|
-
}
|
|
1263
|
-
escaped += "'";
|
|
1264
|
-
if (hasBackslash === true) escaped = " E" + escaped;
|
|
1265
|
-
return escaped;
|
|
1266
|
-
};
|
|
1267
|
-
module.exports = {
|
|
1268
|
-
prepareValue: function prepareValueWrapper(value) {
|
|
1269
|
-
return prepareValue(value);
|
|
1270
|
-
},
|
|
1271
|
-
normalizeQueryConfig,
|
|
1272
|
-
escapeIdentifier,
|
|
1273
|
-
escapeLiteral
|
|
1274
|
-
};
|
|
1275
|
-
}));
|
|
1276
|
-
//#endregion
|
|
1277
|
-
//#region node_modules/pg/lib/crypto/utils-legacy.js
|
|
1278
|
-
var require_utils_legacy = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1279
|
-
const nodeCrypto$1 = __require("crypto");
|
|
1280
|
-
function md5(string) {
|
|
1281
|
-
return nodeCrypto$1.createHash("md5").update(string, "utf-8").digest("hex");
|
|
1282
|
-
}
|
|
1283
|
-
function postgresMd5PasswordHash(user, password, salt) {
|
|
1284
|
-
const inner = md5(password + user);
|
|
1285
|
-
return "md5" + md5(Buffer.concat([Buffer.from(inner), salt]));
|
|
1286
|
-
}
|
|
1287
|
-
function sha256(text) {
|
|
1288
|
-
return nodeCrypto$1.createHash("sha256").update(text).digest();
|
|
1289
|
-
}
|
|
1290
|
-
function hashByName(hashName, text) {
|
|
1291
|
-
hashName = hashName.replace(/(\D)-/, "$1");
|
|
1292
|
-
return nodeCrypto$1.createHash(hashName).update(text).digest();
|
|
1293
|
-
}
|
|
1294
|
-
function hmacSha256(key, msg) {
|
|
1295
|
-
return nodeCrypto$1.createHmac("sha256", key).update(msg).digest();
|
|
1296
|
-
}
|
|
1297
|
-
async function deriveKey(password, salt, iterations) {
|
|
1298
|
-
return nodeCrypto$1.pbkdf2Sync(password, salt, iterations, 32, "sha256");
|
|
1299
|
-
}
|
|
1300
|
-
module.exports = {
|
|
1301
|
-
postgresMd5PasswordHash,
|
|
1302
|
-
randomBytes: nodeCrypto$1.randomBytes,
|
|
1303
|
-
deriveKey,
|
|
1304
|
-
sha256,
|
|
1305
|
-
hashByName,
|
|
1306
|
-
hmacSha256,
|
|
1307
|
-
md5
|
|
1308
|
-
};
|
|
1309
|
-
}));
|
|
1310
|
-
//#endregion
|
|
1311
|
-
//#region node_modules/pg/lib/crypto/utils-webcrypto.js
|
|
1312
|
-
var require_utils_webcrypto = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1313
|
-
const nodeCrypto = __require("crypto");
|
|
1314
|
-
module.exports = {
|
|
1315
|
-
postgresMd5PasswordHash,
|
|
1316
|
-
randomBytes,
|
|
1317
|
-
deriveKey,
|
|
1318
|
-
sha256,
|
|
1319
|
-
hashByName,
|
|
1320
|
-
hmacSha256,
|
|
1321
|
-
md5
|
|
1322
|
-
};
|
|
1323
|
-
/**
|
|
1324
|
-
* The Web Crypto API - grabbed from the Node.js library or the global
|
|
1325
|
-
* @type Crypto
|
|
1326
|
-
*/
|
|
1327
|
-
const webCrypto = nodeCrypto.webcrypto || globalThis.crypto;
|
|
1328
|
-
/**
|
|
1329
|
-
* The SubtleCrypto API for low level crypto operations.
|
|
1330
|
-
* @type SubtleCrypto
|
|
1331
|
-
*/
|
|
1332
|
-
const subtleCrypto = webCrypto.subtle;
|
|
1333
|
-
const textEncoder = new TextEncoder();
|
|
1334
|
-
/**
|
|
1335
|
-
*
|
|
1336
|
-
* @param {*} length
|
|
1337
|
-
* @returns
|
|
1338
|
-
*/
|
|
1339
|
-
function randomBytes(length) {
|
|
1340
|
-
return webCrypto.getRandomValues(Buffer.alloc(length));
|
|
1341
|
-
}
|
|
1342
|
-
async function md5(string) {
|
|
1343
|
-
try {
|
|
1344
|
-
return nodeCrypto.createHash("md5").update(string, "utf-8").digest("hex");
|
|
1345
|
-
} catch (e) {
|
|
1346
|
-
const data = typeof string === "string" ? textEncoder.encode(string) : string;
|
|
1347
|
-
const hash = await subtleCrypto.digest("MD5", data);
|
|
1348
|
-
return Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
async function postgresMd5PasswordHash(user, password, salt) {
|
|
1352
|
-
const inner = await md5(password + user);
|
|
1353
|
-
return "md5" + await md5(Buffer.concat([Buffer.from(inner), salt]));
|
|
1354
|
-
}
|
|
1355
|
-
/**
|
|
1356
|
-
* Create a SHA-256 digest of the given data
|
|
1357
|
-
* @param {Buffer} data
|
|
1358
|
-
*/
|
|
1359
|
-
async function sha256(text) {
|
|
1360
|
-
return await subtleCrypto.digest("SHA-256", text);
|
|
1361
|
-
}
|
|
1362
|
-
async function hashByName(hashName, text) {
|
|
1363
|
-
return await subtleCrypto.digest(hashName, text);
|
|
1364
|
-
}
|
|
1365
|
-
/**
|
|
1366
|
-
* Sign the message with the given key
|
|
1367
|
-
* @param {ArrayBuffer} keyBuffer
|
|
1368
|
-
* @param {string} msg
|
|
1369
|
-
*/
|
|
1370
|
-
async function hmacSha256(keyBuffer, msg) {
|
|
1371
|
-
const key = await subtleCrypto.importKey("raw", keyBuffer, {
|
|
1372
|
-
name: "HMAC",
|
|
1373
|
-
hash: "SHA-256"
|
|
1374
|
-
}, false, ["sign"]);
|
|
1375
|
-
return await subtleCrypto.sign("HMAC", key, textEncoder.encode(msg));
|
|
1376
|
-
}
|
|
1377
|
-
/**
|
|
1378
|
-
* Derive a key from the password and salt
|
|
1379
|
-
* @param {string} password
|
|
1380
|
-
* @param {Uint8Array} salt
|
|
1381
|
-
* @param {number} iterations
|
|
1382
|
-
*/
|
|
1383
|
-
async function deriveKey(password, salt, iterations) {
|
|
1384
|
-
const key = await subtleCrypto.importKey("raw", textEncoder.encode(password), "PBKDF2", false, ["deriveBits"]);
|
|
1385
|
-
const params = {
|
|
1386
|
-
name: "PBKDF2",
|
|
1387
|
-
hash: "SHA-256",
|
|
1388
|
-
salt,
|
|
1389
|
-
iterations
|
|
1390
|
-
};
|
|
1391
|
-
return await subtleCrypto.deriveBits(params, key, 256, ["deriveBits"]);
|
|
1392
|
-
}
|
|
1393
|
-
}));
|
|
1394
|
-
//#endregion
|
|
1395
|
-
//#region node_modules/pg/lib/crypto/utils.js
|
|
1396
|
-
var require_utils = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1397
|
-
if (parseInt(process.versions && process.versions.node && process.versions.node.split(".")[0]) < 15) module.exports = require_utils_legacy();
|
|
1398
|
-
else module.exports = require_utils_webcrypto();
|
|
1399
|
-
}));
|
|
1400
|
-
//#endregion
|
|
1401
|
-
//#region node_modules/pg/lib/crypto/cert-signatures.js
|
|
1402
|
-
var require_cert_signatures = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1403
|
-
function x509Error(msg, cert) {
|
|
1404
|
-
return /* @__PURE__ */ new Error("SASL channel binding: " + msg + " when parsing public certificate " + cert.toString("base64"));
|
|
1405
|
-
}
|
|
1406
|
-
function readASN1Length(data, index) {
|
|
1407
|
-
let length = data[index++];
|
|
1408
|
-
if (length < 128) return {
|
|
1409
|
-
length,
|
|
1410
|
-
index
|
|
1411
|
-
};
|
|
1412
|
-
const lengthBytes = length & 127;
|
|
1413
|
-
if (lengthBytes > 4) throw x509Error("bad length", data);
|
|
1414
|
-
length = 0;
|
|
1415
|
-
for (let i = 0; i < lengthBytes; i++) length = length << 8 | data[index++];
|
|
1416
|
-
return {
|
|
1417
|
-
length,
|
|
1418
|
-
index
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
function readASN1OID(data, index) {
|
|
1422
|
-
if (data[index++] !== 6) throw x509Error("non-OID data", data);
|
|
1423
|
-
const { length: OIDLength, index: indexAfterOIDLength } = readASN1Length(data, index);
|
|
1424
|
-
index = indexAfterOIDLength;
|
|
1425
|
-
const lastIndex = index + OIDLength;
|
|
1426
|
-
const byte1 = data[index++];
|
|
1427
|
-
let oid = (byte1 / 40 >> 0) + "." + byte1 % 40;
|
|
1428
|
-
while (index < lastIndex) {
|
|
1429
|
-
let value = 0;
|
|
1430
|
-
while (index < lastIndex) {
|
|
1431
|
-
const nextByte = data[index++];
|
|
1432
|
-
value = value << 7 | nextByte & 127;
|
|
1433
|
-
if (nextByte < 128) break;
|
|
1434
|
-
}
|
|
1435
|
-
oid += "." + value;
|
|
1436
|
-
}
|
|
1437
|
-
return {
|
|
1438
|
-
oid,
|
|
1439
|
-
index
|
|
1440
|
-
};
|
|
1441
|
-
}
|
|
1442
|
-
function expectASN1Seq(data, index) {
|
|
1443
|
-
if (data[index++] !== 48) throw x509Error("non-sequence data", data);
|
|
1444
|
-
return readASN1Length(data, index);
|
|
1445
|
-
}
|
|
1446
|
-
function signatureAlgorithmHashFromCertificate(data, index) {
|
|
1447
|
-
if (index === void 0) index = 0;
|
|
1448
|
-
index = expectASN1Seq(data, index).index;
|
|
1449
|
-
const { length: certInfoLength, index: indexAfterCertInfoLength } = expectASN1Seq(data, index);
|
|
1450
|
-
index = indexAfterCertInfoLength + certInfoLength;
|
|
1451
|
-
index = expectASN1Seq(data, index).index;
|
|
1452
|
-
const { oid, index: indexAfterOID } = readASN1OID(data, index);
|
|
1453
|
-
switch (oid) {
|
|
1454
|
-
case "1.2.840.113549.1.1.4": return "MD5";
|
|
1455
|
-
case "1.2.840.113549.1.1.5": return "SHA-1";
|
|
1456
|
-
case "1.2.840.113549.1.1.11": return "SHA-256";
|
|
1457
|
-
case "1.2.840.113549.1.1.12": return "SHA-384";
|
|
1458
|
-
case "1.2.840.113549.1.1.13": return "SHA-512";
|
|
1459
|
-
case "1.2.840.113549.1.1.14": return "SHA-224";
|
|
1460
|
-
case "1.2.840.113549.1.1.15": return "SHA512-224";
|
|
1461
|
-
case "1.2.840.113549.1.1.16": return "SHA512-256";
|
|
1462
|
-
case "1.2.840.10045.4.1": return "SHA-1";
|
|
1463
|
-
case "1.2.840.10045.4.3.1": return "SHA-224";
|
|
1464
|
-
case "1.2.840.10045.4.3.2": return "SHA-256";
|
|
1465
|
-
case "1.2.840.10045.4.3.3": return "SHA-384";
|
|
1466
|
-
case "1.2.840.10045.4.3.4": return "SHA-512";
|
|
1467
|
-
case "1.2.840.113549.1.1.10": {
|
|
1468
|
-
index = indexAfterOID;
|
|
1469
|
-
index = expectASN1Seq(data, index).index;
|
|
1470
|
-
if (data[index++] !== 160) throw x509Error("non-tag data", data);
|
|
1471
|
-
index = readASN1Length(data, index).index;
|
|
1472
|
-
index = expectASN1Seq(data, index).index;
|
|
1473
|
-
const { oid: hashOID } = readASN1OID(data, index);
|
|
1474
|
-
switch (hashOID) {
|
|
1475
|
-
case "1.2.840.113549.2.5": return "MD5";
|
|
1476
|
-
case "1.3.14.3.2.26": return "SHA-1";
|
|
1477
|
-
case "2.16.840.1.101.3.4.2.1": return "SHA-256";
|
|
1478
|
-
case "2.16.840.1.101.3.4.2.2": return "SHA-384";
|
|
1479
|
-
case "2.16.840.1.101.3.4.2.3": return "SHA-512";
|
|
1480
|
-
}
|
|
1481
|
-
throw x509Error("unknown hash OID " + hashOID, data);
|
|
1482
|
-
}
|
|
1483
|
-
case "1.3.101.110":
|
|
1484
|
-
case "1.3.101.112": return "SHA-512";
|
|
1485
|
-
case "1.3.101.111":
|
|
1486
|
-
case "1.3.101.113": throw x509Error("Ed448 certificate channel binding is not currently supported by Postgres");
|
|
1487
|
-
}
|
|
1488
|
-
throw x509Error("unknown OID " + oid, data);
|
|
1489
|
-
}
|
|
1490
|
-
module.exports = { signatureAlgorithmHashFromCertificate };
|
|
1491
|
-
}));
|
|
1492
|
-
//#endregion
|
|
1493
|
-
//#region node_modules/pg/lib/crypto/sasl.js
|
|
1494
|
-
var require_sasl = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1495
|
-
const crypto = require_utils();
|
|
1496
|
-
const { signatureAlgorithmHashFromCertificate } = require_cert_signatures();
|
|
1497
|
-
function startSession(mechanisms, stream) {
|
|
1498
|
-
const candidates = ["SCRAM-SHA-256"];
|
|
1499
|
-
if (stream) candidates.unshift("SCRAM-SHA-256-PLUS");
|
|
1500
|
-
const mechanism = candidates.find((candidate) => mechanisms.includes(candidate));
|
|
1501
|
-
if (!mechanism) throw new Error("SASL: Only mechanism(s) " + candidates.join(" and ") + " are supported");
|
|
1502
|
-
if (mechanism === "SCRAM-SHA-256-PLUS" && typeof stream.getPeerCertificate !== "function") throw new Error("SASL: Mechanism SCRAM-SHA-256-PLUS requires a certificate");
|
|
1503
|
-
const clientNonce = crypto.randomBytes(18).toString("base64");
|
|
1504
|
-
return {
|
|
1505
|
-
mechanism,
|
|
1506
|
-
clientNonce,
|
|
1507
|
-
response: (mechanism === "SCRAM-SHA-256-PLUS" ? "p=tls-server-end-point" : stream ? "y" : "n") + ",,n=*,r=" + clientNonce,
|
|
1508
|
-
message: "SASLInitialResponse"
|
|
1509
|
-
};
|
|
1510
|
-
}
|
|
1511
|
-
async function continueSession(session, password, serverData, stream) {
|
|
1512
|
-
if (session.message !== "SASLInitialResponse") throw new Error("SASL: Last message was not SASLInitialResponse");
|
|
1513
|
-
if (typeof password !== "string") throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string");
|
|
1514
|
-
if (password === "") throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string");
|
|
1515
|
-
if (typeof serverData !== "string") throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: serverData must be a string");
|
|
1516
|
-
const sv = parseServerFirstMessage(serverData);
|
|
1517
|
-
if (!sv.nonce.startsWith(session.clientNonce)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce does not start with client nonce");
|
|
1518
|
-
else if (sv.nonce.length === session.clientNonce.length) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce is too short");
|
|
1519
|
-
const clientFirstMessageBare = "n=*,r=" + session.clientNonce;
|
|
1520
|
-
const serverFirstMessage = "r=" + sv.nonce + ",s=" + sv.salt + ",i=" + sv.iteration;
|
|
1521
|
-
let channelBinding = stream ? "eSws" : "biws";
|
|
1522
|
-
if (session.mechanism === "SCRAM-SHA-256-PLUS") {
|
|
1523
|
-
const peerCert = stream.getPeerCertificate().raw;
|
|
1524
|
-
let hashName = signatureAlgorithmHashFromCertificate(peerCert);
|
|
1525
|
-
if (hashName === "MD5" || hashName === "SHA-1") hashName = "SHA-256";
|
|
1526
|
-
const certHash = await crypto.hashByName(hashName, peerCert);
|
|
1527
|
-
channelBinding = Buffer.concat([Buffer.from("p=tls-server-end-point,,"), Buffer.from(certHash)]).toString("base64");
|
|
1528
|
-
}
|
|
1529
|
-
const clientFinalMessageWithoutProof = "c=" + channelBinding + ",r=" + sv.nonce;
|
|
1530
|
-
const authMessage = clientFirstMessageBare + "," + serverFirstMessage + "," + clientFinalMessageWithoutProof;
|
|
1531
|
-
const saltBytes = Buffer.from(sv.salt, "base64");
|
|
1532
|
-
const saltedPassword = await crypto.deriveKey(password, saltBytes, sv.iteration);
|
|
1533
|
-
const clientKey = await crypto.hmacSha256(saltedPassword, "Client Key");
|
|
1534
|
-
const storedKey = await crypto.sha256(clientKey);
|
|
1535
|
-
const clientSignature = await crypto.hmacSha256(storedKey, authMessage);
|
|
1536
|
-
const clientProof = xorBuffers(Buffer.from(clientKey), Buffer.from(clientSignature)).toString("base64");
|
|
1537
|
-
const serverKey = await crypto.hmacSha256(saltedPassword, "Server Key");
|
|
1538
|
-
const serverSignatureBytes = await crypto.hmacSha256(serverKey, authMessage);
|
|
1539
|
-
session.message = "SASLResponse";
|
|
1540
|
-
session.serverSignature = Buffer.from(serverSignatureBytes).toString("base64");
|
|
1541
|
-
session.response = clientFinalMessageWithoutProof + ",p=" + clientProof;
|
|
1542
|
-
}
|
|
1543
|
-
function finalizeSession(session, serverData) {
|
|
1544
|
-
if (session.message !== "SASLResponse") throw new Error("SASL: Last message was not SASLResponse");
|
|
1545
|
-
if (typeof serverData !== "string") throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: serverData must be a string");
|
|
1546
|
-
const { serverSignature } = parseServerFinalMessage(serverData);
|
|
1547
|
-
if (serverSignature !== session.serverSignature) throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature does not match");
|
|
1548
|
-
}
|
|
1549
|
-
/**
|
|
1550
|
-
* printable = %x21-2B / %x2D-7E
|
|
1551
|
-
* ;; Printable ASCII except ",".
|
|
1552
|
-
* ;; Note that any "printable" is also
|
|
1553
|
-
* ;; a valid "value".
|
|
1554
|
-
*/
|
|
1555
|
-
function isPrintableChars(text) {
|
|
1556
|
-
if (typeof text !== "string") throw new TypeError("SASL: text must be a string");
|
|
1557
|
-
return text.split("").map((_, i) => text.charCodeAt(i)).every((c) => c >= 33 && c <= 43 || c >= 45 && c <= 126);
|
|
1558
|
-
}
|
|
1559
|
-
/**
|
|
1560
|
-
* base64-char = ALPHA / DIGIT / "/" / "+"
|
|
1561
|
-
*
|
|
1562
|
-
* base64-4 = 4base64-char
|
|
1563
|
-
*
|
|
1564
|
-
* base64-3 = 3base64-char "="
|
|
1565
|
-
*
|
|
1566
|
-
* base64-2 = 2base64-char "=="
|
|
1567
|
-
*
|
|
1568
|
-
* base64 = *base64-4 [base64-3 / base64-2]
|
|
1569
|
-
*/
|
|
1570
|
-
function isBase64(text) {
|
|
1571
|
-
return /^(?:[a-zA-Z0-9+/]{4})*(?:[a-zA-Z0-9+/]{2}==|[a-zA-Z0-9+/]{3}=)?$/.test(text);
|
|
1572
|
-
}
|
|
1573
|
-
function parseAttributePairs(text) {
|
|
1574
|
-
if (typeof text !== "string") throw new TypeError("SASL: attribute pairs text must be a string");
|
|
1575
|
-
return new Map(text.split(",").map((attrValue) => {
|
|
1576
|
-
if (!/^.=/.test(attrValue)) throw new Error("SASL: Invalid attribute pair entry");
|
|
1577
|
-
return [attrValue[0], attrValue.substring(2)];
|
|
1578
|
-
}));
|
|
1579
|
-
}
|
|
1580
|
-
function parseServerFirstMessage(data) {
|
|
1581
|
-
const attrPairs = parseAttributePairs(data);
|
|
1582
|
-
const nonce = attrPairs.get("r");
|
|
1583
|
-
if (!nonce) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing");
|
|
1584
|
-
else if (!isPrintableChars(nonce)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce must only contain printable characters");
|
|
1585
|
-
const salt = attrPairs.get("s");
|
|
1586
|
-
if (!salt) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing");
|
|
1587
|
-
else if (!isBase64(salt)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: salt must be base64");
|
|
1588
|
-
const iterationText = attrPairs.get("i");
|
|
1589
|
-
if (!iterationText) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing");
|
|
1590
|
-
else if (!/^[1-9][0-9]*$/.test(iterationText)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: invalid iteration count");
|
|
1591
|
-
return {
|
|
1592
|
-
nonce,
|
|
1593
|
-
salt,
|
|
1594
|
-
iteration: parseInt(iterationText, 10)
|
|
1595
|
-
};
|
|
1596
|
-
}
|
|
1597
|
-
function parseServerFinalMessage(serverData) {
|
|
1598
|
-
const serverSignature = parseAttributePairs(serverData).get("v");
|
|
1599
|
-
if (!serverSignature) throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature is missing");
|
|
1600
|
-
else if (!isBase64(serverSignature)) throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature must be base64");
|
|
1601
|
-
return { serverSignature };
|
|
1602
|
-
}
|
|
1603
|
-
function xorBuffers(a, b) {
|
|
1604
|
-
if (!Buffer.isBuffer(a)) throw new TypeError("first argument must be a Buffer");
|
|
1605
|
-
if (!Buffer.isBuffer(b)) throw new TypeError("second argument must be a Buffer");
|
|
1606
|
-
if (a.length !== b.length) throw new Error("Buffer lengths must match");
|
|
1607
|
-
if (a.length === 0) throw new Error("Buffers cannot be empty");
|
|
1608
|
-
return Buffer.from(a.map((_, i) => a[i] ^ b[i]));
|
|
1609
|
-
}
|
|
1610
|
-
module.exports = {
|
|
1611
|
-
startSession,
|
|
1612
|
-
continueSession,
|
|
1613
|
-
finalizeSession
|
|
1614
|
-
};
|
|
1615
|
-
}));
|
|
1616
|
-
//#endregion
|
|
1617
|
-
//#region node_modules/pg/lib/type-overrides.js
|
|
1618
|
-
var require_type_overrides = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1619
|
-
const types = require_pg_types();
|
|
1620
|
-
function TypeOverrides(userTypes) {
|
|
1621
|
-
this._types = userTypes || types;
|
|
1622
|
-
this.text = {};
|
|
1623
|
-
this.binary = {};
|
|
1624
|
-
}
|
|
1625
|
-
TypeOverrides.prototype.getOverrides = function(format) {
|
|
1626
|
-
switch (format) {
|
|
1627
|
-
case "text": return this.text;
|
|
1628
|
-
case "binary": return this.binary;
|
|
1629
|
-
default: return {};
|
|
1630
|
-
}
|
|
1631
|
-
};
|
|
1632
|
-
TypeOverrides.prototype.setTypeParser = function(oid, format, parseFn) {
|
|
1633
|
-
if (typeof format === "function") {
|
|
1634
|
-
parseFn = format;
|
|
1635
|
-
format = "text";
|
|
1636
|
-
}
|
|
1637
|
-
this.getOverrides(format)[oid] = parseFn;
|
|
1638
|
-
};
|
|
1639
|
-
TypeOverrides.prototype.getTypeParser = function(oid, format) {
|
|
1640
|
-
format = format || "text";
|
|
1641
|
-
return this.getOverrides(format)[oid] || this._types.getTypeParser(oid, format);
|
|
1642
|
-
};
|
|
1643
|
-
module.exports = TypeOverrides;
|
|
1644
|
-
}));
|
|
1645
|
-
//#endregion
|
|
1646
|
-
//#region node_modules/pg-connection-string/index.js
|
|
1647
|
-
var require_pg_connection_string = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1648
|
-
function parse(str, options = {}) {
|
|
1649
|
-
if (str.charAt(0) === "/") {
|
|
1650
|
-
const config = str.split(" ");
|
|
1651
|
-
return {
|
|
1652
|
-
host: config[0],
|
|
1653
|
-
database: config[1]
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
1656
|
-
const config = {};
|
|
1657
|
-
let result;
|
|
1658
|
-
let dummyHost = false;
|
|
1659
|
-
if (/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) str = encodeURI(str).replace(/%25(\d\d)/g, "%$1");
|
|
1660
|
-
try {
|
|
1661
|
-
try {
|
|
1662
|
-
result = new URL(str, "postgres://base");
|
|
1663
|
-
} catch (e) {
|
|
1664
|
-
result = new URL(str.replace("@/", "@___DUMMY___/"), "postgres://base");
|
|
1665
|
-
dummyHost = true;
|
|
1666
|
-
}
|
|
1667
|
-
} catch (err) {
|
|
1668
|
-
err.input && (err.input = "*****REDACTED*****");
|
|
1669
|
-
throw err;
|
|
1670
|
-
}
|
|
1671
|
-
for (const entry of result.searchParams.entries()) config[entry[0]] = entry[1];
|
|
1672
|
-
config.user = config.user || decodeURIComponent(result.username);
|
|
1673
|
-
config.password = config.password || decodeURIComponent(result.password);
|
|
1674
|
-
if (result.protocol == "socket:") {
|
|
1675
|
-
config.host = decodeURI(result.pathname);
|
|
1676
|
-
config.database = result.searchParams.get("db");
|
|
1677
|
-
config.client_encoding = result.searchParams.get("encoding");
|
|
1678
|
-
return config;
|
|
1679
|
-
}
|
|
1680
|
-
const hostname = dummyHost ? "" : result.hostname;
|
|
1681
|
-
if (!config.host) config.host = decodeURIComponent(hostname);
|
|
1682
|
-
else if (hostname && /^%2f/i.test(hostname)) result.pathname = hostname + result.pathname;
|
|
1683
|
-
if (!config.port) config.port = result.port;
|
|
1684
|
-
const pathname = result.pathname.slice(1) || null;
|
|
1685
|
-
config.database = pathname ? decodeURI(pathname) : null;
|
|
1686
|
-
if (config.ssl === "true" || config.ssl === "1") config.ssl = true;
|
|
1687
|
-
if (config.ssl === "0") config.ssl = false;
|
|
1688
|
-
if (config.sslcert || config.sslkey || config.sslrootcert || config.sslmode) config.ssl = {};
|
|
1689
|
-
const fs = config.sslcert || config.sslkey || config.sslrootcert ? __require("fs") : null;
|
|
1690
|
-
if (config.sslcert) config.ssl.cert = fs.readFileSync(config.sslcert).toString();
|
|
1691
|
-
if (config.sslkey) config.ssl.key = fs.readFileSync(config.sslkey).toString();
|
|
1692
|
-
if (config.sslrootcert) config.ssl.ca = fs.readFileSync(config.sslrootcert).toString();
|
|
1693
|
-
if (options.useLibpqCompat && config.uselibpqcompat) throw new Error("Both useLibpqCompat and uselibpqcompat are set. Please use only one of them.");
|
|
1694
|
-
if (config.uselibpqcompat === "true" || options.useLibpqCompat) switch (config.sslmode) {
|
|
1695
|
-
case "disable":
|
|
1696
|
-
config.ssl = false;
|
|
1697
|
-
break;
|
|
1698
|
-
case "prefer":
|
|
1699
|
-
config.ssl.rejectUnauthorized = false;
|
|
1700
|
-
break;
|
|
1701
|
-
case "require":
|
|
1702
|
-
if (config.sslrootcert) config.ssl.checkServerIdentity = function() {};
|
|
1703
|
-
else config.ssl.rejectUnauthorized = false;
|
|
1704
|
-
break;
|
|
1705
|
-
case "verify-ca":
|
|
1706
|
-
if (!config.ssl.ca) throw new Error("SECURITY WARNING: Using sslmode=verify-ca requires specifying a CA with sslrootcert. If a public CA is used, verify-ca allows connections to a server that somebody else may have registered with the CA, making you vulnerable to Man-in-the-Middle attacks. Either specify a custom CA certificate with sslrootcert parameter or use sslmode=verify-full for proper security.");
|
|
1707
|
-
config.ssl.checkServerIdentity = function() {};
|
|
1708
|
-
break;
|
|
1709
|
-
case "verify-full": break;
|
|
1710
|
-
}
|
|
1711
|
-
else switch (config.sslmode) {
|
|
1712
|
-
case "disable":
|
|
1713
|
-
config.ssl = false;
|
|
1714
|
-
break;
|
|
1715
|
-
case "prefer":
|
|
1716
|
-
case "require":
|
|
1717
|
-
case "verify-ca":
|
|
1718
|
-
case "verify-full":
|
|
1719
|
-
if (config.sslmode !== "verify-full") deprecatedSslModeWarning(config.sslmode);
|
|
1720
|
-
break;
|
|
1721
|
-
case "no-verify":
|
|
1722
|
-
config.ssl.rejectUnauthorized = false;
|
|
1723
|
-
break;
|
|
1724
|
-
}
|
|
1725
|
-
return config;
|
|
1726
|
-
}
|
|
1727
|
-
function toConnectionOptions(sslConfig) {
|
|
1728
|
-
return Object.entries(sslConfig).reduce((c, [key, value]) => {
|
|
1729
|
-
if (value !== void 0 && value !== null) c[key] = value;
|
|
1730
|
-
return c;
|
|
1731
|
-
}, {});
|
|
1732
|
-
}
|
|
1733
|
-
function toClientConfig(config) {
|
|
1734
|
-
return Object.entries(config).reduce((c, [key, value]) => {
|
|
1735
|
-
if (key === "ssl") {
|
|
1736
|
-
const sslConfig = value;
|
|
1737
|
-
if (typeof sslConfig === "boolean") c[key] = sslConfig;
|
|
1738
|
-
if (typeof sslConfig === "object") c[key] = toConnectionOptions(sslConfig);
|
|
1739
|
-
} else if (value !== void 0 && value !== null) if (key === "port") {
|
|
1740
|
-
if (value !== "") {
|
|
1741
|
-
const v = parseInt(value, 10);
|
|
1742
|
-
if (isNaN(v)) throw new Error(`Invalid ${key}: ${value}`);
|
|
1743
|
-
c[key] = v;
|
|
1744
|
-
}
|
|
1745
|
-
} else c[key] = value;
|
|
1746
|
-
return c;
|
|
1747
|
-
}, {});
|
|
1748
|
-
}
|
|
1749
|
-
function parseIntoClientConfig(str) {
|
|
1750
|
-
return toClientConfig(parse(str));
|
|
1751
|
-
}
|
|
1752
|
-
function deprecatedSslModeWarning(sslmode) {
|
|
1753
|
-
if (!deprecatedSslModeWarning.warned && typeof process !== "undefined" && process.emitWarning) {
|
|
1754
|
-
deprecatedSslModeWarning.warned = true;
|
|
1755
|
-
process.emitWarning(`SECURITY WARNING: The SSL modes 'prefer', 'require', and 'verify-ca' are treated as aliases for 'verify-full'.
|
|
1756
|
-
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.
|
|
1757
|
-
|
|
1758
|
-
To prepare for this change:
|
|
1759
|
-
- If you want the current behavior, explicitly use 'sslmode=verify-full'
|
|
1760
|
-
- If you want libpq compatibility now, use 'uselibpqcompat=true&sslmode=${sslmode}'
|
|
1761
|
-
|
|
1762
|
-
See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode definitions.`);
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
module.exports = parse;
|
|
1766
|
-
parse.parse = parse;
|
|
1767
|
-
parse.toClientConfig = toClientConfig;
|
|
1768
|
-
parse.parseIntoClientConfig = parseIntoClientConfig;
|
|
1769
|
-
}));
|
|
1770
|
-
//#endregion
|
|
1771
|
-
//#region node_modules/pg/lib/connection-parameters.js
|
|
1772
|
-
var require_connection_parameters = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1773
|
-
const dns = __require("dns");
|
|
1774
|
-
const defaults = require_defaults();
|
|
1775
|
-
const parse = require_pg_connection_string().parse;
|
|
1776
|
-
const val = function(key, config, envVar) {
|
|
1777
|
-
if (config[key]) return config[key];
|
|
1778
|
-
if (envVar === void 0) envVar = process.env["PG" + key.toUpperCase()];
|
|
1779
|
-
else if (envVar === false) {} else envVar = process.env[envVar];
|
|
1780
|
-
return envVar || defaults[key];
|
|
1781
|
-
};
|
|
1782
|
-
const readSSLConfigFromEnvironment = function() {
|
|
1783
|
-
switch (process.env.PGSSLMODE) {
|
|
1784
|
-
case "disable": return false;
|
|
1785
|
-
case "prefer":
|
|
1786
|
-
case "require":
|
|
1787
|
-
case "verify-ca":
|
|
1788
|
-
case "verify-full": return true;
|
|
1789
|
-
case "no-verify": return { rejectUnauthorized: false };
|
|
1790
|
-
}
|
|
1791
|
-
return defaults.ssl;
|
|
1792
|
-
};
|
|
1793
|
-
const quoteParamValue = function(value) {
|
|
1794
|
-
return "'" + ("" + value).replace(/\\/g, "\\\\").replace(/'/g, "\\'") + "'";
|
|
1795
|
-
};
|
|
1796
|
-
const add = function(params, config, paramName) {
|
|
1797
|
-
const value = config[paramName];
|
|
1798
|
-
if (value !== void 0 && value !== null) params.push(paramName + "=" + quoteParamValue(value));
|
|
1799
|
-
};
|
|
1800
|
-
var ConnectionParameters = class {
|
|
1801
|
-
constructor(config) {
|
|
1802
|
-
config = typeof config === "string" ? parse(config) : config || {};
|
|
1803
|
-
if (config.connectionString) config = Object.assign({}, config, parse(config.connectionString));
|
|
1804
|
-
this.user = val("user", config);
|
|
1805
|
-
this.database = val("database", config);
|
|
1806
|
-
if (this.database === void 0) this.database = this.user;
|
|
1807
|
-
this.port = parseInt(val("port", config), 10);
|
|
1808
|
-
this.host = val("host", config);
|
|
1809
|
-
Object.defineProperty(this, "password", {
|
|
1810
|
-
configurable: true,
|
|
1811
|
-
enumerable: false,
|
|
1812
|
-
writable: true,
|
|
1813
|
-
value: val("password", config)
|
|
1814
|
-
});
|
|
1815
|
-
this.binary = val("binary", config);
|
|
1816
|
-
this.options = val("options", config);
|
|
1817
|
-
this.ssl = typeof config.ssl === "undefined" ? readSSLConfigFromEnvironment() : config.ssl;
|
|
1818
|
-
if (typeof this.ssl === "string") {
|
|
1819
|
-
if (this.ssl === "true") this.ssl = true;
|
|
1820
|
-
}
|
|
1821
|
-
if (this.ssl === "no-verify") this.ssl = { rejectUnauthorized: false };
|
|
1822
|
-
if (this.ssl && this.ssl.key) Object.defineProperty(this.ssl, "key", { enumerable: false });
|
|
1823
|
-
this.client_encoding = val("client_encoding", config);
|
|
1824
|
-
this.replication = val("replication", config);
|
|
1825
|
-
this.isDomainSocket = !(this.host || "").indexOf("/");
|
|
1826
|
-
this.application_name = val("application_name", config, "PGAPPNAME");
|
|
1827
|
-
this.fallback_application_name = val("fallback_application_name", config, false);
|
|
1828
|
-
this.statement_timeout = val("statement_timeout", config, false);
|
|
1829
|
-
this.lock_timeout = val("lock_timeout", config, false);
|
|
1830
|
-
this.idle_in_transaction_session_timeout = val("idle_in_transaction_session_timeout", config, false);
|
|
1831
|
-
this.query_timeout = val("query_timeout", config, false);
|
|
1832
|
-
if (config.connectionTimeoutMillis === void 0) this.connect_timeout = process.env.PGCONNECT_TIMEOUT || 0;
|
|
1833
|
-
else this.connect_timeout = Math.floor(config.connectionTimeoutMillis / 1e3);
|
|
1834
|
-
if (config.keepAlive === false) this.keepalives = 0;
|
|
1835
|
-
else if (config.keepAlive === true) this.keepalives = 1;
|
|
1836
|
-
if (typeof config.keepAliveInitialDelayMillis === "number") this.keepalives_idle = Math.floor(config.keepAliveInitialDelayMillis / 1e3);
|
|
1837
|
-
}
|
|
1838
|
-
getLibpqConnectionString(cb) {
|
|
1839
|
-
const params = [];
|
|
1840
|
-
add(params, this, "user");
|
|
1841
|
-
add(params, this, "password");
|
|
1842
|
-
add(params, this, "port");
|
|
1843
|
-
add(params, this, "application_name");
|
|
1844
|
-
add(params, this, "fallback_application_name");
|
|
1845
|
-
add(params, this, "connect_timeout");
|
|
1846
|
-
add(params, this, "options");
|
|
1847
|
-
const ssl = typeof this.ssl === "object" ? this.ssl : this.ssl ? { sslmode: this.ssl } : {};
|
|
1848
|
-
add(params, ssl, "sslmode");
|
|
1849
|
-
add(params, ssl, "sslca");
|
|
1850
|
-
add(params, ssl, "sslkey");
|
|
1851
|
-
add(params, ssl, "sslcert");
|
|
1852
|
-
add(params, ssl, "sslrootcert");
|
|
1853
|
-
if (this.database) params.push("dbname=" + quoteParamValue(this.database));
|
|
1854
|
-
if (this.replication) params.push("replication=" + quoteParamValue(this.replication));
|
|
1855
|
-
if (this.host) params.push("host=" + quoteParamValue(this.host));
|
|
1856
|
-
if (this.isDomainSocket) return cb(null, params.join(" "));
|
|
1857
|
-
if (this.client_encoding) params.push("client_encoding=" + quoteParamValue(this.client_encoding));
|
|
1858
|
-
dns.lookup(this.host, function(err, address) {
|
|
1859
|
-
if (err) return cb(err, null);
|
|
1860
|
-
params.push("hostaddr=" + quoteParamValue(address));
|
|
1861
|
-
return cb(null, params.join(" "));
|
|
1862
|
-
});
|
|
1863
|
-
}
|
|
1864
|
-
};
|
|
1865
|
-
module.exports = ConnectionParameters;
|
|
1866
|
-
}));
|
|
1867
|
-
//#endregion
|
|
1868
|
-
//#region node_modules/pg/lib/result.js
|
|
1869
|
-
var require_result = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1870
|
-
const types = require_pg_types();
|
|
1871
|
-
const matchRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/;
|
|
1872
|
-
var Result = class {
|
|
1873
|
-
constructor(rowMode, types) {
|
|
1874
|
-
this.command = null;
|
|
1875
|
-
this.rowCount = null;
|
|
1876
|
-
this.oid = null;
|
|
1877
|
-
this.rows = [];
|
|
1878
|
-
this.fields = [];
|
|
1879
|
-
this._parsers = void 0;
|
|
1880
|
-
this._types = types;
|
|
1881
|
-
this.RowCtor = null;
|
|
1882
|
-
this.rowAsArray = rowMode === "array";
|
|
1883
|
-
if (this.rowAsArray) this.parseRow = this._parseRowAsArray;
|
|
1884
|
-
this._prebuiltEmptyResultObject = null;
|
|
1885
|
-
}
|
|
1886
|
-
addCommandComplete(msg) {
|
|
1887
|
-
let match;
|
|
1888
|
-
if (msg.text) match = matchRegexp.exec(msg.text);
|
|
1889
|
-
else match = matchRegexp.exec(msg.command);
|
|
1890
|
-
if (match) {
|
|
1891
|
-
this.command = match[1];
|
|
1892
|
-
if (match[3]) {
|
|
1893
|
-
this.oid = parseInt(match[2], 10);
|
|
1894
|
-
this.rowCount = parseInt(match[3], 10);
|
|
1895
|
-
} else if (match[2]) this.rowCount = parseInt(match[2], 10);
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
_parseRowAsArray(rowData) {
|
|
1899
|
-
const row = new Array(rowData.length);
|
|
1900
|
-
for (let i = 0, len = rowData.length; i < len; i++) {
|
|
1901
|
-
const rawValue = rowData[i];
|
|
1902
|
-
if (rawValue !== null) row[i] = this._parsers[i](rawValue);
|
|
1903
|
-
else row[i] = null;
|
|
1904
|
-
}
|
|
1905
|
-
return row;
|
|
1906
|
-
}
|
|
1907
|
-
parseRow(rowData) {
|
|
1908
|
-
const row = { ...this._prebuiltEmptyResultObject };
|
|
1909
|
-
for (let i = 0, len = rowData.length; i < len; i++) {
|
|
1910
|
-
const rawValue = rowData[i];
|
|
1911
|
-
const field = this.fields[i].name;
|
|
1912
|
-
if (rawValue !== null) {
|
|
1913
|
-
const v = this.fields[i].format === "binary" ? Buffer.from(rawValue) : rawValue;
|
|
1914
|
-
row[field] = this._parsers[i](v);
|
|
1915
|
-
} else row[field] = null;
|
|
1916
|
-
}
|
|
1917
|
-
return row;
|
|
1918
|
-
}
|
|
1919
|
-
addRow(row) {
|
|
1920
|
-
this.rows.push(row);
|
|
1921
|
-
}
|
|
1922
|
-
addFields(fieldDescriptions) {
|
|
1923
|
-
this.fields = fieldDescriptions;
|
|
1924
|
-
if (this.fields.length) this._parsers = new Array(fieldDescriptions.length);
|
|
1925
|
-
const row = {};
|
|
1926
|
-
for (let i = 0; i < fieldDescriptions.length; i++) {
|
|
1927
|
-
const desc = fieldDescriptions[i];
|
|
1928
|
-
row[desc.name] = null;
|
|
1929
|
-
if (this._types) this._parsers[i] = this._types.getTypeParser(desc.dataTypeID, desc.format || "text");
|
|
1930
|
-
else this._parsers[i] = types.getTypeParser(desc.dataTypeID, desc.format || "text");
|
|
1931
|
-
}
|
|
1932
|
-
this._prebuiltEmptyResultObject = { ...row };
|
|
1933
|
-
}
|
|
1934
|
-
};
|
|
1935
|
-
module.exports = Result;
|
|
1936
|
-
}));
|
|
1937
|
-
//#endregion
|
|
1938
|
-
//#region node_modules/pg/lib/query.js
|
|
1939
|
-
var require_query$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1940
|
-
const { EventEmitter: EventEmitter$5 } = __require("events");
|
|
1941
|
-
const Result = require_result();
|
|
1942
|
-
const utils = require_utils$1();
|
|
1943
|
-
var Query = class extends EventEmitter$5 {
|
|
1944
|
-
constructor(config, values, callback) {
|
|
1945
|
-
super();
|
|
1946
|
-
config = utils.normalizeQueryConfig(config, values, callback);
|
|
1947
|
-
this.text = config.text;
|
|
1948
|
-
this.values = config.values;
|
|
1949
|
-
this.rows = config.rows;
|
|
1950
|
-
this.types = config.types;
|
|
1951
|
-
this.name = config.name;
|
|
1952
|
-
this.queryMode = config.queryMode;
|
|
1953
|
-
this.binary = config.binary;
|
|
1954
|
-
this.portal = config.portal || "";
|
|
1955
|
-
this.callback = config.callback;
|
|
1956
|
-
this._rowMode = config.rowMode;
|
|
1957
|
-
if (process.domain && config.callback) this.callback = process.domain.bind(config.callback);
|
|
1958
|
-
this._result = new Result(this._rowMode, this.types);
|
|
1959
|
-
this._results = this._result;
|
|
1960
|
-
this._canceledDueToError = false;
|
|
1961
|
-
}
|
|
1962
|
-
requiresPreparation() {
|
|
1963
|
-
if (this.queryMode === "extended") return true;
|
|
1964
|
-
if (this.name) return true;
|
|
1965
|
-
if (this.rows) return true;
|
|
1966
|
-
if (!this.text) return false;
|
|
1967
|
-
if (!this.values) return false;
|
|
1968
|
-
return this.values.length > 0;
|
|
1969
|
-
}
|
|
1970
|
-
_checkForMultirow() {
|
|
1971
|
-
if (this._result.command) {
|
|
1972
|
-
if (!Array.isArray(this._results)) this._results = [this._result];
|
|
1973
|
-
this._result = new Result(this._rowMode, this._result._types);
|
|
1974
|
-
this._results.push(this._result);
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
handleRowDescription(msg) {
|
|
1978
|
-
this._checkForMultirow();
|
|
1979
|
-
this._result.addFields(msg.fields);
|
|
1980
|
-
this._accumulateRows = this.callback || !this.listeners("row").length;
|
|
1981
|
-
}
|
|
1982
|
-
handleDataRow(msg) {
|
|
1983
|
-
let row;
|
|
1984
|
-
if (this._canceledDueToError) return;
|
|
1985
|
-
try {
|
|
1986
|
-
row = this._result.parseRow(msg.fields);
|
|
1987
|
-
} catch (err) {
|
|
1988
|
-
this._canceledDueToError = err;
|
|
1989
|
-
return;
|
|
1990
|
-
}
|
|
1991
|
-
this.emit("row", row, this._result);
|
|
1992
|
-
if (this._accumulateRows) this._result.addRow(row);
|
|
1993
|
-
}
|
|
1994
|
-
handleCommandComplete(msg, connection) {
|
|
1995
|
-
this._checkForMultirow();
|
|
1996
|
-
this._result.addCommandComplete(msg);
|
|
1997
|
-
if (this.rows) connection.sync();
|
|
1998
|
-
}
|
|
1999
|
-
handleEmptyQuery(connection) {
|
|
2000
|
-
if (this.rows) connection.sync();
|
|
2001
|
-
}
|
|
2002
|
-
handleError(err, connection) {
|
|
2003
|
-
if (this._canceledDueToError) {
|
|
2004
|
-
err = this._canceledDueToError;
|
|
2005
|
-
this._canceledDueToError = false;
|
|
2006
|
-
}
|
|
2007
|
-
if (this.callback) return this.callback(err);
|
|
2008
|
-
this.emit("error", err);
|
|
2009
|
-
}
|
|
2010
|
-
handleReadyForQuery(con) {
|
|
2011
|
-
if (this._canceledDueToError) return this.handleError(this._canceledDueToError, con);
|
|
2012
|
-
if (this.callback) try {
|
|
2013
|
-
this.callback(null, this._results);
|
|
2014
|
-
} catch (err) {
|
|
2015
|
-
process.nextTick(() => {
|
|
2016
|
-
throw err;
|
|
2017
|
-
});
|
|
2018
|
-
}
|
|
2019
|
-
this.emit("end", this._results);
|
|
2020
|
-
}
|
|
2021
|
-
submit(connection) {
|
|
2022
|
-
if (typeof this.text !== "string" && typeof this.name !== "string") return /* @__PURE__ */ new Error("A query must have either text or a name. Supplying neither is unsupported.");
|
|
2023
|
-
const previous = connection.parsedStatements[this.name];
|
|
2024
|
-
if (this.text && previous && this.text !== previous) return /* @__PURE__ */ new Error(`Prepared statements must be unique - '${this.name}' was used for a different statement`);
|
|
2025
|
-
if (this.values && !Array.isArray(this.values)) return /* @__PURE__ */ new Error("Query values must be an array");
|
|
2026
|
-
if (this.requiresPreparation()) {
|
|
2027
|
-
connection.stream.cork && connection.stream.cork();
|
|
2028
|
-
try {
|
|
2029
|
-
this.prepare(connection);
|
|
2030
|
-
} finally {
|
|
2031
|
-
connection.stream.uncork && connection.stream.uncork();
|
|
2032
|
-
}
|
|
2033
|
-
} else connection.query(this.text);
|
|
2034
|
-
return null;
|
|
2035
|
-
}
|
|
2036
|
-
hasBeenParsed(connection) {
|
|
2037
|
-
return this.name && connection.parsedStatements[this.name];
|
|
2038
|
-
}
|
|
2039
|
-
handlePortalSuspended(connection) {
|
|
2040
|
-
this._getRows(connection, this.rows);
|
|
2041
|
-
}
|
|
2042
|
-
_getRows(connection, rows) {
|
|
2043
|
-
connection.execute({
|
|
2044
|
-
portal: this.portal,
|
|
2045
|
-
rows
|
|
2046
|
-
});
|
|
2047
|
-
if (!rows) connection.sync();
|
|
2048
|
-
else connection.flush();
|
|
2049
|
-
}
|
|
2050
|
-
prepare(connection) {
|
|
2051
|
-
if (!this.hasBeenParsed(connection)) connection.parse({
|
|
2052
|
-
text: this.text,
|
|
2053
|
-
name: this.name,
|
|
2054
|
-
types: this.types
|
|
2055
|
-
});
|
|
2056
|
-
try {
|
|
2057
|
-
connection.bind({
|
|
2058
|
-
portal: this.portal,
|
|
2059
|
-
statement: this.name,
|
|
2060
|
-
values: this.values,
|
|
2061
|
-
binary: this.binary,
|
|
2062
|
-
valueMapper: utils.prepareValue
|
|
2063
|
-
});
|
|
2064
|
-
} catch (err) {
|
|
2065
|
-
this.handleError(err, connection);
|
|
2066
|
-
return;
|
|
2067
|
-
}
|
|
2068
|
-
connection.describe({
|
|
2069
|
-
type: "P",
|
|
2070
|
-
name: this.portal || ""
|
|
2071
|
-
});
|
|
2072
|
-
this._getRows(connection, this.rows);
|
|
2073
|
-
}
|
|
2074
|
-
handleCopyInResponse(connection) {
|
|
2075
|
-
connection.sendCopyFail("No source stream defined");
|
|
2076
|
-
}
|
|
2077
|
-
handleCopyData(msg, connection) {}
|
|
2078
|
-
};
|
|
2079
|
-
module.exports = Query;
|
|
2080
|
-
}));
|
|
2081
|
-
//#endregion
|
|
2082
|
-
//#region node_modules/pg-protocol/dist/messages.js
|
|
2083
|
-
var require_messages = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2084
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2085
|
-
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;
|
|
2086
|
-
exports.parseComplete = {
|
|
2087
|
-
name: "parseComplete",
|
|
2088
|
-
length: 5
|
|
2089
|
-
};
|
|
2090
|
-
exports.bindComplete = {
|
|
2091
|
-
name: "bindComplete",
|
|
2092
|
-
length: 5
|
|
2093
|
-
};
|
|
2094
|
-
exports.closeComplete = {
|
|
2095
|
-
name: "closeComplete",
|
|
2096
|
-
length: 5
|
|
2097
|
-
};
|
|
2098
|
-
exports.noData = {
|
|
2099
|
-
name: "noData",
|
|
2100
|
-
length: 5
|
|
2101
|
-
};
|
|
2102
|
-
exports.portalSuspended = {
|
|
2103
|
-
name: "portalSuspended",
|
|
2104
|
-
length: 5
|
|
2105
|
-
};
|
|
2106
|
-
exports.replicationStart = {
|
|
2107
|
-
name: "replicationStart",
|
|
2108
|
-
length: 4
|
|
2109
|
-
};
|
|
2110
|
-
exports.emptyQuery = {
|
|
2111
|
-
name: "emptyQuery",
|
|
2112
|
-
length: 4
|
|
2113
|
-
};
|
|
2114
|
-
exports.copyDone = {
|
|
2115
|
-
name: "copyDone",
|
|
2116
|
-
length: 4
|
|
2117
|
-
};
|
|
2118
|
-
var DatabaseError = class extends Error {
|
|
2119
|
-
constructor(message, length, name) {
|
|
2120
|
-
super(message);
|
|
2121
|
-
this.length = length;
|
|
2122
|
-
this.name = name;
|
|
2123
|
-
}
|
|
2124
|
-
};
|
|
2125
|
-
exports.DatabaseError = DatabaseError;
|
|
2126
|
-
var CopyDataMessage = class {
|
|
2127
|
-
constructor(length, chunk) {
|
|
2128
|
-
this.length = length;
|
|
2129
|
-
this.chunk = chunk;
|
|
2130
|
-
this.name = "copyData";
|
|
2131
|
-
}
|
|
2132
|
-
};
|
|
2133
|
-
exports.CopyDataMessage = CopyDataMessage;
|
|
2134
|
-
var CopyResponse = class {
|
|
2135
|
-
constructor(length, name, binary, columnCount) {
|
|
2136
|
-
this.length = length;
|
|
2137
|
-
this.name = name;
|
|
2138
|
-
this.binary = binary;
|
|
2139
|
-
this.columnTypes = new Array(columnCount);
|
|
2140
|
-
}
|
|
2141
|
-
};
|
|
2142
|
-
exports.CopyResponse = CopyResponse;
|
|
2143
|
-
var Field = class {
|
|
2144
|
-
constructor(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, format) {
|
|
2145
|
-
this.name = name;
|
|
2146
|
-
this.tableID = tableID;
|
|
2147
|
-
this.columnID = columnID;
|
|
2148
|
-
this.dataTypeID = dataTypeID;
|
|
2149
|
-
this.dataTypeSize = dataTypeSize;
|
|
2150
|
-
this.dataTypeModifier = dataTypeModifier;
|
|
2151
|
-
this.format = format;
|
|
2152
|
-
}
|
|
2153
|
-
};
|
|
2154
|
-
exports.Field = Field;
|
|
2155
|
-
var RowDescriptionMessage = class {
|
|
2156
|
-
constructor(length, fieldCount) {
|
|
2157
|
-
this.length = length;
|
|
2158
|
-
this.fieldCount = fieldCount;
|
|
2159
|
-
this.name = "rowDescription";
|
|
2160
|
-
this.fields = new Array(this.fieldCount);
|
|
2161
|
-
}
|
|
2162
|
-
};
|
|
2163
|
-
exports.RowDescriptionMessage = RowDescriptionMessage;
|
|
2164
|
-
var ParameterDescriptionMessage = class {
|
|
2165
|
-
constructor(length, parameterCount) {
|
|
2166
|
-
this.length = length;
|
|
2167
|
-
this.parameterCount = parameterCount;
|
|
2168
|
-
this.name = "parameterDescription";
|
|
2169
|
-
this.dataTypeIDs = new Array(this.parameterCount);
|
|
2170
|
-
}
|
|
2171
|
-
};
|
|
2172
|
-
exports.ParameterDescriptionMessage = ParameterDescriptionMessage;
|
|
2173
|
-
var ParameterStatusMessage = class {
|
|
2174
|
-
constructor(length, parameterName, parameterValue) {
|
|
2175
|
-
this.length = length;
|
|
2176
|
-
this.parameterName = parameterName;
|
|
2177
|
-
this.parameterValue = parameterValue;
|
|
2178
|
-
this.name = "parameterStatus";
|
|
2179
|
-
}
|
|
2180
|
-
};
|
|
2181
|
-
exports.ParameterStatusMessage = ParameterStatusMessage;
|
|
2182
|
-
var AuthenticationMD5Password = class {
|
|
2183
|
-
constructor(length, salt) {
|
|
2184
|
-
this.length = length;
|
|
2185
|
-
this.salt = salt;
|
|
2186
|
-
this.name = "authenticationMD5Password";
|
|
2187
|
-
}
|
|
2188
|
-
};
|
|
2189
|
-
exports.AuthenticationMD5Password = AuthenticationMD5Password;
|
|
2190
|
-
var BackendKeyDataMessage = class {
|
|
2191
|
-
constructor(length, processID, secretKey) {
|
|
2192
|
-
this.length = length;
|
|
2193
|
-
this.processID = processID;
|
|
2194
|
-
this.secretKey = secretKey;
|
|
2195
|
-
this.name = "backendKeyData";
|
|
2196
|
-
}
|
|
2197
|
-
};
|
|
2198
|
-
exports.BackendKeyDataMessage = BackendKeyDataMessage;
|
|
2199
|
-
var NotificationResponseMessage = class {
|
|
2200
|
-
constructor(length, processId, channel, payload) {
|
|
2201
|
-
this.length = length;
|
|
2202
|
-
this.processId = processId;
|
|
2203
|
-
this.channel = channel;
|
|
2204
|
-
this.payload = payload;
|
|
2205
|
-
this.name = "notification";
|
|
2206
|
-
}
|
|
2207
|
-
};
|
|
2208
|
-
exports.NotificationResponseMessage = NotificationResponseMessage;
|
|
2209
|
-
var ReadyForQueryMessage = class {
|
|
2210
|
-
constructor(length, status) {
|
|
2211
|
-
this.length = length;
|
|
2212
|
-
this.status = status;
|
|
2213
|
-
this.name = "readyForQuery";
|
|
2214
|
-
}
|
|
2215
|
-
};
|
|
2216
|
-
exports.ReadyForQueryMessage = ReadyForQueryMessage;
|
|
2217
|
-
var CommandCompleteMessage = class {
|
|
2218
|
-
constructor(length, text) {
|
|
2219
|
-
this.length = length;
|
|
2220
|
-
this.text = text;
|
|
2221
|
-
this.name = "commandComplete";
|
|
2222
|
-
}
|
|
2223
|
-
};
|
|
2224
|
-
exports.CommandCompleteMessage = CommandCompleteMessage;
|
|
2225
|
-
var DataRowMessage = class {
|
|
2226
|
-
constructor(length, fields) {
|
|
2227
|
-
this.length = length;
|
|
2228
|
-
this.fields = fields;
|
|
2229
|
-
this.name = "dataRow";
|
|
2230
|
-
this.fieldCount = fields.length;
|
|
2231
|
-
}
|
|
2232
|
-
};
|
|
2233
|
-
exports.DataRowMessage = DataRowMessage;
|
|
2234
|
-
var NoticeMessage = class {
|
|
2235
|
-
constructor(length, message) {
|
|
2236
|
-
this.length = length;
|
|
2237
|
-
this.message = message;
|
|
2238
|
-
this.name = "notice";
|
|
2239
|
-
}
|
|
2240
|
-
};
|
|
2241
|
-
exports.NoticeMessage = NoticeMessage;
|
|
2242
|
-
}));
|
|
2243
|
-
//#endregion
|
|
2244
|
-
//#region node_modules/pg-protocol/dist/buffer-writer.js
|
|
2245
|
-
var require_buffer_writer = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2246
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2247
|
-
exports.Writer = void 0;
|
|
2248
|
-
var Writer = class {
|
|
2249
|
-
constructor(size = 256) {
|
|
2250
|
-
this.size = size;
|
|
2251
|
-
this.offset = 5;
|
|
2252
|
-
this.headerPosition = 0;
|
|
2253
|
-
this.buffer = Buffer.allocUnsafe(size);
|
|
2254
|
-
}
|
|
2255
|
-
ensure(size) {
|
|
2256
|
-
if (this.buffer.length - this.offset < size) {
|
|
2257
|
-
const oldBuffer = this.buffer;
|
|
2258
|
-
const newSize = oldBuffer.length + (oldBuffer.length >> 1) + size;
|
|
2259
|
-
this.buffer = Buffer.allocUnsafe(newSize);
|
|
2260
|
-
oldBuffer.copy(this.buffer);
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
addInt32(num) {
|
|
2264
|
-
this.ensure(4);
|
|
2265
|
-
this.buffer[this.offset++] = num >>> 24 & 255;
|
|
2266
|
-
this.buffer[this.offset++] = num >>> 16 & 255;
|
|
2267
|
-
this.buffer[this.offset++] = num >>> 8 & 255;
|
|
2268
|
-
this.buffer[this.offset++] = num >>> 0 & 255;
|
|
2269
|
-
return this;
|
|
2270
|
-
}
|
|
2271
|
-
addInt16(num) {
|
|
2272
|
-
this.ensure(2);
|
|
2273
|
-
this.buffer[this.offset++] = num >>> 8 & 255;
|
|
2274
|
-
this.buffer[this.offset++] = num >>> 0 & 255;
|
|
2275
|
-
return this;
|
|
2276
|
-
}
|
|
2277
|
-
addCString(string) {
|
|
2278
|
-
if (!string) this.ensure(1);
|
|
2279
|
-
else {
|
|
2280
|
-
const len = Buffer.byteLength(string);
|
|
2281
|
-
this.ensure(len + 1);
|
|
2282
|
-
this.buffer.write(string, this.offset, "utf-8");
|
|
2283
|
-
this.offset += len;
|
|
2284
|
-
}
|
|
2285
|
-
this.buffer[this.offset++] = 0;
|
|
2286
|
-
return this;
|
|
2287
|
-
}
|
|
2288
|
-
addString(string = "") {
|
|
2289
|
-
const len = Buffer.byteLength(string);
|
|
2290
|
-
this.ensure(len);
|
|
2291
|
-
this.buffer.write(string, this.offset);
|
|
2292
|
-
this.offset += len;
|
|
2293
|
-
return this;
|
|
2294
|
-
}
|
|
2295
|
-
add(otherBuffer) {
|
|
2296
|
-
this.ensure(otherBuffer.length);
|
|
2297
|
-
otherBuffer.copy(this.buffer, this.offset);
|
|
2298
|
-
this.offset += otherBuffer.length;
|
|
2299
|
-
return this;
|
|
2300
|
-
}
|
|
2301
|
-
join(code) {
|
|
2302
|
-
if (code) {
|
|
2303
|
-
this.buffer[this.headerPosition] = code;
|
|
2304
|
-
const length = this.offset - (this.headerPosition + 1);
|
|
2305
|
-
this.buffer.writeInt32BE(length, this.headerPosition + 1);
|
|
2306
|
-
}
|
|
2307
|
-
return this.buffer.slice(code ? 0 : 5, this.offset);
|
|
2308
|
-
}
|
|
2309
|
-
flush(code) {
|
|
2310
|
-
const result = this.join(code);
|
|
2311
|
-
this.offset = 5;
|
|
2312
|
-
this.headerPosition = 0;
|
|
2313
|
-
this.buffer = Buffer.allocUnsafe(this.size);
|
|
2314
|
-
return result;
|
|
2315
|
-
}
|
|
2316
|
-
};
|
|
2317
|
-
exports.Writer = Writer;
|
|
2318
|
-
}));
|
|
2319
|
-
//#endregion
|
|
2320
|
-
//#region node_modules/pg-protocol/dist/serializer.js
|
|
2321
|
-
var require_serializer = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2322
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2323
|
-
exports.serialize = void 0;
|
|
2324
|
-
const buffer_writer_1 = require_buffer_writer();
|
|
2325
|
-
const writer = new buffer_writer_1.Writer();
|
|
2326
|
-
const startup = (opts) => {
|
|
2327
|
-
writer.addInt16(3).addInt16(0);
|
|
2328
|
-
for (const key of Object.keys(opts)) writer.addCString(key).addCString(opts[key]);
|
|
2329
|
-
writer.addCString("client_encoding").addCString("UTF8");
|
|
2330
|
-
const bodyBuffer = writer.addCString("").flush();
|
|
2331
|
-
const length = bodyBuffer.length + 4;
|
|
2332
|
-
return new buffer_writer_1.Writer().addInt32(length).add(bodyBuffer).flush();
|
|
2333
|
-
};
|
|
2334
|
-
const requestSsl = () => {
|
|
2335
|
-
const response = Buffer.allocUnsafe(8);
|
|
2336
|
-
response.writeInt32BE(8, 0);
|
|
2337
|
-
response.writeInt32BE(80877103, 4);
|
|
2338
|
-
return response;
|
|
2339
|
-
};
|
|
2340
|
-
const password = (password) => {
|
|
2341
|
-
return writer.addCString(password).flush(112);
|
|
2342
|
-
};
|
|
2343
|
-
const sendSASLInitialResponseMessage = function(mechanism, initialResponse) {
|
|
2344
|
-
writer.addCString(mechanism).addInt32(Buffer.byteLength(initialResponse)).addString(initialResponse);
|
|
2345
|
-
return writer.flush(112);
|
|
2346
|
-
};
|
|
2347
|
-
const sendSCRAMClientFinalMessage = function(additionalData) {
|
|
2348
|
-
return writer.addString(additionalData).flush(112);
|
|
2349
|
-
};
|
|
2350
|
-
const query = (text) => {
|
|
2351
|
-
return writer.addCString(text).flush(81);
|
|
2352
|
-
};
|
|
2353
|
-
const emptyArray = [];
|
|
2354
|
-
const parse = (query) => {
|
|
2355
|
-
const name = query.name || "";
|
|
2356
|
-
if (name.length > 63) {
|
|
2357
|
-
console.error("Warning! Postgres only supports 63 characters for query names.");
|
|
2358
|
-
console.error("You supplied %s (%s)", name, name.length);
|
|
2359
|
-
console.error("This can cause conflicts and silent errors executing queries");
|
|
2360
|
-
}
|
|
2361
|
-
const types = query.types || emptyArray;
|
|
2362
|
-
const len = types.length;
|
|
2363
|
-
const buffer = writer.addCString(name).addCString(query.text).addInt16(len);
|
|
2364
|
-
for (let i = 0; i < len; i++) buffer.addInt32(types[i]);
|
|
2365
|
-
return writer.flush(80);
|
|
2366
|
-
};
|
|
2367
|
-
const paramWriter = new buffer_writer_1.Writer();
|
|
2368
|
-
const writeValues = function(values, valueMapper) {
|
|
2369
|
-
for (let i = 0; i < values.length; i++) {
|
|
2370
|
-
const mappedVal = valueMapper ? valueMapper(values[i], i) : values[i];
|
|
2371
|
-
if (mappedVal == null) {
|
|
2372
|
-
writer.addInt16(0);
|
|
2373
|
-
paramWriter.addInt32(-1);
|
|
2374
|
-
} else if (mappedVal instanceof Buffer) {
|
|
2375
|
-
writer.addInt16(1);
|
|
2376
|
-
paramWriter.addInt32(mappedVal.length);
|
|
2377
|
-
paramWriter.add(mappedVal);
|
|
2378
|
-
} else {
|
|
2379
|
-
writer.addInt16(0);
|
|
2380
|
-
paramWriter.addInt32(Buffer.byteLength(mappedVal));
|
|
2381
|
-
paramWriter.addString(mappedVal);
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
};
|
|
2385
|
-
const bind = (config = {}) => {
|
|
2386
|
-
const portal = config.portal || "";
|
|
2387
|
-
const statement = config.statement || "";
|
|
2388
|
-
const binary = config.binary || false;
|
|
2389
|
-
const values = config.values || emptyArray;
|
|
2390
|
-
const len = values.length;
|
|
2391
|
-
writer.addCString(portal).addCString(statement);
|
|
2392
|
-
writer.addInt16(len);
|
|
2393
|
-
writeValues(values, config.valueMapper);
|
|
2394
|
-
writer.addInt16(len);
|
|
2395
|
-
writer.add(paramWriter.flush());
|
|
2396
|
-
writer.addInt16(1);
|
|
2397
|
-
writer.addInt16(binary ? 1 : 0);
|
|
2398
|
-
return writer.flush(66);
|
|
2399
|
-
};
|
|
2400
|
-
const emptyExecute = Buffer.from([
|
|
2401
|
-
69,
|
|
2402
|
-
0,
|
|
2403
|
-
0,
|
|
2404
|
-
0,
|
|
2405
|
-
9,
|
|
2406
|
-
0,
|
|
2407
|
-
0,
|
|
2408
|
-
0,
|
|
2409
|
-
0,
|
|
2410
|
-
0
|
|
2411
|
-
]);
|
|
2412
|
-
const execute = (config) => {
|
|
2413
|
-
if (!config || !config.portal && !config.rows) return emptyExecute;
|
|
2414
|
-
const portal = config.portal || "";
|
|
2415
|
-
const rows = config.rows || 0;
|
|
2416
|
-
const portalLength = Buffer.byteLength(portal);
|
|
2417
|
-
const len = 4 + portalLength + 1 + 4;
|
|
2418
|
-
const buff = Buffer.allocUnsafe(1 + len);
|
|
2419
|
-
buff[0] = 69;
|
|
2420
|
-
buff.writeInt32BE(len, 1);
|
|
2421
|
-
buff.write(portal, 5, "utf-8");
|
|
2422
|
-
buff[portalLength + 5] = 0;
|
|
2423
|
-
buff.writeUInt32BE(rows, buff.length - 4);
|
|
2424
|
-
return buff;
|
|
2425
|
-
};
|
|
2426
|
-
const cancel = (processID, secretKey) => {
|
|
2427
|
-
const buffer = Buffer.allocUnsafe(16);
|
|
2428
|
-
buffer.writeInt32BE(16, 0);
|
|
2429
|
-
buffer.writeInt16BE(1234, 4);
|
|
2430
|
-
buffer.writeInt16BE(5678, 6);
|
|
2431
|
-
buffer.writeInt32BE(processID, 8);
|
|
2432
|
-
buffer.writeInt32BE(secretKey, 12);
|
|
2433
|
-
return buffer;
|
|
2434
|
-
};
|
|
2435
|
-
const cstringMessage = (code, string) => {
|
|
2436
|
-
const len = 4 + Buffer.byteLength(string) + 1;
|
|
2437
|
-
const buffer = Buffer.allocUnsafe(1 + len);
|
|
2438
|
-
buffer[0] = code;
|
|
2439
|
-
buffer.writeInt32BE(len, 1);
|
|
2440
|
-
buffer.write(string, 5, "utf-8");
|
|
2441
|
-
buffer[len] = 0;
|
|
2442
|
-
return buffer;
|
|
2443
|
-
};
|
|
2444
|
-
const emptyDescribePortal = writer.addCString("P").flush(68);
|
|
2445
|
-
const emptyDescribeStatement = writer.addCString("S").flush(68);
|
|
2446
|
-
const describe = (msg) => {
|
|
2447
|
-
return msg.name ? cstringMessage(68, `${msg.type}${msg.name || ""}`) : msg.type === "P" ? emptyDescribePortal : emptyDescribeStatement;
|
|
2448
|
-
};
|
|
2449
|
-
const close = (msg) => {
|
|
2450
|
-
return cstringMessage(67, `${msg.type}${msg.name || ""}`);
|
|
2451
|
-
};
|
|
2452
|
-
const copyData = (chunk) => {
|
|
2453
|
-
return writer.add(chunk).flush(100);
|
|
2454
|
-
};
|
|
2455
|
-
const copyFail = (message) => {
|
|
2456
|
-
return cstringMessage(102, message);
|
|
2457
|
-
};
|
|
2458
|
-
const codeOnlyBuffer = (code) => Buffer.from([
|
|
2459
|
-
code,
|
|
2460
|
-
0,
|
|
2461
|
-
0,
|
|
2462
|
-
0,
|
|
2463
|
-
4
|
|
2464
|
-
]);
|
|
2465
|
-
const flushBuffer = codeOnlyBuffer(72);
|
|
2466
|
-
const syncBuffer = codeOnlyBuffer(83);
|
|
2467
|
-
const endBuffer = codeOnlyBuffer(88);
|
|
2468
|
-
const copyDoneBuffer = codeOnlyBuffer(99);
|
|
2469
|
-
exports.serialize = {
|
|
2470
|
-
startup,
|
|
2471
|
-
password,
|
|
2472
|
-
requestSsl,
|
|
2473
|
-
sendSASLInitialResponseMessage,
|
|
2474
|
-
sendSCRAMClientFinalMessage,
|
|
2475
|
-
query,
|
|
2476
|
-
parse,
|
|
2477
|
-
bind,
|
|
2478
|
-
execute,
|
|
2479
|
-
describe,
|
|
2480
|
-
close,
|
|
2481
|
-
flush: () => flushBuffer,
|
|
2482
|
-
sync: () => syncBuffer,
|
|
2483
|
-
end: () => endBuffer,
|
|
2484
|
-
copyData,
|
|
2485
|
-
copyDone: () => copyDoneBuffer,
|
|
2486
|
-
copyFail,
|
|
2487
|
-
cancel
|
|
2488
|
-
};
|
|
2489
|
-
}));
|
|
2490
|
-
//#endregion
|
|
2491
|
-
//#region node_modules/pg-protocol/dist/buffer-reader.js
|
|
2492
|
-
var require_buffer_reader = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2493
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2494
|
-
exports.BufferReader = void 0;
|
|
2495
|
-
var BufferReader = class {
|
|
2496
|
-
constructor(offset = 0) {
|
|
2497
|
-
this.offset = offset;
|
|
2498
|
-
this.buffer = Buffer.allocUnsafe(0);
|
|
2499
|
-
this.encoding = "utf-8";
|
|
2500
|
-
}
|
|
2501
|
-
setBuffer(offset, buffer) {
|
|
2502
|
-
this.offset = offset;
|
|
2503
|
-
this.buffer = buffer;
|
|
2504
|
-
}
|
|
2505
|
-
int16() {
|
|
2506
|
-
const result = this.buffer.readInt16BE(this.offset);
|
|
2507
|
-
this.offset += 2;
|
|
2508
|
-
return result;
|
|
2509
|
-
}
|
|
2510
|
-
byte() {
|
|
2511
|
-
const result = this.buffer[this.offset];
|
|
2512
|
-
this.offset++;
|
|
2513
|
-
return result;
|
|
2514
|
-
}
|
|
2515
|
-
int32() {
|
|
2516
|
-
const result = this.buffer.readInt32BE(this.offset);
|
|
2517
|
-
this.offset += 4;
|
|
2518
|
-
return result;
|
|
2519
|
-
}
|
|
2520
|
-
uint32() {
|
|
2521
|
-
const result = this.buffer.readUInt32BE(this.offset);
|
|
2522
|
-
this.offset += 4;
|
|
2523
|
-
return result;
|
|
2524
|
-
}
|
|
2525
|
-
string(length) {
|
|
2526
|
-
const result = this.buffer.toString(this.encoding, this.offset, this.offset + length);
|
|
2527
|
-
this.offset += length;
|
|
2528
|
-
return result;
|
|
2529
|
-
}
|
|
2530
|
-
cstring() {
|
|
2531
|
-
const start = this.offset;
|
|
2532
|
-
let end = start;
|
|
2533
|
-
while (this.buffer[end++] !== 0);
|
|
2534
|
-
this.offset = end;
|
|
2535
|
-
return this.buffer.toString(this.encoding, start, end - 1);
|
|
2536
|
-
}
|
|
2537
|
-
bytes(length) {
|
|
2538
|
-
const result = this.buffer.slice(this.offset, this.offset + length);
|
|
2539
|
-
this.offset += length;
|
|
2540
|
-
return result;
|
|
2541
|
-
}
|
|
2542
|
-
};
|
|
2543
|
-
exports.BufferReader = BufferReader;
|
|
2544
|
-
}));
|
|
2545
|
-
//#endregion
|
|
2546
|
-
//#region node_modules/pg-protocol/dist/parser.js
|
|
2547
|
-
var require_parser = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2548
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2549
|
-
exports.Parser = void 0;
|
|
2550
|
-
const messages_1 = require_messages();
|
|
2551
|
-
const buffer_reader_1 = require_buffer_reader();
|
|
2552
|
-
const CODE_LENGTH = 1;
|
|
2553
|
-
const HEADER_LENGTH = CODE_LENGTH + 4;
|
|
2554
|
-
const LATEINIT_LENGTH = -1;
|
|
2555
|
-
const emptyBuffer = Buffer.allocUnsafe(0);
|
|
2556
|
-
var Parser = class {
|
|
2557
|
-
constructor(opts) {
|
|
2558
|
-
this.buffer = emptyBuffer;
|
|
2559
|
-
this.bufferLength = 0;
|
|
2560
|
-
this.bufferOffset = 0;
|
|
2561
|
-
this.reader = new buffer_reader_1.BufferReader();
|
|
2562
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.mode) === "binary") throw new Error("Binary mode not supported yet");
|
|
2563
|
-
this.mode = (opts === null || opts === void 0 ? void 0 : opts.mode) || "text";
|
|
2564
|
-
}
|
|
2565
|
-
parse(buffer, callback) {
|
|
2566
|
-
this.mergeBuffer(buffer);
|
|
2567
|
-
const bufferFullLength = this.bufferOffset + this.bufferLength;
|
|
2568
|
-
let offset = this.bufferOffset;
|
|
2569
|
-
while (offset + HEADER_LENGTH <= bufferFullLength) {
|
|
2570
|
-
const code = this.buffer[offset];
|
|
2571
|
-
const length = this.buffer.readUInt32BE(offset + CODE_LENGTH);
|
|
2572
|
-
const fullMessageLength = CODE_LENGTH + length;
|
|
2573
|
-
if (fullMessageLength + offset <= bufferFullLength) {
|
|
2574
|
-
callback(this.handlePacket(offset + HEADER_LENGTH, code, length, this.buffer));
|
|
2575
|
-
offset += fullMessageLength;
|
|
2576
|
-
} else break;
|
|
2577
|
-
}
|
|
2578
|
-
if (offset === bufferFullLength) {
|
|
2579
|
-
this.buffer = emptyBuffer;
|
|
2580
|
-
this.bufferLength = 0;
|
|
2581
|
-
this.bufferOffset = 0;
|
|
2582
|
-
} else {
|
|
2583
|
-
this.bufferLength = bufferFullLength - offset;
|
|
2584
|
-
this.bufferOffset = offset;
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
2587
|
-
mergeBuffer(buffer) {
|
|
2588
|
-
if (this.bufferLength > 0) {
|
|
2589
|
-
const newLength = this.bufferLength + buffer.byteLength;
|
|
2590
|
-
if (newLength + this.bufferOffset > this.buffer.byteLength) {
|
|
2591
|
-
let newBuffer;
|
|
2592
|
-
if (newLength <= this.buffer.byteLength && this.bufferOffset >= this.bufferLength) newBuffer = this.buffer;
|
|
2593
|
-
else {
|
|
2594
|
-
let newBufferLength = this.buffer.byteLength * 2;
|
|
2595
|
-
while (newLength >= newBufferLength) newBufferLength *= 2;
|
|
2596
|
-
newBuffer = Buffer.allocUnsafe(newBufferLength);
|
|
2597
|
-
}
|
|
2598
|
-
this.buffer.copy(newBuffer, 0, this.bufferOffset, this.bufferOffset + this.bufferLength);
|
|
2599
|
-
this.buffer = newBuffer;
|
|
2600
|
-
this.bufferOffset = 0;
|
|
2601
|
-
}
|
|
2602
|
-
buffer.copy(this.buffer, this.bufferOffset + this.bufferLength);
|
|
2603
|
-
this.bufferLength = newLength;
|
|
2604
|
-
} else {
|
|
2605
|
-
this.buffer = buffer;
|
|
2606
|
-
this.bufferOffset = 0;
|
|
2607
|
-
this.bufferLength = buffer.byteLength;
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
|
-
handlePacket(offset, code, length, bytes) {
|
|
2611
|
-
const { reader } = this;
|
|
2612
|
-
reader.setBuffer(offset, bytes);
|
|
2613
|
-
let message;
|
|
2614
|
-
switch (code) {
|
|
2615
|
-
case 50:
|
|
2616
|
-
message = messages_1.bindComplete;
|
|
2617
|
-
break;
|
|
2618
|
-
case 49:
|
|
2619
|
-
message = messages_1.parseComplete;
|
|
2620
|
-
break;
|
|
2621
|
-
case 51:
|
|
2622
|
-
message = messages_1.closeComplete;
|
|
2623
|
-
break;
|
|
2624
|
-
case 110:
|
|
2625
|
-
message = messages_1.noData;
|
|
2626
|
-
break;
|
|
2627
|
-
case 115:
|
|
2628
|
-
message = messages_1.portalSuspended;
|
|
2629
|
-
break;
|
|
2630
|
-
case 99:
|
|
2631
|
-
message = messages_1.copyDone;
|
|
2632
|
-
break;
|
|
2633
|
-
case 87:
|
|
2634
|
-
message = messages_1.replicationStart;
|
|
2635
|
-
break;
|
|
2636
|
-
case 73:
|
|
2637
|
-
message = messages_1.emptyQuery;
|
|
2638
|
-
break;
|
|
2639
|
-
case 68:
|
|
2640
|
-
message = parseDataRowMessage(reader);
|
|
2641
|
-
break;
|
|
2642
|
-
case 67:
|
|
2643
|
-
message = parseCommandCompleteMessage(reader);
|
|
2644
|
-
break;
|
|
2645
|
-
case 90:
|
|
2646
|
-
message = parseReadyForQueryMessage(reader);
|
|
2647
|
-
break;
|
|
2648
|
-
case 65:
|
|
2649
|
-
message = parseNotificationMessage(reader);
|
|
2650
|
-
break;
|
|
2651
|
-
case 82:
|
|
2652
|
-
message = parseAuthenticationResponse(reader, length);
|
|
2653
|
-
break;
|
|
2654
|
-
case 83:
|
|
2655
|
-
message = parseParameterStatusMessage(reader);
|
|
2656
|
-
break;
|
|
2657
|
-
case 75:
|
|
2658
|
-
message = parseBackendKeyData(reader);
|
|
2659
|
-
break;
|
|
2660
|
-
case 69:
|
|
2661
|
-
message = parseErrorMessage(reader, "error");
|
|
2662
|
-
break;
|
|
2663
|
-
case 78:
|
|
2664
|
-
message = parseErrorMessage(reader, "notice");
|
|
2665
|
-
break;
|
|
2666
|
-
case 84:
|
|
2667
|
-
message = parseRowDescriptionMessage(reader);
|
|
2668
|
-
break;
|
|
2669
|
-
case 116:
|
|
2670
|
-
message = parseParameterDescriptionMessage(reader);
|
|
2671
|
-
break;
|
|
2672
|
-
case 71:
|
|
2673
|
-
message = parseCopyInMessage(reader);
|
|
2674
|
-
break;
|
|
2675
|
-
case 72:
|
|
2676
|
-
message = parseCopyOutMessage(reader);
|
|
2677
|
-
break;
|
|
2678
|
-
case 100:
|
|
2679
|
-
message = parseCopyData(reader, length);
|
|
2680
|
-
break;
|
|
2681
|
-
default: return new messages_1.DatabaseError("received invalid response: " + code.toString(16), length, "error");
|
|
2682
|
-
}
|
|
2683
|
-
reader.setBuffer(0, emptyBuffer);
|
|
2684
|
-
message.length = length;
|
|
2685
|
-
return message;
|
|
2686
|
-
}
|
|
2687
|
-
};
|
|
2688
|
-
exports.Parser = Parser;
|
|
2689
|
-
const parseReadyForQueryMessage = (reader) => {
|
|
2690
|
-
const status = reader.string(1);
|
|
2691
|
-
return new messages_1.ReadyForQueryMessage(LATEINIT_LENGTH, status);
|
|
2692
|
-
};
|
|
2693
|
-
const parseCommandCompleteMessage = (reader) => {
|
|
2694
|
-
const text = reader.cstring();
|
|
2695
|
-
return new messages_1.CommandCompleteMessage(LATEINIT_LENGTH, text);
|
|
2696
|
-
};
|
|
2697
|
-
const parseCopyData = (reader, length) => {
|
|
2698
|
-
const chunk = reader.bytes(length - 4);
|
|
2699
|
-
return new messages_1.CopyDataMessage(LATEINIT_LENGTH, chunk);
|
|
2700
|
-
};
|
|
2701
|
-
const parseCopyInMessage = (reader) => parseCopyMessage(reader, "copyInResponse");
|
|
2702
|
-
const parseCopyOutMessage = (reader) => parseCopyMessage(reader, "copyOutResponse");
|
|
2703
|
-
const parseCopyMessage = (reader, messageName) => {
|
|
2704
|
-
const isBinary = reader.byte() !== 0;
|
|
2705
|
-
const columnCount = reader.int16();
|
|
2706
|
-
const message = new messages_1.CopyResponse(LATEINIT_LENGTH, messageName, isBinary, columnCount);
|
|
2707
|
-
for (let i = 0; i < columnCount; i++) message.columnTypes[i] = reader.int16();
|
|
2708
|
-
return message;
|
|
2709
|
-
};
|
|
2710
|
-
const parseNotificationMessage = (reader) => {
|
|
2711
|
-
const processId = reader.int32();
|
|
2712
|
-
const channel = reader.cstring();
|
|
2713
|
-
const payload = reader.cstring();
|
|
2714
|
-
return new messages_1.NotificationResponseMessage(LATEINIT_LENGTH, processId, channel, payload);
|
|
2715
|
-
};
|
|
2716
|
-
const parseRowDescriptionMessage = (reader) => {
|
|
2717
|
-
const fieldCount = reader.int16();
|
|
2718
|
-
const message = new messages_1.RowDescriptionMessage(LATEINIT_LENGTH, fieldCount);
|
|
2719
|
-
for (let i = 0; i < fieldCount; i++) message.fields[i] = parseField(reader);
|
|
2720
|
-
return message;
|
|
2721
|
-
};
|
|
2722
|
-
const parseField = (reader) => {
|
|
2723
|
-
const name = reader.cstring();
|
|
2724
|
-
const tableID = reader.uint32();
|
|
2725
|
-
const columnID = reader.int16();
|
|
2726
|
-
const dataTypeID = reader.uint32();
|
|
2727
|
-
const dataTypeSize = reader.int16();
|
|
2728
|
-
const dataTypeModifier = reader.int32();
|
|
2729
|
-
const mode = reader.int16() === 0 ? "text" : "binary";
|
|
2730
|
-
return new messages_1.Field(name, tableID, columnID, dataTypeID, dataTypeSize, dataTypeModifier, mode);
|
|
2731
|
-
};
|
|
2732
|
-
const parseParameterDescriptionMessage = (reader) => {
|
|
2733
|
-
const parameterCount = reader.int16();
|
|
2734
|
-
const message = new messages_1.ParameterDescriptionMessage(LATEINIT_LENGTH, parameterCount);
|
|
2735
|
-
for (let i = 0; i < parameterCount; i++) message.dataTypeIDs[i] = reader.int32();
|
|
2736
|
-
return message;
|
|
2737
|
-
};
|
|
2738
|
-
const parseDataRowMessage = (reader) => {
|
|
2739
|
-
const fieldCount = reader.int16();
|
|
2740
|
-
const fields = new Array(fieldCount);
|
|
2741
|
-
for (let i = 0; i < fieldCount; i++) {
|
|
2742
|
-
const len = reader.int32();
|
|
2743
|
-
fields[i] = len === -1 ? null : reader.string(len);
|
|
2744
|
-
}
|
|
2745
|
-
return new messages_1.DataRowMessage(LATEINIT_LENGTH, fields);
|
|
2746
|
-
};
|
|
2747
|
-
const parseParameterStatusMessage = (reader) => {
|
|
2748
|
-
const name = reader.cstring();
|
|
2749
|
-
const value = reader.cstring();
|
|
2750
|
-
return new messages_1.ParameterStatusMessage(LATEINIT_LENGTH, name, value);
|
|
2751
|
-
};
|
|
2752
|
-
const parseBackendKeyData = (reader) => {
|
|
2753
|
-
const processID = reader.int32();
|
|
2754
|
-
const secretKey = reader.int32();
|
|
2755
|
-
return new messages_1.BackendKeyDataMessage(LATEINIT_LENGTH, processID, secretKey);
|
|
2756
|
-
};
|
|
2757
|
-
const parseAuthenticationResponse = (reader, length) => {
|
|
2758
|
-
const code = reader.int32();
|
|
2759
|
-
const message = {
|
|
2760
|
-
name: "authenticationOk",
|
|
2761
|
-
length
|
|
2762
|
-
};
|
|
2763
|
-
switch (code) {
|
|
2764
|
-
case 0: break;
|
|
2765
|
-
case 3:
|
|
2766
|
-
if (message.length === 8) message.name = "authenticationCleartextPassword";
|
|
2767
|
-
break;
|
|
2768
|
-
case 5:
|
|
2769
|
-
if (message.length === 12) {
|
|
2770
|
-
message.name = "authenticationMD5Password";
|
|
2771
|
-
const salt = reader.bytes(4);
|
|
2772
|
-
return new messages_1.AuthenticationMD5Password(LATEINIT_LENGTH, salt);
|
|
2773
|
-
}
|
|
2774
|
-
break;
|
|
2775
|
-
case 10:
|
|
2776
|
-
{
|
|
2777
|
-
message.name = "authenticationSASL";
|
|
2778
|
-
message.mechanisms = [];
|
|
2779
|
-
let mechanism;
|
|
2780
|
-
do {
|
|
2781
|
-
mechanism = reader.cstring();
|
|
2782
|
-
if (mechanism) message.mechanisms.push(mechanism);
|
|
2783
|
-
} while (mechanism);
|
|
2784
|
-
}
|
|
2785
|
-
break;
|
|
2786
|
-
case 11:
|
|
2787
|
-
message.name = "authenticationSASLContinue";
|
|
2788
|
-
message.data = reader.string(length - 8);
|
|
2789
|
-
break;
|
|
2790
|
-
case 12:
|
|
2791
|
-
message.name = "authenticationSASLFinal";
|
|
2792
|
-
message.data = reader.string(length - 8);
|
|
2793
|
-
break;
|
|
2794
|
-
default: throw new Error("Unknown authenticationOk message type " + code);
|
|
2795
|
-
}
|
|
2796
|
-
return message;
|
|
2797
|
-
};
|
|
2798
|
-
const parseErrorMessage = (reader, name) => {
|
|
2799
|
-
const fields = {};
|
|
2800
|
-
let fieldType = reader.string(1);
|
|
2801
|
-
while (fieldType !== "\0") {
|
|
2802
|
-
fields[fieldType] = reader.cstring();
|
|
2803
|
-
fieldType = reader.string(1);
|
|
2804
|
-
}
|
|
2805
|
-
const messageValue = fields.M;
|
|
2806
|
-
const message = name === "notice" ? new messages_1.NoticeMessage(LATEINIT_LENGTH, messageValue) : new messages_1.DatabaseError(messageValue, LATEINIT_LENGTH, name);
|
|
2807
|
-
message.severity = fields.S;
|
|
2808
|
-
message.code = fields.C;
|
|
2809
|
-
message.detail = fields.D;
|
|
2810
|
-
message.hint = fields.H;
|
|
2811
|
-
message.position = fields.P;
|
|
2812
|
-
message.internalPosition = fields.p;
|
|
2813
|
-
message.internalQuery = fields.q;
|
|
2814
|
-
message.where = fields.W;
|
|
2815
|
-
message.schema = fields.s;
|
|
2816
|
-
message.table = fields.t;
|
|
2817
|
-
message.column = fields.c;
|
|
2818
|
-
message.dataType = fields.d;
|
|
2819
|
-
message.constraint = fields.n;
|
|
2820
|
-
message.file = fields.F;
|
|
2821
|
-
message.line = fields.L;
|
|
2822
|
-
message.routine = fields.R;
|
|
2823
|
-
return message;
|
|
2824
|
-
};
|
|
2825
|
-
}));
|
|
2826
|
-
//#endregion
|
|
2827
|
-
//#region node_modules/pg-protocol/dist/index.js
|
|
2828
|
-
var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2829
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2830
|
-
exports.DatabaseError = exports.serialize = exports.parse = void 0;
|
|
2831
|
-
const messages_1 = require_messages();
|
|
2832
|
-
Object.defineProperty(exports, "DatabaseError", {
|
|
2833
|
-
enumerable: true,
|
|
2834
|
-
get: function() {
|
|
2835
|
-
return messages_1.DatabaseError;
|
|
2836
|
-
}
|
|
2837
|
-
});
|
|
2838
|
-
const serializer_1 = require_serializer();
|
|
2839
|
-
Object.defineProperty(exports, "serialize", {
|
|
2840
|
-
enumerable: true,
|
|
2841
|
-
get: function() {
|
|
2842
|
-
return serializer_1.serialize;
|
|
2843
|
-
}
|
|
2844
|
-
});
|
|
2845
|
-
const parser_1 = require_parser();
|
|
2846
|
-
function parse(stream, callback) {
|
|
2847
|
-
const parser = new parser_1.Parser();
|
|
2848
|
-
stream.on("data", (buffer) => parser.parse(buffer, callback));
|
|
2849
|
-
return new Promise((resolve) => stream.on("end", () => resolve()));
|
|
2850
|
-
}
|
|
2851
|
-
exports.parse = parse;
|
|
2852
|
-
}));
|
|
2853
|
-
//#endregion
|
|
2854
|
-
//#region node_modules/pg-cloudflare/dist/empty.js
|
|
2855
|
-
var require_empty = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2856
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2857
|
-
exports.default = {};
|
|
2858
|
-
}));
|
|
2859
|
-
//#endregion
|
|
2860
|
-
//#region node_modules/pg/lib/stream.js
|
|
2861
|
-
var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2862
|
-
const { getStream, getSecureStream } = getStreamFuncs();
|
|
2863
|
-
module.exports = {
|
|
2864
|
-
getStream,
|
|
2865
|
-
getSecureStream
|
|
2866
|
-
};
|
|
2867
|
-
/**
|
|
2868
|
-
* The stream functions that work in Node.js
|
|
2869
|
-
*/
|
|
2870
|
-
function getNodejsStreamFuncs() {
|
|
2871
|
-
function getStream(ssl) {
|
|
2872
|
-
return new (__require("net")).Socket();
|
|
2873
|
-
}
|
|
2874
|
-
function getSecureStream(options) {
|
|
2875
|
-
return __require("tls").connect(options);
|
|
2876
|
-
}
|
|
2877
|
-
return {
|
|
2878
|
-
getStream,
|
|
2879
|
-
getSecureStream
|
|
2880
|
-
};
|
|
2881
|
-
}
|
|
2882
|
-
/**
|
|
2883
|
-
* The stream functions that work in Cloudflare Workers
|
|
2884
|
-
*/
|
|
2885
|
-
function getCloudflareStreamFuncs() {
|
|
2886
|
-
function getStream(ssl) {
|
|
2887
|
-
const { CloudflareSocket } = require_empty();
|
|
2888
|
-
return new CloudflareSocket(ssl);
|
|
2889
|
-
}
|
|
2890
|
-
function getSecureStream(options) {
|
|
2891
|
-
options.socket.startTls(options);
|
|
2892
|
-
return options.socket;
|
|
2893
|
-
}
|
|
2894
|
-
return {
|
|
2895
|
-
getStream,
|
|
2896
|
-
getSecureStream
|
|
2897
|
-
};
|
|
2898
|
-
}
|
|
2899
|
-
/**
|
|
2900
|
-
* Are we running in a Cloudflare Worker?
|
|
2901
|
-
*
|
|
2902
|
-
* @returns true if the code is currently running inside a Cloudflare Worker.
|
|
2903
|
-
*/
|
|
2904
|
-
function isCloudflareRuntime() {
|
|
2905
|
-
if (typeof navigator === "object" && navigator !== null && typeof navigator.userAgent === "string") return navigator.userAgent === "Cloudflare-Workers";
|
|
2906
|
-
if (typeof Response === "function") {
|
|
2907
|
-
const resp = new Response(null, { cf: { thing: true } });
|
|
2908
|
-
if (typeof resp.cf === "object" && resp.cf !== null && resp.cf.thing) return true;
|
|
2909
|
-
}
|
|
2910
|
-
return false;
|
|
2911
|
-
}
|
|
2912
|
-
function getStreamFuncs() {
|
|
2913
|
-
if (isCloudflareRuntime()) return getCloudflareStreamFuncs();
|
|
2914
|
-
return getNodejsStreamFuncs();
|
|
2915
|
-
}
|
|
2916
|
-
}));
|
|
2917
|
-
//#endregion
|
|
2918
|
-
//#region node_modules/pg/lib/connection.js
|
|
2919
|
-
var require_connection = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2920
|
-
const EventEmitter$4 = __require("events").EventEmitter;
|
|
2921
|
-
const { parse, serialize } = require_dist();
|
|
2922
|
-
const { getStream, getSecureStream } = require_stream();
|
|
2923
|
-
const flushBuffer = serialize.flush();
|
|
2924
|
-
const syncBuffer = serialize.sync();
|
|
2925
|
-
const endBuffer = serialize.end();
|
|
2926
|
-
var Connection$1 = class extends EventEmitter$4 {
|
|
2927
|
-
constructor(config) {
|
|
2928
|
-
super();
|
|
2929
|
-
config = config || {};
|
|
2930
|
-
this.stream = config.stream || getStream(config.ssl);
|
|
2931
|
-
if (typeof this.stream === "function") this.stream = this.stream(config);
|
|
2932
|
-
this._keepAlive = config.keepAlive;
|
|
2933
|
-
this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis;
|
|
2934
|
-
this.parsedStatements = {};
|
|
2935
|
-
this.ssl = config.ssl || false;
|
|
2936
|
-
this._ending = false;
|
|
2937
|
-
this._emitMessage = false;
|
|
2938
|
-
const self = this;
|
|
2939
|
-
this.on("newListener", function(eventName) {
|
|
2940
|
-
if (eventName === "message") self._emitMessage = true;
|
|
2941
|
-
});
|
|
2942
|
-
}
|
|
2943
|
-
connect(port, host) {
|
|
2944
|
-
const self = this;
|
|
2945
|
-
this._connecting = true;
|
|
2946
|
-
this.stream.setNoDelay(true);
|
|
2947
|
-
this.stream.connect(port, host);
|
|
2948
|
-
this.stream.once("connect", function() {
|
|
2949
|
-
if (self._keepAlive) self.stream.setKeepAlive(true, self._keepAliveInitialDelayMillis);
|
|
2950
|
-
self.emit("connect");
|
|
2951
|
-
});
|
|
2952
|
-
const reportStreamError = function(error) {
|
|
2953
|
-
if (self._ending && (error.code === "ECONNRESET" || error.code === "EPIPE")) return;
|
|
2954
|
-
self.emit("error", error);
|
|
2955
|
-
};
|
|
2956
|
-
this.stream.on("error", reportStreamError);
|
|
2957
|
-
this.stream.on("close", function() {
|
|
2958
|
-
self.emit("end");
|
|
2959
|
-
});
|
|
2960
|
-
if (!this.ssl) return this.attachListeners(this.stream);
|
|
2961
|
-
this.stream.once("data", function(buffer) {
|
|
2962
|
-
switch (buffer.toString("utf8")) {
|
|
2963
|
-
case "S": break;
|
|
2964
|
-
case "N":
|
|
2965
|
-
self.stream.end();
|
|
2966
|
-
return self.emit("error", /* @__PURE__ */ new Error("The server does not support SSL connections"));
|
|
2967
|
-
default:
|
|
2968
|
-
self.stream.end();
|
|
2969
|
-
return self.emit("error", /* @__PURE__ */ new Error("There was an error establishing an SSL connection"));
|
|
2970
|
-
}
|
|
2971
|
-
const options = { socket: self.stream };
|
|
2972
|
-
if (self.ssl !== true) {
|
|
2973
|
-
Object.assign(options, self.ssl);
|
|
2974
|
-
if ("key" in self.ssl) options.key = self.ssl.key;
|
|
2975
|
-
}
|
|
2976
|
-
const net = __require("net");
|
|
2977
|
-
if (net.isIP && net.isIP(host) === 0) options.servername = host;
|
|
2978
|
-
try {
|
|
2979
|
-
self.stream = getSecureStream(options);
|
|
2980
|
-
} catch (err) {
|
|
2981
|
-
return self.emit("error", err);
|
|
2982
|
-
}
|
|
2983
|
-
self.attachListeners(self.stream);
|
|
2984
|
-
self.stream.on("error", reportStreamError);
|
|
2985
|
-
self.emit("sslconnect");
|
|
2986
|
-
});
|
|
2987
|
-
}
|
|
2988
|
-
attachListeners(stream) {
|
|
2989
|
-
parse(stream, (msg) => {
|
|
2990
|
-
const eventName = msg.name === "error" ? "errorMessage" : msg.name;
|
|
2991
|
-
if (this._emitMessage) this.emit("message", msg);
|
|
2992
|
-
this.emit(eventName, msg);
|
|
2993
|
-
});
|
|
2994
|
-
}
|
|
2995
|
-
requestSsl() {
|
|
2996
|
-
this.stream.write(serialize.requestSsl());
|
|
2997
|
-
}
|
|
2998
|
-
startup(config) {
|
|
2999
|
-
this.stream.write(serialize.startup(config));
|
|
3000
|
-
}
|
|
3001
|
-
cancel(processID, secretKey) {
|
|
3002
|
-
this._send(serialize.cancel(processID, secretKey));
|
|
3003
|
-
}
|
|
3004
|
-
password(password) {
|
|
3005
|
-
this._send(serialize.password(password));
|
|
3006
|
-
}
|
|
3007
|
-
sendSASLInitialResponseMessage(mechanism, initialResponse) {
|
|
3008
|
-
this._send(serialize.sendSASLInitialResponseMessage(mechanism, initialResponse));
|
|
3009
|
-
}
|
|
3010
|
-
sendSCRAMClientFinalMessage(additionalData) {
|
|
3011
|
-
this._send(serialize.sendSCRAMClientFinalMessage(additionalData));
|
|
3012
|
-
}
|
|
3013
|
-
_send(buffer) {
|
|
3014
|
-
if (!this.stream.writable) return false;
|
|
3015
|
-
return this.stream.write(buffer);
|
|
3016
|
-
}
|
|
3017
|
-
query(text) {
|
|
3018
|
-
this._send(serialize.query(text));
|
|
3019
|
-
}
|
|
3020
|
-
parse(query) {
|
|
3021
|
-
this._send(serialize.parse(query));
|
|
3022
|
-
}
|
|
3023
|
-
bind(config) {
|
|
3024
|
-
this._send(serialize.bind(config));
|
|
3025
|
-
}
|
|
3026
|
-
execute(config) {
|
|
3027
|
-
this._send(serialize.execute(config));
|
|
3028
|
-
}
|
|
3029
|
-
flush() {
|
|
3030
|
-
if (this.stream.writable) this.stream.write(flushBuffer);
|
|
3031
|
-
}
|
|
3032
|
-
sync() {
|
|
3033
|
-
this._ending = true;
|
|
3034
|
-
this._send(syncBuffer);
|
|
3035
|
-
}
|
|
3036
|
-
ref() {
|
|
3037
|
-
this.stream.ref();
|
|
3038
|
-
}
|
|
3039
|
-
unref() {
|
|
3040
|
-
this.stream.unref();
|
|
3041
|
-
}
|
|
3042
|
-
end() {
|
|
3043
|
-
this._ending = true;
|
|
3044
|
-
if (!this._connecting || !this.stream.writable) {
|
|
3045
|
-
this.stream.end();
|
|
3046
|
-
return;
|
|
3047
|
-
}
|
|
3048
|
-
return this.stream.write(endBuffer, () => {
|
|
3049
|
-
this.stream.end();
|
|
3050
|
-
});
|
|
3051
|
-
}
|
|
3052
|
-
close(msg) {
|
|
3053
|
-
this._send(serialize.close(msg));
|
|
3054
|
-
}
|
|
3055
|
-
describe(msg) {
|
|
3056
|
-
this._send(serialize.describe(msg));
|
|
3057
|
-
}
|
|
3058
|
-
sendCopyFromChunk(chunk) {
|
|
3059
|
-
this._send(serialize.copyData(chunk));
|
|
3060
|
-
}
|
|
3061
|
-
endCopyFrom() {
|
|
3062
|
-
this._send(serialize.copyDone());
|
|
3063
|
-
}
|
|
3064
|
-
sendCopyFail(msg) {
|
|
3065
|
-
this._send(serialize.copyFail(msg));
|
|
3066
|
-
}
|
|
3067
|
-
};
|
|
3068
|
-
module.exports = Connection$1;
|
|
3069
|
-
}));
|
|
3070
|
-
//#endregion
|
|
3071
|
-
//#region node_modules/split2/index.js
|
|
3072
|
-
var require_split2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3073
|
-
const { Transform } = __require("stream");
|
|
3074
|
-
const { StringDecoder } = __require("string_decoder");
|
|
3075
|
-
const kLast = Symbol("last");
|
|
3076
|
-
const kDecoder = Symbol("decoder");
|
|
3077
|
-
function transform(chunk, enc, cb) {
|
|
3078
|
-
let list;
|
|
3079
|
-
if (this.overflow) {
|
|
3080
|
-
list = this[kDecoder].write(chunk).split(this.matcher);
|
|
3081
|
-
if (list.length === 1) return cb();
|
|
3082
|
-
list.shift();
|
|
3083
|
-
this.overflow = false;
|
|
3084
|
-
} else {
|
|
3085
|
-
this[kLast] += this[kDecoder].write(chunk);
|
|
3086
|
-
list = this[kLast].split(this.matcher);
|
|
3087
|
-
}
|
|
3088
|
-
this[kLast] = list.pop();
|
|
3089
|
-
for (let i = 0; i < list.length; i++) try {
|
|
3090
|
-
push(this, this.mapper(list[i]));
|
|
3091
|
-
} catch (error) {
|
|
3092
|
-
return cb(error);
|
|
3093
|
-
}
|
|
3094
|
-
this.overflow = this[kLast].length > this.maxLength;
|
|
3095
|
-
if (this.overflow && !this.skipOverflow) {
|
|
3096
|
-
cb(/* @__PURE__ */ new Error("maximum buffer reached"));
|
|
3097
|
-
return;
|
|
3098
|
-
}
|
|
3099
|
-
cb();
|
|
3100
|
-
}
|
|
3101
|
-
function flush(cb) {
|
|
3102
|
-
this[kLast] += this[kDecoder].end();
|
|
3103
|
-
if (this[kLast]) try {
|
|
3104
|
-
push(this, this.mapper(this[kLast]));
|
|
3105
|
-
} catch (error) {
|
|
3106
|
-
return cb(error);
|
|
3107
|
-
}
|
|
3108
|
-
cb();
|
|
3109
|
-
}
|
|
3110
|
-
function push(self, val) {
|
|
3111
|
-
if (val !== void 0) self.push(val);
|
|
3112
|
-
}
|
|
3113
|
-
function noop(incoming) {
|
|
3114
|
-
return incoming;
|
|
3115
|
-
}
|
|
3116
|
-
function split(matcher, mapper, options) {
|
|
3117
|
-
matcher = matcher || /\r?\n/;
|
|
3118
|
-
mapper = mapper || noop;
|
|
3119
|
-
options = options || {};
|
|
3120
|
-
switch (arguments.length) {
|
|
3121
|
-
case 1:
|
|
3122
|
-
if (typeof matcher === "function") {
|
|
3123
|
-
mapper = matcher;
|
|
3124
|
-
matcher = /\r?\n/;
|
|
3125
|
-
} else if (typeof matcher === "object" && !(matcher instanceof RegExp) && !matcher[Symbol.split]) {
|
|
3126
|
-
options = matcher;
|
|
3127
|
-
matcher = /\r?\n/;
|
|
3128
|
-
}
|
|
3129
|
-
break;
|
|
3130
|
-
case 2: if (typeof matcher === "function") {
|
|
3131
|
-
options = mapper;
|
|
3132
|
-
mapper = matcher;
|
|
3133
|
-
matcher = /\r?\n/;
|
|
3134
|
-
} else if (typeof mapper === "object") {
|
|
3135
|
-
options = mapper;
|
|
3136
|
-
mapper = noop;
|
|
3137
|
-
}
|
|
3138
|
-
}
|
|
3139
|
-
options = Object.assign({}, options);
|
|
3140
|
-
options.autoDestroy = true;
|
|
3141
|
-
options.transform = transform;
|
|
3142
|
-
options.flush = flush;
|
|
3143
|
-
options.readableObjectMode = true;
|
|
3144
|
-
const stream = new Transform(options);
|
|
3145
|
-
stream[kLast] = "";
|
|
3146
|
-
stream[kDecoder] = new StringDecoder("utf8");
|
|
3147
|
-
stream.matcher = matcher;
|
|
3148
|
-
stream.mapper = mapper;
|
|
3149
|
-
stream.maxLength = options.maxLength;
|
|
3150
|
-
stream.skipOverflow = options.skipOverflow || false;
|
|
3151
|
-
stream.overflow = false;
|
|
3152
|
-
stream._destroy = function(err, cb) {
|
|
3153
|
-
this._writableState.errorEmitted = false;
|
|
3154
|
-
cb(err);
|
|
3155
|
-
};
|
|
3156
|
-
return stream;
|
|
3157
|
-
}
|
|
3158
|
-
module.exports = split;
|
|
3159
|
-
}));
|
|
3160
|
-
//#endregion
|
|
3161
|
-
//#region node_modules/pgpass/lib/helper.js
|
|
3162
|
-
var require_helper = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3163
|
-
var path = __require("path"), Stream = __require("stream").Stream, split = require_split2(), util$2 = __require("util"), defaultPort = 5432, isWin = process.platform === "win32", warnStream = process.stderr;
|
|
3164
|
-
var S_IRWXG = 56, S_IRWXO = 7, S_IFMT = 61440, S_IFREG = 32768;
|
|
3165
|
-
function isRegFile(mode) {
|
|
3166
|
-
return (mode & S_IFMT) == S_IFREG;
|
|
3167
|
-
}
|
|
3168
|
-
var fieldNames = [
|
|
3169
|
-
"host",
|
|
3170
|
-
"port",
|
|
3171
|
-
"database",
|
|
3172
|
-
"user",
|
|
3173
|
-
"password"
|
|
3174
|
-
];
|
|
3175
|
-
var nrOfFields = fieldNames.length;
|
|
3176
|
-
var passKey = fieldNames[nrOfFields - 1];
|
|
3177
|
-
function warn() {
|
|
3178
|
-
if (warnStream instanceof Stream && true === warnStream.writable) {
|
|
3179
|
-
var args = Array.prototype.slice.call(arguments).concat("\n");
|
|
3180
|
-
warnStream.write(util$2.format.apply(util$2, args));
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
Object.defineProperty(module.exports, "isWin", {
|
|
3184
|
-
get: function() {
|
|
3185
|
-
return isWin;
|
|
3186
|
-
},
|
|
3187
|
-
set: function(val) {
|
|
3188
|
-
isWin = val;
|
|
3189
|
-
}
|
|
3190
|
-
});
|
|
3191
|
-
module.exports.warnTo = function(stream) {
|
|
3192
|
-
var old = warnStream;
|
|
3193
|
-
warnStream = stream;
|
|
3194
|
-
return old;
|
|
3195
|
-
};
|
|
3196
|
-
module.exports.getFileName = function(rawEnv) {
|
|
3197
|
-
var env = rawEnv || process.env;
|
|
3198
|
-
return env.PGPASSFILE || (isWin ? path.join(env.APPDATA || "./", "postgresql", "pgpass.conf") : path.join(env.HOME || "./", ".pgpass"));
|
|
3199
|
-
};
|
|
3200
|
-
module.exports.usePgPass = function(stats, fname) {
|
|
3201
|
-
if (Object.prototype.hasOwnProperty.call(process.env, "PGPASSWORD")) return false;
|
|
3202
|
-
if (isWin) return true;
|
|
3203
|
-
fname = fname || "<unkn>";
|
|
3204
|
-
if (!isRegFile(stats.mode)) {
|
|
3205
|
-
warn("WARNING: password file \"%s\" is not a plain file", fname);
|
|
3206
|
-
return false;
|
|
3207
|
-
}
|
|
3208
|
-
if (stats.mode & (S_IRWXG | S_IRWXO)) {
|
|
3209
|
-
warn("WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less", fname);
|
|
3210
|
-
return false;
|
|
3211
|
-
}
|
|
3212
|
-
return true;
|
|
3213
|
-
};
|
|
3214
|
-
var matcher = module.exports.match = function(connInfo, entry) {
|
|
3215
|
-
return fieldNames.slice(0, -1).reduce(function(prev, field, idx) {
|
|
3216
|
-
if (idx == 1) {
|
|
3217
|
-
if (Number(connInfo[field] || defaultPort) === Number(entry[field])) return prev && true;
|
|
3218
|
-
}
|
|
3219
|
-
return prev && (entry[field] === "*" || entry[field] === connInfo[field]);
|
|
3220
|
-
}, true);
|
|
3221
|
-
};
|
|
3222
|
-
module.exports.getPassword = function(connInfo, stream, cb) {
|
|
3223
|
-
var pass;
|
|
3224
|
-
var lineStream = stream.pipe(split());
|
|
3225
|
-
function onLine(line) {
|
|
3226
|
-
var entry = parseLine(line);
|
|
3227
|
-
if (entry && isValidEntry(entry) && matcher(connInfo, entry)) {
|
|
3228
|
-
pass = entry[passKey];
|
|
3229
|
-
lineStream.end();
|
|
3230
|
-
}
|
|
3231
|
-
}
|
|
3232
|
-
var onEnd = function() {
|
|
3233
|
-
stream.destroy();
|
|
3234
|
-
cb(pass);
|
|
3235
|
-
};
|
|
3236
|
-
var onErr = function(err) {
|
|
3237
|
-
stream.destroy();
|
|
3238
|
-
warn("WARNING: error on reading file: %s", err);
|
|
3239
|
-
cb(void 0);
|
|
3240
|
-
};
|
|
3241
|
-
stream.on("error", onErr);
|
|
3242
|
-
lineStream.on("data", onLine).on("end", onEnd).on("error", onErr);
|
|
3243
|
-
};
|
|
3244
|
-
var parseLine = module.exports.parseLine = function(line) {
|
|
3245
|
-
if (line.length < 11 || line.match(/^\s+#/)) return null;
|
|
3246
|
-
var curChar = "";
|
|
3247
|
-
var prevChar = "";
|
|
3248
|
-
var fieldIdx = 0;
|
|
3249
|
-
var startIdx = 0;
|
|
3250
|
-
var obj = {};
|
|
3251
|
-
var isLastField = false;
|
|
3252
|
-
var addToObj = function(idx, i0, i1) {
|
|
3253
|
-
var field = line.substring(i0, i1);
|
|
3254
|
-
if (!Object.hasOwnProperty.call(process.env, "PGPASS_NO_DEESCAPE")) field = field.replace(/\\([:\\])/g, "$1");
|
|
3255
|
-
obj[fieldNames[idx]] = field;
|
|
3256
|
-
};
|
|
3257
|
-
for (var i = 0; i < line.length - 1; i += 1) {
|
|
3258
|
-
curChar = line.charAt(i + 1);
|
|
3259
|
-
prevChar = line.charAt(i);
|
|
3260
|
-
isLastField = fieldIdx == nrOfFields - 1;
|
|
3261
|
-
if (isLastField) {
|
|
3262
|
-
addToObj(fieldIdx, startIdx);
|
|
3263
|
-
break;
|
|
3264
|
-
}
|
|
3265
|
-
if (i >= 0 && curChar == ":" && prevChar !== "\\") {
|
|
3266
|
-
addToObj(fieldIdx, startIdx, i + 1);
|
|
3267
|
-
startIdx = i + 2;
|
|
3268
|
-
fieldIdx += 1;
|
|
3269
|
-
}
|
|
3270
|
-
}
|
|
3271
|
-
obj = Object.keys(obj).length === nrOfFields ? obj : null;
|
|
3272
|
-
return obj;
|
|
3273
|
-
};
|
|
3274
|
-
var isValidEntry = module.exports.isValidEntry = function(entry) {
|
|
3275
|
-
var rules = {
|
|
3276
|
-
0: function(x) {
|
|
3277
|
-
return x.length > 0;
|
|
3278
|
-
},
|
|
3279
|
-
1: function(x) {
|
|
3280
|
-
if (x === "*") return true;
|
|
3281
|
-
x = Number(x);
|
|
3282
|
-
return isFinite(x) && x > 0 && x < 9007199254740992 && Math.floor(x) === x;
|
|
3283
|
-
},
|
|
3284
|
-
2: function(x) {
|
|
3285
|
-
return x.length > 0;
|
|
3286
|
-
},
|
|
3287
|
-
3: function(x) {
|
|
3288
|
-
return x.length > 0;
|
|
3289
|
-
},
|
|
3290
|
-
4: function(x) {
|
|
3291
|
-
return x.length > 0;
|
|
3292
|
-
}
|
|
3293
|
-
};
|
|
3294
|
-
for (var idx = 0; idx < fieldNames.length; idx += 1) {
|
|
3295
|
-
var rule = rules[idx];
|
|
3296
|
-
if (!rule(entry[fieldNames[idx]] || "")) return false;
|
|
3297
|
-
}
|
|
3298
|
-
return true;
|
|
3299
|
-
};
|
|
3300
|
-
}));
|
|
3301
|
-
//#endregion
|
|
3302
|
-
//#region node_modules/pgpass/lib/index.js
|
|
3303
|
-
var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3304
|
-
__require("path");
|
|
3305
|
-
var fs = __require("fs"), helper = require_helper();
|
|
3306
|
-
module.exports = function(connInfo, cb) {
|
|
3307
|
-
var file = helper.getFileName();
|
|
3308
|
-
fs.stat(file, function(err, stat) {
|
|
3309
|
-
if (err || !helper.usePgPass(stat, file)) return cb(void 0);
|
|
3310
|
-
var st = fs.createReadStream(file);
|
|
3311
|
-
helper.getPassword(connInfo, st, cb);
|
|
3312
|
-
});
|
|
3313
|
-
};
|
|
3314
|
-
module.exports.warnTo = helper.warnTo;
|
|
3315
|
-
}));
|
|
3316
|
-
//#endregion
|
|
3317
|
-
//#region node_modules/pg/lib/client.js
|
|
3318
|
-
var require_client$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3319
|
-
const EventEmitter$3 = __require("events").EventEmitter;
|
|
3320
|
-
const utils = require_utils$1();
|
|
3321
|
-
const nodeUtils$1 = __require("util");
|
|
3322
|
-
const sasl = require_sasl();
|
|
3323
|
-
const TypeOverrides = require_type_overrides();
|
|
3324
|
-
const ConnectionParameters = require_connection_parameters();
|
|
3325
|
-
const Query = require_query$1();
|
|
3326
|
-
const defaults = require_defaults();
|
|
3327
|
-
const Connection = require_connection();
|
|
3328
|
-
const crypto = require_utils();
|
|
3329
|
-
const activeQueryDeprecationNotice = nodeUtils$1.deprecate(() => {}, "Client.activeQuery is deprecated and will be removed in pg@9.0");
|
|
3330
|
-
const queryQueueDeprecationNotice = nodeUtils$1.deprecate(() => {}, "Client.queryQueue is deprecated and will be removed in pg@9.0.");
|
|
3331
|
-
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.");
|
|
3332
|
-
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.");
|
|
3333
|
-
const queryQueueLengthDeprecationNotice = 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.");
|
|
3334
|
-
var Client = class extends EventEmitter$3 {
|
|
3335
|
-
constructor(config) {
|
|
3336
|
-
super();
|
|
3337
|
-
this.connectionParameters = new ConnectionParameters(config);
|
|
3338
|
-
this.user = this.connectionParameters.user;
|
|
3339
|
-
this.database = this.connectionParameters.database;
|
|
3340
|
-
this.port = this.connectionParameters.port;
|
|
3341
|
-
this.host = this.connectionParameters.host;
|
|
3342
|
-
Object.defineProperty(this, "password", {
|
|
3343
|
-
configurable: true,
|
|
3344
|
-
enumerable: false,
|
|
3345
|
-
writable: true,
|
|
3346
|
-
value: this.connectionParameters.password
|
|
3347
|
-
});
|
|
3348
|
-
this.replication = this.connectionParameters.replication;
|
|
3349
|
-
const c = config || {};
|
|
3350
|
-
if (c.Promise) byoPromiseDeprecationNotice();
|
|
3351
|
-
this._Promise = c.Promise || global.Promise;
|
|
3352
|
-
this._types = new TypeOverrides(c.types);
|
|
3353
|
-
this._ending = false;
|
|
3354
|
-
this._ended = false;
|
|
3355
|
-
this._connecting = false;
|
|
3356
|
-
this._connected = false;
|
|
3357
|
-
this._connectionError = false;
|
|
3358
|
-
this._queryable = true;
|
|
3359
|
-
this._activeQuery = null;
|
|
3360
|
-
this.enableChannelBinding = Boolean(c.enableChannelBinding);
|
|
3361
|
-
this.connection = c.connection || new Connection({
|
|
3362
|
-
stream: c.stream,
|
|
3363
|
-
ssl: this.connectionParameters.ssl,
|
|
3364
|
-
keepAlive: c.keepAlive || false,
|
|
3365
|
-
keepAliveInitialDelayMillis: c.keepAliveInitialDelayMillis || 0,
|
|
3366
|
-
encoding: this.connectionParameters.client_encoding || "utf8"
|
|
3367
|
-
});
|
|
3368
|
-
this._queryQueue = [];
|
|
3369
|
-
this.binary = c.binary || defaults.binary;
|
|
3370
|
-
this.processID = null;
|
|
3371
|
-
this.secretKey = null;
|
|
3372
|
-
this.ssl = this.connectionParameters.ssl || false;
|
|
3373
|
-
if (this.ssl && this.ssl.key) Object.defineProperty(this.ssl, "key", { enumerable: false });
|
|
3374
|
-
this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0;
|
|
3375
|
-
}
|
|
3376
|
-
get activeQuery() {
|
|
3377
|
-
activeQueryDeprecationNotice();
|
|
3378
|
-
return this._activeQuery;
|
|
3379
|
-
}
|
|
3380
|
-
set activeQuery(val) {
|
|
3381
|
-
activeQueryDeprecationNotice();
|
|
3382
|
-
this._activeQuery = val;
|
|
3383
|
-
}
|
|
3384
|
-
_getActiveQuery() {
|
|
3385
|
-
return this._activeQuery;
|
|
3386
|
-
}
|
|
3387
|
-
_errorAllQueries(err) {
|
|
3388
|
-
const enqueueError = (query) => {
|
|
3389
|
-
process.nextTick(() => {
|
|
3390
|
-
query.handleError(err, this.connection);
|
|
3391
|
-
});
|
|
3392
|
-
};
|
|
3393
|
-
const activeQuery = this._getActiveQuery();
|
|
3394
|
-
if (activeQuery) {
|
|
3395
|
-
enqueueError(activeQuery);
|
|
3396
|
-
this._activeQuery = null;
|
|
3397
|
-
}
|
|
3398
|
-
this._queryQueue.forEach(enqueueError);
|
|
3399
|
-
this._queryQueue.length = 0;
|
|
3400
|
-
}
|
|
3401
|
-
_connect(callback) {
|
|
3402
|
-
const self = this;
|
|
3403
|
-
const con = this.connection;
|
|
3404
|
-
this._connectionCallback = callback;
|
|
3405
|
-
if (this._connecting || this._connected) {
|
|
3406
|
-
const err = /* @__PURE__ */ new Error("Client has already been connected. You cannot reuse a client.");
|
|
3407
|
-
process.nextTick(() => {
|
|
3408
|
-
callback(err);
|
|
3409
|
-
});
|
|
3410
|
-
return;
|
|
3411
|
-
}
|
|
3412
|
-
this._connecting = true;
|
|
3413
|
-
if (this._connectionTimeoutMillis > 0) {
|
|
3414
|
-
this.connectionTimeoutHandle = setTimeout(() => {
|
|
3415
|
-
con._ending = true;
|
|
3416
|
-
con.stream.destroy(/* @__PURE__ */ new Error("timeout expired"));
|
|
3417
|
-
}, this._connectionTimeoutMillis);
|
|
3418
|
-
if (this.connectionTimeoutHandle.unref) this.connectionTimeoutHandle.unref();
|
|
3419
|
-
}
|
|
3420
|
-
if (this.host && this.host.indexOf("/") === 0) con.connect(this.host + "/.s.PGSQL." + this.port);
|
|
3421
|
-
else con.connect(this.port, this.host);
|
|
3422
|
-
con.on("connect", function() {
|
|
3423
|
-
if (self.ssl) con.requestSsl();
|
|
3424
|
-
else con.startup(self.getStartupConf());
|
|
3425
|
-
});
|
|
3426
|
-
con.on("sslconnect", function() {
|
|
3427
|
-
con.startup(self.getStartupConf());
|
|
3428
|
-
});
|
|
3429
|
-
this._attachListeners(con);
|
|
3430
|
-
con.once("end", () => {
|
|
3431
|
-
const error = this._ending ? /* @__PURE__ */ new Error("Connection terminated") : /* @__PURE__ */ new Error("Connection terminated unexpectedly");
|
|
3432
|
-
clearTimeout(this.connectionTimeoutHandle);
|
|
3433
|
-
this._errorAllQueries(error);
|
|
3434
|
-
this._ended = true;
|
|
3435
|
-
if (!this._ending) {
|
|
3436
|
-
if (this._connecting && !this._connectionError) if (this._connectionCallback) this._connectionCallback(error);
|
|
3437
|
-
else this._handleErrorEvent(error);
|
|
3438
|
-
else if (!this._connectionError) this._handleErrorEvent(error);
|
|
3439
|
-
}
|
|
3440
|
-
process.nextTick(() => {
|
|
3441
|
-
this.emit("end");
|
|
3442
|
-
});
|
|
3443
|
-
});
|
|
3444
|
-
}
|
|
3445
|
-
connect(callback) {
|
|
3446
|
-
if (callback) {
|
|
3447
|
-
this._connect(callback);
|
|
3448
|
-
return;
|
|
3449
|
-
}
|
|
3450
|
-
return new this._Promise((resolve, reject) => {
|
|
3451
|
-
this._connect((error) => {
|
|
3452
|
-
if (error) reject(error);
|
|
3453
|
-
else resolve(this);
|
|
3454
|
-
});
|
|
3455
|
-
});
|
|
3456
|
-
}
|
|
3457
|
-
_attachListeners(con) {
|
|
3458
|
-
con.on("authenticationCleartextPassword", this._handleAuthCleartextPassword.bind(this));
|
|
3459
|
-
con.on("authenticationMD5Password", this._handleAuthMD5Password.bind(this));
|
|
3460
|
-
con.on("authenticationSASL", this._handleAuthSASL.bind(this));
|
|
3461
|
-
con.on("authenticationSASLContinue", this._handleAuthSASLContinue.bind(this));
|
|
3462
|
-
con.on("authenticationSASLFinal", this._handleAuthSASLFinal.bind(this));
|
|
3463
|
-
con.on("backendKeyData", this._handleBackendKeyData.bind(this));
|
|
3464
|
-
con.on("error", this._handleErrorEvent.bind(this));
|
|
3465
|
-
con.on("errorMessage", this._handleErrorMessage.bind(this));
|
|
3466
|
-
con.on("readyForQuery", this._handleReadyForQuery.bind(this));
|
|
3467
|
-
con.on("notice", this._handleNotice.bind(this));
|
|
3468
|
-
con.on("rowDescription", this._handleRowDescription.bind(this));
|
|
3469
|
-
con.on("dataRow", this._handleDataRow.bind(this));
|
|
3470
|
-
con.on("portalSuspended", this._handlePortalSuspended.bind(this));
|
|
3471
|
-
con.on("emptyQuery", this._handleEmptyQuery.bind(this));
|
|
3472
|
-
con.on("commandComplete", this._handleCommandComplete.bind(this));
|
|
3473
|
-
con.on("parseComplete", this._handleParseComplete.bind(this));
|
|
3474
|
-
con.on("copyInResponse", this._handleCopyInResponse.bind(this));
|
|
3475
|
-
con.on("copyData", this._handleCopyData.bind(this));
|
|
3476
|
-
con.on("notification", this._handleNotification.bind(this));
|
|
3477
|
-
}
|
|
3478
|
-
_getPassword(cb) {
|
|
3479
|
-
const con = this.connection;
|
|
3480
|
-
if (typeof this.password === "function") this._Promise.resolve().then(() => this.password(this.connectionParameters)).then((pass) => {
|
|
3481
|
-
if (pass !== void 0) {
|
|
3482
|
-
if (typeof pass !== "string") {
|
|
3483
|
-
con.emit("error", /* @__PURE__ */ new TypeError("Password must be a string"));
|
|
3484
|
-
return;
|
|
3485
|
-
}
|
|
3486
|
-
this.connectionParameters.password = this.password = pass;
|
|
3487
|
-
} else this.connectionParameters.password = this.password = null;
|
|
3488
|
-
cb();
|
|
3489
|
-
}).catch((err) => {
|
|
3490
|
-
con.emit("error", err);
|
|
3491
|
-
});
|
|
3492
|
-
else if (this.password !== null) cb();
|
|
3493
|
-
else try {
|
|
3494
|
-
require_lib$1()(this.connectionParameters, (pass) => {
|
|
3495
|
-
if (void 0 !== pass) {
|
|
3496
|
-
pgPassDeprecationNotice();
|
|
3497
|
-
this.connectionParameters.password = this.password = pass;
|
|
3498
|
-
}
|
|
3499
|
-
cb();
|
|
3500
|
-
});
|
|
3501
|
-
} catch (e) {
|
|
3502
|
-
this.emit("error", e);
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
_handleAuthCleartextPassword(msg) {
|
|
3506
|
-
this._getPassword(() => {
|
|
3507
|
-
this.connection.password(this.password);
|
|
3508
|
-
});
|
|
3509
|
-
}
|
|
3510
|
-
_handleAuthMD5Password(msg) {
|
|
3511
|
-
this._getPassword(async () => {
|
|
3512
|
-
try {
|
|
3513
|
-
const hashedPassword = await crypto.postgresMd5PasswordHash(this.user, this.password, msg.salt);
|
|
3514
|
-
this.connection.password(hashedPassword);
|
|
3515
|
-
} catch (e) {
|
|
3516
|
-
this.emit("error", e);
|
|
3517
|
-
}
|
|
3518
|
-
});
|
|
3519
|
-
}
|
|
3520
|
-
_handleAuthSASL(msg) {
|
|
3521
|
-
this._getPassword(() => {
|
|
3522
|
-
try {
|
|
3523
|
-
this.saslSession = sasl.startSession(msg.mechanisms, this.enableChannelBinding && this.connection.stream);
|
|
3524
|
-
this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
|
|
3525
|
-
} catch (err) {
|
|
3526
|
-
this.connection.emit("error", err);
|
|
3527
|
-
}
|
|
3528
|
-
});
|
|
3529
|
-
}
|
|
3530
|
-
async _handleAuthSASLContinue(msg) {
|
|
3531
|
-
try {
|
|
3532
|
-
await sasl.continueSession(this.saslSession, this.password, msg.data, this.enableChannelBinding && this.connection.stream);
|
|
3533
|
-
this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
|
|
3534
|
-
} catch (err) {
|
|
3535
|
-
this.connection.emit("error", err);
|
|
3536
|
-
}
|
|
3537
|
-
}
|
|
3538
|
-
_handleAuthSASLFinal(msg) {
|
|
3539
|
-
try {
|
|
3540
|
-
sasl.finalizeSession(this.saslSession, msg.data);
|
|
3541
|
-
this.saslSession = null;
|
|
3542
|
-
} catch (err) {
|
|
3543
|
-
this.connection.emit("error", err);
|
|
3544
|
-
}
|
|
3545
|
-
}
|
|
3546
|
-
_handleBackendKeyData(msg) {
|
|
3547
|
-
this.processID = msg.processID;
|
|
3548
|
-
this.secretKey = msg.secretKey;
|
|
3549
|
-
}
|
|
3550
|
-
_handleReadyForQuery(msg) {
|
|
3551
|
-
if (this._connecting) {
|
|
3552
|
-
this._connecting = false;
|
|
3553
|
-
this._connected = true;
|
|
3554
|
-
clearTimeout(this.connectionTimeoutHandle);
|
|
3555
|
-
if (this._connectionCallback) {
|
|
3556
|
-
this._connectionCallback(null, this);
|
|
3557
|
-
this._connectionCallback = null;
|
|
3558
|
-
}
|
|
3559
|
-
this.emit("connect");
|
|
3560
|
-
}
|
|
3561
|
-
const activeQuery = this._getActiveQuery();
|
|
3562
|
-
this._activeQuery = null;
|
|
3563
|
-
this.readyForQuery = true;
|
|
3564
|
-
if (activeQuery) activeQuery.handleReadyForQuery(this.connection);
|
|
3565
|
-
this._pulseQueryQueue();
|
|
3566
|
-
}
|
|
3567
|
-
_handleErrorWhileConnecting(err) {
|
|
3568
|
-
if (this._connectionError) return;
|
|
3569
|
-
this._connectionError = true;
|
|
3570
|
-
clearTimeout(this.connectionTimeoutHandle);
|
|
3571
|
-
if (this._connectionCallback) return this._connectionCallback(err);
|
|
3572
|
-
this.emit("error", err);
|
|
3573
|
-
}
|
|
3574
|
-
_handleErrorEvent(err) {
|
|
3575
|
-
if (this._connecting) return this._handleErrorWhileConnecting(err);
|
|
3576
|
-
this._queryable = false;
|
|
3577
|
-
this._errorAllQueries(err);
|
|
3578
|
-
this.emit("error", err);
|
|
3579
|
-
}
|
|
3580
|
-
_handleErrorMessage(msg) {
|
|
3581
|
-
if (this._connecting) return this._handleErrorWhileConnecting(msg);
|
|
3582
|
-
const activeQuery = this._getActiveQuery();
|
|
3583
|
-
if (!activeQuery) {
|
|
3584
|
-
this._handleErrorEvent(msg);
|
|
3585
|
-
return;
|
|
3586
|
-
}
|
|
3587
|
-
this._activeQuery = null;
|
|
3588
|
-
activeQuery.handleError(msg, this.connection);
|
|
3589
|
-
}
|
|
3590
|
-
_handleRowDescription(msg) {
|
|
3591
|
-
const activeQuery = this._getActiveQuery();
|
|
3592
|
-
if (activeQuery == null) {
|
|
3593
|
-
const error = /* @__PURE__ */ new Error("Received unexpected rowDescription message from backend.");
|
|
3594
|
-
this._handleErrorEvent(error);
|
|
3595
|
-
return;
|
|
3596
|
-
}
|
|
3597
|
-
activeQuery.handleRowDescription(msg);
|
|
3598
|
-
}
|
|
3599
|
-
_handleDataRow(msg) {
|
|
3600
|
-
const activeQuery = this._getActiveQuery();
|
|
3601
|
-
if (activeQuery == null) {
|
|
3602
|
-
const error = /* @__PURE__ */ new Error("Received unexpected dataRow message from backend.");
|
|
3603
|
-
this._handleErrorEvent(error);
|
|
3604
|
-
return;
|
|
3605
|
-
}
|
|
3606
|
-
activeQuery.handleDataRow(msg);
|
|
3607
|
-
}
|
|
3608
|
-
_handlePortalSuspended(msg) {
|
|
3609
|
-
const activeQuery = this._getActiveQuery();
|
|
3610
|
-
if (activeQuery == null) {
|
|
3611
|
-
const error = /* @__PURE__ */ new Error("Received unexpected portalSuspended message from backend.");
|
|
3612
|
-
this._handleErrorEvent(error);
|
|
3613
|
-
return;
|
|
3614
|
-
}
|
|
3615
|
-
activeQuery.handlePortalSuspended(this.connection);
|
|
3616
|
-
}
|
|
3617
|
-
_handleEmptyQuery(msg) {
|
|
3618
|
-
const activeQuery = this._getActiveQuery();
|
|
3619
|
-
if (activeQuery == null) {
|
|
3620
|
-
const error = /* @__PURE__ */ new Error("Received unexpected emptyQuery message from backend.");
|
|
3621
|
-
this._handleErrorEvent(error);
|
|
3622
|
-
return;
|
|
3623
|
-
}
|
|
3624
|
-
activeQuery.handleEmptyQuery(this.connection);
|
|
3625
|
-
}
|
|
3626
|
-
_handleCommandComplete(msg) {
|
|
3627
|
-
const activeQuery = this._getActiveQuery();
|
|
3628
|
-
if (activeQuery == null) {
|
|
3629
|
-
const error = /* @__PURE__ */ new Error("Received unexpected commandComplete message from backend.");
|
|
3630
|
-
this._handleErrorEvent(error);
|
|
3631
|
-
return;
|
|
3632
|
-
}
|
|
3633
|
-
activeQuery.handleCommandComplete(msg, this.connection);
|
|
3634
|
-
}
|
|
3635
|
-
_handleParseComplete() {
|
|
3636
|
-
const activeQuery = this._getActiveQuery();
|
|
3637
|
-
if (activeQuery == null) {
|
|
3638
|
-
const error = /* @__PURE__ */ new Error("Received unexpected parseComplete message from backend.");
|
|
3639
|
-
this._handleErrorEvent(error);
|
|
3640
|
-
return;
|
|
3641
|
-
}
|
|
3642
|
-
if (activeQuery.name) this.connection.parsedStatements[activeQuery.name] = activeQuery.text;
|
|
3643
|
-
}
|
|
3644
|
-
_handleCopyInResponse(msg) {
|
|
3645
|
-
const activeQuery = this._getActiveQuery();
|
|
3646
|
-
if (activeQuery == null) {
|
|
3647
|
-
const error = /* @__PURE__ */ new Error("Received unexpected copyInResponse message from backend.");
|
|
3648
|
-
this._handleErrorEvent(error);
|
|
3649
|
-
return;
|
|
3650
|
-
}
|
|
3651
|
-
activeQuery.handleCopyInResponse(this.connection);
|
|
3652
|
-
}
|
|
3653
|
-
_handleCopyData(msg) {
|
|
3654
|
-
const activeQuery = this._getActiveQuery();
|
|
3655
|
-
if (activeQuery == null) {
|
|
3656
|
-
const error = /* @__PURE__ */ new Error("Received unexpected copyData message from backend.");
|
|
3657
|
-
this._handleErrorEvent(error);
|
|
3658
|
-
return;
|
|
3659
|
-
}
|
|
3660
|
-
activeQuery.handleCopyData(msg, this.connection);
|
|
3661
|
-
}
|
|
3662
|
-
_handleNotification(msg) {
|
|
3663
|
-
this.emit("notification", msg);
|
|
3664
|
-
}
|
|
3665
|
-
_handleNotice(msg) {
|
|
3666
|
-
this.emit("notice", msg);
|
|
3667
|
-
}
|
|
3668
|
-
getStartupConf() {
|
|
3669
|
-
const params = this.connectionParameters;
|
|
3670
|
-
const data = {
|
|
3671
|
-
user: params.user,
|
|
3672
|
-
database: params.database
|
|
3673
|
-
};
|
|
3674
|
-
const appName = params.application_name || params.fallback_application_name;
|
|
3675
|
-
if (appName) data.application_name = appName;
|
|
3676
|
-
if (params.replication) data.replication = "" + params.replication;
|
|
3677
|
-
if (params.statement_timeout) data.statement_timeout = String(parseInt(params.statement_timeout, 10));
|
|
3678
|
-
if (params.lock_timeout) data.lock_timeout = String(parseInt(params.lock_timeout, 10));
|
|
3679
|
-
if (params.idle_in_transaction_session_timeout) data.idle_in_transaction_session_timeout = String(parseInt(params.idle_in_transaction_session_timeout, 10));
|
|
3680
|
-
if (params.options) data.options = params.options;
|
|
3681
|
-
return data;
|
|
3682
|
-
}
|
|
3683
|
-
cancel(client, query) {
|
|
3684
|
-
if (client.activeQuery === query) {
|
|
3685
|
-
const con = this.connection;
|
|
3686
|
-
if (this.host && this.host.indexOf("/") === 0) con.connect(this.host + "/.s.PGSQL." + this.port);
|
|
3687
|
-
else con.connect(this.port, this.host);
|
|
3688
|
-
con.on("connect", function() {
|
|
3689
|
-
con.cancel(client.processID, client.secretKey);
|
|
3690
|
-
});
|
|
3691
|
-
} else if (client._queryQueue.indexOf(query) !== -1) client._queryQueue.splice(client._queryQueue.indexOf(query), 1);
|
|
3692
|
-
}
|
|
3693
|
-
setTypeParser(oid, format, parseFn) {
|
|
3694
|
-
return this._types.setTypeParser(oid, format, parseFn);
|
|
3695
|
-
}
|
|
3696
|
-
getTypeParser(oid, format) {
|
|
3697
|
-
return this._types.getTypeParser(oid, format);
|
|
3698
|
-
}
|
|
3699
|
-
escapeIdentifier(str) {
|
|
3700
|
-
return utils.escapeIdentifier(str);
|
|
3701
|
-
}
|
|
3702
|
-
escapeLiteral(str) {
|
|
3703
|
-
return utils.escapeLiteral(str);
|
|
3704
|
-
}
|
|
3705
|
-
_pulseQueryQueue() {
|
|
3706
|
-
if (this.readyForQuery === true) {
|
|
3707
|
-
this._activeQuery = this._queryQueue.shift();
|
|
3708
|
-
const activeQuery = this._getActiveQuery();
|
|
3709
|
-
if (activeQuery) {
|
|
3710
|
-
this.readyForQuery = false;
|
|
3711
|
-
this.hasExecuted = true;
|
|
3712
|
-
const queryError = activeQuery.submit(this.connection);
|
|
3713
|
-
if (queryError) process.nextTick(() => {
|
|
3714
|
-
activeQuery.handleError(queryError, this.connection);
|
|
3715
|
-
this.readyForQuery = true;
|
|
3716
|
-
this._pulseQueryQueue();
|
|
3717
|
-
});
|
|
3718
|
-
} else if (this.hasExecuted) {
|
|
3719
|
-
this._activeQuery = null;
|
|
3720
|
-
this.emit("drain");
|
|
3721
|
-
}
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
query(config, values, callback) {
|
|
3725
|
-
let query;
|
|
3726
|
-
let result;
|
|
3727
|
-
let readTimeout;
|
|
3728
|
-
let readTimeoutTimer;
|
|
3729
|
-
let queryCallback;
|
|
3730
|
-
if (config === null || config === void 0) throw new TypeError("Client was passed a null or undefined query");
|
|
3731
|
-
else if (typeof config.submit === "function") {
|
|
3732
|
-
readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
|
|
3733
|
-
result = query = config;
|
|
3734
|
-
if (!query.callback) {
|
|
3735
|
-
if (typeof values === "function") query.callback = values;
|
|
3736
|
-
else if (callback) query.callback = callback;
|
|
3737
|
-
}
|
|
3738
|
-
} else {
|
|
3739
|
-
readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
|
|
3740
|
-
query = new Query(config, values, callback);
|
|
3741
|
-
if (!query.callback) result = new this._Promise((resolve, reject) => {
|
|
3742
|
-
query.callback = (err, res) => err ? reject(err) : resolve(res);
|
|
3743
|
-
}).catch((err) => {
|
|
3744
|
-
Error.captureStackTrace(err);
|
|
3745
|
-
throw err;
|
|
3746
|
-
});
|
|
3747
|
-
}
|
|
3748
|
-
if (readTimeout) {
|
|
3749
|
-
queryCallback = query.callback || (() => {});
|
|
3750
|
-
readTimeoutTimer = setTimeout(() => {
|
|
3751
|
-
const error = /* @__PURE__ */ new Error("Query read timeout");
|
|
3752
|
-
process.nextTick(() => {
|
|
3753
|
-
query.handleError(error, this.connection);
|
|
3754
|
-
});
|
|
3755
|
-
queryCallback(error);
|
|
3756
|
-
query.callback = () => {};
|
|
3757
|
-
const index = this._queryQueue.indexOf(query);
|
|
3758
|
-
if (index > -1) this._queryQueue.splice(index, 1);
|
|
3759
|
-
this._pulseQueryQueue();
|
|
3760
|
-
}, readTimeout);
|
|
3761
|
-
query.callback = (err, res) => {
|
|
3762
|
-
clearTimeout(readTimeoutTimer);
|
|
3763
|
-
queryCallback(err, res);
|
|
3764
|
-
};
|
|
3765
|
-
}
|
|
3766
|
-
if (this.binary && !query.binary) query.binary = true;
|
|
3767
|
-
if (query._result && !query._result._types) query._result._types = this._types;
|
|
3768
|
-
if (!this._queryable) {
|
|
3769
|
-
process.nextTick(() => {
|
|
3770
|
-
query.handleError(/* @__PURE__ */ new Error("Client has encountered a connection error and is not queryable"), this.connection);
|
|
3771
|
-
});
|
|
3772
|
-
return result;
|
|
3773
|
-
}
|
|
3774
|
-
if (this._ending) {
|
|
3775
|
-
process.nextTick(() => {
|
|
3776
|
-
query.handleError(/* @__PURE__ */ new Error("Client was closed and is not queryable"), this.connection);
|
|
3777
|
-
});
|
|
3778
|
-
return result;
|
|
3779
|
-
}
|
|
3780
|
-
if (this._queryQueue.length > 0) queryQueueLengthDeprecationNotice();
|
|
3781
|
-
this._queryQueue.push(query);
|
|
3782
|
-
this._pulseQueryQueue();
|
|
3783
|
-
return result;
|
|
3784
|
-
}
|
|
3785
|
-
ref() {
|
|
3786
|
-
this.connection.ref();
|
|
3787
|
-
}
|
|
3788
|
-
unref() {
|
|
3789
|
-
this.connection.unref();
|
|
3790
|
-
}
|
|
3791
|
-
end(cb) {
|
|
3792
|
-
this._ending = true;
|
|
3793
|
-
if (!this.connection._connecting || this._ended) if (cb) cb();
|
|
3794
|
-
else return this._Promise.resolve();
|
|
3795
|
-
if (this._getActiveQuery() || !this._queryable) this.connection.stream.destroy();
|
|
3796
|
-
else this.connection.end();
|
|
3797
|
-
if (cb) this.connection.once("end", cb);
|
|
3798
|
-
else return new this._Promise((resolve) => {
|
|
3799
|
-
this.connection.once("end", resolve);
|
|
3800
|
-
});
|
|
3801
|
-
}
|
|
3802
|
-
get queryQueue() {
|
|
3803
|
-
queryQueueDeprecationNotice();
|
|
3804
|
-
return this._queryQueue;
|
|
3805
|
-
}
|
|
3806
|
-
};
|
|
3807
|
-
Client.Query = Query;
|
|
3808
|
-
module.exports = Client;
|
|
3809
|
-
}));
|
|
3810
|
-
//#endregion
|
|
3811
|
-
//#region node_modules/pg-pool/index.js
|
|
3812
|
-
var require_pg_pool = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3813
|
-
const EventEmitter$2 = __require("events").EventEmitter;
|
|
3814
|
-
const NOOP = function() {};
|
|
3815
|
-
const removeWhere = (list, predicate) => {
|
|
3816
|
-
const i = list.findIndex(predicate);
|
|
3817
|
-
return i === -1 ? void 0 : list.splice(i, 1)[0];
|
|
3818
|
-
};
|
|
3819
|
-
var IdleItem = class {
|
|
3820
|
-
constructor(client, idleListener, timeoutId) {
|
|
3821
|
-
this.client = client;
|
|
3822
|
-
this.idleListener = idleListener;
|
|
3823
|
-
this.timeoutId = timeoutId;
|
|
3824
|
-
}
|
|
3825
|
-
};
|
|
3826
|
-
var PendingItem = class {
|
|
3827
|
-
constructor(callback) {
|
|
3828
|
-
this.callback = callback;
|
|
3829
|
-
}
|
|
3830
|
-
};
|
|
3831
|
-
function throwOnDoubleRelease() {
|
|
3832
|
-
throw new Error("Release called on client which has already been released to the pool.");
|
|
3833
|
-
}
|
|
3834
|
-
function promisify(Promise, callback) {
|
|
3835
|
-
if (callback) return {
|
|
3836
|
-
callback,
|
|
3837
|
-
result: void 0
|
|
3838
|
-
};
|
|
3839
|
-
let rej;
|
|
3840
|
-
let res;
|
|
3841
|
-
const cb = function(err, client) {
|
|
3842
|
-
err ? rej(err) : res(client);
|
|
3843
|
-
};
|
|
3844
|
-
return {
|
|
3845
|
-
callback: cb,
|
|
3846
|
-
result: new Promise(function(resolve, reject) {
|
|
3847
|
-
res = resolve;
|
|
3848
|
-
rej = reject;
|
|
3849
|
-
}).catch((err) => {
|
|
3850
|
-
Error.captureStackTrace(err);
|
|
3851
|
-
throw err;
|
|
3852
|
-
})
|
|
3853
|
-
};
|
|
3854
|
-
}
|
|
3855
|
-
function makeIdleListener(pool, client) {
|
|
3856
|
-
return function idleListener(err) {
|
|
3857
|
-
err.client = client;
|
|
3858
|
-
client.removeListener("error", idleListener);
|
|
3859
|
-
client.on("error", () => {
|
|
3860
|
-
pool.log("additional client error after disconnection due to error", err);
|
|
3861
|
-
});
|
|
3862
|
-
pool._remove(client);
|
|
3863
|
-
pool.emit("error", err, client);
|
|
3864
|
-
};
|
|
3865
|
-
}
|
|
3866
|
-
var Pool = class extends EventEmitter$2 {
|
|
3867
|
-
constructor(options, Client) {
|
|
3868
|
-
super();
|
|
3869
|
-
this.options = Object.assign({}, options);
|
|
3870
|
-
if (options != null && "password" in options) Object.defineProperty(this.options, "password", {
|
|
3871
|
-
configurable: true,
|
|
3872
|
-
enumerable: false,
|
|
3873
|
-
writable: true,
|
|
3874
|
-
value: options.password
|
|
3875
|
-
});
|
|
3876
|
-
if (options != null && options.ssl && options.ssl.key) Object.defineProperty(this.options.ssl, "key", { enumerable: false });
|
|
3877
|
-
this.options.max = this.options.max || this.options.poolSize || 10;
|
|
3878
|
-
this.options.min = this.options.min || 0;
|
|
3879
|
-
this.options.maxUses = this.options.maxUses || Infinity;
|
|
3880
|
-
this.options.allowExitOnIdle = this.options.allowExitOnIdle || false;
|
|
3881
|
-
this.options.maxLifetimeSeconds = this.options.maxLifetimeSeconds || 0;
|
|
3882
|
-
this.log = this.options.log || function() {};
|
|
3883
|
-
this.Client = this.options.Client || Client || require_lib().Client;
|
|
3884
|
-
this.Promise = this.options.Promise || global.Promise;
|
|
3885
|
-
if (typeof this.options.idleTimeoutMillis === "undefined") this.options.idleTimeoutMillis = 1e4;
|
|
3886
|
-
this._clients = [];
|
|
3887
|
-
this._idle = [];
|
|
3888
|
-
this._expired = /* @__PURE__ */ new WeakSet();
|
|
3889
|
-
this._pendingQueue = [];
|
|
3890
|
-
this._endCallback = void 0;
|
|
3891
|
-
this.ending = false;
|
|
3892
|
-
this.ended = false;
|
|
3893
|
-
}
|
|
3894
|
-
_promiseTry(f) {
|
|
3895
|
-
const Promise = this.Promise;
|
|
3896
|
-
if (typeof Promise.try === "function") return Promise.try(f);
|
|
3897
|
-
return new Promise((resolve) => resolve(f()));
|
|
3898
|
-
}
|
|
3899
|
-
_isFull() {
|
|
3900
|
-
return this._clients.length >= this.options.max;
|
|
3901
|
-
}
|
|
3902
|
-
_isAboveMin() {
|
|
3903
|
-
return this._clients.length > this.options.min;
|
|
3904
|
-
}
|
|
3905
|
-
_pulseQueue() {
|
|
3906
|
-
this.log("pulse queue");
|
|
3907
|
-
if (this.ended) {
|
|
3908
|
-
this.log("pulse queue ended");
|
|
3909
|
-
return;
|
|
3910
|
-
}
|
|
3911
|
-
if (this.ending) {
|
|
3912
|
-
this.log("pulse queue on ending");
|
|
3913
|
-
if (this._idle.length) this._idle.slice().map((item) => {
|
|
3914
|
-
this._remove(item.client);
|
|
3915
|
-
});
|
|
3916
|
-
if (!this._clients.length) {
|
|
3917
|
-
this.ended = true;
|
|
3918
|
-
this._endCallback();
|
|
3919
|
-
}
|
|
3920
|
-
return;
|
|
3921
|
-
}
|
|
3922
|
-
if (!this._pendingQueue.length) {
|
|
3923
|
-
this.log("no queued requests");
|
|
3924
|
-
return;
|
|
3925
|
-
}
|
|
3926
|
-
if (!this._idle.length && this._isFull()) return;
|
|
3927
|
-
const pendingItem = this._pendingQueue.shift();
|
|
3928
|
-
if (this._idle.length) {
|
|
3929
|
-
const idleItem = this._idle.pop();
|
|
3930
|
-
clearTimeout(idleItem.timeoutId);
|
|
3931
|
-
const client = idleItem.client;
|
|
3932
|
-
client.ref && client.ref();
|
|
3933
|
-
const idleListener = idleItem.idleListener;
|
|
3934
|
-
return this._acquireClient(client, pendingItem, idleListener, false);
|
|
3935
|
-
}
|
|
3936
|
-
if (!this._isFull()) return this.newClient(pendingItem);
|
|
3937
|
-
throw new Error("unexpected condition");
|
|
3938
|
-
}
|
|
3939
|
-
_remove(client, callback) {
|
|
3940
|
-
const removed = removeWhere(this._idle, (item) => item.client === client);
|
|
3941
|
-
if (removed !== void 0) clearTimeout(removed.timeoutId);
|
|
3942
|
-
this._clients = this._clients.filter((c) => c !== client);
|
|
3943
|
-
const context = this;
|
|
3944
|
-
client.end(() => {
|
|
3945
|
-
context.emit("remove", client);
|
|
3946
|
-
if (typeof callback === "function") callback();
|
|
3947
|
-
});
|
|
3948
|
-
}
|
|
3949
|
-
connect(cb) {
|
|
3950
|
-
if (this.ending) {
|
|
3951
|
-
const err = /* @__PURE__ */ new Error("Cannot use a pool after calling end on the pool");
|
|
3952
|
-
return cb ? cb(err) : this.Promise.reject(err);
|
|
3953
|
-
}
|
|
3954
|
-
const response = promisify(this.Promise, cb);
|
|
3955
|
-
const result = response.result;
|
|
3956
|
-
if (this._isFull() || this._idle.length) {
|
|
3957
|
-
if (this._idle.length) process.nextTick(() => this._pulseQueue());
|
|
3958
|
-
if (!this.options.connectionTimeoutMillis) {
|
|
3959
|
-
this._pendingQueue.push(new PendingItem(response.callback));
|
|
3960
|
-
return result;
|
|
3961
|
-
}
|
|
3962
|
-
const queueCallback = (err, res, done) => {
|
|
3963
|
-
clearTimeout(tid);
|
|
3964
|
-
response.callback(err, res, done);
|
|
3965
|
-
};
|
|
3966
|
-
const pendingItem = new PendingItem(queueCallback);
|
|
3967
|
-
const tid = setTimeout(() => {
|
|
3968
|
-
removeWhere(this._pendingQueue, (i) => i.callback === queueCallback);
|
|
3969
|
-
pendingItem.timedOut = true;
|
|
3970
|
-
response.callback(/* @__PURE__ */ new Error("timeout exceeded when trying to connect"));
|
|
3971
|
-
}, this.options.connectionTimeoutMillis);
|
|
3972
|
-
if (tid.unref) tid.unref();
|
|
3973
|
-
this._pendingQueue.push(pendingItem);
|
|
3974
|
-
return result;
|
|
3975
|
-
}
|
|
3976
|
-
this.newClient(new PendingItem(response.callback));
|
|
3977
|
-
return result;
|
|
3978
|
-
}
|
|
3979
|
-
newClient(pendingItem) {
|
|
3980
|
-
const client = new this.Client(this.options);
|
|
3981
|
-
this._clients.push(client);
|
|
3982
|
-
const idleListener = makeIdleListener(this, client);
|
|
3983
|
-
this.log("checking client timeout");
|
|
3984
|
-
let tid;
|
|
3985
|
-
let timeoutHit = false;
|
|
3986
|
-
if (this.options.connectionTimeoutMillis) tid = setTimeout(() => {
|
|
3987
|
-
if (client.connection) {
|
|
3988
|
-
this.log("ending client due to timeout");
|
|
3989
|
-
timeoutHit = true;
|
|
3990
|
-
client.connection.stream.destroy();
|
|
3991
|
-
} else if (!client.isConnected()) {
|
|
3992
|
-
this.log("ending client due to timeout");
|
|
3993
|
-
timeoutHit = true;
|
|
3994
|
-
client.end();
|
|
3995
|
-
}
|
|
3996
|
-
}, this.options.connectionTimeoutMillis);
|
|
3997
|
-
this.log("connecting new client");
|
|
3998
|
-
client.connect((err) => {
|
|
3999
|
-
if (tid) clearTimeout(tid);
|
|
4000
|
-
client.on("error", idleListener);
|
|
4001
|
-
if (err) {
|
|
4002
|
-
this.log("client failed to connect", err);
|
|
4003
|
-
this._clients = this._clients.filter((c) => c !== client);
|
|
4004
|
-
if (timeoutHit) err = new Error("Connection terminated due to connection timeout", { cause: err });
|
|
4005
|
-
this._pulseQueue();
|
|
4006
|
-
if (!pendingItem.timedOut) pendingItem.callback(err, void 0, NOOP);
|
|
4007
|
-
} else {
|
|
4008
|
-
this.log("new client connected");
|
|
4009
|
-
if (this.options.onConnect) {
|
|
4010
|
-
this._promiseTry(() => this.options.onConnect(client)).then(() => {
|
|
4011
|
-
this._afterConnect(client, pendingItem, idleListener);
|
|
4012
|
-
}, (hookErr) => {
|
|
4013
|
-
this._clients = this._clients.filter((c) => c !== client);
|
|
4014
|
-
client.end(() => {
|
|
4015
|
-
this._pulseQueue();
|
|
4016
|
-
if (!pendingItem.timedOut) pendingItem.callback(hookErr, void 0, NOOP);
|
|
4017
|
-
});
|
|
4018
|
-
});
|
|
4019
|
-
return;
|
|
4020
|
-
}
|
|
4021
|
-
return this._afterConnect(client, pendingItem, idleListener);
|
|
4022
|
-
}
|
|
4023
|
-
});
|
|
4024
|
-
}
|
|
4025
|
-
_afterConnect(client, pendingItem, idleListener) {
|
|
4026
|
-
if (this.options.maxLifetimeSeconds !== 0) {
|
|
4027
|
-
const maxLifetimeTimeout = setTimeout(() => {
|
|
4028
|
-
this.log("ending client due to expired lifetime");
|
|
4029
|
-
this._expired.add(client);
|
|
4030
|
-
if (this._idle.findIndex((idleItem) => idleItem.client === client) !== -1) this._acquireClient(client, new PendingItem((err, client, clientRelease) => clientRelease()), idleListener, false);
|
|
4031
|
-
}, this.options.maxLifetimeSeconds * 1e3);
|
|
4032
|
-
maxLifetimeTimeout.unref();
|
|
4033
|
-
client.once("end", () => clearTimeout(maxLifetimeTimeout));
|
|
4034
|
-
}
|
|
4035
|
-
return this._acquireClient(client, pendingItem, idleListener, true);
|
|
4036
|
-
}
|
|
4037
|
-
_acquireClient(client, pendingItem, idleListener, isNew) {
|
|
4038
|
-
if (isNew) this.emit("connect", client);
|
|
4039
|
-
this.emit("acquire", client);
|
|
4040
|
-
client.release = this._releaseOnce(client, idleListener);
|
|
4041
|
-
client.removeListener("error", idleListener);
|
|
4042
|
-
if (!pendingItem.timedOut) if (isNew && this.options.verify) this.options.verify(client, (err) => {
|
|
4043
|
-
if (err) {
|
|
4044
|
-
client.release(err);
|
|
4045
|
-
return pendingItem.callback(err, void 0, NOOP);
|
|
4046
|
-
}
|
|
4047
|
-
pendingItem.callback(void 0, client, client.release);
|
|
4048
|
-
});
|
|
4049
|
-
else pendingItem.callback(void 0, client, client.release);
|
|
4050
|
-
else if (isNew && this.options.verify) this.options.verify(client, client.release);
|
|
4051
|
-
else client.release();
|
|
4052
|
-
}
|
|
4053
|
-
_releaseOnce(client, idleListener) {
|
|
4054
|
-
let released = false;
|
|
4055
|
-
return (err) => {
|
|
4056
|
-
if (released) throwOnDoubleRelease();
|
|
4057
|
-
released = true;
|
|
4058
|
-
this._release(client, idleListener, err);
|
|
4059
|
-
};
|
|
4060
|
-
}
|
|
4061
|
-
_release(client, idleListener, err) {
|
|
4062
|
-
client.on("error", idleListener);
|
|
4063
|
-
client._poolUseCount = (client._poolUseCount || 0) + 1;
|
|
4064
|
-
this.emit("release", err, client);
|
|
4065
|
-
if (err || this.ending || !client._queryable || client._ending || client._poolUseCount >= this.options.maxUses) {
|
|
4066
|
-
if (client._poolUseCount >= this.options.maxUses) this.log("remove expended client");
|
|
4067
|
-
return this._remove(client, this._pulseQueue.bind(this));
|
|
4068
|
-
}
|
|
4069
|
-
if (this._expired.has(client)) {
|
|
4070
|
-
this.log("remove expired client");
|
|
4071
|
-
this._expired.delete(client);
|
|
4072
|
-
return this._remove(client, this._pulseQueue.bind(this));
|
|
4073
|
-
}
|
|
4074
|
-
let tid;
|
|
4075
|
-
if (this.options.idleTimeoutMillis && this._isAboveMin()) {
|
|
4076
|
-
tid = setTimeout(() => {
|
|
4077
|
-
if (this._isAboveMin()) {
|
|
4078
|
-
this.log("remove idle client");
|
|
4079
|
-
this._remove(client, this._pulseQueue.bind(this));
|
|
4080
|
-
}
|
|
4081
|
-
}, this.options.idleTimeoutMillis);
|
|
4082
|
-
if (this.options.allowExitOnIdle) tid.unref();
|
|
4083
|
-
}
|
|
4084
|
-
if (this.options.allowExitOnIdle) client.unref();
|
|
4085
|
-
this._idle.push(new IdleItem(client, idleListener, tid));
|
|
4086
|
-
this._pulseQueue();
|
|
4087
|
-
}
|
|
4088
|
-
query(text, values, cb) {
|
|
4089
|
-
if (typeof text === "function") {
|
|
4090
|
-
const response = promisify(this.Promise, text);
|
|
4091
|
-
setImmediate(function() {
|
|
4092
|
-
return response.callback(/* @__PURE__ */ new Error("Passing a function as the first parameter to pool.query is not supported"));
|
|
4093
|
-
});
|
|
4094
|
-
return response.result;
|
|
4095
|
-
}
|
|
4096
|
-
if (typeof values === "function") {
|
|
4097
|
-
cb = values;
|
|
4098
|
-
values = void 0;
|
|
4099
|
-
}
|
|
4100
|
-
const response = promisify(this.Promise, cb);
|
|
4101
|
-
cb = response.callback;
|
|
4102
|
-
this.connect((err, client) => {
|
|
4103
|
-
if (err) return cb(err);
|
|
4104
|
-
let clientReleased = false;
|
|
4105
|
-
const onError = (err) => {
|
|
4106
|
-
if (clientReleased) return;
|
|
4107
|
-
clientReleased = true;
|
|
4108
|
-
client.release(err);
|
|
4109
|
-
cb(err);
|
|
4110
|
-
};
|
|
4111
|
-
client.once("error", onError);
|
|
4112
|
-
this.log("dispatching query");
|
|
4113
|
-
try {
|
|
4114
|
-
client.query(text, values, (err, res) => {
|
|
4115
|
-
this.log("query dispatched");
|
|
4116
|
-
client.removeListener("error", onError);
|
|
4117
|
-
if (clientReleased) return;
|
|
4118
|
-
clientReleased = true;
|
|
4119
|
-
client.release(err);
|
|
4120
|
-
if (err) return cb(err);
|
|
4121
|
-
return cb(void 0, res);
|
|
4122
|
-
});
|
|
4123
|
-
} catch (err) {
|
|
4124
|
-
client.release(err);
|
|
4125
|
-
return cb(err);
|
|
4126
|
-
}
|
|
4127
|
-
});
|
|
4128
|
-
return response.result;
|
|
4129
|
-
}
|
|
4130
|
-
end(cb) {
|
|
4131
|
-
this.log("ending");
|
|
4132
|
-
if (this.ending) {
|
|
4133
|
-
const err = /* @__PURE__ */ new Error("Called end on pool more than once");
|
|
4134
|
-
return cb ? cb(err) : this.Promise.reject(err);
|
|
4135
|
-
}
|
|
4136
|
-
this.ending = true;
|
|
4137
|
-
const promised = promisify(this.Promise, cb);
|
|
4138
|
-
this._endCallback = promised.callback;
|
|
4139
|
-
this._pulseQueue();
|
|
4140
|
-
return promised.result;
|
|
4141
|
-
}
|
|
4142
|
-
get waitingCount() {
|
|
4143
|
-
return this._pendingQueue.length;
|
|
4144
|
-
}
|
|
4145
|
-
get idleCount() {
|
|
4146
|
-
return this._idle.length;
|
|
4147
|
-
}
|
|
4148
|
-
get expiredCount() {
|
|
4149
|
-
return this._clients.reduce((acc, client) => acc + (this._expired.has(client) ? 1 : 0), 0);
|
|
4150
|
-
}
|
|
4151
|
-
get totalCount() {
|
|
4152
|
-
return this._clients.length;
|
|
4153
|
-
}
|
|
4154
|
-
};
|
|
4155
|
-
module.exports = Pool;
|
|
4156
|
-
}));
|
|
4157
|
-
//#endregion
|
|
4158
|
-
//#region node_modules/pg/lib/native/query.js
|
|
4159
|
-
var require_query = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4160
|
-
const EventEmitter$1 = __require("events").EventEmitter;
|
|
4161
|
-
const util$1 = __require("util");
|
|
4162
|
-
const utils = require_utils$1();
|
|
4163
|
-
const NativeQuery = module.exports = function(config, values, callback) {
|
|
4164
|
-
EventEmitter$1.call(this);
|
|
4165
|
-
config = utils.normalizeQueryConfig(config, values, callback);
|
|
4166
|
-
this.text = config.text;
|
|
4167
|
-
this.values = config.values;
|
|
4168
|
-
this.name = config.name;
|
|
4169
|
-
this.queryMode = config.queryMode;
|
|
4170
|
-
this.callback = config.callback;
|
|
4171
|
-
this.state = "new";
|
|
4172
|
-
this._arrayMode = config.rowMode === "array";
|
|
4173
|
-
this._emitRowEvents = false;
|
|
4174
|
-
this.on("newListener", function(event) {
|
|
4175
|
-
if (event === "row") this._emitRowEvents = true;
|
|
4176
|
-
}.bind(this));
|
|
4177
|
-
};
|
|
4178
|
-
util$1.inherits(NativeQuery, EventEmitter$1);
|
|
4179
|
-
const errorFieldMap = {
|
|
4180
|
-
sqlState: "code",
|
|
4181
|
-
statementPosition: "position",
|
|
4182
|
-
messagePrimary: "message",
|
|
4183
|
-
context: "where",
|
|
4184
|
-
schemaName: "schema",
|
|
4185
|
-
tableName: "table",
|
|
4186
|
-
columnName: "column",
|
|
4187
|
-
dataTypeName: "dataType",
|
|
4188
|
-
constraintName: "constraint",
|
|
4189
|
-
sourceFile: "file",
|
|
4190
|
-
sourceLine: "line",
|
|
4191
|
-
sourceFunction: "routine"
|
|
4192
|
-
};
|
|
4193
|
-
NativeQuery.prototype.handleError = function(err) {
|
|
4194
|
-
const fields = this.native.pq.resultErrorFields();
|
|
4195
|
-
if (fields) for (const key in fields) {
|
|
4196
|
-
const normalizedFieldName = errorFieldMap[key] || key;
|
|
4197
|
-
err[normalizedFieldName] = fields[key];
|
|
4198
|
-
}
|
|
4199
|
-
if (this.callback) this.callback(err);
|
|
4200
|
-
else this.emit("error", err);
|
|
4201
|
-
this.state = "error";
|
|
4202
|
-
};
|
|
4203
|
-
NativeQuery.prototype.then = function(onSuccess, onFailure) {
|
|
4204
|
-
return this._getPromise().then(onSuccess, onFailure);
|
|
4205
|
-
};
|
|
4206
|
-
NativeQuery.prototype.catch = function(callback) {
|
|
4207
|
-
return this._getPromise().catch(callback);
|
|
4208
|
-
};
|
|
4209
|
-
NativeQuery.prototype._getPromise = function() {
|
|
4210
|
-
if (this._promise) return this._promise;
|
|
4211
|
-
this._promise = new Promise(function(resolve, reject) {
|
|
4212
|
-
this._once("end", resolve);
|
|
4213
|
-
this._once("error", reject);
|
|
4214
|
-
}.bind(this));
|
|
4215
|
-
return this._promise;
|
|
4216
|
-
};
|
|
4217
|
-
NativeQuery.prototype.submit = function(client) {
|
|
4218
|
-
this.state = "running";
|
|
4219
|
-
const self = this;
|
|
4220
|
-
this.native = client.native;
|
|
4221
|
-
client.native.arrayMode = this._arrayMode;
|
|
4222
|
-
let after = function(err, rows, results) {
|
|
4223
|
-
client.native.arrayMode = false;
|
|
4224
|
-
setImmediate(function() {
|
|
4225
|
-
self.emit("_done");
|
|
4226
|
-
});
|
|
4227
|
-
if (err) return self.handleError(err);
|
|
4228
|
-
if (self._emitRowEvents) if (results.length > 1) rows.forEach((rowOfRows, i) => {
|
|
4229
|
-
rowOfRows.forEach((row) => {
|
|
4230
|
-
self.emit("row", row, results[i]);
|
|
4231
|
-
});
|
|
4232
|
-
});
|
|
4233
|
-
else rows.forEach(function(row) {
|
|
4234
|
-
self.emit("row", row, results);
|
|
4235
|
-
});
|
|
4236
|
-
self.state = "end";
|
|
4237
|
-
self.emit("end", results);
|
|
4238
|
-
if (self.callback) self.callback(null, results);
|
|
4239
|
-
};
|
|
4240
|
-
if (process.domain) after = process.domain.bind(after);
|
|
4241
|
-
if (this.name) {
|
|
4242
|
-
if (this.name.length > 63) {
|
|
4243
|
-
console.error("Warning! Postgres only supports 63 characters for query names.");
|
|
4244
|
-
console.error("You supplied %s (%s)", this.name, this.name.length);
|
|
4245
|
-
console.error("This can cause conflicts and silent errors executing queries");
|
|
4246
|
-
}
|
|
4247
|
-
const values = (this.values || []).map(utils.prepareValue);
|
|
4248
|
-
if (client.namedQueries[this.name]) {
|
|
4249
|
-
if (this.text && client.namedQueries[this.name] !== this.text) {
|
|
4250
|
-
const err = /* @__PURE__ */ new Error(`Prepared statements must be unique - '${this.name}' was used for a different statement`);
|
|
4251
|
-
return after(err);
|
|
4252
|
-
}
|
|
4253
|
-
return client.native.execute(this.name, values, after);
|
|
4254
|
-
}
|
|
4255
|
-
return client.native.prepare(this.name, this.text, values.length, function(err) {
|
|
4256
|
-
if (err) return after(err);
|
|
4257
|
-
client.namedQueries[self.name] = self.text;
|
|
4258
|
-
return self.native.execute(self.name, values, after);
|
|
4259
|
-
});
|
|
4260
|
-
} else if (this.values) {
|
|
4261
|
-
if (!Array.isArray(this.values)) return after(/* @__PURE__ */ new Error("Query values must be an array"));
|
|
4262
|
-
const vals = this.values.map(utils.prepareValue);
|
|
4263
|
-
client.native.query(this.text, vals, after);
|
|
4264
|
-
} else if (this.queryMode === "extended") client.native.query(this.text, [], after);
|
|
4265
|
-
else client.native.query(this.text, after);
|
|
4266
|
-
};
|
|
4267
|
-
}));
|
|
4268
|
-
//#endregion
|
|
4269
|
-
//#region node_modules/pg/lib/native/client.js
|
|
4270
|
-
var require_client = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4271
|
-
const nodeUtils = __require("util");
|
|
4272
|
-
var Native;
|
|
4273
|
-
try {
|
|
4274
|
-
Native = __require("pg-native");
|
|
4275
|
-
} catch (e) {
|
|
4276
|
-
throw e;
|
|
4277
|
-
}
|
|
4278
|
-
const TypeOverrides = require_type_overrides();
|
|
4279
|
-
const EventEmitter = __require("events").EventEmitter;
|
|
4280
|
-
const util = __require("util");
|
|
4281
|
-
const ConnectionParameters = require_connection_parameters();
|
|
4282
|
-
const NativeQuery = require_query();
|
|
4283
|
-
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.");
|
|
4284
|
-
const Client = module.exports = function(config) {
|
|
4285
|
-
EventEmitter.call(this);
|
|
4286
|
-
config = config || {};
|
|
4287
|
-
this._Promise = config.Promise || global.Promise;
|
|
4288
|
-
this._types = new TypeOverrides(config.types);
|
|
4289
|
-
this.native = new Native({ types: this._types });
|
|
4290
|
-
this._queryQueue = [];
|
|
4291
|
-
this._ending = false;
|
|
4292
|
-
this._connecting = false;
|
|
4293
|
-
this._connected = false;
|
|
4294
|
-
this._queryable = true;
|
|
4295
|
-
const cp = this.connectionParameters = new ConnectionParameters(config);
|
|
4296
|
-
if (config.nativeConnectionString) cp.nativeConnectionString = config.nativeConnectionString;
|
|
4297
|
-
this.user = cp.user;
|
|
4298
|
-
Object.defineProperty(this, "password", {
|
|
4299
|
-
configurable: true,
|
|
4300
|
-
enumerable: false,
|
|
4301
|
-
writable: true,
|
|
4302
|
-
value: cp.password
|
|
4303
|
-
});
|
|
4304
|
-
this.database = cp.database;
|
|
4305
|
-
this.host = cp.host;
|
|
4306
|
-
this.port = cp.port;
|
|
4307
|
-
this.namedQueries = {};
|
|
4308
|
-
};
|
|
4309
|
-
Client.Query = NativeQuery;
|
|
4310
|
-
util.inherits(Client, EventEmitter);
|
|
4311
|
-
Client.prototype._errorAllQueries = function(err) {
|
|
4312
|
-
const enqueueError = (query) => {
|
|
4313
|
-
process.nextTick(() => {
|
|
4314
|
-
query.native = this.native;
|
|
4315
|
-
query.handleError(err);
|
|
4316
|
-
});
|
|
4317
|
-
};
|
|
4318
|
-
if (this._hasActiveQuery()) {
|
|
4319
|
-
enqueueError(this._activeQuery);
|
|
4320
|
-
this._activeQuery = null;
|
|
4321
|
-
}
|
|
4322
|
-
this._queryQueue.forEach(enqueueError);
|
|
4323
|
-
this._queryQueue.length = 0;
|
|
4324
|
-
};
|
|
4325
|
-
Client.prototype._connect = function(cb) {
|
|
4326
|
-
const self = this;
|
|
4327
|
-
if (this._connecting) {
|
|
4328
|
-
process.nextTick(() => cb(/* @__PURE__ */ new Error("Client has already been connected. You cannot reuse a client.")));
|
|
4329
|
-
return;
|
|
4330
|
-
}
|
|
4331
|
-
this._connecting = true;
|
|
4332
|
-
this.connectionParameters.getLibpqConnectionString(function(err, conString) {
|
|
4333
|
-
if (self.connectionParameters.nativeConnectionString) conString = self.connectionParameters.nativeConnectionString;
|
|
4334
|
-
if (err) return cb(err);
|
|
4335
|
-
self.native.connect(conString, function(err) {
|
|
4336
|
-
if (err) {
|
|
4337
|
-
self.native.end();
|
|
4338
|
-
return cb(err);
|
|
4339
|
-
}
|
|
4340
|
-
self._connected = true;
|
|
4341
|
-
self.native.on("error", function(err) {
|
|
4342
|
-
self._queryable = false;
|
|
4343
|
-
self._errorAllQueries(err);
|
|
4344
|
-
self.emit("error", err);
|
|
4345
|
-
});
|
|
4346
|
-
self.native.on("notification", function(msg) {
|
|
4347
|
-
self.emit("notification", {
|
|
4348
|
-
channel: msg.relname,
|
|
4349
|
-
payload: msg.extra
|
|
4350
|
-
});
|
|
4351
|
-
});
|
|
4352
|
-
self.emit("connect");
|
|
4353
|
-
self._pulseQueryQueue(true);
|
|
4354
|
-
cb(null, this);
|
|
4355
|
-
});
|
|
4356
|
-
});
|
|
4357
|
-
};
|
|
4358
|
-
Client.prototype.connect = function(callback) {
|
|
4359
|
-
if (callback) {
|
|
4360
|
-
this._connect(callback);
|
|
4361
|
-
return;
|
|
4362
|
-
}
|
|
4363
|
-
return new this._Promise((resolve, reject) => {
|
|
4364
|
-
this._connect((error) => {
|
|
4365
|
-
if (error) reject(error);
|
|
4366
|
-
else resolve(this);
|
|
4367
|
-
});
|
|
4368
|
-
});
|
|
4369
|
-
};
|
|
4370
|
-
Client.prototype.query = function(config, values, callback) {
|
|
4371
|
-
let query;
|
|
4372
|
-
let result;
|
|
4373
|
-
let readTimeout;
|
|
4374
|
-
let readTimeoutTimer;
|
|
4375
|
-
let queryCallback;
|
|
4376
|
-
if (config === null || config === void 0) throw new TypeError("Client was passed a null or undefined query");
|
|
4377
|
-
else if (typeof config.submit === "function") {
|
|
4378
|
-
readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
|
|
4379
|
-
result = query = config;
|
|
4380
|
-
if (typeof values === "function") config.callback = values;
|
|
4381
|
-
} else {
|
|
4382
|
-
readTimeout = config.query_timeout || this.connectionParameters.query_timeout;
|
|
4383
|
-
query = new NativeQuery(config, values, callback);
|
|
4384
|
-
if (!query.callback) {
|
|
4385
|
-
let resolveOut, rejectOut;
|
|
4386
|
-
result = new this._Promise((resolve, reject) => {
|
|
4387
|
-
resolveOut = resolve;
|
|
4388
|
-
rejectOut = reject;
|
|
4389
|
-
}).catch((err) => {
|
|
4390
|
-
Error.captureStackTrace(err);
|
|
4391
|
-
throw err;
|
|
4392
|
-
});
|
|
4393
|
-
query.callback = (err, res) => err ? rejectOut(err) : resolveOut(res);
|
|
4394
|
-
}
|
|
4395
|
-
}
|
|
4396
|
-
if (readTimeout) {
|
|
4397
|
-
queryCallback = query.callback || (() => {});
|
|
4398
|
-
readTimeoutTimer = setTimeout(() => {
|
|
4399
|
-
const error = /* @__PURE__ */ new Error("Query read timeout");
|
|
4400
|
-
process.nextTick(() => {
|
|
4401
|
-
query.handleError(error, this.connection);
|
|
4402
|
-
});
|
|
4403
|
-
queryCallback(error);
|
|
4404
|
-
query.callback = () => {};
|
|
4405
|
-
const index = this._queryQueue.indexOf(query);
|
|
4406
|
-
if (index > -1) this._queryQueue.splice(index, 1);
|
|
4407
|
-
this._pulseQueryQueue();
|
|
4408
|
-
}, readTimeout);
|
|
4409
|
-
query.callback = (err, res) => {
|
|
4410
|
-
clearTimeout(readTimeoutTimer);
|
|
4411
|
-
queryCallback(err, res);
|
|
4412
|
-
};
|
|
4413
|
-
}
|
|
4414
|
-
if (!this._queryable) {
|
|
4415
|
-
query.native = this.native;
|
|
4416
|
-
process.nextTick(() => {
|
|
4417
|
-
query.handleError(/* @__PURE__ */ new Error("Client has encountered a connection error and is not queryable"));
|
|
4418
|
-
});
|
|
4419
|
-
return result;
|
|
4420
|
-
}
|
|
4421
|
-
if (this._ending) {
|
|
4422
|
-
query.native = this.native;
|
|
4423
|
-
process.nextTick(() => {
|
|
4424
|
-
query.handleError(/* @__PURE__ */ new Error("Client was closed and is not queryable"));
|
|
4425
|
-
});
|
|
4426
|
-
return result;
|
|
4427
|
-
}
|
|
4428
|
-
if (this._queryQueue.length > 0) queryQueueLengthDeprecationNotice();
|
|
4429
|
-
this._queryQueue.push(query);
|
|
4430
|
-
this._pulseQueryQueue();
|
|
4431
|
-
return result;
|
|
4432
|
-
};
|
|
4433
|
-
Client.prototype.end = function(cb) {
|
|
4434
|
-
const self = this;
|
|
4435
|
-
this._ending = true;
|
|
4436
|
-
if (!this._connected) this.once("connect", this.end.bind(this, cb));
|
|
4437
|
-
let result;
|
|
4438
|
-
if (!cb) result = new this._Promise(function(resolve, reject) {
|
|
4439
|
-
cb = (err) => err ? reject(err) : resolve();
|
|
4440
|
-
});
|
|
4441
|
-
this.native.end(function() {
|
|
4442
|
-
self._connected = false;
|
|
4443
|
-
self._errorAllQueries(/* @__PURE__ */ new Error("Connection terminated"));
|
|
4444
|
-
process.nextTick(() => {
|
|
4445
|
-
self.emit("end");
|
|
4446
|
-
if (cb) cb();
|
|
4447
|
-
});
|
|
4448
|
-
});
|
|
4449
|
-
return result;
|
|
4450
|
-
};
|
|
4451
|
-
Client.prototype._hasActiveQuery = function() {
|
|
4452
|
-
return this._activeQuery && this._activeQuery.state !== "error" && this._activeQuery.state !== "end";
|
|
4453
|
-
};
|
|
4454
|
-
Client.prototype._pulseQueryQueue = function(initialConnection) {
|
|
4455
|
-
if (!this._connected) return;
|
|
4456
|
-
if (this._hasActiveQuery()) return;
|
|
4457
|
-
const query = this._queryQueue.shift();
|
|
4458
|
-
if (!query) {
|
|
4459
|
-
if (!initialConnection) this.emit("drain");
|
|
4460
|
-
return;
|
|
4461
|
-
}
|
|
4462
|
-
this._activeQuery = query;
|
|
4463
|
-
query.submit(this);
|
|
4464
|
-
const self = this;
|
|
4465
|
-
query.once("_done", function() {
|
|
4466
|
-
self._pulseQueryQueue();
|
|
4467
|
-
});
|
|
4468
|
-
};
|
|
4469
|
-
Client.prototype.cancel = function(query) {
|
|
4470
|
-
if (this._activeQuery === query) this.native.cancel(function() {});
|
|
4471
|
-
else if (this._queryQueue.indexOf(query) !== -1) this._queryQueue.splice(this._queryQueue.indexOf(query), 1);
|
|
4472
|
-
};
|
|
4473
|
-
Client.prototype.ref = function() {};
|
|
4474
|
-
Client.prototype.unref = function() {};
|
|
4475
|
-
Client.prototype.setTypeParser = function(oid, format, parseFn) {
|
|
4476
|
-
return this._types.setTypeParser(oid, format, parseFn);
|
|
4477
|
-
};
|
|
4478
|
-
Client.prototype.getTypeParser = function(oid, format) {
|
|
4479
|
-
return this._types.getTypeParser(oid, format);
|
|
4480
|
-
};
|
|
4481
|
-
Client.prototype.isConnected = function() {
|
|
4482
|
-
return this._connected;
|
|
4483
|
-
};
|
|
4484
|
-
}));
|
|
4485
|
-
//#endregion
|
|
4486
|
-
//#region node_modules/pg/lib/native/index.js
|
|
4487
|
-
var require_native = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4488
|
-
module.exports = require_client();
|
|
4489
|
-
}));
|
|
4490
|
-
//#endregion
|
|
4491
|
-
//#region node_modules/pg/lib/index.js
|
|
4492
|
-
var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4493
|
-
const Client = require_client$1();
|
|
4494
|
-
const defaults = require_defaults();
|
|
4495
|
-
const Connection = require_connection();
|
|
4496
|
-
const Result = require_result();
|
|
4497
|
-
const utils = require_utils$1();
|
|
4498
|
-
const Pool = require_pg_pool();
|
|
4499
|
-
const TypeOverrides = require_type_overrides();
|
|
4500
|
-
const { DatabaseError } = require_dist();
|
|
4501
|
-
const { escapeIdentifier, escapeLiteral } = require_utils$1();
|
|
4502
|
-
const poolFactory = (Client) => {
|
|
4503
|
-
return class BoundPool extends Pool {
|
|
4504
|
-
constructor(options) {
|
|
4505
|
-
super(options, Client);
|
|
4506
|
-
}
|
|
4507
|
-
};
|
|
4508
|
-
};
|
|
4509
|
-
const PG = function(clientConstructor) {
|
|
4510
|
-
this.defaults = defaults;
|
|
4511
|
-
this.Client = clientConstructor;
|
|
4512
|
-
this.Query = this.Client.Query;
|
|
4513
|
-
this.Pool = poolFactory(this.Client);
|
|
4514
|
-
this._pools = [];
|
|
4515
|
-
this.Connection = Connection;
|
|
4516
|
-
this.types = require_pg_types();
|
|
4517
|
-
this.DatabaseError = DatabaseError;
|
|
4518
|
-
this.TypeOverrides = TypeOverrides;
|
|
4519
|
-
this.escapeIdentifier = escapeIdentifier;
|
|
4520
|
-
this.escapeLiteral = escapeLiteral;
|
|
4521
|
-
this.Result = Result;
|
|
4522
|
-
this.utils = utils;
|
|
4523
|
-
};
|
|
4524
|
-
let clientConstructor = Client;
|
|
4525
|
-
let forceNative = false;
|
|
4526
|
-
try {
|
|
4527
|
-
forceNative = !!process.env.NODE_PG_FORCE_NATIVE;
|
|
4528
|
-
} catch {}
|
|
4529
|
-
if (forceNative) clientConstructor = require_native();
|
|
4530
|
-
module.exports = new PG(clientConstructor);
|
|
4531
|
-
Object.defineProperty(module.exports, "native", {
|
|
4532
|
-
configurable: true,
|
|
4533
|
-
enumerable: false,
|
|
4534
|
-
get() {
|
|
4535
|
-
let native = null;
|
|
4536
|
-
try {
|
|
4537
|
-
native = new PG(require_native());
|
|
4538
|
-
} catch (err) {
|
|
4539
|
-
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
|
4540
|
-
}
|
|
4541
|
-
Object.defineProperty(module.exports, "native", { value: native });
|
|
4542
|
-
return native;
|
|
4543
|
-
}
|
|
4544
|
-
});
|
|
4545
|
-
}));
|
|
4546
|
-
//#endregion
|
|
4547
|
-
//#region node_modules/pg/esm/index.mjs
|
|
4548
|
-
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
4549
|
-
const Client = import_lib.default.Client;
|
|
4550
|
-
import_lib.default.Pool;
|
|
4551
|
-
import_lib.default.Connection;
|
|
4552
|
-
import_lib.default.types;
|
|
4553
|
-
import_lib.default.Query;
|
|
4554
|
-
import_lib.default.DatabaseError;
|
|
4555
|
-
import_lib.default.escapeIdentifier;
|
|
4556
|
-
import_lib.default.escapeLiteral;
|
|
4557
|
-
import_lib.default.Result;
|
|
4558
|
-
import_lib.default.TypeOverrides;
|
|
4559
|
-
import_lib.default.defaults;
|
|
4560
|
-
//#endregion
|
|
4561
355
|
//#region src/infrastructure/services/postgres.ts
|
|
4562
356
|
var PostgresHandle = class {
|
|
4563
357
|
type = "postgres";
|
|
@@ -4567,6 +361,7 @@ var PostgresHandle = class {
|
|
|
4567
361
|
environment;
|
|
4568
362
|
connectionString = "";
|
|
4569
363
|
started = false;
|
|
364
|
+
client = null;
|
|
4570
365
|
constructor(options = {}) {
|
|
4571
366
|
this.composeName = options.compose ?? null;
|
|
4572
367
|
this.defaultImage = options.image ?? "postgres:17";
|
|
@@ -4586,7 +381,8 @@ var PostgresHandle = class {
|
|
|
4586
381
|
async healthcheck() {
|
|
4587
382
|
if (!this.connectionString) throw new Error("postgres: cannot healthcheck — no connection string");
|
|
4588
383
|
try {
|
|
4589
|
-
const client =
|
|
384
|
+
const client = new Client({ connectionString: this.connectionString });
|
|
385
|
+
await client.connect();
|
|
4590
386
|
await client.query("SELECT 1");
|
|
4591
387
|
await client.end();
|
|
4592
388
|
} catch (error) {
|
|
@@ -4607,39 +403,31 @@ var PostgresHandle = class {
|
|
|
4607
403
|
}
|
|
4608
404
|
}
|
|
4609
405
|
async getClient() {
|
|
406
|
+
if (this.client) return this.client;
|
|
4610
407
|
const client = new Client({ connectionString: this.connectionString });
|
|
408
|
+
client.on("error", () => {
|
|
409
|
+
this.client = null;
|
|
410
|
+
});
|
|
4611
411
|
await client.connect();
|
|
412
|
+
this.client = client;
|
|
4612
413
|
return client;
|
|
4613
414
|
}
|
|
4614
415
|
async seed(sql) {
|
|
4615
|
-
|
|
4616
|
-
try {
|
|
4617
|
-
await client.query(sql);
|
|
4618
|
-
} finally {
|
|
4619
|
-
await client.end();
|
|
4620
|
-
}
|
|
416
|
+
await (await this.getClient()).query(sql);
|
|
4621
417
|
}
|
|
4622
418
|
async query(table, columns) {
|
|
4623
419
|
const client = await this.getClient();
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
return (await client.query(`SELECT ${columnList} FROM "${table}" ORDER BY 1`)).rows.map((row) => columns.map((col) => row[col]));
|
|
4627
|
-
} finally {
|
|
4628
|
-
await client.end();
|
|
4629
|
-
}
|
|
420
|
+
const columnList = columns.join(", ");
|
|
421
|
+
return (await client.query(`SELECT ${columnList} FROM "${table}" ORDER BY 1`)).rows.map((row) => columns.map((col) => row[col]));
|
|
4630
422
|
}
|
|
4631
423
|
async reset() {
|
|
4632
424
|
const client = await this.getClient();
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
for (const row of result.rows) await client.query(`TRUNCATE "${row.tablename}" CASCADE`);
|
|
4640
|
-
} finally {
|
|
4641
|
-
await client.end();
|
|
4642
|
-
}
|
|
425
|
+
const result = await client.query(`
|
|
426
|
+
SELECT tablename FROM pg_tables
|
|
427
|
+
WHERE schemaname = 'public'
|
|
428
|
+
AND tablename NOT LIKE '_prisma%'
|
|
429
|
+
`);
|
|
430
|
+
for (const row of result.rows) await client.query(`TRUNCATE "${row.tablename}" CASCADE`);
|
|
4643
431
|
}
|
|
4644
432
|
};
|
|
4645
433
|
/**
|
|
@@ -4675,7 +463,7 @@ var RedisHandle = class {
|
|
|
4675
463
|
async healthcheck() {
|
|
4676
464
|
if (!this.connectionString) throw new Error("redis: cannot healthcheck — no connection string");
|
|
4677
465
|
try {
|
|
4678
|
-
const { createClient } = await import("
|
|
466
|
+
const { createClient } = await import("redis");
|
|
4679
467
|
const client = createClient({ url: this.connectionString });
|
|
4680
468
|
await client.connect();
|
|
4681
469
|
await client.ping();
|
|
@@ -4686,7 +474,7 @@ var RedisHandle = class {
|
|
|
4686
474
|
}
|
|
4687
475
|
async initialize() {}
|
|
4688
476
|
async reset() {
|
|
4689
|
-
const { createClient } = await import("
|
|
477
|
+
const { createClient } = await import("redis");
|
|
4690
478
|
const client = createClient({ url: this.connectionString });
|
|
4691
479
|
await client.connect();
|
|
4692
480
|
try {
|
|
@@ -4728,37 +516,42 @@ var Orchestrator = class {
|
|
|
4728
516
|
}
|
|
4729
517
|
/**
|
|
4730
518
|
* Start declared services via testcontainers (integration mode).
|
|
4731
|
-
*
|
|
519
|
+
* Phase 1: start all containers in parallel (the slow part).
|
|
520
|
+
* Phase 2: wire connections, healthcheck, and init sequentially (fast).
|
|
4732
521
|
*/
|
|
4733
522
|
async start() {
|
|
4734
523
|
if (this.started) return;
|
|
4735
524
|
const composePath = findComposeFile(this.root);
|
|
4736
525
|
const composeDir = composePath ? dirname(composePath) : this.root;
|
|
4737
526
|
const composeConfig = composePath ? parseComposeFile(composePath) : null;
|
|
4738
|
-
const
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
...env,
|
|
4751
|
-
...composeService.environment
|
|
4752
|
-
};
|
|
4753
|
-
Object.assign(handle.environment, composeService.environment);
|
|
4754
|
-
}
|
|
527
|
+
const containerTasks = this.services.map((handle) => {
|
|
528
|
+
let image = handle.defaultImage;
|
|
529
|
+
let env = { ...handle.environment };
|
|
530
|
+
if (handle.composeName && composeConfig) {
|
|
531
|
+
const composeService = composeConfig.services.find((s) => s.name === handle.composeName);
|
|
532
|
+
if (composeService) {
|
|
533
|
+
image = composeService.image ?? image;
|
|
534
|
+
env = {
|
|
535
|
+
...env,
|
|
536
|
+
...composeService.environment
|
|
537
|
+
};
|
|
538
|
+
Object.assign(handle.environment, composeService.environment);
|
|
4755
539
|
}
|
|
4756
|
-
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
container: new TestcontainersAdapter({
|
|
4757
543
|
image,
|
|
4758
544
|
port: handle.defaultPort,
|
|
4759
545
|
env
|
|
4760
|
-
})
|
|
4761
|
-
|
|
546
|
+
}),
|
|
547
|
+
handle
|
|
548
|
+
};
|
|
549
|
+
});
|
|
550
|
+
await Promise.all(containerTasks.map(({ container }) => container.start()));
|
|
551
|
+
const reports = [];
|
|
552
|
+
for (const { container, handle } of containerTasks) {
|
|
553
|
+
const serviceStartTime = Date.now();
|
|
554
|
+
try {
|
|
4762
555
|
const host = container.getHost();
|
|
4763
556
|
const port = container.getMappedPort(handle.defaultPort);
|
|
4764
557
|
handle.connectionString = handle.buildConnectionString(host, port);
|
|
@@ -4769,7 +562,7 @@ var Orchestrator = class {
|
|
|
4769
562
|
name: handle.composeName ?? handle.type,
|
|
4770
563
|
type: handle.type,
|
|
4771
564
|
connectionString: handle.connectionString,
|
|
4772
|
-
durationMs: Date.now() -
|
|
565
|
+
durationMs: Date.now() - serviceStartTime
|
|
4773
566
|
});
|
|
4774
567
|
this.running.push({
|
|
4775
568
|
handle,
|
|
@@ -4777,18 +570,16 @@ var Orchestrator = class {
|
|
|
4777
570
|
});
|
|
4778
571
|
} catch (error) {
|
|
4779
572
|
let logs = "";
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
} catch {}
|
|
4787
|
-
}
|
|
573
|
+
try {
|
|
574
|
+
logs = await container.getLogs();
|
|
575
|
+
} catch {}
|
|
576
|
+
try {
|
|
577
|
+
await container.stop();
|
|
578
|
+
} catch {}
|
|
4788
579
|
reports.push({
|
|
4789
580
|
name: handle.composeName ?? handle.type,
|
|
4790
581
|
type: handle.type,
|
|
4791
|
-
durationMs: Date.now() -
|
|
582
|
+
durationMs: Date.now() - serviceStartTime,
|
|
4792
583
|
error: error.message,
|
|
4793
584
|
logs
|
|
4794
585
|
});
|
|
@@ -4899,7 +690,7 @@ var Orchestrator = class {
|
|
|
4899
690
|
//#endregion
|
|
4900
691
|
//#region src/specification/adapters/exec.adapter.ts
|
|
4901
692
|
/**
|
|
4902
|
-
* Executes CLI commands via execSync.
|
|
693
|
+
* Executes CLI commands via execSync (blocking) or spawn (long-running).
|
|
4903
694
|
* Used by cli() for local command execution.
|
|
4904
695
|
*/
|
|
4905
696
|
var ExecAdapter = class {
|
|
@@ -4935,6 +726,55 @@ var ExecAdapter = class {
|
|
|
4935
726
|
};
|
|
4936
727
|
}
|
|
4937
728
|
}
|
|
729
|
+
async spawn(args, cwd, options) {
|
|
730
|
+
const env = {
|
|
731
|
+
...process.env,
|
|
732
|
+
INIT_CWD: void 0
|
|
733
|
+
};
|
|
734
|
+
return new Promise((resolve) => {
|
|
735
|
+
let stdout = "";
|
|
736
|
+
let stderr = "";
|
|
737
|
+
let resolved = false;
|
|
738
|
+
const child = spawn(this.command, args.split(/\s+/).filter(Boolean), {
|
|
739
|
+
cwd,
|
|
740
|
+
env,
|
|
741
|
+
stdio: [
|
|
742
|
+
"pipe",
|
|
743
|
+
"pipe",
|
|
744
|
+
"pipe"
|
|
745
|
+
]
|
|
746
|
+
});
|
|
747
|
+
const finish = (exitCode) => {
|
|
748
|
+
if (resolved) return;
|
|
749
|
+
resolved = true;
|
|
750
|
+
child.kill("SIGTERM");
|
|
751
|
+
resolve({
|
|
752
|
+
exitCode,
|
|
753
|
+
stdout,
|
|
754
|
+
stderr
|
|
755
|
+
});
|
|
756
|
+
};
|
|
757
|
+
let patternMatched = false;
|
|
758
|
+
const checkPattern = () => {
|
|
759
|
+
if (!patternMatched && (stdout.includes(options.waitFor) || stderr.includes(options.waitFor))) {
|
|
760
|
+
patternMatched = true;
|
|
761
|
+
finish(0);
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
child.stdout?.on("data", (data) => {
|
|
765
|
+
stdout += data.toString();
|
|
766
|
+
checkPattern();
|
|
767
|
+
});
|
|
768
|
+
child.stderr?.on("data", (data) => {
|
|
769
|
+
stderr += data.toString();
|
|
770
|
+
checkPattern();
|
|
771
|
+
});
|
|
772
|
+
child.on("exit", (code) => {
|
|
773
|
+
if (!patternMatched) finish(code === 0 ? 1 : code ?? 1);
|
|
774
|
+
});
|
|
775
|
+
setTimeout(() => finish(124), options.timeout);
|
|
776
|
+
});
|
|
777
|
+
}
|
|
4938
778
|
};
|
|
4939
779
|
//#endregion
|
|
4940
780
|
//#region src/specification/adapters/fetch.adapter.ts
|
|
@@ -5093,6 +933,7 @@ var SpecificationBuilder = class {
|
|
|
5093
933
|
projectName = null;
|
|
5094
934
|
request = null;
|
|
5095
935
|
seeds = [];
|
|
936
|
+
spawnConfig = null;
|
|
5096
937
|
testDir;
|
|
5097
938
|
constructor(config, testDir, label) {
|
|
5098
939
|
this.config = config;
|
|
@@ -5152,11 +993,18 @@ var SpecificationBuilder = class {
|
|
|
5152
993
|
this.commandArgs = args;
|
|
5153
994
|
return this;
|
|
5154
995
|
}
|
|
996
|
+
spawn(args, options) {
|
|
997
|
+
this.spawnConfig = {
|
|
998
|
+
args,
|
|
999
|
+
options
|
|
1000
|
+
};
|
|
1001
|
+
return this;
|
|
1002
|
+
}
|
|
5155
1003
|
async run() {
|
|
5156
1004
|
const hasHttpAction = this.request !== null;
|
|
5157
|
-
const hasCliAction = this.commandArgs !== null;
|
|
1005
|
+
const hasCliAction = this.commandArgs !== null || this.spawnConfig !== null;
|
|
5158
1006
|
if (!hasHttpAction && !hasCliAction) throw new Error(`Specification "${this.label}": no action defined. Call .get(), .post(), .exec(), etc. before .run()`);
|
|
5159
|
-
if (hasHttpAction && hasCliAction) throw new Error(`Specification "${this.label}": cannot mix HTTP (.get/.post) and CLI (.exec) actions`);
|
|
1007
|
+
if (hasHttpAction && hasCliAction) throw new Error(`Specification "${this.label}": cannot mix HTTP (.get/.post) and CLI (.exec/.spawn) actions`);
|
|
5160
1008
|
let workDir = null;
|
|
5161
1009
|
if (hasCliAction) workDir = this.prepareWorkDir();
|
|
5162
1010
|
if (this.config.databases) for (const db of this.config.databases.values()) await db.reset();
|
|
@@ -5203,8 +1051,21 @@ var SpecificationBuilder = class {
|
|
|
5203
1051
|
}
|
|
5204
1052
|
async runCliAction(workDir) {
|
|
5205
1053
|
if (!this.config.command) throw new Error("CLI actions require a command adapter (use cli())");
|
|
1054
|
+
let commandResult;
|
|
1055
|
+
if (this.spawnConfig) commandResult = await this.config.command.spawn(this.spawnConfig.args, workDir, this.spawnConfig.options);
|
|
1056
|
+
else if (Array.isArray(this.commandArgs)) {
|
|
1057
|
+
commandResult = {
|
|
1058
|
+
exitCode: 0,
|
|
1059
|
+
stdout: "",
|
|
1060
|
+
stderr: ""
|
|
1061
|
+
};
|
|
1062
|
+
for (const args of this.commandArgs) {
|
|
1063
|
+
commandResult = await this.config.command.exec(args, workDir);
|
|
1064
|
+
if (commandResult.exitCode !== 0) break;
|
|
1065
|
+
}
|
|
1066
|
+
} else commandResult = await this.config.command.exec(this.commandArgs, workDir);
|
|
5206
1067
|
return new SpecificationResult({
|
|
5207
|
-
commandResult
|
|
1068
|
+
commandResult,
|
|
5208
1069
|
config: this.config,
|
|
5209
1070
|
testDir: this.testDir,
|
|
5210
1071
|
workDir
|