@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.
Files changed (43) hide show
  1. package/README.md +48 -31
  2. package/dist/batch.d.ts +4 -1
  3. package/dist/batch.d.ts.map +1 -1
  4. package/dist/batch.js +14 -7
  5. package/dist/clauses/fragment.clause.js +1 -1
  6. package/dist/connection.d.ts +17 -16
  7. package/dist/connection.d.ts.map +1 -1
  8. package/dist/connection.js +182 -166
  9. package/dist/error.d.ts +4 -1
  10. package/dist/error.d.ts.map +1 -1
  11. package/dist/error.js +15 -7
  12. package/dist/pool.d.ts +1 -1
  13. package/dist/pool.d.ts.map +1 -1
  14. package/dist/pool.js +5 -3
  15. package/dist/protocol/connection-request-writer.d.ts +24 -11
  16. package/dist/protocol/connection-request-writer.d.ts.map +1 -1
  17. package/dist/protocol/connection-request-writer.js +217 -47
  18. package/dist/protocol/connection-response-reader.d.ts +3 -15
  19. package/dist/protocol/connection-response-reader.d.ts.map +1 -1
  20. package/dist/protocol/connection-response-reader.js +57 -79
  21. package/dist/protocol/constants.d.ts +37 -30
  22. package/dist/protocol/constants.d.ts.map +1 -1
  23. package/dist/protocol/constants.js +35 -29
  24. package/dist/protocol/socket-authorization.d.ts.map +1 -1
  25. package/dist/protocol/socket-authorization.js +3 -3
  26. package/dist/protocol/socket-connector.d.ts +4 -4
  27. package/dist/protocol/socket-connector.d.ts.map +1 -1
  28. package/dist/protocol/socket-connector.js +2 -2
  29. package/dist/query.d.ts +16 -20
  30. package/dist/query.d.ts.map +1 -1
  31. package/dist/query.js +15 -22
  32. package/dist/queue.d.ts +1 -0
  33. package/dist/queue.d.ts.map +1 -1
  34. package/dist/queue.js +1 -0
  35. package/dist/types.d.ts +3 -1
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/utils/template-compiler.d.ts +5 -2
  38. package/dist/utils/template-compiler.d.ts.map +1 -1
  39. package/dist/utils/template-compiler.js +4 -1
  40. package/dist/utils.d.ts +8 -0
  41. package/dist/utils.d.ts.map +1 -0
  42. package/dist/utils.js +73 -0
  43. 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.buffer.readChar(), length: this.buffer.readInt32() };
176
+ return { type: this.readByte(), length: this.readInt32() - INT4Length };
187
177
  }
188
178
  readAuthentication() {
189
- return this.buffer.readInt32();
179
+ return this.readInt32();
190
180
  }
191
181
  readMD5Salt() {
192
- return this.buffer.readBytes(4);
182
+ return this.readBytes(4);
193
183
  }
194
184
  readParameterStatus() {
195
185
  return {
196
- name: this.buffer.readCString(),
197
- value: this.buffer.readCString()
186
+ name: this.readCString(),
187
+ value: this.readCString()
198
188
  };
199
189
  }
200
190
  readBackendKeyData() {
201
191
  return {
202
- PID: this.buffer.readInt32(),
203
- secret: this.buffer.readInt32()
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.buffer.readChar();
207
+ const marker = this.readChar();
218
208
  if (marker === '\0')
219
209
  break;
220
- const text = this.buffer.readCString();
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.buffer.readChar();
244
+ return this.readByte();
255
245
  }
256
246
  readSaslMechanisms() {
257
247
  const mechanisms = [];
258
248
  while (true) {
259
- const mech = this.buffer.readCString();
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.buffer.readRawString(length - 4 - 4);
257
+ return this.readRawString(length - 4);
268
258
  }
269
259
  readRowDescription() {
270
- const columnsCount = this.buffer.readInt16();
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.buffer.readCString();
274
- this.buffer.readInt32();
275
- this.buffer.readInt16();
263
+ const name = this.readCString();
264
+ this.readInt32();
265
+ this.readInt16();
276
266
  columns[i] = {
277
267
  name: name,
278
- typeOID: this.buffer.readInt32(),
268
+ typeOID: this.readInt32(),
279
269
  };
280
- this.buffer.readInt32();
281
- this.buffer.readInt32();
270
+ this.readInt32();
271
+ this.readInt32();
282
272
  }
283
273
  return columns;
284
274
  }
285
275
  readDataRow(descriptions, int8toBigint) {
286
- const fieldsCount = this.buffer.readInt16();
276
+ const fieldsCount = this.readInt16();
287
277
  const row = {};
288
278
  for (let i = 0; i < fieldsCount; i++) {
289
- const fieldLength = this.buffer.readInt32();
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.buffer.getBufferHash(fieldLength);
299
+ const byteHash = this.getBufferHash(fieldLength);
310
300
  let cachedString = cacheForColumn.get(byteHash);
311
301
  if (cachedString === undefined) {
312
- cachedString = this.buffer.readRawString(fieldLength);
313
- if (cacheForColumn.size < 512) {
314
- cacheForColumn.set(byteHash, cachedString);
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.buffer.skipBytes(fieldLength);
309
+ this.skipBytes(fieldLength);
319
310
  }
320
311
  row[key] = cachedString;
321
312
  }
322
313
  else {
323
- row[key] = this.buffer.readRawString(fieldLength);
314
+ row[key] = this.readRawString(fieldLength);
324
315
  }
325
316
  }
326
317
  break;
327
318
  case DataTypeOids.Int2:
328
319
  {
329
- row[key] = this.buffer.readInt16();
320
+ row[key] = this.readInt16();
330
321
  }
331
322
  break;
332
323
  case DataTypeOids.Int4:
333
324
  {
334
- row[key] = this.buffer.readInt32();
325
+ row[key] = this.readInt32();
335
326
  }
336
327
  break;
337
328
  case DataTypeOids.Int8:
338
329
  {
339
- row[key] = int8toBigint ? this.buffer.readBigInt64() : this.buffer.readInt64();
330
+ row[key] = int8toBigint ? this.readBigInt64() : this.readInt64();
340
331
  }
341
332
  break;
342
333
  case DataTypeOids.Float4:
343
334
  {
344
- row[key] = this.buffer.readFloat32();
335
+ row[key] = this.readFloat32();
345
336
  }
346
337
  break;
347
338
  case DataTypeOids.Float8:
348
339
  {
349
- row[key] = this.buffer.readFloat64();
340
+ row[key] = this.readFloat64();
350
341
  }
351
342
  break;
352
343
  case DataTypeOids.Bool:
353
344
  {
354
- row[key] = this.buffer.readBool();
345
+ row[key] = this.readBool();
355
346
  }
356
347
  break;
357
348
  case DataTypeOids.Bytea:
358
349
  {
359
- row[key] = this.buffer.readBytes(fieldLength);
350
+ row[key] = this.readBytes(fieldLength);
360
351
  }
361
352
  break;
362
353
  case DataTypeOids.Jsonb:
363
354
  {
364
- this.buffer.skipBytes(1);
365
- row[key] = JSON.parse(this.buffer.readRawString(fieldLength - 1));
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.buffer.readRawString(fieldLength));
361
+ row[key] = JSON.parse(this.readRawString(fieldLength));
371
362
  }
372
363
  break;
373
364
  case DataTypeOids.Date:
374
365
  {
375
- row[key] = this.buffer.readBinaryDate();
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.buffer.readBinaryTimestamp();
372
+ row[key] = this.readBinaryTimestamp();
382
373
  }
383
374
  break;
384
375
  case DataTypeOids.Uuid:
385
376
  {
386
- row[key] = this.buffer.readUuid();
377
+ row[key] = this.readUuid();
387
378
  }
388
379
  break;
389
380
  case DataTypeOids.Time:
390
381
  {
391
- row[key] = this.buffer.readBinaryTime();
382
+ row[key] = this.readBinaryTime();
392
383
  }
393
384
  break;
394
385
  case DataTypeOids.Timetz:
395
386
  {
396
- row[key] = this.buffer.readBinaryTimetz();
387
+ row[key] = this.readBinaryTimetz();
397
388
  }
398
389
  break;
399
390
  case DataTypeOids.Numeric:
400
391
  {
401
- row[key] = this.buffer.readNumeric();
392
+ row[key] = this.readNumeric();
402
393
  }
403
394
  break;
404
395
  default:
405
396
  {
406
- this.buffer.skipBytes(fieldLength);
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.buffer.readInt32();
416
- const name = this.buffer.readCString();
417
- const payload = this.buffer.readCString();
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.buffer.readCString();
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.buffer.readInt16();
415
+ const count = this.readInt16();
416
+ const description = Array(count);
436
417
  for (let i = 0; i < count; i++) {
437
- this.buffer.readInt32();
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: "Q";
4
- readonly Parse: "P";
5
- readonly Bind: "B";
6
- readonly Execute: "E";
7
- readonly Sync: "S";
8
- readonly Password: "p";
9
- readonly Describe: "D";
10
- readonly Close: "C";
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: "T";
15
- readonly DataRow: "D";
16
- readonly ComandComplete: "C";
17
- readonly ReadyForQuery: "Z";
18
- readonly ErrorResponse: "E";
19
- readonly NoticeResponse: "N";
20
- readonly Authentication: "R";
21
- readonly BackendKeyData: "K";
22
- readonly ParamaterStatus: "S";
23
- readonly ParseComplete: "1";
24
- readonly BindComplete: "2";
25
- readonly CloseComplete: "3";
26
- readonly ParameterDescription: "t";
27
- readonly NoData: "n";
28
- readonly Notice: "N";
29
- readonly NotificationResponse: "A";
30
- readonly SSLOk: "S";
31
- readonly SSLDenied: "N";
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 type ResponseType = ValueOF<typeof ResponseTypes>;
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: "I";
93
- readonly InTransactionBlock: "T";
94
- readonly FailedTransactionBlock: "E";
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;AAGV,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDf,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAIzE,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,aAAa,CAAC,CAAA;AAGxD,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"}
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: 'D',
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":"AAKA,OAAO,EAA4J,aAAa,EAAE,MAAM,UAAU,CAAA;AAClM,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,OAAO,EAAoB,MAAM,EAAE,MAAM,UAAU,CAAA;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAI3C,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
+ {"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 = ConnectionRequestWriter.new();
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 = ConnectionRequestWriter.new();
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 { ConnectionResponseReader } from '../protocol/connection-response-reader';
4
- import { ConnectionRequestWriter } from '../protocol/connection-request-writer';
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: ConnectionResponseReader) => void, onError: (error: unknown) => void);
13
- write(writer: ConnectionRequestWriter): void;
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,KAA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,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 { ConnectionResponseReader } from '../protocol/connection-response-reader';
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 = ConnectionResponseReader.from(currentBuffer);
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: (string | null)[];
7
+ args: unknown[];
8
8
  protected _timer?: NodeJS.Timeout;
9
- constructor(statement: StatementName, text: QueryText, args: (string | null)[], timeout: number);
10
- abstract reject(cause: PostgresError): void;
11
- abstract resolve(...args: any[]): void;
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
- future: Future<T[], PostgresError>;
16
- private _resolve;
17
- private _reject;
15
+ resolvers: Resolvers<Future<T[], PostgresError>>;
18
16
  private _rows;
19
- constructor(statement: StatementName, text: QueryText, args: (string | null)[], columns: ColumnDescription[] | null, timeout: number);
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
- reject(cause: PostgresError): void;
22
- resolve(): void;
19
+ error(cause: PostgresError): void;
20
+ complete(): void;
23
21
  }
24
22
  export declare class ExecuteQuery extends Query {
25
- future: Future<void, PostgresError>;
26
- private _resolve;
27
- private _reject;
28
- constructor(statement: StatementName, text: QueryText, args: (string | null)[], timeout: number);
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: (string | null)[], controller: ReadableStreamDefaultController<T>, columns: ColumnDescription[] | null, timeout: number);
31
+ constructor(statement: StatementName, text: QueryText, args: unknown[], controller: ReadableStreamDefaultController<T>, columns: ColumnDescription[] | null, timeout: number);
36
32
  push(value: T): void;
37
- reject(cause: PostgresError): void;
38
- resolve(): void;
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
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAa,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAmB,aAAa,EAAE,MAAM,SAAS,CAAC;AAGzD,8BAAsB,KAAK;IAIZ,SAAS,EAA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