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