@m2k-5f/pgtx 2.7.2 → 2.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -31
- package/dist/batch.d.ts +4 -1
- package/dist/batch.d.ts.map +1 -1
- package/dist/batch.js +14 -7
- package/dist/clauses/fragment.clause.js +1 -1
- package/dist/connection.d.ts +17 -16
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +182 -166
- package/dist/error.d.ts +4 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +15 -7
- package/dist/pool.d.ts +1 -1
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +5 -3
- package/dist/protocol/connection-request-writer.d.ts +24 -11
- package/dist/protocol/connection-request-writer.d.ts.map +1 -1
- package/dist/protocol/connection-request-writer.js +217 -47
- package/dist/protocol/connection-response-reader.d.ts +3 -15
- package/dist/protocol/connection-response-reader.d.ts.map +1 -1
- package/dist/protocol/connection-response-reader.js +57 -79
- package/dist/protocol/constants.d.ts +37 -30
- package/dist/protocol/constants.d.ts.map +1 -1
- package/dist/protocol/constants.js +35 -29
- package/dist/protocol/socket-authorization.d.ts.map +1 -1
- package/dist/protocol/socket-authorization.js +3 -3
- package/dist/protocol/socket-connector.d.ts +4 -4
- package/dist/protocol/socket-connector.d.ts.map +1 -1
- package/dist/protocol/socket-connector.js +2 -2
- package/dist/query.d.ts +16 -20
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +15 -22
- package/dist/queue.d.ts +1 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +1 -0
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/template-compiler.d.ts +5 -2
- package/dist/utils/template-compiler.d.ts.map +1 -1
- package/dist/utils/template-compiler.js +4 -1
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +73 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataTypeOids } from "./constants";
|
|
1
|
+
import { DataTypeOids, INT4Length } from "./constants";
|
|
2
2
|
import { PostgresError } from "../error";
|
|
3
3
|
const columnValueCache = new Map();
|
|
4
4
|
const POSTGRES_EPOCH_MS = 946684800000;
|
|
@@ -39,16 +39,14 @@ export class ConnectionResponseBuffer {
|
|
|
39
39
|
hasMore() {
|
|
40
40
|
return this.caret < this.buffer.length;
|
|
41
41
|
}
|
|
42
|
-
readRawBinaryString(length) {
|
|
43
|
-
const text = this.buffer.toString('latin1', this.caret, this.caret + length);
|
|
44
|
-
this.caret += length;
|
|
45
|
-
return text;
|
|
46
|
-
}
|
|
47
42
|
readBinaryDate() {
|
|
48
43
|
const daysSince2000 = this.readInt32();
|
|
49
44
|
const ms = POSTGRES_EPOCH_MS + (daysSince2000 * 86400000);
|
|
50
45
|
return new Date(ms);
|
|
51
46
|
}
|
|
47
|
+
readByte() {
|
|
48
|
+
return this.buffer[this.caret++];
|
|
49
|
+
}
|
|
52
50
|
readBinaryTimestamp() {
|
|
53
51
|
const microSecondsSince2000 = this.readInt64();
|
|
54
52
|
const msSince2000 = Number(microSecondsSince2000 / 1000);
|
|
@@ -174,33 +172,25 @@ export class ConnectionResponseBuffer {
|
|
|
174
172
|
}
|
|
175
173
|
return hash >>> 0;
|
|
176
174
|
}
|
|
177
|
-
}
|
|
178
|
-
export class ConnectionResponseReader {
|
|
179
|
-
constructor(buffer) {
|
|
180
|
-
this.buffer = buffer;
|
|
181
|
-
}
|
|
182
|
-
static from(buffer) {
|
|
183
|
-
return new ConnectionResponseReader(ConnectionResponseBuffer.from(buffer));
|
|
184
|
-
}
|
|
185
175
|
readType() {
|
|
186
|
-
return { type: this.
|
|
176
|
+
return { type: this.readByte(), length: this.readInt32() - INT4Length };
|
|
187
177
|
}
|
|
188
178
|
readAuthentication() {
|
|
189
|
-
return this.
|
|
179
|
+
return this.readInt32();
|
|
190
180
|
}
|
|
191
181
|
readMD5Salt() {
|
|
192
|
-
return this.
|
|
182
|
+
return this.readBytes(4);
|
|
193
183
|
}
|
|
194
184
|
readParameterStatus() {
|
|
195
185
|
return {
|
|
196
|
-
name: this.
|
|
197
|
-
value: this.
|
|
186
|
+
name: this.readCString(),
|
|
187
|
+
value: this.readCString()
|
|
198
188
|
};
|
|
199
189
|
}
|
|
200
190
|
readBackendKeyData() {
|
|
201
191
|
return {
|
|
202
|
-
PID: this.
|
|
203
|
-
secret: this.
|
|
192
|
+
PID: this.readInt32(),
|
|
193
|
+
secret: this.readInt32()
|
|
204
194
|
};
|
|
205
195
|
}
|
|
206
196
|
readErrorResponse() {
|
|
@@ -214,10 +204,10 @@ export class ConnectionResponseReader {
|
|
|
214
204
|
let dataType = '';
|
|
215
205
|
let constraint = '';
|
|
216
206
|
while (true) {
|
|
217
|
-
const marker = this.
|
|
207
|
+
const marker = this.readChar();
|
|
218
208
|
if (marker === '\0')
|
|
219
209
|
break;
|
|
220
|
-
const text = this.
|
|
210
|
+
const text = this.readCString();
|
|
221
211
|
switch (marker) {
|
|
222
212
|
case 'S':
|
|
223
213
|
severity = text;
|
|
@@ -251,12 +241,12 @@ export class ConnectionResponseReader {
|
|
|
251
241
|
return new PostgresError(message, code, detail, severity, where, hint, position, dataType, constraint);
|
|
252
242
|
}
|
|
253
243
|
readReadyForQuery() {
|
|
254
|
-
return this.
|
|
244
|
+
return this.readByte();
|
|
255
245
|
}
|
|
256
246
|
readSaslMechanisms() {
|
|
257
247
|
const mechanisms = [];
|
|
258
248
|
while (true) {
|
|
259
|
-
const mech = this.
|
|
249
|
+
const mech = this.readCString();
|
|
260
250
|
if (mech === "")
|
|
261
251
|
break;
|
|
262
252
|
mechanisms.push(mech);
|
|
@@ -264,29 +254,29 @@ export class ConnectionResponseReader {
|
|
|
264
254
|
return mechanisms;
|
|
265
255
|
}
|
|
266
256
|
readSaslMessage(length) {
|
|
267
|
-
return this.
|
|
257
|
+
return this.readRawString(length - 4);
|
|
268
258
|
}
|
|
269
259
|
readRowDescription() {
|
|
270
|
-
const columnsCount = this.
|
|
260
|
+
const columnsCount = this.readInt16();
|
|
271
261
|
const columns = new Array(columnsCount);
|
|
272
262
|
for (let i = 0; i < columnsCount; i++) {
|
|
273
|
-
const name = this.
|
|
274
|
-
this.
|
|
275
|
-
this.
|
|
263
|
+
const name = this.readCString();
|
|
264
|
+
this.readInt32();
|
|
265
|
+
this.readInt16();
|
|
276
266
|
columns[i] = {
|
|
277
267
|
name: name,
|
|
278
|
-
typeOID: this.
|
|
268
|
+
typeOID: this.readInt32(),
|
|
279
269
|
};
|
|
280
|
-
this.
|
|
281
|
-
this.
|
|
270
|
+
this.readInt32();
|
|
271
|
+
this.readInt32();
|
|
282
272
|
}
|
|
283
273
|
return columns;
|
|
284
274
|
}
|
|
285
275
|
readDataRow(descriptions, int8toBigint) {
|
|
286
|
-
const fieldsCount = this.
|
|
276
|
+
const fieldsCount = this.readInt16();
|
|
287
277
|
const row = {};
|
|
288
278
|
for (let i = 0; i < fieldsCount; i++) {
|
|
289
|
-
const fieldLength = this.
|
|
279
|
+
const fieldLength = this.readInt32();
|
|
290
280
|
const desc = descriptions[i];
|
|
291
281
|
const key = desc.name;
|
|
292
282
|
if (fieldLength === -1) {
|
|
@@ -306,104 +296,105 @@ export class ConnectionResponseReader {
|
|
|
306
296
|
cacheForColumn = new Map();
|
|
307
297
|
columnValueCache.set(i, cacheForColumn);
|
|
308
298
|
}
|
|
309
|
-
const byteHash = this.
|
|
299
|
+
const byteHash = this.getBufferHash(fieldLength);
|
|
310
300
|
let cachedString = cacheForColumn.get(byteHash);
|
|
311
301
|
if (cachedString === undefined) {
|
|
312
|
-
cachedString = this.
|
|
313
|
-
if (cacheForColumn.size
|
|
314
|
-
cacheForColumn.
|
|
302
|
+
cachedString = this.readRawString(fieldLength);
|
|
303
|
+
if (cacheForColumn.size > 512) {
|
|
304
|
+
cacheForColumn.clear();
|
|
315
305
|
}
|
|
306
|
+
cacheForColumn.set(byteHash, cachedString);
|
|
316
307
|
}
|
|
317
308
|
else {
|
|
318
|
-
this.
|
|
309
|
+
this.skipBytes(fieldLength);
|
|
319
310
|
}
|
|
320
311
|
row[key] = cachedString;
|
|
321
312
|
}
|
|
322
313
|
else {
|
|
323
|
-
row[key] = this.
|
|
314
|
+
row[key] = this.readRawString(fieldLength);
|
|
324
315
|
}
|
|
325
316
|
}
|
|
326
317
|
break;
|
|
327
318
|
case DataTypeOids.Int2:
|
|
328
319
|
{
|
|
329
|
-
row[key] = this.
|
|
320
|
+
row[key] = this.readInt16();
|
|
330
321
|
}
|
|
331
322
|
break;
|
|
332
323
|
case DataTypeOids.Int4:
|
|
333
324
|
{
|
|
334
|
-
row[key] = this.
|
|
325
|
+
row[key] = this.readInt32();
|
|
335
326
|
}
|
|
336
327
|
break;
|
|
337
328
|
case DataTypeOids.Int8:
|
|
338
329
|
{
|
|
339
|
-
row[key] = int8toBigint ? this.
|
|
330
|
+
row[key] = int8toBigint ? this.readBigInt64() : this.readInt64();
|
|
340
331
|
}
|
|
341
332
|
break;
|
|
342
333
|
case DataTypeOids.Float4:
|
|
343
334
|
{
|
|
344
|
-
row[key] = this.
|
|
335
|
+
row[key] = this.readFloat32();
|
|
345
336
|
}
|
|
346
337
|
break;
|
|
347
338
|
case DataTypeOids.Float8:
|
|
348
339
|
{
|
|
349
|
-
row[key] = this.
|
|
340
|
+
row[key] = this.readFloat64();
|
|
350
341
|
}
|
|
351
342
|
break;
|
|
352
343
|
case DataTypeOids.Bool:
|
|
353
344
|
{
|
|
354
|
-
row[key] = this.
|
|
345
|
+
row[key] = this.readBool();
|
|
355
346
|
}
|
|
356
347
|
break;
|
|
357
348
|
case DataTypeOids.Bytea:
|
|
358
349
|
{
|
|
359
|
-
row[key] = this.
|
|
350
|
+
row[key] = this.readBytes(fieldLength);
|
|
360
351
|
}
|
|
361
352
|
break;
|
|
362
353
|
case DataTypeOids.Jsonb:
|
|
363
354
|
{
|
|
364
|
-
this.
|
|
365
|
-
row[key] = JSON.parse(this.
|
|
355
|
+
this.skipBytes(1);
|
|
356
|
+
row[key] = JSON.parse(this.readRawString(fieldLength - 1));
|
|
366
357
|
}
|
|
367
358
|
break;
|
|
368
359
|
case DataTypeOids.Json:
|
|
369
360
|
{
|
|
370
|
-
row[key] = JSON.parse(this.
|
|
361
|
+
row[key] = JSON.parse(this.readRawString(fieldLength));
|
|
371
362
|
}
|
|
372
363
|
break;
|
|
373
364
|
case DataTypeOids.Date:
|
|
374
365
|
{
|
|
375
|
-
row[key] = this.
|
|
366
|
+
row[key] = this.readBinaryDate();
|
|
376
367
|
}
|
|
377
368
|
break;
|
|
378
369
|
case DataTypeOids.Timestamp:
|
|
379
370
|
case DataTypeOids.Timestamptz:
|
|
380
371
|
{
|
|
381
|
-
row[key] = this.
|
|
372
|
+
row[key] = this.readBinaryTimestamp();
|
|
382
373
|
}
|
|
383
374
|
break;
|
|
384
375
|
case DataTypeOids.Uuid:
|
|
385
376
|
{
|
|
386
|
-
row[key] = this.
|
|
377
|
+
row[key] = this.readUuid();
|
|
387
378
|
}
|
|
388
379
|
break;
|
|
389
380
|
case DataTypeOids.Time:
|
|
390
381
|
{
|
|
391
|
-
row[key] = this.
|
|
382
|
+
row[key] = this.readBinaryTime();
|
|
392
383
|
}
|
|
393
384
|
break;
|
|
394
385
|
case DataTypeOids.Timetz:
|
|
395
386
|
{
|
|
396
|
-
row[key] = this.
|
|
387
|
+
row[key] = this.readBinaryTimetz();
|
|
397
388
|
}
|
|
398
389
|
break;
|
|
399
390
|
case DataTypeOids.Numeric:
|
|
400
391
|
{
|
|
401
|
-
row[key] = this.
|
|
392
|
+
row[key] = this.readNumeric();
|
|
402
393
|
}
|
|
403
394
|
break;
|
|
404
395
|
default:
|
|
405
396
|
{
|
|
406
|
-
this.
|
|
397
|
+
this.skipBytes(fieldLength);
|
|
407
398
|
row[key] = null;
|
|
408
399
|
}
|
|
409
400
|
break;
|
|
@@ -412,33 +403,20 @@ export class ConnectionResponseReader {
|
|
|
412
403
|
return row;
|
|
413
404
|
}
|
|
414
405
|
readNotificationResponse() {
|
|
415
|
-
this.
|
|
416
|
-
const name = this.
|
|
417
|
-
const payload = this.
|
|
406
|
+
this.readInt32();
|
|
407
|
+
const name = this.readCString();
|
|
408
|
+
const payload = this.readCString();
|
|
418
409
|
return { name, payload };
|
|
419
410
|
}
|
|
420
411
|
readCommandComplete() {
|
|
421
|
-
return this.
|
|
422
|
-
}
|
|
423
|
-
hasMore() {
|
|
424
|
-
return this.buffer.hasMore();
|
|
425
|
-
}
|
|
426
|
-
hasFullPacket() {
|
|
427
|
-
return this.buffer.hasFullPacket();
|
|
428
|
-
}
|
|
429
|
-
getResidualBuffer() {
|
|
430
|
-
return this.buffer.getResidualBuffer();
|
|
412
|
+
return this.readCString();
|
|
431
413
|
}
|
|
432
|
-
readParseComplete() { }
|
|
433
|
-
readBindComplete() { }
|
|
434
414
|
readParameterDescription() {
|
|
435
|
-
const count = this.
|
|
415
|
+
const count = this.readInt16();
|
|
416
|
+
const description = Array(count);
|
|
436
417
|
for (let i = 0; i < count; i++) {
|
|
437
|
-
this.
|
|
418
|
+
description[i] = this.readInt32();
|
|
438
419
|
}
|
|
439
|
-
|
|
440
|
-
readNoData() { }
|
|
441
|
-
skip(count) {
|
|
442
|
-
this.buffer.skipBytes(count);
|
|
420
|
+
return description;
|
|
443
421
|
}
|
|
444
422
|
}
|
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
import { ValueOF } from "../types";
|
|
2
2
|
export declare const RequestTypes: {
|
|
3
|
-
readonly SimpleQuery:
|
|
4
|
-
readonly Parse:
|
|
5
|
-
readonly Bind:
|
|
6
|
-
readonly Execute:
|
|
7
|
-
readonly Sync:
|
|
8
|
-
readonly Password:
|
|
9
|
-
readonly Describe:
|
|
10
|
-
readonly Close:
|
|
3
|
+
readonly SimpleQuery: 81;
|
|
4
|
+
readonly Parse: 80;
|
|
5
|
+
readonly Bind: 66;
|
|
6
|
+
readonly Execute: 69;
|
|
7
|
+
readonly Sync: 83;
|
|
8
|
+
readonly Password: 112;
|
|
9
|
+
readonly Describe: 68;
|
|
10
|
+
readonly Close: 67;
|
|
11
11
|
};
|
|
12
12
|
export type RequestType = ValueOF<typeof RequestTypes>;
|
|
13
13
|
export declare const ResponseTypes: {
|
|
14
|
-
readonly RowDescription:
|
|
15
|
-
readonly DataRow:
|
|
16
|
-
readonly ComandComplete:
|
|
17
|
-
readonly ReadyForQuery:
|
|
18
|
-
readonly ErrorResponse:
|
|
19
|
-
readonly NoticeResponse:
|
|
20
|
-
readonly Authentication:
|
|
21
|
-
readonly BackendKeyData:
|
|
22
|
-
readonly ParamaterStatus:
|
|
23
|
-
readonly ParseComplete:
|
|
24
|
-
readonly BindComplete:
|
|
25
|
-
readonly CloseComplete:
|
|
26
|
-
readonly ParameterDescription:
|
|
27
|
-
readonly NoData:
|
|
28
|
-
readonly Notice:
|
|
29
|
-
readonly NotificationResponse:
|
|
30
|
-
readonly SSLOk:
|
|
31
|
-
readonly SSLDenied:
|
|
14
|
+
readonly RowDescription: 84;
|
|
15
|
+
readonly DataRow: 68;
|
|
16
|
+
readonly ComandComplete: 67;
|
|
17
|
+
readonly ReadyForQuery: 90;
|
|
18
|
+
readonly ErrorResponse: 69;
|
|
19
|
+
readonly NoticeResponse: 78;
|
|
20
|
+
readonly Authentication: 82;
|
|
21
|
+
readonly BackendKeyData: 75;
|
|
22
|
+
readonly ParamaterStatus: 83;
|
|
23
|
+
readonly ParseComplete: 49;
|
|
24
|
+
readonly BindComplete: 50;
|
|
25
|
+
readonly CloseComplete: 51;
|
|
26
|
+
readonly ParameterDescription: 116;
|
|
27
|
+
readonly NoData: 110;
|
|
28
|
+
readonly Notice: 78;
|
|
29
|
+
readonly NotificationResponse: 65;
|
|
30
|
+
readonly SSLOk: 83;
|
|
31
|
+
readonly SSLDenied: 78;
|
|
32
32
|
};
|
|
33
|
+
export type ResponseType = ValueOF<typeof ResponseTypes>;
|
|
33
34
|
export declare const DataTypeOids: {
|
|
34
35
|
readonly Bool: 16;
|
|
35
36
|
readonly Bytea: 17;
|
|
@@ -78,7 +79,7 @@ export declare const DataTypeOids: {
|
|
|
78
79
|
readonly NumericArray: 1231;
|
|
79
80
|
};
|
|
80
81
|
export type DataTypeOid = typeof DataTypeOids[keyof typeof DataTypeOids];
|
|
81
|
-
export
|
|
82
|
+
export declare const INT4Length = 4;
|
|
82
83
|
export declare const AuthenticationCodes: {
|
|
83
84
|
readonly Ok: 0;
|
|
84
85
|
readonly CleartextPassword: 3;
|
|
@@ -89,9 +90,15 @@ export declare const AuthenticationCodes: {
|
|
|
89
90
|
};
|
|
90
91
|
export type AuthenticationCode = ValueOF<typeof AuthenticationCodes>;
|
|
91
92
|
export declare const TransactionStatuses: {
|
|
92
|
-
readonly Idle:
|
|
93
|
-
readonly InTransactionBlock:
|
|
94
|
-
readonly FailedTransactionBlock:
|
|
93
|
+
readonly Idle: 73;
|
|
94
|
+
readonly InTransactionBlock: 84;
|
|
95
|
+
readonly FailedTransactionBlock: 69;
|
|
95
96
|
};
|
|
96
97
|
export type TransactionStatus = ValueOF<typeof TransactionStatuses>;
|
|
98
|
+
export declare const DescribeType: {
|
|
99
|
+
readonly Statement: "S";
|
|
100
|
+
readonly Portal: "P";
|
|
101
|
+
};
|
|
102
|
+
export type DescribeType = ValueOF<typeof DescribeType>;
|
|
103
|
+
export declare const EMPTY_ARRAY: never[];
|
|
97
104
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/protocol/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC,eAAO,MAAM,YAAY;;;;;;;;;CASf,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,YAAY,CAAC,CAAA;AAGtD,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;CAmBhB,CAAA;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/protocol/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC,eAAO,MAAM,YAAY;;;;;;;;;CASf,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,YAAY,CAAC,CAAA;AAGtD,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;CAmBhB,CAAA;AAEV,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,aAAa,CAAC,CAAA;AAGxD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDf,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAEzE,eAAO,MAAM,UAAU,IAAI,CAAA;AAG3B,eAAO,MAAM,mBAAmB;;;;;;;CAOtB,CAAA;AAEV,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAGpE,eAAO,MAAM,mBAAmB;;;;CAItB,CAAA;AAEV,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAGnE,eAAO,MAAM,YAAY;;;CAGf,CAAA;AAEV,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,YAAY,CAAC,CAAA;AAEvD,eAAO,MAAM,WAAW,EAAwB,KAAK,EAAE,CAAA"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
export const RequestTypes = {
|
|
2
|
-
SimpleQuery: "Q"
|
|
3
|
-
Parse: "P"
|
|
4
|
-
Bind: "B"
|
|
5
|
-
Execute: "E"
|
|
6
|
-
Sync: "S"
|
|
7
|
-
Password: "p"
|
|
8
|
-
Describe:
|
|
9
|
-
Close: "C"
|
|
2
|
+
SimpleQuery: 81, // "Q"
|
|
3
|
+
Parse: 80, // "P"
|
|
4
|
+
Bind: 66, // "B"
|
|
5
|
+
Execute: 69, // "E"
|
|
6
|
+
Sync: 83, // "S"
|
|
7
|
+
Password: 112, // "p"
|
|
8
|
+
Describe: 68, // "D"
|
|
9
|
+
Close: 67 // "C"
|
|
10
10
|
};
|
|
11
11
|
export const ResponseTypes = {
|
|
12
|
-
RowDescription: "T"
|
|
13
|
-
DataRow: "D"
|
|
14
|
-
ComandComplete: "C"
|
|
15
|
-
ReadyForQuery: "Z"
|
|
16
|
-
ErrorResponse: "E"
|
|
17
|
-
NoticeResponse: "N"
|
|
18
|
-
Authentication: "R"
|
|
19
|
-
BackendKeyData: "K"
|
|
20
|
-
ParamaterStatus: "S"
|
|
21
|
-
ParseComplete: "1"
|
|
22
|
-
BindComplete: "2"
|
|
23
|
-
CloseComplete: "3"
|
|
24
|
-
ParameterDescription: "t"
|
|
25
|
-
NoData: "n"
|
|
26
|
-
Notice: "N"
|
|
27
|
-
NotificationResponse: "A"
|
|
28
|
-
SSLOk: "S"
|
|
29
|
-
SSLDenied: "N"
|
|
12
|
+
RowDescription: 84, // "T"
|
|
13
|
+
DataRow: 68, // "D"
|
|
14
|
+
ComandComplete: 67, // "C"
|
|
15
|
+
ReadyForQuery: 90, // "Z"
|
|
16
|
+
ErrorResponse: 69, // "E"
|
|
17
|
+
NoticeResponse: 78, // "N"
|
|
18
|
+
Authentication: 82, // "R"
|
|
19
|
+
BackendKeyData: 75, // "K"
|
|
20
|
+
ParamaterStatus: 83, // "S"
|
|
21
|
+
ParseComplete: 49, // "1"
|
|
22
|
+
BindComplete: 50, // "2"
|
|
23
|
+
CloseComplete: 51, // "3"
|
|
24
|
+
ParameterDescription: 116, // "t"
|
|
25
|
+
NoData: 110, // "n"
|
|
26
|
+
Notice: 78, // "N"
|
|
27
|
+
NotificationResponse: 65, // "A"
|
|
28
|
+
SSLOk: 83, // "S"
|
|
29
|
+
SSLDenied: 78 // "N"
|
|
30
30
|
};
|
|
31
31
|
export const DataTypeOids = {
|
|
32
32
|
Bool: 16,
|
|
@@ -75,6 +75,7 @@ export const DataTypeOids = {
|
|
|
75
75
|
UuidArray: 2951,
|
|
76
76
|
NumericArray: 1231
|
|
77
77
|
};
|
|
78
|
+
export const INT4Length = 4;
|
|
78
79
|
export const AuthenticationCodes = {
|
|
79
80
|
Ok: 0,
|
|
80
81
|
CleartextPassword: 3,
|
|
@@ -84,7 +85,12 @@ export const AuthenticationCodes = {
|
|
|
84
85
|
SASLFinal: 12,
|
|
85
86
|
};
|
|
86
87
|
export const TransactionStatuses = {
|
|
87
|
-
Idle: "I"
|
|
88
|
-
InTransactionBlock: "T"
|
|
89
|
-
FailedTransactionBlock: "E"
|
|
88
|
+
Idle: 73, // "I"
|
|
89
|
+
InTransactionBlock: 84, // "T"
|
|
90
|
+
FailedTransactionBlock: 69, // "E"
|
|
90
91
|
};
|
|
92
|
+
export const DescribeType = {
|
|
93
|
+
Statement: "S",
|
|
94
|
+
Portal: "P",
|
|
95
|
+
};
|
|
96
|
+
export const EMPTY_ARRAY = Object.freeze([]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-authorization.d.ts","sourceRoot":"","sources":["../../src/protocol/socket-authorization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"socket-authorization.d.ts","sourceRoot":"","sources":["../../src/protocol/socket-authorization.ts"],"names":[],"mappings":"AAIA,OAAO,EAA4J,aAAa,EAAE,MAAM,UAAU,CAAA;AAClM,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,OAAO,EAAoB,MAAM,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAM3C,eAAO,MAAM,YAAY,GAAI,QAAQ,gBAAgB,kCASpD,CAAA;AAGD,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,EAAE,QAAQ,gBAAgB,kCA+ErE,CAAA;AAGD,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,QAAQ,gBAAgB,kCAyHvE,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ConnectionRequestWriter } from "./connection-request-writer";
|
|
2
1
|
import { calculateScramAuth, generateNonce } from "../security/sasl";
|
|
3
2
|
import { SocketConnector } from "./socket-connector";
|
|
4
3
|
import { AuthenticationCodes, ResponseTypes } from "./constants";
|
|
@@ -8,6 +7,7 @@ import { Future } from "fluent-future";
|
|
|
8
7
|
import { connect } from "node:tls";
|
|
9
8
|
import { createConnection } from "node:net";
|
|
10
9
|
import { readFileSync } from "node:fs";
|
|
10
|
+
import { ConnectionRequestBuffer } from "./connection-request-writer";
|
|
11
11
|
export const createSocket = (config) => {
|
|
12
12
|
const { future, resolve, reject } = Future.withResolvers();
|
|
13
13
|
const socket = createConnection({ host: config.host, port: config.port });
|
|
@@ -19,7 +19,7 @@ export const upgradeSocket = (socket, config) => {
|
|
|
19
19
|
if (config.ssl === 'disable')
|
|
20
20
|
return Future.resolve(socket);
|
|
21
21
|
const { future, reject, resolve } = Future.withResolvers();
|
|
22
|
-
const writer =
|
|
22
|
+
const writer = ConnectionRequestBuffer.new(2048);
|
|
23
23
|
const onError = () => {
|
|
24
24
|
cleanup();
|
|
25
25
|
reject(ErrSocketFailedDuringAuth);
|
|
@@ -84,7 +84,7 @@ export const upgradeSocket = (socket, config) => {
|
|
|
84
84
|
};
|
|
85
85
|
export const authorizeSocket = (socket, config) => {
|
|
86
86
|
const { future, reject, resolve } = Future.withResolvers();
|
|
87
|
-
const writer =
|
|
87
|
+
const writer = ConnectionRequestBuffer.new(2048);
|
|
88
88
|
const nonce = generateNonce();
|
|
89
89
|
let clientMessage = '';
|
|
90
90
|
let serverMessage = '';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Socket } from 'net';
|
|
2
2
|
import { ResponseType } from './constants';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { ConnectionResponseBuffer } from './connection-response-reader';
|
|
4
|
+
import { ConnectionRequestBuffer } from './connection-request-writer';
|
|
5
5
|
export declare class SocketConnector {
|
|
6
6
|
private _socket;
|
|
7
7
|
private residualBuffer;
|
|
@@ -9,8 +9,8 @@ export declare class SocketConnector {
|
|
|
9
9
|
private _onClose;
|
|
10
10
|
private _onData;
|
|
11
11
|
private _destroyed;
|
|
12
|
-
constructor(_socket: Socket, onData: (type: ResponseType, length: number, reader:
|
|
13
|
-
write(writer:
|
|
12
|
+
constructor(_socket: Socket, onData: (type: ResponseType, length: number, reader: ConnectionResponseBuffer) => void, onError: (error: unknown) => void);
|
|
13
|
+
write(writer: ConnectionRequestBuffer): void;
|
|
14
14
|
unwrapSocket(): Socket;
|
|
15
15
|
destroy(): void;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-connector.d.ts","sourceRoot":"","sources":["../../src/protocol/socket-connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"socket-connector.d.ts","sourceRoot":"","sources":["../../src/protocol/socket-connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAErE,qBAAa,eAAe;IAQpB,OAAO,CAAC,OAAO;IAPnB,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAAQ;gBAGd,OAAO,EAAE,MAAM,EACvB,MAAM,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,wBAAwB,KAAK,IAAI,EACtF,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI;IA4CrC,KAAK,CAAC,MAAM,EAAE,uBAAuB;IAKrC,YAAY;IASZ,OAAO;CAGV"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConnectionResponseBuffer } from './connection-response-reader';
|
|
2
2
|
export class SocketConnector {
|
|
3
3
|
constructor(_socket, onData, onError) {
|
|
4
4
|
this._socket = _socket;
|
|
@@ -23,7 +23,7 @@ export class SocketConnector {
|
|
|
23
23
|
? Buffer.concat([this.residualBuffer, buffer])
|
|
24
24
|
: buffer;
|
|
25
25
|
this.residualBuffer = null;
|
|
26
|
-
const reader =
|
|
26
|
+
const reader = ConnectionResponseBuffer.from(currentBuffer);
|
|
27
27
|
while (reader.hasMore()) {
|
|
28
28
|
if (!reader.hasFullPacket()) {
|
|
29
29
|
this.residualBuffer = reader.getResidualBuffer();
|
package/dist/query.d.ts
CHANGED
|
@@ -1,41 +1,37 @@
|
|
|
1
|
-
import { Future } from "fluent-future";
|
|
1
|
+
import { Future, Resolvers } from "fluent-future";
|
|
2
2
|
import { ColumnDescription, QueryText, Row, StatementName } from "./types";
|
|
3
3
|
import { PostgresError } from "./error";
|
|
4
4
|
export declare abstract class Query {
|
|
5
5
|
statement: StatementName;
|
|
6
6
|
text: QueryText;
|
|
7
|
-
args:
|
|
7
|
+
args: unknown[];
|
|
8
8
|
protected _timer?: NodeJS.Timeout;
|
|
9
|
-
constructor(statement: StatementName, text: QueryText, args:
|
|
10
|
-
abstract
|
|
11
|
-
abstract
|
|
9
|
+
constructor(statement: StatementName, text: QueryText, args: unknown[], timeout: number);
|
|
10
|
+
abstract error(cause: PostgresError): void;
|
|
11
|
+
abstract complete(...args: any[]): void;
|
|
12
12
|
}
|
|
13
13
|
export declare class CollectQuery<T extends Row> extends Query {
|
|
14
14
|
columns: ColumnDescription[] | null;
|
|
15
|
-
|
|
16
|
-
private _resolve;
|
|
17
|
-
private _reject;
|
|
15
|
+
resolvers: Resolvers<Future<T[], PostgresError>>;
|
|
18
16
|
private _rows;
|
|
19
|
-
constructor(statement: StatementName, text: QueryText, args:
|
|
17
|
+
constructor(statement: StatementName, text: QueryText, args: unknown[], columns: ColumnDescription[] | null, timeout: number, resolvers: Resolvers<Future<T[], PostgresError>>);
|
|
20
18
|
push(value: T): void;
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
error(cause: PostgresError): void;
|
|
20
|
+
complete(): void;
|
|
23
21
|
}
|
|
24
22
|
export declare class ExecuteQuery extends Query {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
reject(cause: PostgresError): void;
|
|
30
|
-
resolve(): void;
|
|
23
|
+
resolvers: Resolvers<Future<void, PostgresError>>;
|
|
24
|
+
constructor(statement: StatementName, text: QueryText, args: unknown[], timeout: number, resolvers: Resolvers<Future<void, PostgresError>>);
|
|
25
|
+
error(cause: PostgresError): void;
|
|
26
|
+
complete(): void;
|
|
31
27
|
}
|
|
32
28
|
export declare class StreamQuery<T> extends Query {
|
|
33
29
|
controller: ReadableStreamDefaultController<T>;
|
|
34
30
|
columns: ColumnDescription[] | null;
|
|
35
|
-
constructor(statement: StatementName, text: QueryText, args:
|
|
31
|
+
constructor(statement: StatementName, text: QueryText, args: unknown[], controller: ReadableStreamDefaultController<T>, columns: ColumnDescription[] | null, timeout: number);
|
|
36
32
|
push(value: T): void;
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
error(cause: PostgresError): void;
|
|
34
|
+
complete(): void;
|
|
39
35
|
}
|
|
40
36
|
export type PostgresQuery = CollectQuery<any> | StreamQuery<any> | ExecuteQuery;
|
|
41
37
|
//# sourceMappingURL=query.d.ts.map
|
package/dist/query.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAmB,aAAa,EAAE,MAAM,SAAS,CAAC;AAGzD,8BAAsB,KAAK;IAIZ,SAAS,EAAE,aAAa;IACxB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,OAAO,EAAE;IAL1B,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAA;gBAGtB,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,OAAO,EAAE,EACtB,OAAO,EAAE,MAAM;IAQnB,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAE1C,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;CAC1C;AAGD,qBAAa,YAAY,CAAC,CAAC,SAAS,GAAG,CAAE,SAAQ,KAAK;IAOvC,OAAO,EAAE,iBAAiB,EAAE,GAAG,IAAI;IAEnC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IAR3D,OAAO,CAAC,KAAK,CAAU;gBAGnB,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,OAAO,EAAE,EACR,OAAO,EAAE,iBAAiB,EAAE,GAAG,IAAI,EAC1C,OAAO,EAAE,MAAM,EACR,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IAM3D,IAAI,CAAC,KAAK,EAAE,CAAC;IAKb,KAAK,CAAC,KAAK,EAAE,aAAa;IAM1B,QAAQ;CAIX;AAGD,qBAAa,YAAa,SAAQ,KAAK;IAMxB,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;gBAJxD,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,OAAO,EAAE,EACf,OAAO,EAAE,MAAM,EACR,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAK5D,KAAK,CAAC,KAAK,EAAE,aAAa;IAM1B,QAAQ;CAIX;AAGD,qBAAa,WAAW,CAAC,CAAC,CAAE,SAAQ,KAAK;IAK1B,UAAU,EAAE,+BAA+B,CAAC,CAAC,CAAC;IAC9C,OAAO,EAAE,iBAAiB,EAAE,GAAG,IAAI;gBAJ1C,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,OAAO,EAAE,EACR,UAAU,EAAE,+BAA+B,CAAC,CAAC,CAAC,EAC9C,OAAO,EAAE,iBAAiB,EAAE,GAAG,IAAI,EAC1C,OAAO,EAAE,MAAM;IAMnB,IAAI,CAAC,KAAK,EAAE,CAAC;IAOb,KAAK,CAAC,KAAK,EAAE,aAAa;IAM1B,QAAQ;CAMX;AAED,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,YAAY,CAAA"}
|