@noldova/context.data.sql.postgresql 0.0.12 → 0.0.14

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 (127) hide show
  1. package/README.md +38 -2
  2. package/api/index.d.ts +91 -1
  3. package/exceptions/batch-skipped.exception.js +2 -2
  4. package/exceptions/batch-skipped.exception.js.map +1 -1
  5. package/exceptions/batch.exception.js +2 -2
  6. package/exceptions/batch.exception.js.map +1 -1
  7. package/exceptions/callbacks-failed.exception.js +17 -0
  8. package/exceptions/callbacks-failed.exception.js.map +1 -0
  9. package/exceptions/cancel-unanswered.exception.js +2 -2
  10. package/exceptions/cancel-unanswered.exception.js.map +1 -1
  11. package/exceptions/connection-closed.exception.js +2 -2
  12. package/exceptions/connection-closed.exception.js.map +1 -1
  13. package/exceptions/connection-ended.exception.js +2 -2
  14. package/exceptions/connection-ended.exception.js.map +1 -1
  15. package/exceptions/malformed-message.exception.js +2 -2
  16. package/exceptions/malformed-message.exception.js.map +1 -1
  17. package/exceptions/postgresql-client.exception.js +14 -0
  18. package/exceptions/postgresql-client.exception.js.map +1 -0
  19. package/exceptions/postgresql.exception.js +2 -2
  20. package/exceptions/postgresql.exception.js.map +1 -1
  21. package/exceptions/query-canceled.exception.js +2 -2
  22. package/exceptions/query-canceled.exception.js.map +1 -1
  23. package/exceptions/query-timeout.exception.js +2 -2
  24. package/exceptions/query-timeout.exception.js.map +1 -1
  25. package/exceptions/queue-timeout.exception.js +2 -2
  26. package/exceptions/queue-timeout.exception.js.map +1 -1
  27. package/exceptions/stray-cancel.exception.js +2 -2
  28. package/exceptions/stray-cancel.exception.js.map +1 -1
  29. package/exceptions/transaction-rolled-back.exception.js +2 -2
  30. package/exceptions/transaction-rolled-back.exception.js.map +1 -1
  31. package/exceptions/type-not-found.exception.js +2 -2
  32. package/exceptions/type-not-found.exception.js.map +1 -1
  33. package/exceptions/unsafe-transaction.exception.js +2 -2
  34. package/exceptions/unsafe-transaction.exception.js.map +1 -1
  35. package/models/{row-column.js → array-element.js} +5 -5
  36. package/models/array-element.js.map +1 -0
  37. package/models/channel-listener.js +3 -0
  38. package/models/channel-listener.js.map +1 -1
  39. package/models/client/client-listener.js +67 -22
  40. package/models/client/client-listener.js.map +1 -1
  41. package/models/client/client-query.js.map +1 -1
  42. package/models/client/connection-socket.js.map +1 -1
  43. package/models/client/copy-both-stream.js +2 -2
  44. package/models/client/copy-both-stream.js.map +1 -1
  45. package/models/client/copy-in-stream.js +2 -2
  46. package/models/client/copy-in-stream.js.map +1 -1
  47. package/models/client/copy-out-stream.js +2 -2
  48. package/models/client/copy-out-stream.js.map +1 -1
  49. package/models/client/deferred.js +1 -1
  50. package/models/client/deferred.js.map +1 -1
  51. package/models/client/listen-subscription.js +3 -0
  52. package/models/client/listen-subscription.js.map +1 -1
  53. package/models/client/pool-lease.js +11 -15
  54. package/models/client/pool-lease.js.map +1 -1
  55. package/models/client/pool-queue.js +42 -4
  56. package/models/client/pool-queue.js.map +1 -1
  57. package/models/client/postgresql-client.js +2 -2
  58. package/models/client/postgresql-client.js.map +1 -1
  59. package/models/client/postgresql-connection.js +70 -77
  60. package/models/client/postgresql-connection.js.map +1 -1
  61. package/models/client/postgresql-pool.js +133 -39
  62. package/models/client/postgresql-pool.js.map +1 -1
  63. package/models/client/query.js +4 -4
  64. package/models/client/query.js.map +1 -1
  65. package/models/client/reserved-client.js.map +1 -1
  66. package/models/client/transaction-scope.js +2 -2
  67. package/models/client/transaction-scope.js.map +1 -1
  68. package/models/described-result.js +20 -0
  69. package/models/described-result.js.map +1 -0
  70. package/models/host-target.js +16 -0
  71. package/models/host-target.js.map +1 -0
  72. package/models/parser-variant.js +16 -0
  73. package/models/parser-variant.js.map +1 -0
  74. package/models/postgresql-session.js +6 -8
  75. package/models/postgresql-session.js.map +1 -1
  76. package/models/postgresql-socket.js +17 -20
  77. package/models/postgresql-socket.js.map +1 -1
  78. package/models/result.js +1 -1
  79. package/models/result.js.map +1 -1
  80. package/models/started-session.js +1 -1
  81. package/models/started-session.js.map +1 -1
  82. package/models/type-registry.js +19 -26
  83. package/models/type-registry.js.map +1 -1
  84. package/package.json +6 -6
  85. package/resources.js +3 -0
  86. package/resources.js.map +1 -1
  87. package/services/authenticator.js +7 -1
  88. package/services/authenticator.js.map +1 -1
  89. package/services/client/connection-lease.js.map +1 -1
  90. package/services/client/file-query-handler.js.map +1 -1
  91. package/services/client/row.reader.js +13 -20
  92. package/services/client/row.reader.js.map +1 -1
  93. package/services/client/type-loader-events.js.map +1 -1
  94. package/services/client-options.parser.js +12 -11
  95. package/services/client-options.parser.js.map +1 -1
  96. package/services/parameter-rewriter.js +22 -17
  97. package/services/parameter-rewriter.js.map +1 -1
  98. package/services/protocol/backend.js +0 -19
  99. package/services/protocol/backend.js.map +1 -1
  100. package/services/protocol/frame.reader.js +21 -37
  101. package/services/protocol/frame.reader.js.map +1 -1
  102. package/services/protocol/frontend.js +2 -2
  103. package/services/protocol/frontend.js.map +1 -1
  104. package/services/session-starter.js +15 -8
  105. package/services/session-starter.js.map +1 -1
  106. package/services/tls-options.reader.js +6 -6
  107. package/services/tls-options.reader.js.map +1 -1
  108. package/services/types/array-serializer.js +9 -3
  109. package/services/types/array-serializer.js.map +1 -1
  110. package/services/types/array.parser.js +23 -10
  111. package/services/types/array.parser.js.map +1 -1
  112. package/services/types/binary-array.reader.js +69 -0
  113. package/services/types/binary-array.reader.js.map +1 -0
  114. package/services/types/binary-readers.js +1 -60
  115. package/services/types/binary-readers.js.map +1 -1
  116. package/services/types/date.parser.js +7 -11
  117. package/services/types/date.parser.js.map +1 -1
  118. package/services/value-converter.js +3 -1
  119. package/services/value-converter.js.map +1 -1
  120. package/types/column-transform.js +9 -0
  121. package/types/column-transform.js.map +1 -0
  122. package/types/{host-target.js → row-transform.js} +1 -1
  123. package/types/row-transform.js.map +1 -0
  124. package/types/value-transform.js +9 -0
  125. package/types/value-transform.js.map +1 -0
  126. package/models/row-column.js.map +0 -1
  127. package/types/host-target.js.map +0 -1
@@ -45,6 +45,7 @@ import { CopyInStream } from "./copy-in-stream.js";
45
45
  import { CopyOutStream } from "./copy-out-stream.js";
46
46
  import { Deferred } from "./deferred.js";
47
47
  import { Exchange } from "./exchange.js";
48
+ import { PoolQueue } from "./pool-queue.js";
48
49
  import { SentCancel } from "./sent-cancel.js";
49
50
  import { RowReader } from "../../services/client/row.reader.js";
50
51
  export class PostgreSQLConnection {
@@ -54,31 +55,14 @@ export class PostgreSQLConnection {
54
55
  static unknownCost = 100;
55
56
  static flushLength = 65536;
56
57
  static ids = 1;
57
- id;
58
- host;
59
- port;
60
- backend;
61
- parameters;
62
- prepared = new Map();
63
- lease = null;
64
- fatal = null;
65
- uncertain = false;
66
- releasing = false;
67
- retiring = false;
68
- loading = false;
69
- typing = null;
70
- idleTimer = null;
71
- lifeTimer = null;
72
- idleSince = 0;
73
- retired = [];
74
58
  session;
75
59
  options;
76
60
  events;
77
61
  socket;
78
62
  timers;
79
63
  frontend = new Frontend();
80
- sent = [];
81
- pending = [];
64
+ sent = new PoolQueue();
65
+ pending = new PoolQueue();
82
66
  running = new Set();
83
67
  open = new Set();
84
68
  out = new ProtocolWriter();
@@ -100,6 +84,25 @@ export class PostgreSQLConnection {
100
84
  epoch = 0;
101
85
  headSince = 0;
102
86
  notables = 0;
87
+ id;
88
+ host;
89
+ port;
90
+ backend;
91
+ parameters;
92
+ prepared = new Map();
93
+ lease = null;
94
+ fatal = null;
95
+ uncertain = false;
96
+ releasing = null;
97
+ retiring = false;
98
+ closeCalled = false;
99
+ callbackError = null;
100
+ loading = false;
101
+ typing = null;
102
+ idleTimer = null;
103
+ lifeTimer = null;
104
+ idleSince = 0;
105
+ retired = [];
103
106
  constructor(session, options, events) {
104
107
  this.session = session;
105
108
  this.options = options;
@@ -117,7 +120,7 @@ export class PostgreSQLConnection {
117
120
  this.frames = new FrameReader((type, data, start, end) => this.dispatch(type, data, start, end), error => {
118
121
  this.fatal = error;
119
122
  this.socket.destroy();
120
- }, this.socket.isShared);
123
+ });
121
124
  this.socket.onData = data => {
122
125
  this.heard = this.timers.readTime();
123
126
  this.frames.push(data);
@@ -215,7 +218,7 @@ export class PostgreSQLConnection {
215
218
  cancelAsync(query) {
216
219
  if (!Object.isNull(query.parts))
217
220
  return this.cancelBatchAsync(query);
218
- const head = this.sent[0];
221
+ const head = this.sent.peek();
219
222
  if (!Object.isNull(this.stashData) && !Object.isUndefined(head) && head.query === query) {
220
223
  head.own = new QueryCanceledException();
221
224
  this.go();
@@ -226,9 +229,9 @@ export class PostgreSQLConnection {
226
229
  return Promise.resolve();
227
230
  }
228
231
  const index = this.pending.findIndex(item => item.query === query || item.describedFor === query);
229
- const waiting = this.pending[index];
232
+ const waiting = this.pending.get(index);
230
233
  if (!Object.isUndefined(waiting)) {
231
- this.pending.splice(index, 1);
234
+ this.pending.removeAt(index);
232
235
  if (waiting === this.fence)
233
236
  this.fence = null;
234
237
  if (waiting.isNotable(PostgreSQLConnection.notable))
@@ -280,7 +283,7 @@ export class PostgreSQLConnection {
280
283
  }
281
284
  computeBacklog(time) {
282
285
  let wait = 0;
283
- this.sent.forEach((item, index) => {
286
+ this.sent.toArray().forEach((item, index) => {
284
287
  const cost = item.cost ?? 0;
285
288
  if (index === 0) {
286
289
  const elapsed = time - this.headSince;
@@ -289,12 +292,12 @@ export class PostgreSQLConnection {
289
292
  else
290
293
  wait += cost;
291
294
  });
292
- for (const item of this.pending)
295
+ for (const item of this.pending.toArray())
293
296
  wait += item.cost ?? 0;
294
297
  return wait;
295
298
  }
296
299
  isHeavy() {
297
- return this.sent.some(item => item.isNotable(PostgreSQLConnection.slow)) || this.pending.some(item => item.isNotable(PostgreSQLConnection.slow));
300
+ return this.sent.findIndex(item => item.isNotable(PostgreSQLConnection.slow)) !== -1 || this.pending.findIndex(item => item.isNotable(PostgreSQLConnection.slow)) !== -1;
298
301
  }
299
302
  writeCopyData(chunk, callback) {
300
303
  Frontend.writeCopyData(this.out, chunk);
@@ -378,7 +381,7 @@ export class PostgreSQLConnection {
378
381
  if (!Object.isNull(exchange.query))
379
382
  exchange.query.state = this.backend;
380
383
  if (!Object.isNull(this.fence))
381
- this.pending.splice(this.pending.indexOf(this.fence), 0, exchange);
384
+ this.pending.insertAt(this.pending.indexOf(this.fence), exchange);
382
385
  else if (exchange.ends && this.open.size > 0) {
383
386
  this.fence = exchange;
384
387
  this.pending.push(exchange);
@@ -393,7 +396,7 @@ export class PostgreSQLConnection {
393
396
  this.release();
394
397
  }
395
398
  release() {
396
- for (let next = this.pending[0]; Object.isNull(this.blocker) && !Object.isUndefined(next) && next !== this.fence; next = this.pending[0]) {
399
+ for (let next = this.pending.peek(); Object.isNull(this.blocker) && !Object.isUndefined(next) && next !== this.fence; next = this.pending.peek()) {
397
400
  this.pending.shift();
398
401
  this.write(next);
399
402
  }
@@ -405,8 +408,8 @@ export class PostgreSQLConnection {
405
408
  try {
406
409
  outcome = exchange.write(exchange);
407
410
  }
408
- catch (error) {
409
- exchange.own = PostgreSQLConnection.toError(error);
411
+ catch (exception) {
412
+ exchange.own = PostgreSQLConnection.toError(exception);
410
413
  outcome = WriteOutcome.Skipped;
411
414
  }
412
415
  if (outcome === WriteOutcome.Held) {
@@ -557,9 +560,9 @@ export class PostgreSQLConnection {
557
560
  let synced = !exchange.nosync && exchange.synced;
558
561
  const at = this.sent.indexOf(exchange);
559
562
  for (let index = at === -1 ? this.sent.length : at + 1; index < this.sent.length;) {
560
- const item = this.sent[index];
563
+ const item = this.sent.get(index);
561
564
  if (!Object.isUndefined(item) && item.batch === batch) {
562
- this.sent.splice(index, 1);
565
+ this.sent.removeAt(index);
563
566
  synced ||= !item.nosync && item.synced;
564
567
  this.dropFromBatch(item, batch, error);
565
568
  if (this.blocker === item)
@@ -569,9 +572,9 @@ export class PostgreSQLConnection {
569
572
  index += 1;
570
573
  }
571
574
  for (let index = 0; index < this.pending.length;) {
572
- const item = this.pending[index];
575
+ const item = this.pending.get(index);
573
576
  if (!Object.isUndefined(item) && item.batch === batch) {
574
- this.pending.splice(index, 1);
577
+ this.pending.removeAt(index);
575
578
  this.dropFromBatch(item, batch, error);
576
579
  }
577
580
  else
@@ -716,9 +719,9 @@ export class PostgreSQLConnection {
716
719
  else
717
720
  Frontend.writeRun(this.out, exchange.portal, name, exchange.values, exchange.rows, exchange.flushing, exchange.formats);
718
721
  }
719
- catch (error) {
722
+ catch (exception) {
720
723
  this.out.truncate(mark);
721
- throw error;
724
+ throw exception;
722
725
  }
723
726
  if (!exchange.flushing)
724
727
  exchange.synced = true;
@@ -785,8 +788,8 @@ export class PostgreSQLConnection {
785
788
  exchange.values = this.serialize(params, built, entry);
786
789
  this.run(exchange, statement.name);
787
790
  }
788
- catch (error) {
789
- exchange.own = PostgreSQLConnection.toError(error);
791
+ catch (exception) {
792
+ exchange.own = PostgreSQLConnection.toError(exception);
790
793
  if (!Object.isNull(exchange.batch)) {
791
794
  Frontend.writeParse(this.out, "", Resources.refusedQuery);
792
795
  exchange.parses.push("");
@@ -803,7 +806,7 @@ export class PostgreSQLConnection {
803
806
  }
804
807
  const go = () => {
805
808
  exchange.silence = null;
806
- if (!Object.isNull(this.closedError) || exchange.done || this.sent[0] !== exchange) {
809
+ if (!Object.isNull(this.closedError) || exchange.done || this.sent.peek() !== exchange) {
807
810
  cancel.resolve();
808
811
  return;
809
812
  }
@@ -842,7 +845,7 @@ export class PostgreSQLConnection {
842
845
  this.sentCancels.push(sent);
843
846
  const cancel = this.session.cancelAsync(this.events.cancels);
844
847
  const settle = () => {
845
- const last = this.sent.at(-1);
848
+ const last = this.sent.get(this.sent.length - 1);
846
849
  if (Object.isUndefined(last))
847
850
  this.sentCancels = this.sentCancels.filter(t => t !== sent);
848
851
  else
@@ -891,7 +894,7 @@ export class PostgreSQLConnection {
891
894
  cancelBatchAsync(query) {
892
895
  const exchange = this.sent.find(item => item.batch?.query === query);
893
896
  if (!Object.isUndefined(exchange)) {
894
- if (exchange === this.sent[0])
897
+ if (exchange === this.sent.peek())
895
898
  return this.cancelExchangeAsync(exchange);
896
899
  exchange.cancel = new Deferred();
897
900
  return exchange.cancel.promise;
@@ -922,22 +925,22 @@ export class PostgreSQLConnection {
922
925
  this.blocker = null;
923
926
  this.fence = null;
924
927
  this.notables = 0;
925
- const head = this.sent[0];
928
+ const head = this.sent.peek();
926
929
  const failed = head?.error instanceof PostgreSQLException && head.error.severity === Resources.fatalSeverity ? head.error : null;
927
930
  const fatal = this.fatal ?? failed;
928
931
  this.uncertain = !Object.isNull(fatal) && !Object.isUndefined(head) && head.ends;
929
932
  const closed = new ConnectionClosedException(this.closing, this.host, this.port, fatal ?? error);
930
933
  this.closedError = closed;
931
- for (const item of [...this.sent, ...this.pending])
934
+ for (const item of [...this.sent.toArray(), ...this.pending.toArray()])
932
935
  item.cancel?.resolve();
933
- for (const item of this.sent.splice(0)) {
936
+ for (const item of this.sent.take()) {
934
937
  item.stream?.destroy(closed);
935
938
  if (!Object.isNull(item.own))
936
939
  this.settle(item);
937
940
  else
938
941
  this.settleError(item, failed ?? closed);
939
942
  }
940
- for (const item of this.pending.splice(0)) {
943
+ for (const item of this.pending.take()) {
941
944
  if (!Object.isNull(item.own))
942
945
  this.settle(item);
943
946
  else
@@ -979,18 +982,18 @@ export class PostgreSQLConnection {
979
982
  return;
980
983
  this.handleMessage(type, data, start, end);
981
984
  }
982
- catch (error) {
983
- if (error instanceof MalformedMessageException) {
984
- this.fatal = error;
985
+ catch (exception) {
986
+ if (exception instanceof MalformedMessageException) {
987
+ this.fatal = exception;
985
988
  this.frames.pause();
986
989
  this.socket.destroy();
987
990
  return;
988
991
  }
989
- const head = this.sent[0];
992
+ const head = this.sent.peek();
990
993
  if (Object.isUndefined(head))
991
- this.destroy(PostgreSQLConnection.toError(error));
994
+ this.destroy(PostgreSQLConnection.toError(exception));
992
995
  else
993
- this.fail(head, PostgreSQLConnection.toError(error));
996
+ this.fail(head, PostgreSQLConnection.toError(exception));
994
997
  }
995
998
  if (!Object.isNull(this.blocker) && !this.blocker.isHolding()) {
996
999
  this.blocker = null;
@@ -1062,8 +1065,10 @@ export class PostgreSQLConnection {
1062
1065
  case BackendMessage.NegotiateProtocolVersion:
1063
1066
  this.rejectUnsupported(String(BackendMessage[type]));
1064
1067
  break;
1065
- default:
1068
+ case BackendMessage.CloseComplete:
1066
1069
  break;
1070
+ default:
1071
+ throw new MalformedMessageException();
1067
1072
  }
1068
1073
  }
1069
1074
  fail(exchange, error) {
@@ -1076,7 +1081,7 @@ export class PostgreSQLConnection {
1076
1081
  this.abort(exchange);
1077
1082
  }
1078
1083
  rejectUnsupported(name) {
1079
- const head = this.sent[0];
1084
+ const head = this.sent.peek();
1080
1085
  if (!Object.isUndefined(head))
1081
1086
  this.fail(head, new DataException(Resources.formatMessageNotSupported(name)));
1082
1087
  }
@@ -1184,7 +1189,7 @@ export class PostgreSQLConnection {
1184
1189
  markUnsafe(exchange) {
1185
1190
  this.rolling = true;
1186
1191
  exchange.own = new UnsafeTransactionException(Resources.unsafeTransaction);
1187
- for (const item of this.sent)
1192
+ for (const item of this.sent.toArray())
1188
1193
  if (item.kind !== ExchangeKind.Local)
1189
1194
  item.own = new UnsafeTransactionException(Resources.unsafeTransaction);
1190
1195
  this.pending.unshift(new Exchange(ExchangeKind.Internal, null, null, item => {
@@ -1217,7 +1222,7 @@ export class PostgreSQLConnection {
1217
1222
  const next = await query.callCursor(exchange.result);
1218
1223
  exchange.awaiting = false;
1219
1224
  exchange.result = new Result();
1220
- if (!Object.isNull(this.closedError) || exchange.synced || this.sent[0] !== exchange)
1225
+ if (!Object.isNull(this.closedError) || exchange.synced || this.sent.peek() !== exchange)
1221
1226
  return;
1222
1227
  if (!Object.isNull(query.aborted))
1223
1228
  throw query.aborted;
@@ -1231,16 +1236,16 @@ export class PostgreSQLConnection {
1231
1236
  this.schedule();
1232
1237
  }
1233
1238
  }
1234
- catch (error) {
1239
+ catch (exception) {
1235
1240
  exchange.awaiting = false;
1236
- if (!Object.isNull(this.closedError) || exchange.synced || this.sent[0] !== exchange)
1241
+ if (!Object.isNull(this.closedError) || exchange.synced || this.sent.peek() !== exchange)
1237
1242
  return;
1238
- this.fail(exchange, PostgreSQLConnection.toError(error));
1243
+ this.fail(exchange, PostgreSQLConnection.toError(exception));
1239
1244
  }
1240
1245
  this.refresh();
1241
1246
  }
1242
1247
  handleErrorResponse(data, start, end) {
1243
- const exchange = this.sent[0];
1248
+ const exchange = this.sent.peek();
1244
1249
  const error = new PostgreSQLException(Backend.readError(data, start, end));
1245
1250
  if (Object.isUndefined(exchange)) {
1246
1251
  this.fatal = error;
@@ -1256,7 +1261,6 @@ export class PostgreSQLConnection {
1256
1261
  }
1257
1262
  handleReadyForQuery(data, start, end) {
1258
1263
  this.currentStatus = Backend.readReadyForQuery(data, start, end);
1259
- this.frames.setOwning(false);
1260
1264
  const exchange = this.sent.shift();
1261
1265
  if (Object.isUndefined(exchange))
1262
1266
  throw new DataException(Resources.unexpectedMessage);
@@ -1273,7 +1277,7 @@ export class PostgreSQLConnection {
1273
1277
  this.settle(exchange);
1274
1278
  if (exchange.entry?.owner === exchange)
1275
1279
  exchange.entry.owner = null;
1276
- for (let next = this.sent[0]; next?.kind === ExchangeKind.Local; next = this.sent[0]) {
1280
+ for (let next = this.sent.peek(); next?.kind === ExchangeKind.Local; next = this.sent.peek()) {
1277
1281
  this.sent.shift();
1278
1282
  this.settle(next);
1279
1283
  }
@@ -1286,7 +1290,7 @@ export class PostgreSQLConnection {
1286
1290
  this.events.onReady(this);
1287
1291
  }
1288
1292
  activateHead() {
1289
- const next = this.sent[0];
1293
+ const next = this.sent.peek();
1290
1294
  if (Object.isUndefined(next) || Object.isNull(next.query))
1291
1295
  return;
1292
1296
  next.query.active = true;
@@ -1484,7 +1488,7 @@ export class PostgreSQLConnection {
1484
1488
  }
1485
1489
  handleNotificationResponse(data, start, end) {
1486
1490
  const notification = Backend.readNotification(data, start, end);
1487
- PostgreSQLConnection.guard(() => this.events.onNotify(notification.channel, notification.payload, notification.pid));
1491
+ this.events.onNotify(notification.channel, notification.payload, notification.pid);
1488
1492
  }
1489
1493
  handleNoticeResponse(data, start, end) {
1490
1494
  const notice = Backend.readError(data, start, end);
@@ -1492,12 +1496,12 @@ export class PostgreSQLConnection {
1492
1496
  if (Object.isNull(onnotice))
1493
1497
  console.log(Object.fromEntries(notice));
1494
1498
  else if (onnotice !== false)
1495
- PostgreSQLConnection.guard(() => onnotice(notice));
1499
+ onnotice(notice);
1496
1500
  }
1497
1501
  handleParameterStatus(data, start, end) {
1498
1502
  const status = Backend.readParameterStatus(data, start, end);
1499
1503
  this.parameters.set(status.name, status.value);
1500
- PostgreSQLConnection.guard(() => this.events.onParameter(status.name, status.value));
1504
+ this.events.onParameter(status.name, status.value);
1501
1505
  }
1502
1506
  copyInResponse() {
1503
1507
  const exchange = this.peekHead();
@@ -1510,14 +1514,12 @@ export class PostgreSQLConnection {
1510
1514
  const stream = new CopyOutStream(this, exchange);
1511
1515
  exchange.stream = stream;
1512
1516
  exchange.open = false;
1513
- this.frames.setOwning(true);
1514
1517
  PostgreSQLConnection.queryOf(exchange).resolve(stream);
1515
1518
  }
1516
1519
  copyBothResponse() {
1517
1520
  const exchange = this.peekHead();
1518
1521
  const stream = new CopyBothStream(this, exchange);
1519
1522
  exchange.stream = stream;
1520
- this.frames.setOwning(true);
1521
1523
  PostgreSQLConnection.queryOf(exchange).resolve(stream);
1522
1524
  }
1523
1525
  copyData(data, start, end) {
@@ -1532,14 +1534,13 @@ export class PostgreSQLConnection {
1532
1534
  }
1533
1535
  }
1534
1536
  copyDone() {
1535
- this.frames.setOwning(false);
1536
1537
  const exchange = this.peekHead();
1537
1538
  if (exchange.stream instanceof Readable)
1538
1539
  exchange.stream.push(null);
1539
1540
  exchange.stream = null;
1540
1541
  }
1541
1542
  peekHead() {
1542
- const head = this.sent[0];
1543
+ const head = this.sent.peek();
1543
1544
  if (Object.isUndefined(head))
1544
1545
  throw new DataException(Resources.unexpectedMessage);
1545
1546
  return head;
@@ -1586,14 +1587,6 @@ export class PostgreSQLConnection {
1586
1587
  static readStatement(exchange) {
1587
1588
  return PostgreSQLConnection.readWire(PostgreSQLConnection.queryOf(exchange)).statement;
1588
1589
  }
1589
- static guard(action) {
1590
- try {
1591
- action();
1592
- }
1593
- catch {
1594
- return;
1595
- }
1596
- }
1597
1590
  static toError(error) {
1598
1591
  return error instanceof Error ? error : new DataException(Resources.nonErrorThrown, new ExceptionOptions(error));
1599
1592
  }