prisma-sql 1.75.6 → 1.75.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collect-planner-stats.cjs +679 -0
- package/dist/collect-planner-stats.cjs.map +1 -0
- package/dist/collect-planner-stats.d.mts +1 -0
- package/dist/collect-planner-stats.d.ts +1 -0
- package/dist/collect-planner-stats.js +677 -0
- package/dist/collect-planner-stats.js.map +1 -0
- package/dist/generator.cjs +57 -2326
- package/dist/generator.cjs.map +1 -1
- package/dist/generator.js +57 -2317
- package/dist/generator.js.map +1 -1
- package/package.json +5 -4
package/dist/generator.cjs
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var net = require('net');
|
|
5
|
-
var tls = require('tls');
|
|
6
|
-
var crypto = require('crypto');
|
|
7
|
-
var Stream = require('stream');
|
|
8
|
-
var perf_hooks = require('perf_hooks');
|
|
9
|
-
var os = require('os');
|
|
10
|
-
var fs = require('fs');
|
|
11
4
|
var generatorHelper = require('@prisma/generator-helper');
|
|
12
5
|
var schemaParser = require('@dee-wan/schema-parser');
|
|
13
6
|
var promises = require('fs/promises');
|
|
14
7
|
var path = require('path');
|
|
15
8
|
|
|
16
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
-
|
|
18
|
-
var net__default = /*#__PURE__*/_interopDefault(net);
|
|
19
|
-
var tls__default = /*#__PURE__*/_interopDefault(tls);
|
|
20
|
-
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
21
|
-
var Stream__default = /*#__PURE__*/_interopDefault(Stream);
|
|
22
|
-
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
23
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
24
|
-
|
|
25
9
|
var __defProp = Object.defineProperty;
|
|
26
10
|
var __defProps = Object.defineProperties;
|
|
27
11
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -32,30 +16,22 @@ var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
|
32
16
|
var __typeError = (msg) => {
|
|
33
17
|
throw TypeError(msg);
|
|
34
18
|
};
|
|
35
|
-
var __pow = Math.pow;
|
|
36
19
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
37
|
-
var __spreadValues = (a,
|
|
38
|
-
for (var prop in
|
|
39
|
-
if (__hasOwnProp.call(
|
|
40
|
-
__defNormalProp(a, prop,
|
|
20
|
+
var __spreadValues = (a, b) => {
|
|
21
|
+
for (var prop in b || (b = {}))
|
|
22
|
+
if (__hasOwnProp.call(b, prop))
|
|
23
|
+
__defNormalProp(a, prop, b[prop]);
|
|
41
24
|
if (__getOwnPropSymbols)
|
|
42
|
-
for (var prop of __getOwnPropSymbols(
|
|
43
|
-
if (__propIsEnum.call(
|
|
44
|
-
__defNormalProp(a, prop,
|
|
25
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
26
|
+
if (__propIsEnum.call(b, prop))
|
|
27
|
+
__defNormalProp(a, prop, b[prop]);
|
|
45
28
|
}
|
|
46
29
|
return a;
|
|
47
30
|
};
|
|
48
|
-
var __spreadProps = (a,
|
|
49
|
-
var __esm = (fn, res) => function __init() {
|
|
50
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
51
|
-
};
|
|
31
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
52
32
|
var __commonJS = (cb, mod) => function __require() {
|
|
53
33
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
54
34
|
};
|
|
55
|
-
var __export = (target, all) => {
|
|
56
|
-
for (var name in all)
|
|
57
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
58
|
-
};
|
|
59
35
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
60
36
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
61
37
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
@@ -89,2247 +65,19 @@ var __async = (__this, __arguments, generator) => {
|
|
|
89
65
|
});
|
|
90
66
|
};
|
|
91
67
|
|
|
92
|
-
// node_modules/postgres/src/query.js
|
|
93
|
-
function cachedError(xs) {
|
|
94
|
-
if (originCache.has(xs))
|
|
95
|
-
return originCache.get(xs);
|
|
96
|
-
const x = Error.stackTraceLimit;
|
|
97
|
-
Error.stackTraceLimit = 4;
|
|
98
|
-
originCache.set(xs, new Error());
|
|
99
|
-
Error.stackTraceLimit = x;
|
|
100
|
-
return originCache.get(xs);
|
|
101
|
-
}
|
|
102
|
-
var originCache, originStackCache, originError, CLOSE, Query;
|
|
103
|
-
var init_query = __esm({
|
|
104
|
-
"node_modules/postgres/src/query.js"() {
|
|
105
|
-
originCache = /* @__PURE__ */ new Map();
|
|
106
|
-
originStackCache = /* @__PURE__ */ new Map();
|
|
107
|
-
originError = /* @__PURE__ */ Symbol("OriginError");
|
|
108
|
-
CLOSE = {};
|
|
109
|
-
Query = class extends Promise {
|
|
110
|
-
constructor(strings, args, handler, canceller, options = {}) {
|
|
111
|
-
let resolve3, reject;
|
|
112
|
-
super((a, b2) => {
|
|
113
|
-
resolve3 = a;
|
|
114
|
-
reject = b2;
|
|
115
|
-
});
|
|
116
|
-
this.tagged = Array.isArray(strings.raw);
|
|
117
|
-
this.strings = strings;
|
|
118
|
-
this.args = args;
|
|
119
|
-
this.handler = handler;
|
|
120
|
-
this.canceller = canceller;
|
|
121
|
-
this.options = options;
|
|
122
|
-
this.state = null;
|
|
123
|
-
this.statement = null;
|
|
124
|
-
this.resolve = (x) => (this.active = false, resolve3(x));
|
|
125
|
-
this.reject = (x) => (this.active = false, reject(x));
|
|
126
|
-
this.active = false;
|
|
127
|
-
this.cancelled = null;
|
|
128
|
-
this.executed = false;
|
|
129
|
-
this.signature = "";
|
|
130
|
-
this[originError] = this.handler.debug ? new Error() : this.tagged && cachedError(this.strings);
|
|
131
|
-
}
|
|
132
|
-
get origin() {
|
|
133
|
-
return (this.handler.debug ? this[originError].stack : this.tagged && originStackCache.has(this.strings) ? originStackCache.get(this.strings) : originStackCache.set(this.strings, this[originError].stack).get(this.strings)) || "";
|
|
134
|
-
}
|
|
135
|
-
static get [Symbol.species]() {
|
|
136
|
-
return Promise;
|
|
137
|
-
}
|
|
138
|
-
cancel() {
|
|
139
|
-
return this.canceller && (this.canceller(this), this.canceller = null);
|
|
140
|
-
}
|
|
141
|
-
simple() {
|
|
142
|
-
this.options.simple = true;
|
|
143
|
-
this.options.prepare = false;
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
readable() {
|
|
147
|
-
return __async(this, null, function* () {
|
|
148
|
-
this.simple();
|
|
149
|
-
this.streaming = true;
|
|
150
|
-
return this;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
writable() {
|
|
154
|
-
return __async(this, null, function* () {
|
|
155
|
-
this.simple();
|
|
156
|
-
this.streaming = true;
|
|
157
|
-
return this;
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
cursor(rows = 1, fn) {
|
|
161
|
-
this.options.simple = false;
|
|
162
|
-
if (typeof rows === "function") {
|
|
163
|
-
fn = rows;
|
|
164
|
-
rows = 1;
|
|
165
|
-
}
|
|
166
|
-
this.cursorRows = rows;
|
|
167
|
-
if (typeof fn === "function")
|
|
168
|
-
return this.cursorFn = fn, this;
|
|
169
|
-
let prev;
|
|
170
|
-
return {
|
|
171
|
-
[Symbol.asyncIterator]: () => ({
|
|
172
|
-
next: () => {
|
|
173
|
-
if (this.executed && !this.active)
|
|
174
|
-
return { done: true };
|
|
175
|
-
prev && prev();
|
|
176
|
-
const promise = new Promise((resolve3, reject) => {
|
|
177
|
-
this.cursorFn = (value) => {
|
|
178
|
-
resolve3({ value, done: false });
|
|
179
|
-
return new Promise((r) => prev = r);
|
|
180
|
-
};
|
|
181
|
-
this.resolve = () => (this.active = false, resolve3({ done: true }));
|
|
182
|
-
this.reject = (x) => (this.active = false, reject(x));
|
|
183
|
-
});
|
|
184
|
-
this.execute();
|
|
185
|
-
return promise;
|
|
186
|
-
},
|
|
187
|
-
return() {
|
|
188
|
-
prev && prev(CLOSE);
|
|
189
|
-
return { done: true };
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
describe() {
|
|
195
|
-
this.options.simple = false;
|
|
196
|
-
this.onlyDescribe = this.options.prepare = true;
|
|
197
|
-
return this;
|
|
198
|
-
}
|
|
199
|
-
stream() {
|
|
200
|
-
throw new Error(".stream has been renamed to .forEach");
|
|
201
|
-
}
|
|
202
|
-
forEach(fn) {
|
|
203
|
-
this.forEachFn = fn;
|
|
204
|
-
this.handle();
|
|
205
|
-
return this;
|
|
206
|
-
}
|
|
207
|
-
raw() {
|
|
208
|
-
this.isRaw = true;
|
|
209
|
-
return this;
|
|
210
|
-
}
|
|
211
|
-
values() {
|
|
212
|
-
this.isRaw = "values";
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
handle() {
|
|
216
|
-
return __async(this, null, function* () {
|
|
217
|
-
!this.executed && (this.executed = true) && (yield 1) && this.handler(this);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
execute() {
|
|
221
|
-
this.handle();
|
|
222
|
-
return this;
|
|
223
|
-
}
|
|
224
|
-
then() {
|
|
225
|
-
this.handle();
|
|
226
|
-
return super.then.apply(this, arguments);
|
|
227
|
-
}
|
|
228
|
-
catch() {
|
|
229
|
-
this.handle();
|
|
230
|
-
return super.catch.apply(this, arguments);
|
|
231
|
-
}
|
|
232
|
-
finally() {
|
|
233
|
-
this.handle();
|
|
234
|
-
return super.finally.apply(this, arguments);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
// node_modules/postgres/src/errors.js
|
|
241
|
-
function connection(x, options, socket) {
|
|
242
|
-
const { host, port } = socket || options;
|
|
243
|
-
const error = Object.assign(
|
|
244
|
-
new Error("write " + x + " " + (options.path || host + ":" + port)),
|
|
245
|
-
{
|
|
246
|
-
code: x,
|
|
247
|
-
errno: x,
|
|
248
|
-
address: options.path || host
|
|
249
|
-
},
|
|
250
|
-
options.path ? {} : { port }
|
|
251
|
-
);
|
|
252
|
-
Error.captureStackTrace(error, connection);
|
|
253
|
-
return error;
|
|
254
|
-
}
|
|
255
|
-
function postgres(x) {
|
|
256
|
-
const error = new PostgresError(x);
|
|
257
|
-
Error.captureStackTrace(error, postgres);
|
|
258
|
-
return error;
|
|
259
|
-
}
|
|
260
|
-
function generic(code, message) {
|
|
261
|
-
const error = Object.assign(new Error(code + ": " + message), { code });
|
|
262
|
-
Error.captureStackTrace(error, generic);
|
|
263
|
-
return error;
|
|
264
|
-
}
|
|
265
|
-
function notSupported(x) {
|
|
266
|
-
const error = Object.assign(
|
|
267
|
-
new Error(x + " (B) is not supported"),
|
|
268
|
-
{
|
|
269
|
-
code: "MESSAGE_NOT_SUPPORTED",
|
|
270
|
-
name: x
|
|
271
|
-
}
|
|
272
|
-
);
|
|
273
|
-
Error.captureStackTrace(error, notSupported);
|
|
274
|
-
return error;
|
|
275
|
-
}
|
|
276
|
-
var PostgresError, Errors;
|
|
277
|
-
var init_errors = __esm({
|
|
278
|
-
"node_modules/postgres/src/errors.js"() {
|
|
279
|
-
PostgresError = class extends Error {
|
|
280
|
-
constructor(x) {
|
|
281
|
-
super(x.message);
|
|
282
|
-
this.name = this.constructor.name;
|
|
283
|
-
Object.assign(this, x);
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
Errors = {
|
|
287
|
-
connection,
|
|
288
|
-
postgres,
|
|
289
|
-
generic,
|
|
290
|
-
notSupported
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
// node_modules/postgres/src/types.js
|
|
296
|
-
function handleValue(x, parameters, types2, options) {
|
|
297
|
-
let value = x instanceof Parameter ? x.value : x;
|
|
298
|
-
if (value === void 0) {
|
|
299
|
-
x instanceof Parameter ? x.value = options.transform.undefined : value = x = options.transform.undefined;
|
|
300
|
-
if (value === void 0)
|
|
301
|
-
throw Errors.generic("UNDEFINED_VALUE", "Undefined values are not allowed");
|
|
302
|
-
}
|
|
303
|
-
return "$" + types2.push(
|
|
304
|
-
x instanceof Parameter ? (parameters.push(x.value), x.array ? x.array[x.type || inferType(x.value)] || x.type || firstIsString(x.value) : x.type) : (parameters.push(x), inferType(x))
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
function stringify(q, string, value, parameters, types2, options) {
|
|
308
|
-
for (let i = 1; i < q.strings.length; i++) {
|
|
309
|
-
string += stringifyValue(string, value, parameters, types2, options) + q.strings[i];
|
|
310
|
-
value = q.args[i];
|
|
311
|
-
}
|
|
312
|
-
return string;
|
|
313
|
-
}
|
|
314
|
-
function stringifyValue(string, value, parameters, types2, o) {
|
|
315
|
-
return value instanceof Builder ? value.build(string, parameters, types2, o) : value instanceof Query ? fragment(value, parameters, types2, o) : value instanceof Identifier ? value.value : value && value[0] instanceof Query ? value.reduce((acc, x) => acc + " " + fragment(x, parameters, types2, o), "") : handleValue(value, parameters, types2, o);
|
|
316
|
-
}
|
|
317
|
-
function fragment(q, parameters, types2, options) {
|
|
318
|
-
q.fragment = true;
|
|
319
|
-
return stringify(q, q.strings[0], q.args[0], parameters, types2, options);
|
|
320
|
-
}
|
|
321
|
-
function valuesBuilder(first, parameters, types2, columns, options) {
|
|
322
|
-
return first.map(
|
|
323
|
-
(row) => "(" + columns.map(
|
|
324
|
-
(column) => stringifyValue("values", row[column], parameters, types2, options)
|
|
325
|
-
).join(",") + ")"
|
|
326
|
-
).join(",");
|
|
327
|
-
}
|
|
328
|
-
function values(first, rest, parameters, types2, options) {
|
|
329
|
-
const multi = Array.isArray(first[0]);
|
|
330
|
-
const columns = rest.length ? rest.flat() : Object.keys(multi ? first[0] : first);
|
|
331
|
-
return valuesBuilder(multi ? first : [first], parameters, types2, columns, options);
|
|
332
|
-
}
|
|
333
|
-
function select(first, rest, parameters, types2, options) {
|
|
334
|
-
typeof first === "string" && (first = [first].concat(rest));
|
|
335
|
-
if (Array.isArray(first))
|
|
336
|
-
return escapeIdentifiers(first, options);
|
|
337
|
-
let value;
|
|
338
|
-
const columns = rest.length ? rest.flat() : Object.keys(first);
|
|
339
|
-
return columns.map((x) => {
|
|
340
|
-
value = first[x];
|
|
341
|
-
return (value instanceof Query ? fragment(value, parameters, types2, options) : value instanceof Identifier ? value.value : handleValue(value, parameters, types2, options)) + " as " + escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x);
|
|
342
|
-
}).join(",");
|
|
343
|
-
}
|
|
344
|
-
function notTagged() {
|
|
345
|
-
throw Errors.generic("NOT_TAGGED_CALL", "Query not called as a tagged template literal");
|
|
346
|
-
}
|
|
347
|
-
function firstIsString(x) {
|
|
348
|
-
if (Array.isArray(x))
|
|
349
|
-
return firstIsString(x[0]);
|
|
350
|
-
return typeof x === "string" ? 1009 : 0;
|
|
351
|
-
}
|
|
352
|
-
function typeHandlers(types2) {
|
|
353
|
-
return Object.keys(types2).reduce((acc, k) => {
|
|
354
|
-
types2[k].from && [].concat(types2[k].from).forEach((x) => acc.parsers[x] = types2[k].parse);
|
|
355
|
-
if (types2[k].serialize) {
|
|
356
|
-
acc.serializers[types2[k].to] = types2[k].serialize;
|
|
357
|
-
types2[k].from && [].concat(types2[k].from).forEach((x) => acc.serializers[x] = types2[k].serialize);
|
|
358
|
-
}
|
|
359
|
-
return acc;
|
|
360
|
-
}, { parsers: {}, serializers: {} });
|
|
361
|
-
}
|
|
362
|
-
function escapeIdentifiers(xs, { transform: { column } }) {
|
|
363
|
-
return xs.map((x) => escapeIdentifier(column.to ? column.to(x) : x)).join(",");
|
|
364
|
-
}
|
|
365
|
-
function arrayEscape(x) {
|
|
366
|
-
return x.replace(escapeBackslash, "\\\\").replace(escapeQuote, '\\"');
|
|
367
|
-
}
|
|
368
|
-
function arrayParserLoop(s, x, parser, typarray) {
|
|
369
|
-
const xs = [];
|
|
370
|
-
const delimiter = typarray === 1020 ? ";" : ",";
|
|
371
|
-
for (; s.i < x.length; s.i++) {
|
|
372
|
-
s.char = x[s.i];
|
|
373
|
-
if (s.quoted) {
|
|
374
|
-
if (s.char === "\\") {
|
|
375
|
-
s.str += x[++s.i];
|
|
376
|
-
} else if (s.char === '"') {
|
|
377
|
-
xs.push(parser ? parser(s.str) : s.str);
|
|
378
|
-
s.str = "";
|
|
379
|
-
s.quoted = x[s.i + 1] === '"';
|
|
380
|
-
s.last = s.i + 2;
|
|
381
|
-
} else {
|
|
382
|
-
s.str += s.char;
|
|
383
|
-
}
|
|
384
|
-
} else if (s.char === '"') {
|
|
385
|
-
s.quoted = true;
|
|
386
|
-
} else if (s.char === "{") {
|
|
387
|
-
s.last = ++s.i;
|
|
388
|
-
xs.push(arrayParserLoop(s, x, parser, typarray));
|
|
389
|
-
} else if (s.char === "}") {
|
|
390
|
-
s.quoted = false;
|
|
391
|
-
s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i));
|
|
392
|
-
s.last = s.i + 1;
|
|
393
|
-
break;
|
|
394
|
-
} else if (s.char === delimiter && s.p !== "}" && s.p !== '"') {
|
|
395
|
-
xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i));
|
|
396
|
-
s.last = s.i + 1;
|
|
397
|
-
}
|
|
398
|
-
s.p = s.char;
|
|
399
|
-
}
|
|
400
|
-
s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i + 1)) : x.slice(s.last, s.i + 1));
|
|
401
|
-
return xs;
|
|
402
|
-
}
|
|
403
|
-
function createJsonTransform(fn) {
|
|
404
|
-
return function jsonTransform(x, column) {
|
|
405
|
-
return typeof x === "object" && x !== null && (column.type === 114 || column.type === 3802) ? Array.isArray(x) ? x.map((x2) => jsonTransform(x2, column)) : Object.entries(x).reduce((acc, [k, v]) => Object.assign(acc, { [fn(k)]: jsonTransform(v, column) }), {}) : x;
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
var types, NotTagged, Identifier, Parameter, Builder, defaultHandlers, builders, serializers, parsers, mergeUserTypes, escapeIdentifier, inferType, escapeBackslash, escapeQuote, arraySerializer, arrayParserState, arrayParser, toCamel, toPascal, toKebab, fromCamel, fromPascal, fromKebab, camel, pascal, kebab;
|
|
409
|
-
var init_types = __esm({
|
|
410
|
-
"node_modules/postgres/src/types.js"() {
|
|
411
|
-
init_query();
|
|
412
|
-
init_errors();
|
|
413
|
-
types = {
|
|
414
|
-
string: {
|
|
415
|
-
to: 25,
|
|
416
|
-
from: null,
|
|
417
|
-
// defaults to string
|
|
418
|
-
serialize: (x) => "" + x
|
|
419
|
-
},
|
|
420
|
-
number: {
|
|
421
|
-
to: 0,
|
|
422
|
-
from: [21, 23, 26, 700, 701],
|
|
423
|
-
serialize: (x) => "" + x,
|
|
424
|
-
parse: (x) => +x
|
|
425
|
-
},
|
|
426
|
-
json: {
|
|
427
|
-
to: 114,
|
|
428
|
-
from: [114, 3802],
|
|
429
|
-
serialize: (x) => JSON.stringify(x),
|
|
430
|
-
parse: (x) => JSON.parse(x)
|
|
431
|
-
},
|
|
432
|
-
boolean: {
|
|
433
|
-
to: 16,
|
|
434
|
-
from: 16,
|
|
435
|
-
serialize: (x) => x === true ? "t" : "f",
|
|
436
|
-
parse: (x) => x === "t"
|
|
437
|
-
},
|
|
438
|
-
date: {
|
|
439
|
-
to: 1184,
|
|
440
|
-
from: [1082, 1114, 1184],
|
|
441
|
-
serialize: (x) => (x instanceof Date ? x : new Date(x)).toISOString(),
|
|
442
|
-
parse: (x) => new Date(x)
|
|
443
|
-
},
|
|
444
|
-
bytea: {
|
|
445
|
-
to: 17,
|
|
446
|
-
from: 17,
|
|
447
|
-
serialize: (x) => "\\x" + Buffer.from(x).toString("hex"),
|
|
448
|
-
parse: (x) => Buffer.from(x.slice(2), "hex")
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
NotTagged = class {
|
|
452
|
-
then() {
|
|
453
|
-
notTagged();
|
|
454
|
-
}
|
|
455
|
-
catch() {
|
|
456
|
-
notTagged();
|
|
457
|
-
}
|
|
458
|
-
finally() {
|
|
459
|
-
notTagged();
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
Identifier = class extends NotTagged {
|
|
463
|
-
constructor(value) {
|
|
464
|
-
super();
|
|
465
|
-
this.value = escapeIdentifier(value);
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
Parameter = class extends NotTagged {
|
|
469
|
-
constructor(value, type, array) {
|
|
470
|
-
super();
|
|
471
|
-
this.value = value;
|
|
472
|
-
this.type = type;
|
|
473
|
-
this.array = array;
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
Builder = class extends NotTagged {
|
|
477
|
-
constructor(first, rest) {
|
|
478
|
-
super();
|
|
479
|
-
this.first = first;
|
|
480
|
-
this.rest = rest;
|
|
481
|
-
}
|
|
482
|
-
build(before, parameters, types2, options) {
|
|
483
|
-
const keyword = builders.map(([x, fn]) => ({ fn, i: before.search(x) })).sort((a, b2) => a.i - b2.i).pop();
|
|
484
|
-
return keyword.i === -1 ? escapeIdentifiers(this.first, options) : keyword.fn(this.first, this.rest, parameters, types2, options);
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
defaultHandlers = typeHandlers(types);
|
|
488
|
-
builders = Object.entries({
|
|
489
|
-
values,
|
|
490
|
-
in: (...xs) => {
|
|
491
|
-
const x = values(...xs);
|
|
492
|
-
return x === "()" ? "(null)" : x;
|
|
493
|
-
},
|
|
494
|
-
select,
|
|
495
|
-
as: select,
|
|
496
|
-
returning: select,
|
|
497
|
-
"\\(": select,
|
|
498
|
-
update(first, rest, parameters, types2, options) {
|
|
499
|
-
return (rest.length ? rest.flat() : Object.keys(first)).map(
|
|
500
|
-
(x) => escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) + "=" + stringifyValue("values", first[x], parameters, types2, options)
|
|
501
|
-
);
|
|
502
|
-
},
|
|
503
|
-
insert(first, rest, parameters, types2, options) {
|
|
504
|
-
const columns = rest.length ? rest.flat() : Object.keys(Array.isArray(first) ? first[0] : first);
|
|
505
|
-
return "(" + escapeIdentifiers(columns, options) + ")values" + valuesBuilder(Array.isArray(first) ? first : [first], parameters, types2, columns, options);
|
|
506
|
-
}
|
|
507
|
-
}).map(([x, fn]) => [new RegExp("((?:^|[\\s(])" + x + "(?:$|[\\s(]))(?![\\s\\S]*\\1)", "i"), fn]);
|
|
508
|
-
serializers = defaultHandlers.serializers;
|
|
509
|
-
parsers = defaultHandlers.parsers;
|
|
510
|
-
mergeUserTypes = function(types2) {
|
|
511
|
-
const user = typeHandlers(types2 || {});
|
|
512
|
-
return {
|
|
513
|
-
serializers: Object.assign({}, serializers, user.serializers),
|
|
514
|
-
parsers: Object.assign({}, parsers, user.parsers)
|
|
515
|
-
};
|
|
516
|
-
};
|
|
517
|
-
escapeIdentifier = function escape(str) {
|
|
518
|
-
return '"' + str.replace(/"/g, '""').replace(/\./g, '"."') + '"';
|
|
519
|
-
};
|
|
520
|
-
inferType = function inferType2(x) {
|
|
521
|
-
return x instanceof Parameter ? x.type : x instanceof Date ? 1184 : x instanceof Uint8Array ? 17 : x === true || x === false ? 16 : typeof x === "bigint" ? 20 : Array.isArray(x) ? inferType2(x[0]) : 0;
|
|
522
|
-
};
|
|
523
|
-
escapeBackslash = /\\/g;
|
|
524
|
-
escapeQuote = /"/g;
|
|
525
|
-
arraySerializer = function arraySerializer2(xs, serializer, options, typarray) {
|
|
526
|
-
if (Array.isArray(xs) === false)
|
|
527
|
-
return xs;
|
|
528
|
-
if (!xs.length)
|
|
529
|
-
return "{}";
|
|
530
|
-
const first = xs[0];
|
|
531
|
-
const delimiter = typarray === 1020 ? ";" : ",";
|
|
532
|
-
if (Array.isArray(first) && !first.type)
|
|
533
|
-
return "{" + xs.map((x) => arraySerializer2(x, serializer, options, typarray)).join(delimiter) + "}";
|
|
534
|
-
return "{" + xs.map((x) => {
|
|
535
|
-
if (x === void 0) {
|
|
536
|
-
x = options.transform.undefined;
|
|
537
|
-
if (x === void 0)
|
|
538
|
-
throw Errors.generic("UNDEFINED_VALUE", "Undefined values are not allowed");
|
|
539
|
-
}
|
|
540
|
-
return x === null ? "null" : '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : "" + x) + '"';
|
|
541
|
-
}).join(delimiter) + "}";
|
|
542
|
-
};
|
|
543
|
-
arrayParserState = {
|
|
544
|
-
i: 0,
|
|
545
|
-
char: null,
|
|
546
|
-
str: "",
|
|
547
|
-
quoted: false,
|
|
548
|
-
last: 0
|
|
549
|
-
};
|
|
550
|
-
arrayParser = function arrayParser2(x, parser, typarray) {
|
|
551
|
-
arrayParserState.i = arrayParserState.last = 0;
|
|
552
|
-
return arrayParserLoop(arrayParserState, x, parser, typarray);
|
|
553
|
-
};
|
|
554
|
-
toCamel = (x) => {
|
|
555
|
-
let str = x[0];
|
|
556
|
-
for (let i = 1; i < x.length; i++)
|
|
557
|
-
str += x[i] === "_" ? x[++i].toUpperCase() : x[i];
|
|
558
|
-
return str;
|
|
559
|
-
};
|
|
560
|
-
toPascal = (x) => {
|
|
561
|
-
let str = x[0].toUpperCase();
|
|
562
|
-
for (let i = 1; i < x.length; i++)
|
|
563
|
-
str += x[i] === "_" ? x[++i].toUpperCase() : x[i];
|
|
564
|
-
return str;
|
|
565
|
-
};
|
|
566
|
-
toKebab = (x) => x.replace(/_/g, "-");
|
|
567
|
-
fromCamel = (x) => x.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
568
|
-
fromPascal = (x) => (x.slice(0, 1) + x.slice(1).replace(/([A-Z])/g, "_$1")).toLowerCase();
|
|
569
|
-
fromKebab = (x) => x.replace(/-/g, "_");
|
|
570
|
-
toCamel.column = { from: toCamel };
|
|
571
|
-
toCamel.value = { from: createJsonTransform(toCamel) };
|
|
572
|
-
fromCamel.column = { to: fromCamel };
|
|
573
|
-
camel = __spreadValues({}, toCamel);
|
|
574
|
-
camel.column.to = fromCamel;
|
|
575
|
-
toPascal.column = { from: toPascal };
|
|
576
|
-
toPascal.value = { from: createJsonTransform(toPascal) };
|
|
577
|
-
fromPascal.column = { to: fromPascal };
|
|
578
|
-
pascal = __spreadValues({}, toPascal);
|
|
579
|
-
pascal.column.to = fromPascal;
|
|
580
|
-
toKebab.column = { from: toKebab };
|
|
581
|
-
toKebab.value = { from: createJsonTransform(toKebab) };
|
|
582
|
-
fromKebab.column = { to: fromKebab };
|
|
583
|
-
kebab = __spreadValues({}, toKebab);
|
|
584
|
-
kebab.column.to = fromKebab;
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
// node_modules/postgres/src/result.js
|
|
589
|
-
var Result;
|
|
590
|
-
var init_result = __esm({
|
|
591
|
-
"node_modules/postgres/src/result.js"() {
|
|
592
|
-
Result = class extends Array {
|
|
593
|
-
constructor() {
|
|
594
|
-
super();
|
|
595
|
-
Object.defineProperties(this, {
|
|
596
|
-
count: { value: null, writable: true },
|
|
597
|
-
state: { value: null, writable: true },
|
|
598
|
-
command: { value: null, writable: true },
|
|
599
|
-
columns: { value: null, writable: true },
|
|
600
|
-
statement: { value: null, writable: true }
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
static get [Symbol.species]() {
|
|
604
|
-
return Array;
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
// node_modules/postgres/src/queue.js
|
|
611
|
-
function Queue(initial = []) {
|
|
612
|
-
let xs = initial.slice();
|
|
613
|
-
let index = 0;
|
|
614
|
-
return {
|
|
615
|
-
get length() {
|
|
616
|
-
return xs.length - index;
|
|
617
|
-
},
|
|
618
|
-
remove: (x) => {
|
|
619
|
-
const index2 = xs.indexOf(x);
|
|
620
|
-
return index2 === -1 ? null : (xs.splice(index2, 1), x);
|
|
621
|
-
},
|
|
622
|
-
push: (x) => (xs.push(x), x),
|
|
623
|
-
shift: () => {
|
|
624
|
-
const out = xs[index++];
|
|
625
|
-
if (index === xs.length) {
|
|
626
|
-
index = 0;
|
|
627
|
-
xs = [];
|
|
628
|
-
} else {
|
|
629
|
-
xs[index - 1] = void 0;
|
|
630
|
-
}
|
|
631
|
-
return out;
|
|
632
|
-
}
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
var queue_default;
|
|
636
|
-
var init_queue = __esm({
|
|
637
|
-
"node_modules/postgres/src/queue.js"() {
|
|
638
|
-
queue_default = Queue;
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
// node_modules/postgres/src/bytes.js
|
|
643
|
-
function fit(x) {
|
|
644
|
-
if (buffer.length - b.i < x) {
|
|
645
|
-
const prev = buffer, length = prev.length;
|
|
646
|
-
buffer = Buffer.allocUnsafe(length + (length >> 1) + x);
|
|
647
|
-
prev.copy(buffer);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
function reset() {
|
|
651
|
-
b.i = 0;
|
|
652
|
-
return b;
|
|
653
|
-
}
|
|
654
|
-
var size, buffer, messages, b, bytes_default;
|
|
655
|
-
var init_bytes = __esm({
|
|
656
|
-
"node_modules/postgres/src/bytes.js"() {
|
|
657
|
-
size = 256;
|
|
658
|
-
buffer = Buffer.allocUnsafe(size);
|
|
659
|
-
messages = "BCcDdEFfHPpQSX".split("").reduce((acc, x) => {
|
|
660
|
-
const v = x.charCodeAt(0);
|
|
661
|
-
acc[x] = () => {
|
|
662
|
-
buffer[0] = v;
|
|
663
|
-
b.i = 5;
|
|
664
|
-
return b;
|
|
665
|
-
};
|
|
666
|
-
return acc;
|
|
667
|
-
}, {});
|
|
668
|
-
b = Object.assign(reset, messages, {
|
|
669
|
-
N: String.fromCharCode(0),
|
|
670
|
-
i: 0,
|
|
671
|
-
inc(x) {
|
|
672
|
-
b.i += x;
|
|
673
|
-
return b;
|
|
674
|
-
},
|
|
675
|
-
str(x) {
|
|
676
|
-
const length = Buffer.byteLength(x);
|
|
677
|
-
fit(length);
|
|
678
|
-
b.i += buffer.write(x, b.i, length, "utf8");
|
|
679
|
-
return b;
|
|
680
|
-
},
|
|
681
|
-
i16(x) {
|
|
682
|
-
fit(2);
|
|
683
|
-
buffer.writeUInt16BE(x, b.i);
|
|
684
|
-
b.i += 2;
|
|
685
|
-
return b;
|
|
686
|
-
},
|
|
687
|
-
i32(x, i) {
|
|
688
|
-
if (i || i === 0) {
|
|
689
|
-
buffer.writeUInt32BE(x, i);
|
|
690
|
-
return b;
|
|
691
|
-
}
|
|
692
|
-
fit(4);
|
|
693
|
-
buffer.writeUInt32BE(x, b.i);
|
|
694
|
-
b.i += 4;
|
|
695
|
-
return b;
|
|
696
|
-
},
|
|
697
|
-
z(x) {
|
|
698
|
-
fit(x);
|
|
699
|
-
buffer.fill(0, b.i, b.i + x);
|
|
700
|
-
b.i += x;
|
|
701
|
-
return b;
|
|
702
|
-
},
|
|
703
|
-
raw(x) {
|
|
704
|
-
buffer = Buffer.concat([buffer.subarray(0, b.i), x]);
|
|
705
|
-
b.i = buffer.length;
|
|
706
|
-
return b;
|
|
707
|
-
},
|
|
708
|
-
end(at = 1) {
|
|
709
|
-
buffer.writeUInt32BE(b.i - at, at);
|
|
710
|
-
const out = buffer.subarray(0, b.i);
|
|
711
|
-
b.i = 0;
|
|
712
|
-
buffer = Buffer.allocUnsafe(size);
|
|
713
|
-
return out;
|
|
714
|
-
}
|
|
715
|
-
});
|
|
716
|
-
bytes_default = b;
|
|
717
|
-
}
|
|
718
|
-
});
|
|
719
|
-
function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose = noop } = {}) {
|
|
720
|
-
const {
|
|
721
|
-
sslnegotiation,
|
|
722
|
-
ssl,
|
|
723
|
-
max,
|
|
724
|
-
user,
|
|
725
|
-
host,
|
|
726
|
-
port,
|
|
727
|
-
database,
|
|
728
|
-
parsers: parsers2,
|
|
729
|
-
transform,
|
|
730
|
-
onnotice,
|
|
731
|
-
onnotify,
|
|
732
|
-
onparameter,
|
|
733
|
-
max_pipeline,
|
|
734
|
-
keep_alive,
|
|
735
|
-
backoff: backoff2,
|
|
736
|
-
target_session_attrs
|
|
737
|
-
} = options;
|
|
738
|
-
const sent = queue_default(), id = uid++, backend = { pid: null, secret: null }, idleTimer = timer(end, options.idle_timeout), lifeTimer = timer(end, options.max_lifetime), connectTimer = timer(connectTimedOut, options.connect_timeout);
|
|
739
|
-
let socket = null, cancelMessage, errorResponse = null, result = new Result(), incoming = Buffer.alloc(0), needsTypes = options.fetch_types, backendParameters = {}, statements = {}, statementId = Math.random().toString(36).slice(2), statementCount = 1, closedTime = 0, remaining = 0, hostIndex = 0, retries = 0, length = 0, delay = 0, rows = 0, serverSignature = null, nextWriteTimer = null, terminated = false, incomings = null, results = null, initial = null, ending = null, stream = null, chunk = null, ended = null, nonce = null, query = null, final = null;
|
|
740
|
-
const connection2 = {
|
|
741
|
-
queue: queues.closed,
|
|
742
|
-
idleTimer,
|
|
743
|
-
connect(query2) {
|
|
744
|
-
initial = query2;
|
|
745
|
-
reconnect();
|
|
746
|
-
},
|
|
747
|
-
terminate,
|
|
748
|
-
execute,
|
|
749
|
-
cancel,
|
|
750
|
-
end,
|
|
751
|
-
count: 0,
|
|
752
|
-
id
|
|
753
|
-
};
|
|
754
|
-
queues.closed && queues.closed.push(connection2);
|
|
755
|
-
return connection2;
|
|
756
|
-
function createSocket() {
|
|
757
|
-
return __async(this, null, function* () {
|
|
758
|
-
let x;
|
|
759
|
-
try {
|
|
760
|
-
x = options.socket ? yield Promise.resolve(options.socket(options)) : new net__default.default.Socket();
|
|
761
|
-
} catch (e) {
|
|
762
|
-
error(e);
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
x.on("error", error);
|
|
766
|
-
x.on("close", closed);
|
|
767
|
-
x.on("drain", drain);
|
|
768
|
-
return x;
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
function cancel(_0, _1, _2) {
|
|
772
|
-
return __async(this, arguments, function* ({ pid, secret }, resolve3, reject) {
|
|
773
|
-
try {
|
|
774
|
-
cancelMessage = bytes_default().i32(16).i32(80877102).i32(pid).i32(secret).end(16);
|
|
775
|
-
yield connect();
|
|
776
|
-
socket.once("error", reject);
|
|
777
|
-
socket.once("close", resolve3);
|
|
778
|
-
} catch (error2) {
|
|
779
|
-
reject(error2);
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
function execute(q) {
|
|
784
|
-
if (terminated)
|
|
785
|
-
return queryError(q, Errors.connection("CONNECTION_DESTROYED", options));
|
|
786
|
-
if (stream)
|
|
787
|
-
return queryError(q, Errors.generic("COPY_IN_PROGRESS", "You cannot execute queries during copy"));
|
|
788
|
-
if (q.cancelled)
|
|
789
|
-
return;
|
|
790
|
-
try {
|
|
791
|
-
q.state = backend;
|
|
792
|
-
query ? sent.push(q) : (query = q, query.active = true);
|
|
793
|
-
build(q);
|
|
794
|
-
return write(toBuffer(q)) && !q.describeFirst && !q.cursorFn && sent.length < max_pipeline && (!q.options.onexecute || q.options.onexecute(connection2));
|
|
795
|
-
} catch (error2) {
|
|
796
|
-
sent.length === 0 && write(Sync);
|
|
797
|
-
errored(error2);
|
|
798
|
-
return true;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
function toBuffer(q) {
|
|
802
|
-
if (q.parameters.length >= 65534)
|
|
803
|
-
throw Errors.generic("MAX_PARAMETERS_EXCEEDED", "Max number of parameters (65534) exceeded");
|
|
804
|
-
return q.options.simple ? bytes_default().Q().str(q.statement.string + bytes_default.N).end() : q.describeFirst ? Buffer.concat([describe(q), Flush]) : q.prepare ? q.prepared ? prepared(q) : Buffer.concat([describe(q), prepared(q)]) : unnamed(q);
|
|
805
|
-
}
|
|
806
|
-
function describe(q) {
|
|
807
|
-
return Buffer.concat([
|
|
808
|
-
Parse(q.statement.string, q.parameters, q.statement.types, q.statement.name),
|
|
809
|
-
Describe("S", q.statement.name)
|
|
810
|
-
]);
|
|
811
|
-
}
|
|
812
|
-
function prepared(q) {
|
|
813
|
-
return Buffer.concat([
|
|
814
|
-
Bind(q.parameters, q.statement.types, q.statement.name, q.cursorName),
|
|
815
|
-
q.cursorFn ? Execute("", q.cursorRows) : ExecuteUnnamed
|
|
816
|
-
]);
|
|
817
|
-
}
|
|
818
|
-
function unnamed(q) {
|
|
819
|
-
return Buffer.concat([
|
|
820
|
-
Parse(q.statement.string, q.parameters, q.statement.types),
|
|
821
|
-
DescribeUnnamed,
|
|
822
|
-
prepared(q)
|
|
823
|
-
]);
|
|
824
|
-
}
|
|
825
|
-
function build(q) {
|
|
826
|
-
const parameters = [], types2 = [];
|
|
827
|
-
const string = stringify(q, q.strings[0], q.args[0], parameters, types2, options);
|
|
828
|
-
!q.tagged && q.args.forEach((x) => handleValue(x, parameters, types2, options));
|
|
829
|
-
q.prepare = options.prepare && ("prepare" in q.options ? q.options.prepare : true);
|
|
830
|
-
q.string = string;
|
|
831
|
-
q.signature = q.prepare && types2 + string;
|
|
832
|
-
q.onlyDescribe && delete statements[q.signature];
|
|
833
|
-
q.parameters = q.parameters || parameters;
|
|
834
|
-
q.prepared = q.prepare && q.signature in statements;
|
|
835
|
-
q.describeFirst = q.onlyDescribe || parameters.length && !q.prepared;
|
|
836
|
-
q.statement = q.prepared ? statements[q.signature] : { string, types: types2, name: q.prepare ? statementId + statementCount++ : "" };
|
|
837
|
-
typeof options.debug === "function" && options.debug(id, string, parameters, types2);
|
|
838
|
-
}
|
|
839
|
-
function write(x, fn) {
|
|
840
|
-
chunk = chunk ? Buffer.concat([chunk, x]) : Buffer.from(x);
|
|
841
|
-
if (chunk.length >= 1024)
|
|
842
|
-
return nextWrite(fn);
|
|
843
|
-
nextWriteTimer === null && (nextWriteTimer = setImmediate(nextWrite));
|
|
844
|
-
return true;
|
|
845
|
-
}
|
|
846
|
-
function nextWrite(fn) {
|
|
847
|
-
const x = socket.write(chunk, fn);
|
|
848
|
-
nextWriteTimer !== null && clearImmediate(nextWriteTimer);
|
|
849
|
-
chunk = nextWriteTimer = null;
|
|
850
|
-
return x;
|
|
851
|
-
}
|
|
852
|
-
function connectTimedOut() {
|
|
853
|
-
errored(Errors.connection("CONNECT_TIMEOUT", options, socket));
|
|
854
|
-
socket.destroy();
|
|
855
|
-
}
|
|
856
|
-
function secure() {
|
|
857
|
-
return __async(this, null, function* () {
|
|
858
|
-
if (sslnegotiation !== "direct") {
|
|
859
|
-
write(SSLRequest);
|
|
860
|
-
const canSSL = yield new Promise((r) => socket.once("data", (x) => r(x[0] === 83)));
|
|
861
|
-
if (!canSSL && ssl === "prefer")
|
|
862
|
-
return connected();
|
|
863
|
-
}
|
|
864
|
-
const options2 = {
|
|
865
|
-
socket,
|
|
866
|
-
servername: net__default.default.isIP(socket.host) ? void 0 : socket.host
|
|
867
|
-
};
|
|
868
|
-
if (sslnegotiation === "direct")
|
|
869
|
-
options2.ALPNProtocols = ["postgresql"];
|
|
870
|
-
if (ssl === "require" || ssl === "allow" || ssl === "prefer")
|
|
871
|
-
options2.rejectUnauthorized = false;
|
|
872
|
-
else if (typeof ssl === "object")
|
|
873
|
-
Object.assign(options2, ssl);
|
|
874
|
-
socket.removeAllListeners();
|
|
875
|
-
socket = tls__default.default.connect(options2);
|
|
876
|
-
socket.on("secureConnect", connected);
|
|
877
|
-
socket.on("error", error);
|
|
878
|
-
socket.on("close", closed);
|
|
879
|
-
socket.on("drain", drain);
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
function drain() {
|
|
883
|
-
!query && onopen(connection2);
|
|
884
|
-
}
|
|
885
|
-
function data(x) {
|
|
886
|
-
if (incomings) {
|
|
887
|
-
incomings.push(x);
|
|
888
|
-
remaining -= x.length;
|
|
889
|
-
if (remaining > 0)
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
incoming = incomings ? Buffer.concat(incomings, length - remaining) : incoming.length === 0 ? x : Buffer.concat([incoming, x], incoming.length + x.length);
|
|
893
|
-
while (incoming.length > 4) {
|
|
894
|
-
length = incoming.readUInt32BE(1);
|
|
895
|
-
if (length >= incoming.length) {
|
|
896
|
-
remaining = length - incoming.length;
|
|
897
|
-
incomings = [incoming];
|
|
898
|
-
break;
|
|
899
|
-
}
|
|
900
|
-
try {
|
|
901
|
-
handle(incoming.subarray(0, length + 1));
|
|
902
|
-
} catch (e) {
|
|
903
|
-
query && (query.cursorFn || query.describeFirst) && write(Sync);
|
|
904
|
-
errored(e);
|
|
905
|
-
}
|
|
906
|
-
incoming = incoming.subarray(length + 1);
|
|
907
|
-
remaining = 0;
|
|
908
|
-
incomings = null;
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
function connect() {
|
|
912
|
-
return __async(this, null, function* () {
|
|
913
|
-
terminated = false;
|
|
914
|
-
backendParameters = {};
|
|
915
|
-
socket || (socket = yield createSocket());
|
|
916
|
-
if (!socket)
|
|
917
|
-
return;
|
|
918
|
-
connectTimer.start();
|
|
919
|
-
if (options.socket)
|
|
920
|
-
return ssl ? secure() : connected();
|
|
921
|
-
socket.on("connect", ssl ? secure : connected);
|
|
922
|
-
if (options.path)
|
|
923
|
-
return socket.connect(options.path);
|
|
924
|
-
socket.ssl = ssl;
|
|
925
|
-
socket.connect(port[hostIndex], host[hostIndex]);
|
|
926
|
-
socket.host = host[hostIndex];
|
|
927
|
-
socket.port = port[hostIndex];
|
|
928
|
-
hostIndex = (hostIndex + 1) % port.length;
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
function reconnect() {
|
|
932
|
-
setTimeout(connect, closedTime ? Math.max(0, closedTime + delay - perf_hooks.performance.now()) : 0);
|
|
933
|
-
}
|
|
934
|
-
function connected() {
|
|
935
|
-
try {
|
|
936
|
-
statements = {};
|
|
937
|
-
needsTypes = options.fetch_types;
|
|
938
|
-
statementId = Math.random().toString(36).slice(2);
|
|
939
|
-
statementCount = 1;
|
|
940
|
-
lifeTimer.start();
|
|
941
|
-
socket.on("data", data);
|
|
942
|
-
keep_alive && socket.setKeepAlive && socket.setKeepAlive(true, 1e3 * keep_alive);
|
|
943
|
-
const s = StartupMessage();
|
|
944
|
-
write(s);
|
|
945
|
-
} catch (err) {
|
|
946
|
-
error(err);
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
function error(err) {
|
|
950
|
-
if (connection2.queue === queues.connecting && options.host[retries + 1])
|
|
951
|
-
return;
|
|
952
|
-
errored(err);
|
|
953
|
-
while (sent.length)
|
|
954
|
-
queryError(sent.shift(), err);
|
|
955
|
-
}
|
|
956
|
-
function errored(err) {
|
|
957
|
-
stream && (stream.destroy(err), stream = null);
|
|
958
|
-
query && queryError(query, err);
|
|
959
|
-
initial && (queryError(initial, err), initial = null);
|
|
960
|
-
}
|
|
961
|
-
function queryError(query2, err) {
|
|
962
|
-
if (query2.reserve)
|
|
963
|
-
return query2.reject(err);
|
|
964
|
-
if (!err || typeof err !== "object")
|
|
965
|
-
err = new Error(err);
|
|
966
|
-
"query" in err || "parameters" in err || Object.defineProperties(err, {
|
|
967
|
-
stack: { value: err.stack + query2.origin.replace(/.*\n/, "\n"), enumerable: options.debug },
|
|
968
|
-
query: { value: query2.string, enumerable: options.debug },
|
|
969
|
-
parameters: { value: query2.parameters, enumerable: options.debug },
|
|
970
|
-
args: { value: query2.args, enumerable: options.debug },
|
|
971
|
-
types: { value: query2.statement && query2.statement.types, enumerable: options.debug }
|
|
972
|
-
});
|
|
973
|
-
query2.reject(err);
|
|
974
|
-
}
|
|
975
|
-
function end() {
|
|
976
|
-
return ending || (!connection2.reserved && onend(connection2), !connection2.reserved && !initial && !query && sent.length === 0 ? (terminate(), new Promise((r) => socket && socket.readyState !== "closed" ? socket.once("close", r) : r())) : ending = new Promise((r) => ended = r));
|
|
977
|
-
}
|
|
978
|
-
function terminate() {
|
|
979
|
-
terminated = true;
|
|
980
|
-
if (stream || query || initial || sent.length)
|
|
981
|
-
error(Errors.connection("CONNECTION_DESTROYED", options));
|
|
982
|
-
clearImmediate(nextWriteTimer);
|
|
983
|
-
if (socket) {
|
|
984
|
-
socket.removeListener("data", data);
|
|
985
|
-
socket.removeListener("connect", connected);
|
|
986
|
-
socket.readyState === "open" && socket.end(bytes_default().X().end());
|
|
987
|
-
}
|
|
988
|
-
ended && (ended(), ending = ended = null);
|
|
989
|
-
}
|
|
990
|
-
function closed(hadError) {
|
|
991
|
-
return __async(this, null, function* () {
|
|
992
|
-
incoming = Buffer.alloc(0);
|
|
993
|
-
remaining = 0;
|
|
994
|
-
incomings = null;
|
|
995
|
-
clearImmediate(nextWriteTimer);
|
|
996
|
-
socket.removeListener("data", data);
|
|
997
|
-
socket.removeListener("connect", connected);
|
|
998
|
-
idleTimer.cancel();
|
|
999
|
-
lifeTimer.cancel();
|
|
1000
|
-
connectTimer.cancel();
|
|
1001
|
-
socket.removeAllListeners();
|
|
1002
|
-
socket = null;
|
|
1003
|
-
if (initial)
|
|
1004
|
-
return reconnect();
|
|
1005
|
-
!hadError && (query || sent.length) && error(Errors.connection("CONNECTION_CLOSED", options, socket));
|
|
1006
|
-
closedTime = perf_hooks.performance.now();
|
|
1007
|
-
hadError && options.shared.retries++;
|
|
1008
|
-
delay = (typeof backoff2 === "function" ? backoff2(options.shared.retries) : backoff2) * 1e3;
|
|
1009
|
-
onclose(connection2, Errors.connection("CONNECTION_CLOSED", options, socket));
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
function handle(xs, x = xs[0]) {
|
|
1013
|
-
(x === 68 ? DataRow : (
|
|
1014
|
-
// D
|
|
1015
|
-
x === 100 ? CopyData : (
|
|
1016
|
-
// d
|
|
1017
|
-
x === 65 ? NotificationResponse : (
|
|
1018
|
-
// A
|
|
1019
|
-
x === 83 ? ParameterStatus : (
|
|
1020
|
-
// S
|
|
1021
|
-
x === 90 ? ReadyForQuery : (
|
|
1022
|
-
// Z
|
|
1023
|
-
x === 67 ? CommandComplete : (
|
|
1024
|
-
// C
|
|
1025
|
-
x === 50 ? BindComplete : (
|
|
1026
|
-
// 2
|
|
1027
|
-
x === 49 ? ParseComplete : (
|
|
1028
|
-
// 1
|
|
1029
|
-
x === 116 ? ParameterDescription : (
|
|
1030
|
-
// t
|
|
1031
|
-
x === 84 ? RowDescription : (
|
|
1032
|
-
// T
|
|
1033
|
-
x === 82 ? Authentication : (
|
|
1034
|
-
// R
|
|
1035
|
-
x === 110 ? NoData : (
|
|
1036
|
-
// n
|
|
1037
|
-
x === 75 ? BackendKeyData : (
|
|
1038
|
-
// K
|
|
1039
|
-
x === 69 ? ErrorResponse : (
|
|
1040
|
-
// E
|
|
1041
|
-
x === 115 ? PortalSuspended : (
|
|
1042
|
-
// s
|
|
1043
|
-
x === 51 ? CloseComplete : (
|
|
1044
|
-
// 3
|
|
1045
|
-
x === 71 ? CopyInResponse : (
|
|
1046
|
-
// G
|
|
1047
|
-
x === 78 ? NoticeResponse : (
|
|
1048
|
-
// N
|
|
1049
|
-
x === 72 ? CopyOutResponse : (
|
|
1050
|
-
// H
|
|
1051
|
-
x === 99 ? CopyDone : (
|
|
1052
|
-
// c
|
|
1053
|
-
x === 73 ? EmptyQueryResponse : (
|
|
1054
|
-
// I
|
|
1055
|
-
x === 86 ? FunctionCallResponse : (
|
|
1056
|
-
// V
|
|
1057
|
-
x === 118 ? NegotiateProtocolVersion : (
|
|
1058
|
-
// v
|
|
1059
|
-
x === 87 ? CopyBothResponse : (
|
|
1060
|
-
// W
|
|
1061
|
-
/* c8 ignore next */
|
|
1062
|
-
UnknownMessage
|
|
1063
|
-
)
|
|
1064
|
-
)
|
|
1065
|
-
)
|
|
1066
|
-
)
|
|
1067
|
-
)
|
|
1068
|
-
)
|
|
1069
|
-
)
|
|
1070
|
-
)
|
|
1071
|
-
)
|
|
1072
|
-
)
|
|
1073
|
-
)
|
|
1074
|
-
)
|
|
1075
|
-
)
|
|
1076
|
-
)
|
|
1077
|
-
)
|
|
1078
|
-
)
|
|
1079
|
-
)
|
|
1080
|
-
)
|
|
1081
|
-
)
|
|
1082
|
-
)
|
|
1083
|
-
)
|
|
1084
|
-
)
|
|
1085
|
-
)
|
|
1086
|
-
))(xs);
|
|
1087
|
-
}
|
|
1088
|
-
function DataRow(x) {
|
|
1089
|
-
let index = 7;
|
|
1090
|
-
let length2;
|
|
1091
|
-
let column;
|
|
1092
|
-
let value;
|
|
1093
|
-
const row = query.isRaw ? new Array(query.statement.columns.length) : {};
|
|
1094
|
-
for (let i = 0; i < query.statement.columns.length; i++) {
|
|
1095
|
-
column = query.statement.columns[i];
|
|
1096
|
-
length2 = x.readInt32BE(index);
|
|
1097
|
-
index += 4;
|
|
1098
|
-
value = length2 === -1 ? null : query.isRaw === true ? x.subarray(index, index += length2) : column.parser === void 0 ? x.toString("utf8", index, index += length2) : column.parser.array === true ? column.parser(x.toString("utf8", index + 1, index += length2)) : column.parser(x.toString("utf8", index, index += length2));
|
|
1099
|
-
query.isRaw ? row[i] = query.isRaw === true ? value : transform.value.from ? transform.value.from(value, column) : value : row[column.name] = transform.value.from ? transform.value.from(value, column) : value;
|
|
1100
|
-
}
|
|
1101
|
-
query.forEachFn ? query.forEachFn(transform.row.from ? transform.row.from(row) : row, result) : result[rows++] = transform.row.from ? transform.row.from(row) : row;
|
|
1102
|
-
}
|
|
1103
|
-
function ParameterStatus(x) {
|
|
1104
|
-
const [k, v] = x.toString("utf8", 5, x.length - 1).split(bytes_default.N);
|
|
1105
|
-
backendParameters[k] = v;
|
|
1106
|
-
if (options.parameters[k] !== v) {
|
|
1107
|
-
options.parameters[k] = v;
|
|
1108
|
-
onparameter && onparameter(k, v);
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
function ReadyForQuery(x) {
|
|
1112
|
-
if (query) {
|
|
1113
|
-
if (errorResponse) {
|
|
1114
|
-
query.retried ? errored(query.retried) : query.prepared && retryRoutines.has(errorResponse.routine) ? retry(query, errorResponse) : errored(errorResponse);
|
|
1115
|
-
} else {
|
|
1116
|
-
query.resolve(results || result);
|
|
1117
|
-
}
|
|
1118
|
-
} else if (errorResponse) {
|
|
1119
|
-
errored(errorResponse);
|
|
1120
|
-
}
|
|
1121
|
-
query = results = errorResponse = null;
|
|
1122
|
-
result = new Result();
|
|
1123
|
-
connectTimer.cancel();
|
|
1124
|
-
if (initial) {
|
|
1125
|
-
if (target_session_attrs) {
|
|
1126
|
-
if (!backendParameters.in_hot_standby || !backendParameters.default_transaction_read_only)
|
|
1127
|
-
return fetchState();
|
|
1128
|
-
else if (tryNext(target_session_attrs, backendParameters))
|
|
1129
|
-
return terminate();
|
|
1130
|
-
}
|
|
1131
|
-
if (needsTypes) {
|
|
1132
|
-
initial.reserve && (initial = null);
|
|
1133
|
-
return fetchArrayTypes();
|
|
1134
|
-
}
|
|
1135
|
-
initial && !initial.reserve && execute(initial);
|
|
1136
|
-
options.shared.retries = retries = 0;
|
|
1137
|
-
initial = null;
|
|
1138
|
-
return;
|
|
1139
|
-
}
|
|
1140
|
-
while (sent.length && (query = sent.shift()) && (query.active = true, query.cancelled))
|
|
1141
|
-
Connection(options).cancel(query.state, query.cancelled.resolve, query.cancelled.reject);
|
|
1142
|
-
if (query)
|
|
1143
|
-
return;
|
|
1144
|
-
connection2.reserved ? !connection2.reserved.release && x[5] === 73 ? ending ? terminate() : (connection2.reserved = null, onopen(connection2)) : connection2.reserved() : ending ? terminate() : onopen(connection2);
|
|
1145
|
-
}
|
|
1146
|
-
function CommandComplete(x) {
|
|
1147
|
-
rows = 0;
|
|
1148
|
-
for (let i = x.length - 1; i > 0; i--) {
|
|
1149
|
-
if (x[i] === 32 && x[i + 1] < 58 && result.count === null)
|
|
1150
|
-
result.count = +x.toString("utf8", i + 1, x.length - 1);
|
|
1151
|
-
if (x[i - 1] >= 65) {
|
|
1152
|
-
result.command = x.toString("utf8", 5, i);
|
|
1153
|
-
result.state = backend;
|
|
1154
|
-
break;
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
final && (final(), final = null);
|
|
1158
|
-
if (result.command === "BEGIN" && max !== 1 && !connection2.reserved)
|
|
1159
|
-
return errored(Errors.generic("UNSAFE_TRANSACTION", "Only use sql.begin, sql.reserved or max: 1"));
|
|
1160
|
-
if (query.options.simple)
|
|
1161
|
-
return BindComplete();
|
|
1162
|
-
if (query.cursorFn) {
|
|
1163
|
-
result.count && query.cursorFn(result);
|
|
1164
|
-
write(Sync);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
function ParseComplete() {
|
|
1168
|
-
query.parsing = false;
|
|
1169
|
-
}
|
|
1170
|
-
function BindComplete() {
|
|
1171
|
-
!result.statement && (result.statement = query.statement);
|
|
1172
|
-
result.columns = query.statement.columns;
|
|
1173
|
-
}
|
|
1174
|
-
function ParameterDescription(x) {
|
|
1175
|
-
const length2 = x.readUInt16BE(5);
|
|
1176
|
-
for (let i = 0; i < length2; ++i)
|
|
1177
|
-
!query.statement.types[i] && (query.statement.types[i] = x.readUInt32BE(7 + i * 4));
|
|
1178
|
-
query.prepare && (statements[query.signature] = query.statement);
|
|
1179
|
-
query.describeFirst && !query.onlyDescribe && (write(prepared(query)), query.describeFirst = false);
|
|
1180
|
-
}
|
|
1181
|
-
function RowDescription(x) {
|
|
1182
|
-
if (result.command) {
|
|
1183
|
-
results = results || [result];
|
|
1184
|
-
results.push(result = new Result());
|
|
1185
|
-
result.count = null;
|
|
1186
|
-
query.statement.columns = null;
|
|
1187
|
-
}
|
|
1188
|
-
const length2 = x.readUInt16BE(5);
|
|
1189
|
-
let index = 7;
|
|
1190
|
-
let start;
|
|
1191
|
-
query.statement.columns = Array(length2);
|
|
1192
|
-
for (let i = 0; i < length2; ++i) {
|
|
1193
|
-
start = index;
|
|
1194
|
-
while (x[index++] !== 0) ;
|
|
1195
|
-
const table = x.readUInt32BE(index);
|
|
1196
|
-
const number = x.readUInt16BE(index + 4);
|
|
1197
|
-
const type = x.readUInt32BE(index + 6);
|
|
1198
|
-
query.statement.columns[i] = {
|
|
1199
|
-
name: transform.column.from ? transform.column.from(x.toString("utf8", start, index - 1)) : x.toString("utf8", start, index - 1),
|
|
1200
|
-
parser: parsers2[type],
|
|
1201
|
-
table,
|
|
1202
|
-
number,
|
|
1203
|
-
type
|
|
1204
|
-
};
|
|
1205
|
-
index += 18;
|
|
1206
|
-
}
|
|
1207
|
-
result.statement = query.statement;
|
|
1208
|
-
if (query.onlyDescribe)
|
|
1209
|
-
return query.resolve(query.statement), write(Sync);
|
|
1210
|
-
}
|
|
1211
|
-
function Authentication(_0) {
|
|
1212
|
-
return __async(this, arguments, function* (x, type = x.readUInt32BE(5)) {
|
|
1213
|
-
(type === 3 ? AuthenticationCleartextPassword : type === 5 ? AuthenticationMD5Password : type === 10 ? SASL : type === 11 ? SASLContinue : type === 12 ? SASLFinal : type !== 0 ? UnknownAuth : noop)(x, type);
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
function AuthenticationCleartextPassword() {
|
|
1217
|
-
return __async(this, null, function* () {
|
|
1218
|
-
const payload = yield Pass();
|
|
1219
|
-
write(
|
|
1220
|
-
bytes_default().p().str(payload).z(1).end()
|
|
1221
|
-
);
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
function AuthenticationMD5Password(x) {
|
|
1225
|
-
return __async(this, null, function* () {
|
|
1226
|
-
const payload = "md5" + (yield md5(
|
|
1227
|
-
Buffer.concat([
|
|
1228
|
-
Buffer.from(yield md5((yield Pass()) + user)),
|
|
1229
|
-
x.subarray(9)
|
|
1230
|
-
])
|
|
1231
|
-
));
|
|
1232
|
-
write(
|
|
1233
|
-
bytes_default().p().str(payload).z(1).end()
|
|
1234
|
-
);
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
function SASL() {
|
|
1238
|
-
return __async(this, null, function* () {
|
|
1239
|
-
nonce = (yield crypto__default.default.randomBytes(18)).toString("base64");
|
|
1240
|
-
bytes_default().p().str("SCRAM-SHA-256" + bytes_default.N);
|
|
1241
|
-
const i = bytes_default.i;
|
|
1242
|
-
write(bytes_default.inc(4).str("n,,n=*,r=" + nonce).i32(bytes_default.i - i - 4, i).end());
|
|
1243
|
-
});
|
|
1244
|
-
}
|
|
1245
|
-
function SASLContinue(x) {
|
|
1246
|
-
return __async(this, null, function* () {
|
|
1247
|
-
const res = x.toString("utf8", 9).split(",").reduce((acc, x2) => (acc[x2[0]] = x2.slice(2), acc), {});
|
|
1248
|
-
const saltedPassword = yield crypto__default.default.pbkdf2Sync(
|
|
1249
|
-
yield Pass(),
|
|
1250
|
-
Buffer.from(res.s, "base64"),
|
|
1251
|
-
parseInt(res.i),
|
|
1252
|
-
32,
|
|
1253
|
-
"sha256"
|
|
1254
|
-
);
|
|
1255
|
-
const clientKey = yield hmac(saltedPassword, "Client Key");
|
|
1256
|
-
const auth = "n=*,r=" + nonce + ",r=" + res.r + ",s=" + res.s + ",i=" + res.i + ",c=biws,r=" + res.r;
|
|
1257
|
-
serverSignature = (yield hmac(yield hmac(saltedPassword, "Server Key"), auth)).toString("base64");
|
|
1258
|
-
const payload = "c=biws,r=" + res.r + ",p=" + xor(
|
|
1259
|
-
clientKey,
|
|
1260
|
-
Buffer.from(yield hmac(yield sha256(clientKey), auth))
|
|
1261
|
-
).toString("base64");
|
|
1262
|
-
write(
|
|
1263
|
-
bytes_default().p().str(payload).end()
|
|
1264
|
-
);
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
function SASLFinal(x) {
|
|
1268
|
-
if (x.toString("utf8", 9).split(bytes_default.N, 1)[0].slice(2) === serverSignature)
|
|
1269
|
-
return;
|
|
1270
|
-
errored(Errors.generic("SASL_SIGNATURE_MISMATCH", "The server did not return the correct signature"));
|
|
1271
|
-
socket.destroy();
|
|
1272
|
-
}
|
|
1273
|
-
function Pass() {
|
|
1274
|
-
return Promise.resolve(
|
|
1275
|
-
typeof options.pass === "function" ? options.pass() : options.pass
|
|
1276
|
-
);
|
|
1277
|
-
}
|
|
1278
|
-
function NoData() {
|
|
1279
|
-
result.statement = query.statement;
|
|
1280
|
-
result.statement.columns = [];
|
|
1281
|
-
if (query.onlyDescribe)
|
|
1282
|
-
return query.resolve(query.statement), write(Sync);
|
|
1283
|
-
}
|
|
1284
|
-
function BackendKeyData(x) {
|
|
1285
|
-
backend.pid = x.readUInt32BE(5);
|
|
1286
|
-
backend.secret = x.readUInt32BE(9);
|
|
1287
|
-
}
|
|
1288
|
-
function fetchArrayTypes() {
|
|
1289
|
-
return __async(this, null, function* () {
|
|
1290
|
-
needsTypes = false;
|
|
1291
|
-
const types2 = yield new Query([`
|
|
1292
|
-
select b.oid, b.typarray
|
|
1293
|
-
from pg_catalog.pg_type a
|
|
1294
|
-
left join pg_catalog.pg_type b on b.oid = a.typelem
|
|
1295
|
-
where a.typcategory = 'A'
|
|
1296
|
-
group by b.oid, b.typarray
|
|
1297
|
-
order by b.oid
|
|
1298
|
-
`], [], execute);
|
|
1299
|
-
types2.forEach(({ oid, typarray }) => addArrayType(oid, typarray));
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
function addArrayType(oid, typarray) {
|
|
1303
|
-
if (!!options.parsers[typarray] && !!options.serializers[typarray]) return;
|
|
1304
|
-
const parser = options.parsers[oid];
|
|
1305
|
-
options.shared.typeArrayMap[oid] = typarray;
|
|
1306
|
-
options.parsers[typarray] = (xs) => arrayParser(xs, parser, typarray);
|
|
1307
|
-
options.parsers[typarray].array = true;
|
|
1308
|
-
options.serializers[typarray] = (xs) => arraySerializer(xs, options.serializers[oid], options, typarray);
|
|
1309
|
-
}
|
|
1310
|
-
function tryNext(x, xs) {
|
|
1311
|
-
return x === "read-write" && xs.default_transaction_read_only === "on" || x === "read-only" && xs.default_transaction_read_only === "off" || x === "primary" && xs.in_hot_standby === "on" || x === "standby" && xs.in_hot_standby === "off" || x === "prefer-standby" && xs.in_hot_standby === "off" && options.host[retries];
|
|
1312
|
-
}
|
|
1313
|
-
function fetchState() {
|
|
1314
|
-
const query2 = new Query([`
|
|
1315
|
-
show transaction_read_only;
|
|
1316
|
-
select pg_catalog.pg_is_in_recovery()
|
|
1317
|
-
`], [], execute, null, { simple: true });
|
|
1318
|
-
query2.resolve = ([[a], [b2]]) => {
|
|
1319
|
-
backendParameters.default_transaction_read_only = a.transaction_read_only;
|
|
1320
|
-
backendParameters.in_hot_standby = b2.pg_is_in_recovery ? "on" : "off";
|
|
1321
|
-
};
|
|
1322
|
-
query2.execute();
|
|
1323
|
-
}
|
|
1324
|
-
function ErrorResponse(x) {
|
|
1325
|
-
if (query) {
|
|
1326
|
-
(query.cursorFn || query.describeFirst) && write(Sync);
|
|
1327
|
-
errorResponse = Errors.postgres(parseError(x));
|
|
1328
|
-
} else {
|
|
1329
|
-
errored(Errors.postgres(parseError(x)));
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
function retry(q, error2) {
|
|
1333
|
-
delete statements[q.signature];
|
|
1334
|
-
q.retried = error2;
|
|
1335
|
-
execute(q);
|
|
1336
|
-
}
|
|
1337
|
-
function NotificationResponse(x) {
|
|
1338
|
-
if (!onnotify)
|
|
1339
|
-
return;
|
|
1340
|
-
let index = 9;
|
|
1341
|
-
while (x[index++] !== 0) ;
|
|
1342
|
-
onnotify(
|
|
1343
|
-
x.toString("utf8", 9, index - 1),
|
|
1344
|
-
x.toString("utf8", index, x.length - 1)
|
|
1345
|
-
);
|
|
1346
|
-
}
|
|
1347
|
-
function PortalSuspended() {
|
|
1348
|
-
return __async(this, null, function* () {
|
|
1349
|
-
try {
|
|
1350
|
-
const x = yield Promise.resolve(query.cursorFn(result));
|
|
1351
|
-
rows = 0;
|
|
1352
|
-
x === CLOSE ? write(Close(query.portal)) : (result = new Result(), write(Execute("", query.cursorRows)));
|
|
1353
|
-
} catch (err) {
|
|
1354
|
-
write(Sync);
|
|
1355
|
-
query.reject(err);
|
|
1356
|
-
}
|
|
1357
|
-
});
|
|
1358
|
-
}
|
|
1359
|
-
function CloseComplete() {
|
|
1360
|
-
result.count && query.cursorFn(result);
|
|
1361
|
-
query.resolve(result);
|
|
1362
|
-
}
|
|
1363
|
-
function CopyInResponse() {
|
|
1364
|
-
stream = new Stream__default.default.Writable({
|
|
1365
|
-
autoDestroy: true,
|
|
1366
|
-
write(chunk2, encoding, callback) {
|
|
1367
|
-
socket.write(bytes_default().d().raw(chunk2).end(), callback);
|
|
1368
|
-
},
|
|
1369
|
-
destroy(error2, callback) {
|
|
1370
|
-
callback(error2);
|
|
1371
|
-
socket.write(bytes_default().f().str(error2 + bytes_default.N).end());
|
|
1372
|
-
stream = null;
|
|
1373
|
-
},
|
|
1374
|
-
final(callback) {
|
|
1375
|
-
socket.write(bytes_default().c().end());
|
|
1376
|
-
final = callback;
|
|
1377
|
-
stream = null;
|
|
1378
|
-
}
|
|
1379
|
-
});
|
|
1380
|
-
query.resolve(stream);
|
|
1381
|
-
}
|
|
1382
|
-
function CopyOutResponse() {
|
|
1383
|
-
stream = new Stream__default.default.Readable({
|
|
1384
|
-
read() {
|
|
1385
|
-
socket.resume();
|
|
1386
|
-
}
|
|
1387
|
-
});
|
|
1388
|
-
query.resolve(stream);
|
|
1389
|
-
}
|
|
1390
|
-
function CopyBothResponse() {
|
|
1391
|
-
stream = new Stream__default.default.Duplex({
|
|
1392
|
-
autoDestroy: true,
|
|
1393
|
-
read() {
|
|
1394
|
-
socket.resume();
|
|
1395
|
-
},
|
|
1396
|
-
/* c8 ignore next 11 */
|
|
1397
|
-
write(chunk2, encoding, callback) {
|
|
1398
|
-
socket.write(bytes_default().d().raw(chunk2).end(), callback);
|
|
1399
|
-
},
|
|
1400
|
-
destroy(error2, callback) {
|
|
1401
|
-
callback(error2);
|
|
1402
|
-
socket.write(bytes_default().f().str(error2 + bytes_default.N).end());
|
|
1403
|
-
stream = null;
|
|
1404
|
-
},
|
|
1405
|
-
final(callback) {
|
|
1406
|
-
socket.write(bytes_default().c().end());
|
|
1407
|
-
final = callback;
|
|
1408
|
-
}
|
|
1409
|
-
});
|
|
1410
|
-
query.resolve(stream);
|
|
1411
|
-
}
|
|
1412
|
-
function CopyData(x) {
|
|
1413
|
-
stream && (stream.push(x.subarray(5)) || socket.pause());
|
|
1414
|
-
}
|
|
1415
|
-
function CopyDone() {
|
|
1416
|
-
stream && stream.push(null);
|
|
1417
|
-
stream = null;
|
|
1418
|
-
}
|
|
1419
|
-
function NoticeResponse(x) {
|
|
1420
|
-
onnotice ? onnotice(parseError(x)) : console.log(parseError(x));
|
|
1421
|
-
}
|
|
1422
|
-
function EmptyQueryResponse() {
|
|
1423
|
-
}
|
|
1424
|
-
function FunctionCallResponse() {
|
|
1425
|
-
errored(Errors.notSupported("FunctionCallResponse"));
|
|
1426
|
-
}
|
|
1427
|
-
function NegotiateProtocolVersion() {
|
|
1428
|
-
errored(Errors.notSupported("NegotiateProtocolVersion"));
|
|
1429
|
-
}
|
|
1430
|
-
function UnknownMessage(x) {
|
|
1431
|
-
console.error("Postgres.js : Unknown Message:", x[0]);
|
|
1432
|
-
}
|
|
1433
|
-
function UnknownAuth(x, type) {
|
|
1434
|
-
console.error("Postgres.js : Unknown Auth:", type);
|
|
1435
|
-
}
|
|
1436
|
-
function Bind(parameters, types2, statement = "", portal = "") {
|
|
1437
|
-
let prev, type;
|
|
1438
|
-
bytes_default().B().str(portal + bytes_default.N).str(statement + bytes_default.N).i16(0).i16(parameters.length);
|
|
1439
|
-
parameters.forEach((x, i) => {
|
|
1440
|
-
if (x === null)
|
|
1441
|
-
return bytes_default.i32(4294967295);
|
|
1442
|
-
type = types2[i];
|
|
1443
|
-
parameters[i] = x = type in options.serializers ? options.serializers[type](x) : "" + x;
|
|
1444
|
-
prev = bytes_default.i;
|
|
1445
|
-
bytes_default.inc(4).str(x).i32(bytes_default.i - prev - 4, prev);
|
|
1446
|
-
});
|
|
1447
|
-
bytes_default.i16(0);
|
|
1448
|
-
return bytes_default.end();
|
|
1449
|
-
}
|
|
1450
|
-
function Parse(str, parameters, types2, name = "") {
|
|
1451
|
-
bytes_default().P().str(name + bytes_default.N).str(str + bytes_default.N).i16(parameters.length);
|
|
1452
|
-
parameters.forEach((x, i) => bytes_default.i32(types2[i] || 0));
|
|
1453
|
-
return bytes_default.end();
|
|
1454
|
-
}
|
|
1455
|
-
function Describe(x, name = "") {
|
|
1456
|
-
return bytes_default().D().str(x).str(name + bytes_default.N).end();
|
|
1457
|
-
}
|
|
1458
|
-
function Execute(portal = "", rows2 = 0) {
|
|
1459
|
-
return Buffer.concat([
|
|
1460
|
-
bytes_default().E().str(portal + bytes_default.N).i32(rows2).end(),
|
|
1461
|
-
Flush
|
|
1462
|
-
]);
|
|
1463
|
-
}
|
|
1464
|
-
function Close(portal = "") {
|
|
1465
|
-
return Buffer.concat([
|
|
1466
|
-
bytes_default().C().str("P").str(portal + bytes_default.N).end(),
|
|
1467
|
-
bytes_default().S().end()
|
|
1468
|
-
]);
|
|
1469
|
-
}
|
|
1470
|
-
function StartupMessage() {
|
|
1471
|
-
return cancelMessage || bytes_default().inc(4).i16(3).z(2).str(
|
|
1472
|
-
Object.entries(Object.assign(
|
|
1473
|
-
{
|
|
1474
|
-
user,
|
|
1475
|
-
database,
|
|
1476
|
-
client_encoding: "UTF8"
|
|
1477
|
-
},
|
|
1478
|
-
options.connection
|
|
1479
|
-
)).filter(([, v]) => v).map(([k, v]) => k + bytes_default.N + v).join(bytes_default.N)
|
|
1480
|
-
).z(2).end(0);
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
function parseError(x) {
|
|
1484
|
-
const error = {};
|
|
1485
|
-
let start = 5;
|
|
1486
|
-
for (let i = 5; i < x.length - 1; i++) {
|
|
1487
|
-
if (x[i] === 0) {
|
|
1488
|
-
error[errorFields[x[start]]] = x.toString("utf8", start + 1, i);
|
|
1489
|
-
start = i + 1;
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
return error;
|
|
1493
|
-
}
|
|
1494
|
-
function md5(x) {
|
|
1495
|
-
return crypto__default.default.createHash("md5").update(x).digest("hex");
|
|
1496
|
-
}
|
|
1497
|
-
function hmac(key, x) {
|
|
1498
|
-
return crypto__default.default.createHmac("sha256", key).update(x).digest();
|
|
1499
|
-
}
|
|
1500
|
-
function sha256(x) {
|
|
1501
|
-
return crypto__default.default.createHash("sha256").update(x).digest();
|
|
1502
|
-
}
|
|
1503
|
-
function xor(a, b2) {
|
|
1504
|
-
const length = Math.max(a.length, b2.length);
|
|
1505
|
-
const buffer2 = Buffer.allocUnsafe(length);
|
|
1506
|
-
for (let i = 0; i < length; i++)
|
|
1507
|
-
buffer2[i] = a[i] ^ b2[i];
|
|
1508
|
-
return buffer2;
|
|
1509
|
-
}
|
|
1510
|
-
function timer(fn, seconds) {
|
|
1511
|
-
seconds = typeof seconds === "function" ? seconds() : seconds;
|
|
1512
|
-
if (!seconds)
|
|
1513
|
-
return { cancel: noop, start: noop };
|
|
1514
|
-
let timer2;
|
|
1515
|
-
return {
|
|
1516
|
-
cancel() {
|
|
1517
|
-
timer2 && (clearTimeout(timer2), timer2 = null);
|
|
1518
|
-
},
|
|
1519
|
-
start() {
|
|
1520
|
-
timer2 && clearTimeout(timer2);
|
|
1521
|
-
timer2 = setTimeout(done, seconds * 1e3, arguments);
|
|
1522
|
-
}
|
|
1523
|
-
};
|
|
1524
|
-
function done(args) {
|
|
1525
|
-
fn.apply(null, args);
|
|
1526
|
-
timer2 = null;
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
var connection_default, uid, Sync, Flush, SSLRequest, ExecuteUnnamed, DescribeUnnamed, noop, retryRoutines, errorFields;
|
|
1530
|
-
var init_connection = __esm({
|
|
1531
|
-
"node_modules/postgres/src/connection.js"() {
|
|
1532
|
-
init_types();
|
|
1533
|
-
init_errors();
|
|
1534
|
-
init_result();
|
|
1535
|
-
init_queue();
|
|
1536
|
-
init_query();
|
|
1537
|
-
init_bytes();
|
|
1538
|
-
connection_default = Connection;
|
|
1539
|
-
uid = 1;
|
|
1540
|
-
Sync = bytes_default().S().end();
|
|
1541
|
-
Flush = bytes_default().H().end();
|
|
1542
|
-
SSLRequest = bytes_default().i32(8).i32(80877103).end(8);
|
|
1543
|
-
ExecuteUnnamed = Buffer.concat([bytes_default().E().str(bytes_default.N).i32(0).end(), Sync]);
|
|
1544
|
-
DescribeUnnamed = bytes_default().D().str("S").str(bytes_default.N).end();
|
|
1545
|
-
noop = () => {
|
|
1546
|
-
};
|
|
1547
|
-
retryRoutines = /* @__PURE__ */ new Set([
|
|
1548
|
-
"FetchPreparedStatement",
|
|
1549
|
-
"RevalidateCachedQuery",
|
|
1550
|
-
"transformAssignedExpr"
|
|
1551
|
-
]);
|
|
1552
|
-
errorFields = {
|
|
1553
|
-
83: "severity_local",
|
|
1554
|
-
// S
|
|
1555
|
-
86: "severity",
|
|
1556
|
-
// V
|
|
1557
|
-
67: "code",
|
|
1558
|
-
// C
|
|
1559
|
-
77: "message",
|
|
1560
|
-
// M
|
|
1561
|
-
68: "detail",
|
|
1562
|
-
// D
|
|
1563
|
-
72: "hint",
|
|
1564
|
-
// H
|
|
1565
|
-
80: "position",
|
|
1566
|
-
// P
|
|
1567
|
-
112: "internal_position",
|
|
1568
|
-
// p
|
|
1569
|
-
113: "internal_query",
|
|
1570
|
-
// q
|
|
1571
|
-
87: "where",
|
|
1572
|
-
// W
|
|
1573
|
-
115: "schema_name",
|
|
1574
|
-
// s
|
|
1575
|
-
116: "table_name",
|
|
1576
|
-
// t
|
|
1577
|
-
99: "column_name",
|
|
1578
|
-
// c
|
|
1579
|
-
100: "data type_name",
|
|
1580
|
-
// d
|
|
1581
|
-
110: "constraint_name",
|
|
1582
|
-
// n
|
|
1583
|
-
70: "file",
|
|
1584
|
-
// F
|
|
1585
|
-
76: "line",
|
|
1586
|
-
// L
|
|
1587
|
-
82: "routine"
|
|
1588
|
-
// R
|
|
1589
|
-
};
|
|
1590
|
-
}
|
|
1591
|
-
});
|
|
1592
|
-
|
|
1593
|
-
// node_modules/postgres/src/subscribe.js
|
|
1594
|
-
function Subscribe(postgres2, options) {
|
|
1595
|
-
const subscribers = /* @__PURE__ */ new Map(), slot = "postgresjs_" + Math.random().toString(36).slice(2), state = {};
|
|
1596
|
-
let connection2, stream, ended = false;
|
|
1597
|
-
const sql = subscribe.sql = postgres2(__spreadProps(__spreadValues({}, options), {
|
|
1598
|
-
transform: { column: {}, value: {}, row: {} },
|
|
1599
|
-
max: 1,
|
|
1600
|
-
fetch_types: false,
|
|
1601
|
-
idle_timeout: null,
|
|
1602
|
-
max_lifetime: null,
|
|
1603
|
-
connection: __spreadProps(__spreadValues({}, options.connection), {
|
|
1604
|
-
replication: "database"
|
|
1605
|
-
}),
|
|
1606
|
-
onclose: function() {
|
|
1607
|
-
return __async(this, null, function* () {
|
|
1608
|
-
if (ended)
|
|
1609
|
-
return;
|
|
1610
|
-
stream = null;
|
|
1611
|
-
state.pid = state.secret = void 0;
|
|
1612
|
-
connected(yield init(sql, slot, options.publications));
|
|
1613
|
-
subscribers.forEach((event) => event.forEach(({ onsubscribe }) => onsubscribe()));
|
|
1614
|
-
});
|
|
1615
|
-
},
|
|
1616
|
-
no_subscribe: true
|
|
1617
|
-
}));
|
|
1618
|
-
const end = sql.end, close = sql.close;
|
|
1619
|
-
sql.end = () => __async(null, null, function* () {
|
|
1620
|
-
ended = true;
|
|
1621
|
-
stream && (yield new Promise((r) => (stream.once("close", r), stream.end())));
|
|
1622
|
-
return end();
|
|
1623
|
-
});
|
|
1624
|
-
sql.close = () => __async(null, null, function* () {
|
|
1625
|
-
stream && (yield new Promise((r) => (stream.once("close", r), stream.end())));
|
|
1626
|
-
return close();
|
|
1627
|
-
});
|
|
1628
|
-
return subscribe;
|
|
1629
|
-
function subscribe(_0, _1) {
|
|
1630
|
-
return __async(this, arguments, function* (event, fn, onsubscribe = noop2, onerror = noop2) {
|
|
1631
|
-
event = parseEvent(event);
|
|
1632
|
-
if (!connection2)
|
|
1633
|
-
connection2 = init(sql, slot, options.publications);
|
|
1634
|
-
const subscriber = { fn, onsubscribe };
|
|
1635
|
-
const fns = subscribers.has(event) ? subscribers.get(event).add(subscriber) : subscribers.set(event, /* @__PURE__ */ new Set([subscriber])).get(event);
|
|
1636
|
-
const unsubscribe = () => {
|
|
1637
|
-
fns.delete(subscriber);
|
|
1638
|
-
fns.size === 0 && subscribers.delete(event);
|
|
1639
|
-
};
|
|
1640
|
-
return connection2.then((x) => {
|
|
1641
|
-
connected(x);
|
|
1642
|
-
onsubscribe();
|
|
1643
|
-
stream && stream.on("error", onerror);
|
|
1644
|
-
return { unsubscribe, state, sql };
|
|
1645
|
-
});
|
|
1646
|
-
});
|
|
1647
|
-
}
|
|
1648
|
-
function connected(x) {
|
|
1649
|
-
stream = x.stream;
|
|
1650
|
-
state.pid = x.state.pid;
|
|
1651
|
-
state.secret = x.state.secret;
|
|
1652
|
-
}
|
|
1653
|
-
function init(sql2, slot2, publications) {
|
|
1654
|
-
return __async(this, null, function* () {
|
|
1655
|
-
if (!publications)
|
|
1656
|
-
throw new Error("Missing publication names");
|
|
1657
|
-
const xs = yield sql2.unsafe(
|
|
1658
|
-
`CREATE_REPLICATION_SLOT ${slot2} TEMPORARY LOGICAL pgoutput NOEXPORT_SNAPSHOT`
|
|
1659
|
-
);
|
|
1660
|
-
const [x] = xs;
|
|
1661
|
-
const stream2 = yield sql2.unsafe(
|
|
1662
|
-
`START_REPLICATION SLOT ${slot2} LOGICAL ${x.consistent_point} (proto_version '1', publication_names '${publications}')`
|
|
1663
|
-
).writable();
|
|
1664
|
-
const state2 = {
|
|
1665
|
-
lsn: Buffer.concat(x.consistent_point.split("/").map((x2) => Buffer.from(("00000000" + x2).slice(-8), "hex")))
|
|
1666
|
-
};
|
|
1667
|
-
stream2.on("data", data);
|
|
1668
|
-
stream2.on("error", error);
|
|
1669
|
-
stream2.on("close", sql2.close);
|
|
1670
|
-
return { stream: stream2, state: xs.state };
|
|
1671
|
-
function error(e) {
|
|
1672
|
-
console.error("Unexpected error during logical streaming - reconnecting", e);
|
|
1673
|
-
}
|
|
1674
|
-
function data(x2) {
|
|
1675
|
-
if (x2[0] === 119) {
|
|
1676
|
-
parse(x2.subarray(25), state2, sql2.options.parsers, handle, options.transform);
|
|
1677
|
-
} else if (x2[0] === 107 && x2[17]) {
|
|
1678
|
-
state2.lsn = x2.subarray(1, 9);
|
|
1679
|
-
pong();
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
function handle(a, b2) {
|
|
1683
|
-
const path = b2.relation.schema + "." + b2.relation.table;
|
|
1684
|
-
call("*", a, b2);
|
|
1685
|
-
call("*:" + path, a, b2);
|
|
1686
|
-
b2.relation.keys.length && call("*:" + path + "=" + b2.relation.keys.map((x2) => a[x2.name]), a, b2);
|
|
1687
|
-
call(b2.command, a, b2);
|
|
1688
|
-
call(b2.command + ":" + path, a, b2);
|
|
1689
|
-
b2.relation.keys.length && call(b2.command + ":" + path + "=" + b2.relation.keys.map((x2) => a[x2.name]), a, b2);
|
|
1690
|
-
}
|
|
1691
|
-
function pong() {
|
|
1692
|
-
const x2 = Buffer.alloc(34);
|
|
1693
|
-
x2[0] = "r".charCodeAt(0);
|
|
1694
|
-
x2.fill(state2.lsn, 1);
|
|
1695
|
-
x2.writeBigInt64BE(BigInt(Date.now() - Date.UTC(2e3, 0, 1)) * BigInt(1e3), 25);
|
|
1696
|
-
stream2.write(x2);
|
|
1697
|
-
}
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
function call(x, a, b2) {
|
|
1701
|
-
subscribers.has(x) && subscribers.get(x).forEach(({ fn }) => fn(a, b2, x));
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
function Time(x) {
|
|
1705
|
-
return new Date(Date.UTC(2e3, 0, 1) + Number(x / BigInt(1e3)));
|
|
1706
|
-
}
|
|
1707
|
-
function parse(x, state, parsers2, handle, transform) {
|
|
1708
|
-
const char = (acc, [k, v]) => (acc[k.charCodeAt(0)] = v, acc);
|
|
1709
|
-
Object.entries({
|
|
1710
|
-
R: (x2) => {
|
|
1711
|
-
let i = 1;
|
|
1712
|
-
const r = state[x2.readUInt32BE(i)] = {
|
|
1713
|
-
schema: x2.toString("utf8", i += 4, i = x2.indexOf(0, i)) || "pg_catalog",
|
|
1714
|
-
table: x2.toString("utf8", i + 1, i = x2.indexOf(0, i + 1)),
|
|
1715
|
-
columns: Array(x2.readUInt16BE(i += 2)),
|
|
1716
|
-
keys: []
|
|
1717
|
-
};
|
|
1718
|
-
i += 2;
|
|
1719
|
-
let columnIndex = 0, column;
|
|
1720
|
-
while (i < x2.length) {
|
|
1721
|
-
column = r.columns[columnIndex++] = {
|
|
1722
|
-
key: x2[i++],
|
|
1723
|
-
name: transform.column.from ? transform.column.from(x2.toString("utf8", i, i = x2.indexOf(0, i))) : x2.toString("utf8", i, i = x2.indexOf(0, i)),
|
|
1724
|
-
type: x2.readUInt32BE(i += 1),
|
|
1725
|
-
parser: parsers2[x2.readUInt32BE(i)],
|
|
1726
|
-
atttypmod: x2.readUInt32BE(i += 4)
|
|
1727
|
-
};
|
|
1728
|
-
column.key && r.keys.push(column);
|
|
1729
|
-
i += 4;
|
|
1730
|
-
}
|
|
1731
|
-
},
|
|
1732
|
-
Y: () => {
|
|
1733
|
-
},
|
|
1734
|
-
// Type
|
|
1735
|
-
O: () => {
|
|
1736
|
-
},
|
|
1737
|
-
// Origin
|
|
1738
|
-
B: (x2) => {
|
|
1739
|
-
state.date = Time(x2.readBigInt64BE(9));
|
|
1740
|
-
state.lsn = x2.subarray(1, 9);
|
|
1741
|
-
},
|
|
1742
|
-
I: (x2) => {
|
|
1743
|
-
let i = 1;
|
|
1744
|
-
const relation = state[x2.readUInt32BE(i)];
|
|
1745
|
-
const { row } = tuples(x2, relation.columns, i += 7, transform);
|
|
1746
|
-
handle(row, {
|
|
1747
|
-
command: "insert",
|
|
1748
|
-
relation
|
|
1749
|
-
});
|
|
1750
|
-
},
|
|
1751
|
-
D: (x2) => {
|
|
1752
|
-
let i = 1;
|
|
1753
|
-
const relation = state[x2.readUInt32BE(i)];
|
|
1754
|
-
i += 4;
|
|
1755
|
-
const key = x2[i] === 75;
|
|
1756
|
-
handle(
|
|
1757
|
-
key || x2[i] === 79 ? tuples(x2, relation.columns, i += 3, transform).row : null,
|
|
1758
|
-
{
|
|
1759
|
-
command: "delete",
|
|
1760
|
-
relation,
|
|
1761
|
-
key
|
|
1762
|
-
}
|
|
1763
|
-
);
|
|
1764
|
-
},
|
|
1765
|
-
U: (x2) => {
|
|
1766
|
-
let i = 1;
|
|
1767
|
-
const relation = state[x2.readUInt32BE(i)];
|
|
1768
|
-
i += 4;
|
|
1769
|
-
const key = x2[i] === 75;
|
|
1770
|
-
const xs = key || x2[i] === 79 ? tuples(x2, relation.columns, i += 3, transform) : null;
|
|
1771
|
-
xs && (i = xs.i);
|
|
1772
|
-
const { row } = tuples(x2, relation.columns, i + 3, transform);
|
|
1773
|
-
handle(row, {
|
|
1774
|
-
command: "update",
|
|
1775
|
-
relation,
|
|
1776
|
-
key,
|
|
1777
|
-
old: xs && xs.row
|
|
1778
|
-
});
|
|
1779
|
-
},
|
|
1780
|
-
T: () => {
|
|
1781
|
-
},
|
|
1782
|
-
// Truncate,
|
|
1783
|
-
C: () => {
|
|
1784
|
-
}
|
|
1785
|
-
// Commit
|
|
1786
|
-
}).reduce(char, {})[x[0]](x);
|
|
1787
|
-
}
|
|
1788
|
-
function tuples(x, columns, xi, transform) {
|
|
1789
|
-
let type, column, value;
|
|
1790
|
-
const row = transform.raw ? new Array(columns.length) : {};
|
|
1791
|
-
for (let i = 0; i < columns.length; i++) {
|
|
1792
|
-
type = x[xi++];
|
|
1793
|
-
column = columns[i];
|
|
1794
|
-
value = type === 110 ? null : type === 117 ? void 0 : column.parser === void 0 ? x.toString("utf8", xi + 4, xi += 4 + x.readUInt32BE(xi)) : column.parser.array === true ? column.parser(x.toString("utf8", xi + 5, xi += 4 + x.readUInt32BE(xi))) : column.parser(x.toString("utf8", xi + 4, xi += 4 + x.readUInt32BE(xi)));
|
|
1795
|
-
transform.raw ? row[i] = transform.raw === true ? value : transform.value.from ? transform.value.from(value, column) : value : row[column.name] = transform.value.from ? transform.value.from(value, column) : value;
|
|
1796
|
-
}
|
|
1797
|
-
return { i: xi, row: transform.row.from ? transform.row.from(row) : row };
|
|
1798
|
-
}
|
|
1799
|
-
function parseEvent(x) {
|
|
1800
|
-
const xs = x.match(/^(\*|insert|update|delete)?:?([^.]+?\.?[^=]+)?=?(.+)?/i) || [];
|
|
1801
|
-
if (!xs)
|
|
1802
|
-
throw new Error("Malformed subscribe pattern: " + x);
|
|
1803
|
-
const [, command, path, key] = xs;
|
|
1804
|
-
return (command || "*") + (path ? ":" + (path.indexOf(".") === -1 ? "public." + path : path) : "") + (key ? "=" + key : "");
|
|
1805
|
-
}
|
|
1806
|
-
var noop2;
|
|
1807
|
-
var init_subscribe = __esm({
|
|
1808
|
-
"node_modules/postgres/src/subscribe.js"() {
|
|
1809
|
-
noop2 = () => {
|
|
1810
|
-
};
|
|
1811
|
-
}
|
|
1812
|
-
});
|
|
1813
|
-
function largeObject(sql, oid, mode = 131072 | 262144) {
|
|
1814
|
-
return new Promise((resolve3, reject) => __async(null, null, function* () {
|
|
1815
|
-
yield sql.begin((sql2) => __async(null, null, function* () {
|
|
1816
|
-
let finish;
|
|
1817
|
-
!oid && ([{ oid }] = yield sql2`select lo_creat(-1) as oid`);
|
|
1818
|
-
const [{ fd }] = yield sql2`select lo_open(${oid}, ${mode}) as fd`;
|
|
1819
|
-
const lo = {
|
|
1820
|
-
writable,
|
|
1821
|
-
readable,
|
|
1822
|
-
close: () => sql2`select lo_close(${fd})`.then(finish),
|
|
1823
|
-
tell: () => sql2`select lo_tell64(${fd})`,
|
|
1824
|
-
read: (x) => sql2`select loread(${fd}, ${x}) as data`,
|
|
1825
|
-
write: (x) => sql2`select lowrite(${fd}, ${x})`,
|
|
1826
|
-
truncate: (x) => sql2`select lo_truncate64(${fd}, ${x})`,
|
|
1827
|
-
seek: (x, whence = 0) => sql2`select lo_lseek64(${fd}, ${x}, ${whence})`,
|
|
1828
|
-
size: () => sql2`
|
|
1829
|
-
select
|
|
1830
|
-
lo_lseek64(${fd}, location, 0) as position,
|
|
1831
|
-
seek.size
|
|
1832
|
-
from (
|
|
1833
|
-
select
|
|
1834
|
-
lo_lseek64($1, 0, 2) as size,
|
|
1835
|
-
tell.location
|
|
1836
|
-
from (select lo_tell64($1) as location) tell
|
|
1837
|
-
) seek
|
|
1838
|
-
`
|
|
1839
|
-
};
|
|
1840
|
-
resolve3(lo);
|
|
1841
|
-
return new Promise((r) => __async(null, null, function* () {
|
|
1842
|
-
return finish = r;
|
|
1843
|
-
}));
|
|
1844
|
-
function readable() {
|
|
1845
|
-
return __async(this, arguments, function* ({
|
|
1846
|
-
highWaterMark = 2048 * 8,
|
|
1847
|
-
start = 0,
|
|
1848
|
-
end = Infinity
|
|
1849
|
-
} = {}) {
|
|
1850
|
-
let max = end - start;
|
|
1851
|
-
start && (yield lo.seek(start));
|
|
1852
|
-
return new Stream__default.default.Readable({
|
|
1853
|
-
highWaterMark,
|
|
1854
|
-
read(size2) {
|
|
1855
|
-
return __async(this, null, function* () {
|
|
1856
|
-
const l = size2 > max ? size2 - max : size2;
|
|
1857
|
-
max -= size2;
|
|
1858
|
-
const [{ data }] = yield lo.read(l);
|
|
1859
|
-
this.push(data);
|
|
1860
|
-
if (data.length < size2)
|
|
1861
|
-
this.push(null);
|
|
1862
|
-
});
|
|
1863
|
-
}
|
|
1864
|
-
});
|
|
1865
|
-
});
|
|
1866
|
-
}
|
|
1867
|
-
function writable() {
|
|
1868
|
-
return __async(this, arguments, function* ({
|
|
1869
|
-
highWaterMark = 2048 * 8,
|
|
1870
|
-
start = 0
|
|
1871
|
-
} = {}) {
|
|
1872
|
-
start && (yield lo.seek(start));
|
|
1873
|
-
return new Stream__default.default.Writable({
|
|
1874
|
-
highWaterMark,
|
|
1875
|
-
write(chunk, encoding, callback) {
|
|
1876
|
-
lo.write(chunk).then(() => callback(), callback);
|
|
1877
|
-
}
|
|
1878
|
-
});
|
|
1879
|
-
});
|
|
1880
|
-
}
|
|
1881
|
-
})).catch(reject);
|
|
1882
|
-
}));
|
|
1883
|
-
}
|
|
1884
|
-
var init_large = __esm({
|
|
1885
|
-
"node_modules/postgres/src/large.js"() {
|
|
1886
|
-
}
|
|
1887
|
-
});
|
|
1888
|
-
|
|
1889
|
-
// node_modules/postgres/src/index.js
|
|
1890
|
-
var src_exports = {};
|
|
1891
|
-
__export(src_exports, {
|
|
1892
|
-
default: () => src_default
|
|
1893
|
-
});
|
|
1894
|
-
function Postgres(a, b2) {
|
|
1895
|
-
const options = parseOptions(a, b2), subscribe = options.no_subscribe || Subscribe(Postgres, __spreadValues({}, options));
|
|
1896
|
-
let ending = false;
|
|
1897
|
-
const queries = queue_default(), connecting = queue_default(), reserved = queue_default(), closed = queue_default(), ended = queue_default(), open = queue_default(), busy = queue_default(), full = queue_default(), queues = { connecting, reserved, closed, ended, open, busy, full };
|
|
1898
|
-
const connections = [...Array(options.max)].map(() => connection_default(options, queues, { onopen, onend, onclose }));
|
|
1899
|
-
const sql = Sql(handler);
|
|
1900
|
-
Object.assign(sql, {
|
|
1901
|
-
get parameters() {
|
|
1902
|
-
return options.parameters;
|
|
1903
|
-
},
|
|
1904
|
-
largeObject: largeObject.bind(null, sql),
|
|
1905
|
-
subscribe,
|
|
1906
|
-
CLOSE,
|
|
1907
|
-
END: CLOSE,
|
|
1908
|
-
PostgresError,
|
|
1909
|
-
options,
|
|
1910
|
-
reserve,
|
|
1911
|
-
listen,
|
|
1912
|
-
begin,
|
|
1913
|
-
close,
|
|
1914
|
-
end
|
|
1915
|
-
});
|
|
1916
|
-
return sql;
|
|
1917
|
-
function Sql(handler2) {
|
|
1918
|
-
handler2.debug = options.debug;
|
|
1919
|
-
Object.entries(options.types).reduce((acc, [name, type]) => {
|
|
1920
|
-
acc[name] = (x) => new Parameter(x, type.to);
|
|
1921
|
-
return acc;
|
|
1922
|
-
}, typed);
|
|
1923
|
-
Object.assign(sql2, {
|
|
1924
|
-
types: typed,
|
|
1925
|
-
typed,
|
|
1926
|
-
unsafe,
|
|
1927
|
-
notify,
|
|
1928
|
-
array,
|
|
1929
|
-
json,
|
|
1930
|
-
file
|
|
1931
|
-
});
|
|
1932
|
-
return sql2;
|
|
1933
|
-
function typed(value, type) {
|
|
1934
|
-
return new Parameter(value, type);
|
|
1935
|
-
}
|
|
1936
|
-
function sql2(strings, ...args) {
|
|
1937
|
-
const query = strings && Array.isArray(strings.raw) ? new Query(strings, args, handler2, cancel) : typeof strings === "string" && !args.length ? new Identifier(options.transform.column.to ? options.transform.column.to(strings) : strings) : new Builder(strings, args);
|
|
1938
|
-
return query;
|
|
1939
|
-
}
|
|
1940
|
-
function unsafe(string, args = [], options2 = {}) {
|
|
1941
|
-
arguments.length === 2 && !Array.isArray(args) && (options2 = args, args = []);
|
|
1942
|
-
const query = new Query([string], args, handler2, cancel, __spreadProps(__spreadValues({
|
|
1943
|
-
prepare: false
|
|
1944
|
-
}, options2), {
|
|
1945
|
-
simple: "simple" in options2 ? options2.simple : args.length === 0
|
|
1946
|
-
}));
|
|
1947
|
-
return query;
|
|
1948
|
-
}
|
|
1949
|
-
function file(path, args = [], options2 = {}) {
|
|
1950
|
-
arguments.length === 2 && !Array.isArray(args) && (options2 = args, args = []);
|
|
1951
|
-
const query = new Query([], args, (query2) => {
|
|
1952
|
-
fs__default.default.readFile(path, "utf8", (err, string) => {
|
|
1953
|
-
if (err)
|
|
1954
|
-
return query2.reject(err);
|
|
1955
|
-
query2.strings = [string];
|
|
1956
|
-
handler2(query2);
|
|
1957
|
-
});
|
|
1958
|
-
}, cancel, __spreadProps(__spreadValues({}, options2), {
|
|
1959
|
-
simple: "simple" in options2 ? options2.simple : args.length === 0
|
|
1960
|
-
}));
|
|
1961
|
-
return query;
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
function listen(name, fn, onlisten) {
|
|
1965
|
-
return __async(this, null, function* () {
|
|
1966
|
-
const listener = { fn, onlisten };
|
|
1967
|
-
const sql2 = listen.sql || (listen.sql = Postgres(__spreadProps(__spreadValues({}, options), {
|
|
1968
|
-
max: 1,
|
|
1969
|
-
idle_timeout: null,
|
|
1970
|
-
max_lifetime: null,
|
|
1971
|
-
fetch_types: false,
|
|
1972
|
-
onclose() {
|
|
1973
|
-
Object.entries(listen.channels).forEach(([name2, { listeners }]) => {
|
|
1974
|
-
delete listen.channels[name2];
|
|
1975
|
-
Promise.all(listeners.map((l) => listen(name2, l.fn, l.onlisten).catch(() => {
|
|
1976
|
-
})));
|
|
1977
|
-
});
|
|
1978
|
-
},
|
|
1979
|
-
onnotify(c, x) {
|
|
1980
|
-
c in listen.channels && listen.channels[c].listeners.forEach((l) => l.fn(x));
|
|
1981
|
-
}
|
|
1982
|
-
})));
|
|
1983
|
-
const channels = listen.channels || (listen.channels = {}), exists = name in channels;
|
|
1984
|
-
if (exists) {
|
|
1985
|
-
channels[name].listeners.push(listener);
|
|
1986
|
-
const result2 = yield channels[name].result;
|
|
1987
|
-
listener.onlisten && listener.onlisten();
|
|
1988
|
-
return { state: result2.state, unlisten };
|
|
1989
|
-
}
|
|
1990
|
-
channels[name] = { result: sql2`listen ${sql2.unsafe('"' + name.replace(/"/g, '""') + '"')}`, listeners: [listener] };
|
|
1991
|
-
const result = yield channels[name].result;
|
|
1992
|
-
listener.onlisten && listener.onlisten();
|
|
1993
|
-
return { state: result.state, unlisten };
|
|
1994
|
-
function unlisten() {
|
|
1995
|
-
return __async(this, null, function* () {
|
|
1996
|
-
if (name in channels === false)
|
|
1997
|
-
return;
|
|
1998
|
-
channels[name].listeners = channels[name].listeners.filter((x) => x !== listener);
|
|
1999
|
-
if (channels[name].listeners.length)
|
|
2000
|
-
return;
|
|
2001
|
-
delete channels[name];
|
|
2002
|
-
return sql2`unlisten ${sql2.unsafe('"' + name.replace(/"/g, '""') + '"')}`;
|
|
2003
|
-
});
|
|
2004
|
-
}
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
function notify(channel, payload) {
|
|
2008
|
-
return __async(this, null, function* () {
|
|
2009
|
-
return yield sql`select pg_notify(${channel}, ${"" + payload})`;
|
|
2010
|
-
});
|
|
2011
|
-
}
|
|
2012
|
-
function reserve() {
|
|
2013
|
-
return __async(this, null, function* () {
|
|
2014
|
-
const queue = queue_default();
|
|
2015
|
-
const c = open.length ? open.shift() : yield new Promise((resolve3, reject) => {
|
|
2016
|
-
const query = { reserve: resolve3, reject };
|
|
2017
|
-
queries.push(query);
|
|
2018
|
-
closed.length && connect(closed.shift(), query);
|
|
2019
|
-
});
|
|
2020
|
-
move(c, reserved);
|
|
2021
|
-
c.reserved = () => queue.length ? c.execute(queue.shift()) : move(c, reserved);
|
|
2022
|
-
c.reserved.release = true;
|
|
2023
|
-
const sql2 = Sql(handler2);
|
|
2024
|
-
sql2.release = () => {
|
|
2025
|
-
c.reserved = null;
|
|
2026
|
-
onopen(c);
|
|
2027
|
-
};
|
|
2028
|
-
return sql2;
|
|
2029
|
-
function handler2(q) {
|
|
2030
|
-
c.queue === full ? queue.push(q) : c.execute(q) || move(c, full);
|
|
2031
|
-
}
|
|
2032
|
-
});
|
|
2033
|
-
}
|
|
2034
|
-
function begin(options2, fn) {
|
|
2035
|
-
return __async(this, null, function* () {
|
|
2036
|
-
!fn && (fn = options2, options2 = "");
|
|
2037
|
-
const queries2 = queue_default();
|
|
2038
|
-
let savepoints = 0, connection2, prepare = null;
|
|
2039
|
-
try {
|
|
2040
|
-
yield sql.unsafe("begin " + options2.replace(/[^a-z ]/ig, ""), [], { onexecute }).execute();
|
|
2041
|
-
return yield Promise.race([
|
|
2042
|
-
scope(connection2, fn),
|
|
2043
|
-
new Promise((_, reject) => connection2.onclose = reject)
|
|
2044
|
-
]);
|
|
2045
|
-
} catch (error) {
|
|
2046
|
-
throw error;
|
|
2047
|
-
}
|
|
2048
|
-
function scope(c, fn2, name) {
|
|
2049
|
-
return __async(this, null, function* () {
|
|
2050
|
-
const sql2 = Sql(handler2);
|
|
2051
|
-
sql2.savepoint = savepoint;
|
|
2052
|
-
sql2.prepare = (x) => prepare = x.replace(/[^a-z0-9$-_. ]/gi);
|
|
2053
|
-
let uncaughtError, result;
|
|
2054
|
-
name && (yield sql2`savepoint ${sql2(name)}`);
|
|
2055
|
-
try {
|
|
2056
|
-
result = yield new Promise((resolve3, reject) => {
|
|
2057
|
-
const x = fn2(sql2);
|
|
2058
|
-
Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve3, reject);
|
|
2059
|
-
});
|
|
2060
|
-
if (uncaughtError)
|
|
2061
|
-
throw uncaughtError;
|
|
2062
|
-
} catch (e) {
|
|
2063
|
-
yield name ? sql2`rollback to ${sql2(name)}` : sql2`rollback`;
|
|
2064
|
-
throw e instanceof PostgresError && e.code === "25P02" && uncaughtError || e;
|
|
2065
|
-
}
|
|
2066
|
-
if (!name) {
|
|
2067
|
-
prepare ? yield sql2`prepare transaction '${sql2.unsafe(prepare)}'` : yield sql2`commit`;
|
|
2068
|
-
}
|
|
2069
|
-
return result;
|
|
2070
|
-
function savepoint(name2, fn3) {
|
|
2071
|
-
if (name2 && Array.isArray(name2.raw))
|
|
2072
|
-
return savepoint((sql3) => sql3.apply(sql3, arguments));
|
|
2073
|
-
arguments.length === 1 && (fn3 = name2, name2 = null);
|
|
2074
|
-
return scope(c, fn3, "s" + savepoints++ + (name2 ? "_" + name2 : ""));
|
|
2075
|
-
}
|
|
2076
|
-
function handler2(q) {
|
|
2077
|
-
q.catch((e) => uncaughtError || (uncaughtError = e));
|
|
2078
|
-
c.queue === full ? queries2.push(q) : c.execute(q) || move(c, full);
|
|
2079
|
-
}
|
|
2080
|
-
});
|
|
2081
|
-
}
|
|
2082
|
-
function onexecute(c) {
|
|
2083
|
-
connection2 = c;
|
|
2084
|
-
move(c, reserved);
|
|
2085
|
-
c.reserved = () => queries2.length ? c.execute(queries2.shift()) : move(c, reserved);
|
|
2086
|
-
}
|
|
2087
|
-
});
|
|
2088
|
-
}
|
|
2089
|
-
function move(c, queue) {
|
|
2090
|
-
c.queue.remove(c);
|
|
2091
|
-
queue.push(c);
|
|
2092
|
-
c.queue = queue;
|
|
2093
|
-
queue === open ? c.idleTimer.start() : c.idleTimer.cancel();
|
|
2094
|
-
return c;
|
|
2095
|
-
}
|
|
2096
|
-
function json(x) {
|
|
2097
|
-
return new Parameter(x, 3802);
|
|
2098
|
-
}
|
|
2099
|
-
function array(x, type) {
|
|
2100
|
-
if (!Array.isArray(x))
|
|
2101
|
-
return array(Array.from(arguments));
|
|
2102
|
-
return new Parameter(x, type || (x.length ? inferType(x) || 25 : 0), options.shared.typeArrayMap);
|
|
2103
|
-
}
|
|
2104
|
-
function handler(query) {
|
|
2105
|
-
if (ending)
|
|
2106
|
-
return query.reject(Errors.connection("CONNECTION_ENDED", options, options));
|
|
2107
|
-
if (open.length)
|
|
2108
|
-
return go(open.shift(), query);
|
|
2109
|
-
if (closed.length)
|
|
2110
|
-
return connect(closed.shift(), query);
|
|
2111
|
-
busy.length ? go(busy.shift(), query) : queries.push(query);
|
|
2112
|
-
}
|
|
2113
|
-
function go(c, query) {
|
|
2114
|
-
return c.execute(query) ? move(c, busy) : move(c, full);
|
|
2115
|
-
}
|
|
2116
|
-
function cancel(query) {
|
|
2117
|
-
return new Promise((resolve3, reject) => {
|
|
2118
|
-
query.state ? query.active ? connection_default(options).cancel(query.state, resolve3, reject) : query.cancelled = { resolve: resolve3, reject } : (queries.remove(query), query.cancelled = true, query.reject(Errors.generic("57014", "canceling statement due to user request")), resolve3());
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
function end() {
|
|
2122
|
-
return __async(this, arguments, function* ({ timeout = null } = {}) {
|
|
2123
|
-
if (ending)
|
|
2124
|
-
return ending;
|
|
2125
|
-
yield 1;
|
|
2126
|
-
let timer2;
|
|
2127
|
-
return ending = Promise.race([
|
|
2128
|
-
new Promise((r) => timeout !== null && (timer2 = setTimeout(destroy, timeout * 1e3, r))),
|
|
2129
|
-
Promise.all(connections.map((c) => c.end()).concat(
|
|
2130
|
-
listen.sql ? listen.sql.end({ timeout: 0 }) : [],
|
|
2131
|
-
subscribe.sql ? subscribe.sql.end({ timeout: 0 }) : []
|
|
2132
|
-
))
|
|
2133
|
-
]).then(() => clearTimeout(timer2));
|
|
2134
|
-
});
|
|
2135
|
-
}
|
|
2136
|
-
function close() {
|
|
2137
|
-
return __async(this, null, function* () {
|
|
2138
|
-
yield Promise.all(connections.map((c) => c.end()));
|
|
2139
|
-
});
|
|
2140
|
-
}
|
|
2141
|
-
function destroy(resolve3) {
|
|
2142
|
-
return __async(this, null, function* () {
|
|
2143
|
-
yield Promise.all(connections.map((c) => c.terminate()));
|
|
2144
|
-
while (queries.length)
|
|
2145
|
-
queries.shift().reject(Errors.connection("CONNECTION_DESTROYED", options));
|
|
2146
|
-
resolve3();
|
|
2147
|
-
});
|
|
2148
|
-
}
|
|
2149
|
-
function connect(c, query) {
|
|
2150
|
-
move(c, connecting);
|
|
2151
|
-
c.connect(query);
|
|
2152
|
-
return c;
|
|
2153
|
-
}
|
|
2154
|
-
function onend(c) {
|
|
2155
|
-
move(c, ended);
|
|
2156
|
-
}
|
|
2157
|
-
function onopen(c) {
|
|
2158
|
-
if (queries.length === 0)
|
|
2159
|
-
return move(c, open);
|
|
2160
|
-
let max = Math.ceil(queries.length / (connecting.length + 1)), ready = true;
|
|
2161
|
-
while (ready && queries.length && max-- > 0) {
|
|
2162
|
-
const query = queries.shift();
|
|
2163
|
-
if (query.reserve)
|
|
2164
|
-
return query.reserve(c);
|
|
2165
|
-
ready = c.execute(query);
|
|
2166
|
-
}
|
|
2167
|
-
ready ? move(c, busy) : move(c, full);
|
|
2168
|
-
}
|
|
2169
|
-
function onclose(c, e) {
|
|
2170
|
-
move(c, closed);
|
|
2171
|
-
c.reserved = null;
|
|
2172
|
-
c.onclose && (c.onclose(e), c.onclose = null);
|
|
2173
|
-
options.onclose && options.onclose(c.id);
|
|
2174
|
-
queries.length && connect(c, queries.shift());
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
function parseOptions(a, b2) {
|
|
2178
|
-
if (a && a.shared)
|
|
2179
|
-
return a;
|
|
2180
|
-
const env = process.env, o = (!a || typeof a === "string" ? b2 : a) || {}, { url, multihost } = parseUrl(a), query = [...url.searchParams].reduce((a2, [b3, c]) => (a2[b3] = c, a2), {}), host = o.hostname || o.host || multihost || url.hostname || env.PGHOST || "localhost", port = o.port || url.port || env.PGPORT || 5432, user = o.user || o.username || url.username || env.PGUSERNAME || env.PGUSER || osUsername();
|
|
2181
|
-
o.no_prepare && (o.prepare = false);
|
|
2182
|
-
query.sslmode && (query.ssl = query.sslmode, delete query.sslmode);
|
|
2183
|
-
"timeout" in o && (console.log("The timeout option is deprecated, use idle_timeout instead"), o.idle_timeout = o.timeout);
|
|
2184
|
-
query.sslrootcert === "system" && (query.ssl = "verify-full");
|
|
2185
|
-
const ints = ["idle_timeout", "connect_timeout", "max_lifetime", "max_pipeline", "backoff", "keep_alive"];
|
|
2186
|
-
const defaults = {
|
|
2187
|
-
max: globalThis.Cloudflare ? 3 : 10,
|
|
2188
|
-
ssl: false,
|
|
2189
|
-
sslnegotiation: null,
|
|
2190
|
-
idle_timeout: null,
|
|
2191
|
-
connect_timeout: 30,
|
|
2192
|
-
max_lifetime,
|
|
2193
|
-
max_pipeline: 100,
|
|
2194
|
-
backoff,
|
|
2195
|
-
keep_alive: 60,
|
|
2196
|
-
prepare: true,
|
|
2197
|
-
debug: false,
|
|
2198
|
-
fetch_types: true,
|
|
2199
|
-
publications: "alltables",
|
|
2200
|
-
target_session_attrs: null
|
|
2201
|
-
};
|
|
2202
|
-
return __spreadValues(__spreadProps(__spreadValues({
|
|
2203
|
-
host: Array.isArray(host) ? host : host.split(",").map((x) => x.split(":")[0]),
|
|
2204
|
-
port: Array.isArray(port) ? port : host.split(",").map((x) => parseInt(x.split(":")[1] || port)),
|
|
2205
|
-
path: o.path || host.indexOf("/") > -1 && host + "/.s.PGSQL." + port,
|
|
2206
|
-
database: o.database || o.db || (url.pathname || "").slice(1) || env.PGDATABASE || user,
|
|
2207
|
-
user,
|
|
2208
|
-
pass: o.pass || o.password || url.password || env.PGPASSWORD || ""
|
|
2209
|
-
}, Object.entries(defaults).reduce(
|
|
2210
|
-
(acc, [k, d]) => {
|
|
2211
|
-
const value = k in o ? o[k] : k in query ? query[k] === "disable" || query[k] === "false" ? false : query[k] : env["PG" + k.toUpperCase()] || d;
|
|
2212
|
-
acc[k] = typeof value === "string" && ints.includes(k) ? +value : value;
|
|
2213
|
-
return acc;
|
|
2214
|
-
},
|
|
2215
|
-
{}
|
|
2216
|
-
)), {
|
|
2217
|
-
connection: __spreadValues(__spreadValues({
|
|
2218
|
-
application_name: env.PGAPPNAME || "postgres.js"
|
|
2219
|
-
}, o.connection), Object.entries(query).reduce((acc, [k, v]) => (k in defaults || (acc[k] = v), acc), {})),
|
|
2220
|
-
types: o.types || {},
|
|
2221
|
-
target_session_attrs: tsa(o, url, env),
|
|
2222
|
-
onnotice: o.onnotice,
|
|
2223
|
-
onnotify: o.onnotify,
|
|
2224
|
-
onclose: o.onclose,
|
|
2225
|
-
onparameter: o.onparameter,
|
|
2226
|
-
socket: o.socket,
|
|
2227
|
-
transform: parseTransform(o.transform || { undefined: void 0 }),
|
|
2228
|
-
parameters: {},
|
|
2229
|
-
shared: { retries: 0, typeArrayMap: {} }
|
|
2230
|
-
}), mergeUserTypes(o.types));
|
|
2231
|
-
}
|
|
2232
|
-
function tsa(o, url, env) {
|
|
2233
|
-
const x = o.target_session_attrs || url.searchParams.get("target_session_attrs") || env.PGTARGETSESSIONATTRS;
|
|
2234
|
-
if (!x || ["read-write", "read-only", "primary", "standby", "prefer-standby"].includes(x))
|
|
2235
|
-
return x;
|
|
2236
|
-
throw new Error("target_session_attrs " + x + " is not supported");
|
|
2237
|
-
}
|
|
2238
|
-
function backoff(retries) {
|
|
2239
|
-
return (0.5 + Math.random() / 2) * Math.min(__pow(3, retries) / 100, 20);
|
|
2240
|
-
}
|
|
2241
|
-
function max_lifetime() {
|
|
2242
|
-
return 60 * (30 + Math.random() * 30);
|
|
2243
|
-
}
|
|
2244
|
-
function parseTransform(x) {
|
|
2245
|
-
return {
|
|
2246
|
-
undefined: x.undefined,
|
|
2247
|
-
column: {
|
|
2248
|
-
from: typeof x.column === "function" ? x.column : x.column && x.column.from,
|
|
2249
|
-
to: x.column && x.column.to
|
|
2250
|
-
},
|
|
2251
|
-
value: {
|
|
2252
|
-
from: typeof x.value === "function" ? x.value : x.value && x.value.from,
|
|
2253
|
-
to: x.value && x.value.to
|
|
2254
|
-
},
|
|
2255
|
-
row: {
|
|
2256
|
-
from: typeof x.row === "function" ? x.row : x.row && x.row.from,
|
|
2257
|
-
to: x.row && x.row.to
|
|
2258
|
-
}
|
|
2259
|
-
};
|
|
2260
|
-
}
|
|
2261
|
-
function parseUrl(url) {
|
|
2262
|
-
if (!url || typeof url !== "string")
|
|
2263
|
-
return { url: { searchParams: /* @__PURE__ */ new Map() } };
|
|
2264
|
-
let host = url;
|
|
2265
|
-
host = host.slice(host.indexOf("://") + 3).split(/[?/]/)[0];
|
|
2266
|
-
host = decodeURIComponent(host.slice(host.indexOf("@") + 1));
|
|
2267
|
-
const urlObj = new URL(url.replace(host, host.split(",")[0]));
|
|
2268
|
-
return {
|
|
2269
|
-
url: {
|
|
2270
|
-
username: decodeURIComponent(urlObj.username),
|
|
2271
|
-
password: decodeURIComponent(urlObj.password),
|
|
2272
|
-
host: urlObj.host,
|
|
2273
|
-
hostname: urlObj.hostname,
|
|
2274
|
-
port: urlObj.port,
|
|
2275
|
-
pathname: urlObj.pathname,
|
|
2276
|
-
searchParams: urlObj.searchParams
|
|
2277
|
-
},
|
|
2278
|
-
multihost: host.indexOf(",") > -1 && host
|
|
2279
|
-
};
|
|
2280
|
-
}
|
|
2281
|
-
function osUsername() {
|
|
2282
|
-
try {
|
|
2283
|
-
return os__default.default.userInfo().username;
|
|
2284
|
-
} catch (_) {
|
|
2285
|
-
return process.env.USERNAME || process.env.USER || process.env.LOGNAME;
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
var src_default;
|
|
2289
|
-
var init_src = __esm({
|
|
2290
|
-
"node_modules/postgres/src/index.js"() {
|
|
2291
|
-
init_types();
|
|
2292
|
-
init_connection();
|
|
2293
|
-
init_query();
|
|
2294
|
-
init_queue();
|
|
2295
|
-
init_errors();
|
|
2296
|
-
init_subscribe();
|
|
2297
|
-
init_large();
|
|
2298
|
-
Object.assign(Postgres, {
|
|
2299
|
-
PostgresError,
|
|
2300
|
-
toPascal,
|
|
2301
|
-
pascal,
|
|
2302
|
-
toCamel,
|
|
2303
|
-
camel,
|
|
2304
|
-
toKebab,
|
|
2305
|
-
kebab,
|
|
2306
|
-
fromPascal,
|
|
2307
|
-
fromCamel,
|
|
2308
|
-
fromKebab,
|
|
2309
|
-
BigInt: {
|
|
2310
|
-
to: 20,
|
|
2311
|
-
from: [20],
|
|
2312
|
-
parse: (x) => BigInt(x),
|
|
2313
|
-
// eslint-disable-line
|
|
2314
|
-
serialize: (x) => x.toString()
|
|
2315
|
-
}
|
|
2316
|
-
});
|
|
2317
|
-
src_default = Postgres;
|
|
2318
|
-
}
|
|
2319
|
-
});
|
|
2320
|
-
|
|
2321
68
|
// package.json
|
|
2322
69
|
var require_package = __commonJS({
|
|
2323
70
|
"package.json"(exports$1, module) {
|
|
2324
71
|
module.exports = {
|
|
2325
72
|
name: "prisma-sql",
|
|
2326
|
-
version: "1.75.
|
|
73
|
+
version: "1.75.8",
|
|
2327
74
|
description: "Convert Prisma queries to optimized SQL with type safety. 2-7x faster than Prisma Client.",
|
|
2328
75
|
main: "dist/index.cjs",
|
|
2329
76
|
module: "dist/index.js",
|
|
2330
77
|
types: "dist/index.d.ts",
|
|
2331
78
|
bin: {
|
|
2332
|
-
"prisma-sql-generator": "./dist/generator.cjs"
|
|
79
|
+
"prisma-sql-generator": "./dist/generator.cjs",
|
|
80
|
+
"prisma-sql-collect-stats": "./dist/collect-planner-stats.cjs"
|
|
2333
81
|
},
|
|
2334
82
|
exports: {
|
|
2335
83
|
".": {
|
|
@@ -2390,7 +138,8 @@ var require_package = __commonJS({
|
|
|
2390
138
|
dependencies: {
|
|
2391
139
|
"@dee-wan/schema-parser": "1.4.0",
|
|
2392
140
|
"@prisma/generator-helper": "^7.4.0",
|
|
2393
|
-
"@prisma/internals": "^7.4.0"
|
|
141
|
+
"@prisma/internals": "^7.4.0",
|
|
142
|
+
postgres: "^3.4.8"
|
|
2394
143
|
},
|
|
2395
144
|
devDependencies: {
|
|
2396
145
|
"@faker-js/faker": "^10.2.0",
|
|
@@ -2404,7 +153,6 @@ var require_package = __commonJS({
|
|
|
2404
153
|
"better-sqlite3": "^12.6.2",
|
|
2405
154
|
"drizzle-kit": "^0.31.8",
|
|
2406
155
|
"drizzle-orm": "^0.45.1",
|
|
2407
|
-
postgres: "^3.4.8",
|
|
2408
156
|
tsup: "^8.5.1",
|
|
2409
157
|
tsx: "^4.21.0",
|
|
2410
158
|
typescript: "^5.9.3",
|
|
@@ -3690,9 +1438,9 @@ function findTiebreakerField(model) {
|
|
|
3690
1438
|
if (scalarSet.has("id")) return "id";
|
|
3691
1439
|
return null;
|
|
3692
1440
|
}
|
|
3693
|
-
function hasTiebreaker(orderBy,
|
|
1441
|
+
function hasTiebreaker(orderBy, parse, field) {
|
|
3694
1442
|
if (!isNotNullish(orderBy)) return false;
|
|
3695
|
-
const normalized = normalizeOrderByInput(orderBy,
|
|
1443
|
+
const normalized = normalizeOrderByInput(orderBy, parse);
|
|
3696
1444
|
return normalized.some(
|
|
3697
1445
|
(obj) => Object.prototype.hasOwnProperty.call(obj, field)
|
|
3698
1446
|
);
|
|
@@ -5000,7 +2748,7 @@ function extractReferencedParams(whereClause, specParams) {
|
|
|
5000
2748
|
return { cleanWhere: whereClause, params: [] };
|
|
5001
2749
|
}
|
|
5002
2750
|
const allParams = Array.isArray(specParams) ? specParams : typeof specParams.snapshot === "function" ? specParams.snapshot().params : [];
|
|
5003
|
-
const refs = Array.from(refSet).sort((a,
|
|
2751
|
+
const refs = Array.from(refSet).sort((a, b) => a - b);
|
|
5004
2752
|
const params = [];
|
|
5005
2753
|
const indexMap = /* @__PURE__ */ new Map();
|
|
5006
2754
|
for (const oldIdx of refs) {
|
|
@@ -5008,7 +2756,7 @@ function extractReferencedParams(whereClause, specParams) {
|
|
|
5008
2756
|
indexMap.set(oldIdx, params.length);
|
|
5009
2757
|
}
|
|
5010
2758
|
let cleanWhere = whereClause;
|
|
5011
|
-
const sorted = Array.from(indexMap.entries()).sort((a,
|
|
2759
|
+
const sorted = Array.from(indexMap.entries()).sort((a, b) => b[0] - a[0]);
|
|
5012
2760
|
for (const [oldIdx, newIdx] of sorted) {
|
|
5013
2761
|
cleanWhere = cleanWhere.split(`$${oldIdx}`).join(`$${newIdx}`);
|
|
5014
2762
|
}
|
|
@@ -5016,7 +2764,7 @@ function extractReferencedParams(whereClause, specParams) {
|
|
|
5016
2764
|
}
|
|
5017
2765
|
function buildFlatJoinSql(spec) {
|
|
5018
2766
|
const {
|
|
5019
|
-
select
|
|
2767
|
+
select,
|
|
5020
2768
|
from,
|
|
5021
2769
|
whereClause,
|
|
5022
2770
|
whereJoins,
|
|
@@ -5084,7 +2832,7 @@ function buildFlatJoinSql(spec) {
|
|
|
5084
2832
|
if (built.joins.length === 0) {
|
|
5085
2833
|
return emptyResult;
|
|
5086
2834
|
}
|
|
5087
|
-
const baseSelect = (
|
|
2835
|
+
const baseSelect = (select != null ? select : "").trim();
|
|
5088
2836
|
const allSelects = [baseSelect, ...built.selects].filter((s) => s && s.trim().length > 0).join(SQL_SEPARATORS.FIELD_LIST);
|
|
5089
2837
|
if (!allSelects) {
|
|
5090
2838
|
throw new Error("Flat-join SELECT requires at least one selected field");
|
|
@@ -6344,12 +4092,12 @@ function maybeReverseNegativeTake(takeVal, hasOrderBy, orderByInput) {
|
|
|
6344
4092
|
|
|
6345
4093
|
// src/builder/select/lateral-join.ts
|
|
6346
4094
|
function createParamCollector() {
|
|
6347
|
-
const
|
|
4095
|
+
const values = [];
|
|
6348
4096
|
return {
|
|
6349
|
-
values
|
|
4097
|
+
values,
|
|
6350
4098
|
add(value) {
|
|
6351
|
-
|
|
6352
|
-
return `$${
|
|
4099
|
+
values.push(value);
|
|
4100
|
+
return `$${values.length}`;
|
|
6353
4101
|
}
|
|
6354
4102
|
};
|
|
6355
4103
|
}
|
|
@@ -6376,14 +4124,14 @@ function reindexWhereParams(whereClause, specParams, collector) {
|
|
|
6376
4124
|
}
|
|
6377
4125
|
if (refSet.size === 0) return whereClause;
|
|
6378
4126
|
const allParams = Array.isArray(specParams) ? specParams : typeof specParams.snapshot === "function" ? specParams.snapshot().params : [];
|
|
6379
|
-
const refs = Array.from(refSet).sort((a,
|
|
4127
|
+
const refs = Array.from(refSet).sort((a, b) => a - b);
|
|
6380
4128
|
const indexMap = /* @__PURE__ */ new Map();
|
|
6381
4129
|
for (const oldIdx of refs) {
|
|
6382
4130
|
collector.values.push(allParams[oldIdx - 1]);
|
|
6383
4131
|
indexMap.set(oldIdx, collector.values.length);
|
|
6384
4132
|
}
|
|
6385
4133
|
let clean = whereClause;
|
|
6386
|
-
const sorted = Array.from(indexMap.entries()).sort((a,
|
|
4134
|
+
const sorted = Array.from(indexMap.entries()).sort((a, b) => b[0] - a[0]);
|
|
6387
4135
|
for (const [oldIdx, newIdx] of sorted) {
|
|
6388
4136
|
clean = clean.split(`$${oldIdx}`).join(`$${newIdx}`);
|
|
6389
4137
|
}
|
|
@@ -6714,8 +4462,8 @@ Hint: When using distinct with SQLite:
|
|
|
6714
4462
|
}
|
|
6715
4463
|
return unquoteIdent(column);
|
|
6716
4464
|
}
|
|
6717
|
-
function parseSimpleScalarSelect(
|
|
6718
|
-
const raw =
|
|
4465
|
+
function parseSimpleScalarSelect(select, fromAlias) {
|
|
4466
|
+
const raw = select.trim();
|
|
6719
4467
|
if (raw.length === 0) return [];
|
|
6720
4468
|
const parts = raw.split(SQL_SEPARATORS.FIELD_LIST);
|
|
6721
4469
|
const names = [];
|
|
@@ -6928,8 +4676,8 @@ function resolveCountSelect(countSelectRaw, model) {
|
|
|
6928
4676
|
}
|
|
6929
4677
|
function buildIncludeColumns(spec) {
|
|
6930
4678
|
var _a3, _b, _c, _d, _e;
|
|
6931
|
-
const { select
|
|
6932
|
-
const baseSelect = (
|
|
4679
|
+
const { select, includes, dialect, model, schemas, from, params } = spec;
|
|
4680
|
+
const baseSelect = (select != null ? select : "").trim();
|
|
6933
4681
|
let countCols = "";
|
|
6934
4682
|
let countJoins = [];
|
|
6935
4683
|
const countSelectRaw = (_e = (_b = (_a3 = spec.args) == null ? void 0 : _a3.select) == null ? void 0 : _b[COUNT_SELECT_KEY]) != null ? _e : (_d = (_c = spec.args) == null ? void 0 : _c.include) == null ? void 0 : _d[COUNT_SELECT_KEY];
|
|
@@ -7089,7 +4837,7 @@ function hasNestedIncludes(includeSpec) {
|
|
|
7089
4837
|
}
|
|
7090
4838
|
function constructFinalSql(spec) {
|
|
7091
4839
|
const {
|
|
7092
|
-
select
|
|
4840
|
+
select,
|
|
7093
4841
|
from,
|
|
7094
4842
|
whereClause,
|
|
7095
4843
|
whereJoins,
|
|
@@ -7172,7 +4920,7 @@ function constructFinalSql(spec) {
|
|
|
7172
4920
|
parts.push(SQL_TEMPLATES.SELECT);
|
|
7173
4921
|
const distinctOn = dialect === "postgres" ? buildPostgresDistinctOnClause(from.alias, distinct, model) : null;
|
|
7174
4922
|
if (distinctOn) parts.push(distinctOn);
|
|
7175
|
-
const baseSelect = (
|
|
4923
|
+
const baseSelect = (select != null ? select : "").trim();
|
|
7176
4924
|
const fullSelectList = buildSelectList(baseSelect, includeCols);
|
|
7177
4925
|
if (!isNonEmptyString(fullSelectList)) {
|
|
7178
4926
|
throw new Error("SELECT requires at least one selected field or include");
|
|
@@ -7208,9 +4956,9 @@ function constructFinalSql(spec) {
|
|
|
7208
4956
|
|
|
7209
4957
|
// src/builder/select/fields.ts
|
|
7210
4958
|
var DEFAULT_SELECT_CACHE = /* @__PURE__ */ new WeakMap();
|
|
7211
|
-
function toSelectEntries(
|
|
4959
|
+
function toSelectEntries(select) {
|
|
7212
4960
|
const out = [];
|
|
7213
|
-
for (const [k, v] of Object.entries(
|
|
4961
|
+
for (const [k, v] of Object.entries(select)) {
|
|
7214
4962
|
if (v !== false && v !== void 0) out.push([k, v]);
|
|
7215
4963
|
}
|
|
7216
4964
|
return out;
|
|
@@ -8821,11 +6569,11 @@ function buildCountSql(whereResult, tableName, alias, argsOrSkip, dialect, model
|
|
|
8821
6569
|
if (selectFields.length === 0) {
|
|
8822
6570
|
return buildSimpleCountSql(whereResult, tableName, alias, d);
|
|
8823
6571
|
}
|
|
8824
|
-
const
|
|
8825
|
-
for (const f of selectFields)
|
|
6572
|
+
const select = {};
|
|
6573
|
+
for (const f of selectFields) select[f] = true;
|
|
8826
6574
|
const subArgs = __spreadProps(__spreadValues({}, args), {
|
|
8827
6575
|
include: void 0,
|
|
8828
|
-
select
|
|
6576
|
+
select
|
|
8829
6577
|
});
|
|
8830
6578
|
const subSchemas = Array.isArray(schemas) && schemas.length > 0 ? schemas : [model];
|
|
8831
6579
|
const sub = buildSelectSql({
|
|
@@ -9048,7 +6796,7 @@ function normalizeSqlAndMappingsForDialect(sql, paramMappings, dialect) {
|
|
|
9048
6796
|
return { sql: normalizedSql, paramMappings: expandedMappings };
|
|
9049
6797
|
}
|
|
9050
6798
|
function buildParamsFromMappings(mappings) {
|
|
9051
|
-
const sorted = [...mappings].sort((a,
|
|
6799
|
+
const sorted = [...mappings].sort((a, b) => a.index - b.index);
|
|
9052
6800
|
const staticParams = [];
|
|
9053
6801
|
const dynamicKeys = [];
|
|
9054
6802
|
let paramOrder = "";
|
|
@@ -9541,25 +7289,6 @@ function stableJson(value) {
|
|
|
9541
7289
|
2
|
|
9542
7290
|
);
|
|
9543
7291
|
}
|
|
9544
|
-
function cleanDatabaseUrl(url) {
|
|
9545
|
-
try {
|
|
9546
|
-
const parsed = new URL(url);
|
|
9547
|
-
parsed.search = "";
|
|
9548
|
-
if (parsed.password) {
|
|
9549
|
-
parsed.password = "***";
|
|
9550
|
-
}
|
|
9551
|
-
if (parsed.username && parsed.username.length > 0) {
|
|
9552
|
-
if (parsed.username.length <= 3) {
|
|
9553
|
-
parsed.username = "***";
|
|
9554
|
-
} else {
|
|
9555
|
-
parsed.username = parsed.username.slice(0, 3) + "***";
|
|
9556
|
-
}
|
|
9557
|
-
}
|
|
9558
|
-
return parsed.toString();
|
|
9559
|
-
} catch (error) {
|
|
9560
|
-
return "[invalid-url]";
|
|
9561
|
-
}
|
|
9562
|
-
}
|
|
9563
7292
|
function createQueryKey(processedQuery) {
|
|
9564
7293
|
return JSON.stringify(processedQuery, (key, value) => {
|
|
9565
7294
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
@@ -9586,17 +7315,19 @@ function countTotalQueries(queries) {
|
|
|
9586
7315
|
function quoteIdent(dialect, ident) {
|
|
9587
7316
|
return `"${ident.replace(/"/g, '""')}"`;
|
|
9588
7317
|
}
|
|
9589
|
-
function createDatabaseExecutor(
|
|
7318
|
+
function createDatabaseExecutor(options) {
|
|
9590
7319
|
return __async(this, null, function* () {
|
|
9591
|
-
const { databaseUrl, dialect } =
|
|
7320
|
+
const { databaseUrl, dialect, connectTimeoutMs = 3e4 } = options;
|
|
9592
7321
|
if (dialect === "postgres") {
|
|
9593
|
-
const
|
|
9594
|
-
|
|
9595
|
-
|
|
7322
|
+
const postgres = yield import('postgres');
|
|
7323
|
+
const sql = postgres.default(databaseUrl, {
|
|
7324
|
+
connect_timeout: Math.ceil(connectTimeoutMs / 1e3),
|
|
7325
|
+
max: 1
|
|
7326
|
+
});
|
|
9596
7327
|
return {
|
|
9597
7328
|
executor: {
|
|
9598
|
-
query: (
|
|
9599
|
-
return yield sql.unsafe(
|
|
7329
|
+
query: (q, params) => __async(null, null, function* () {
|
|
7330
|
+
return yield sql.unsafe(q, params != null ? params : []);
|
|
9600
7331
|
})
|
|
9601
7332
|
},
|
|
9602
7333
|
cleanup: () => __async(null, null, function* () {
|
|
@@ -9604,7 +7335,7 @@ function createDatabaseExecutor(params) {
|
|
|
9604
7335
|
})
|
|
9605
7336
|
};
|
|
9606
7337
|
}
|
|
9607
|
-
throw new Error(`
|
|
7338
|
+
throw new Error(`createDatabaseExecutor does not support dialect: ${dialect}`);
|
|
9608
7339
|
});
|
|
9609
7340
|
}
|
|
9610
7341
|
function extractMeasurableOneToManyEdges(datamodel) {
|
|
@@ -9764,7 +7495,7 @@ function measureRoundtripCost(params) {
|
|
|
9764
7495
|
yield executor.query("SELECT 1");
|
|
9765
7496
|
roundtripTimes.push(performance.now() - start);
|
|
9766
7497
|
}
|
|
9767
|
-
roundtripTimes.sort((a,
|
|
7498
|
+
roundtripTimes.sort((a, b) => a - b);
|
|
9768
7499
|
const medianRoundtrip = roundtripTimes[Math.floor(SAMPLES / 2)];
|
|
9769
7500
|
console.log(
|
|
9770
7501
|
` [roundtrip] SELECT 1 times (ms): min=${roundtripTimes[0].toFixed(3)} median=${medianRoundtrip.toFixed(3)} max=${roundtripTimes[SAMPLES - 1].toFixed(3)}`
|
|
@@ -9802,7 +7533,7 @@ function estimateFromQueryPairRatio(params) {
|
|
|
9802
7533
|
yield executor.query(`SELECT * FROM ${tableName} LIMIT ${smallLimit}`);
|
|
9803
7534
|
smallTimes.push(performance.now() - start);
|
|
9804
7535
|
}
|
|
9805
|
-
smallTimes.sort((a,
|
|
7536
|
+
smallTimes.sort((a, b) => a - b);
|
|
9806
7537
|
const medianSmall = smallTimes[Math.floor(SAMPLES / 2)];
|
|
9807
7538
|
const largeTimes = [];
|
|
9808
7539
|
let actualLargeRows = 0;
|
|
@@ -9814,7 +7545,7 @@ function estimateFromQueryPairRatio(params) {
|
|
|
9814
7545
|
largeTimes.push(performance.now() - start);
|
|
9815
7546
|
actualLargeRows = rows.length;
|
|
9816
7547
|
}
|
|
9817
|
-
largeTimes.sort((a,
|
|
7548
|
+
largeTimes.sort((a, b) => a - b);
|
|
9818
7549
|
const medianLarge = largeTimes[Math.floor(SAMPLES / 2)];
|
|
9819
7550
|
const rowDiff = actualLargeRows - smallLimit;
|
|
9820
7551
|
const timeDiff = medianLarge - medianSmall;
|
|
@@ -9842,7 +7573,7 @@ function estimateFromQueryPairRatio(params) {
|
|
|
9842
7573
|
yield executor.query(`SELECT * FROM ${tableName} LIMIT ${smallLimit}`);
|
|
9843
7574
|
sequentialTimes.push(performance.now() - start);
|
|
9844
7575
|
}
|
|
9845
|
-
sequentialTimes.sort((a,
|
|
7576
|
+
sequentialTimes.sort((a, b) => a - b);
|
|
9846
7577
|
const median3Sequential = sequentialTimes[Math.floor(SAMPLES / 2)];
|
|
9847
7578
|
const marginalQueryCost = (median3Sequential - medianSmall) / 2;
|
|
9848
7579
|
console.log(
|
|
@@ -9889,7 +7620,7 @@ function measureJsonOverhead(params) {
|
|
|
9889
7620
|
yield executor.query(rawSql);
|
|
9890
7621
|
rawTimes.push(performance.now() - start);
|
|
9891
7622
|
}
|
|
9892
|
-
rawTimes.sort((a,
|
|
7623
|
+
rawTimes.sort((a, b) => a - b);
|
|
9893
7624
|
const medianRaw = rawTimes[Math.floor(SAMPLES / 2)];
|
|
9894
7625
|
const aggTimes = [];
|
|
9895
7626
|
for (let i = 0; i < SAMPLES; i++) {
|
|
@@ -9897,7 +7628,7 @@ function measureJsonOverhead(params) {
|
|
|
9897
7628
|
yield executor.query(aggSql);
|
|
9898
7629
|
aggTimes.push(performance.now() - start);
|
|
9899
7630
|
}
|
|
9900
|
-
aggTimes.sort((a,
|
|
7631
|
+
aggTimes.sort((a, b) => a - b);
|
|
9901
7632
|
const medianAgg = aggTimes[Math.floor(SAMPLES / 2)];
|
|
9902
7633
|
const factor = medianRaw > 0.01 ? medianAgg / medianRaw : 3;
|
|
9903
7634
|
console.log(` [json] Raw ${limit} rows: ${medianRaw.toFixed(3)}ms`);
|
|
@@ -10075,6 +7806,7 @@ function emitPlannerGeneratedModule(artifacts) {
|
|
|
10075
7806
|
}
|
|
10076
7807
|
|
|
10077
7808
|
// src/code-emitter.ts
|
|
7809
|
+
var DB_CONNECT_TIMEOUT_MS = 5e3;
|
|
10078
7810
|
function extractEnumMappings(datamodel) {
|
|
10079
7811
|
const mappings = {};
|
|
10080
7812
|
const fieldTypes = {};
|
|
@@ -10155,9 +7887,7 @@ function generateClient(options) {
|
|
|
10155
7887
|
const directiveResults = schemaParser.processAllDirectives(
|
|
10156
7888
|
datamodel.models,
|
|
10157
7889
|
datamodel,
|
|
10158
|
-
{
|
|
10159
|
-
skipInvalid: config.skipInvalid
|
|
10160
|
-
}
|
|
7890
|
+
{ skipInvalid: config.skipInvalid }
|
|
10161
7891
|
);
|
|
10162
7892
|
const { queries, skippedCount } = processAllModelDirectives(
|
|
10163
7893
|
directiveResults,
|
|
@@ -10173,7 +7903,8 @@ function generateClient(options) {
|
|
|
10173
7903
|
try {
|
|
10174
7904
|
const dbConn = yield createDatabaseExecutor({
|
|
10175
7905
|
databaseUrl: datasourceUrl,
|
|
10176
|
-
dialect: config.dialect
|
|
7906
|
+
dialect: config.dialect,
|
|
7907
|
+
connectTimeoutMs: DB_CONNECT_TIMEOUT_MS
|
|
10177
7908
|
});
|
|
10178
7909
|
executor = dbConn.executor;
|
|
10179
7910
|
cleanup = dbConn.cleanup;
|