@noldova/context.data.sql.postgresql 0.0.11 → 0.0.13
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 +38 -2
- package/api/index.d.ts +91 -1
- package/exceptions/batch-skipped.exception.js +2 -2
- package/exceptions/batch-skipped.exception.js.map +1 -1
- package/exceptions/batch.exception.js +2 -2
- package/exceptions/batch.exception.js.map +1 -1
- package/exceptions/callbacks-failed.exception.js +17 -0
- package/exceptions/callbacks-failed.exception.js.map +1 -0
- package/exceptions/cancel-unanswered.exception.js +2 -2
- package/exceptions/cancel-unanswered.exception.js.map +1 -1
- package/exceptions/connection-closed.exception.js +2 -2
- package/exceptions/connection-closed.exception.js.map +1 -1
- package/exceptions/connection-ended.exception.js +2 -2
- package/exceptions/connection-ended.exception.js.map +1 -1
- package/exceptions/malformed-message.exception.js +2 -2
- package/exceptions/malformed-message.exception.js.map +1 -1
- package/exceptions/postgresql-client.exception.js +14 -0
- package/exceptions/postgresql-client.exception.js.map +1 -0
- package/exceptions/postgresql.exception.js +2 -2
- package/exceptions/postgresql.exception.js.map +1 -1
- package/exceptions/query-canceled.exception.js +2 -2
- package/exceptions/query-canceled.exception.js.map +1 -1
- package/exceptions/query-timeout.exception.js +2 -2
- package/exceptions/query-timeout.exception.js.map +1 -1
- package/exceptions/queue-timeout.exception.js +2 -2
- package/exceptions/queue-timeout.exception.js.map +1 -1
- package/exceptions/stray-cancel.exception.js +2 -2
- package/exceptions/stray-cancel.exception.js.map +1 -1
- package/exceptions/transaction-rolled-back.exception.js +2 -2
- package/exceptions/transaction-rolled-back.exception.js.map +1 -1
- package/exceptions/type-not-found.exception.js +2 -2
- package/exceptions/type-not-found.exception.js.map +1 -1
- package/exceptions/unsafe-transaction.exception.js +2 -2
- package/exceptions/unsafe-transaction.exception.js.map +1 -1
- package/models/{row-column.js → array-element.js} +5 -5
- package/models/array-element.js.map +1 -0
- package/models/channel-listener.js +3 -0
- package/models/channel-listener.js.map +1 -1
- package/models/client/client-listener.js +67 -22
- package/models/client/client-listener.js.map +1 -1
- package/models/client/client-query.js.map +1 -1
- package/models/client/connection-socket.js.map +1 -1
- package/models/client/copy-both-stream.js +2 -2
- package/models/client/copy-both-stream.js.map +1 -1
- package/models/client/copy-in-stream.js +2 -2
- package/models/client/copy-in-stream.js.map +1 -1
- package/models/client/copy-out-stream.js +2 -2
- package/models/client/copy-out-stream.js.map +1 -1
- package/models/client/deferred.js +1 -1
- package/models/client/deferred.js.map +1 -1
- package/models/client/listen-subscription.js +3 -0
- package/models/client/listen-subscription.js.map +1 -1
- package/models/client/pool-lease.js +11 -15
- package/models/client/pool-lease.js.map +1 -1
- package/models/client/pool-queue.js +42 -4
- package/models/client/pool-queue.js.map +1 -1
- package/models/client/postgresql-client.js +2 -2
- package/models/client/postgresql-client.js.map +1 -1
- package/models/client/postgresql-connection.js +70 -77
- package/models/client/postgresql-connection.js.map +1 -1
- package/models/client/postgresql-pool.js +133 -39
- package/models/client/postgresql-pool.js.map +1 -1
- package/models/client/query.js +4 -4
- package/models/client/query.js.map +1 -1
- package/models/client/reserved-client.js.map +1 -1
- package/models/client/transaction-scope.js +2 -2
- package/models/client/transaction-scope.js.map +1 -1
- package/models/described-result.js +20 -0
- package/models/described-result.js.map +1 -0
- package/models/host-target.js +16 -0
- package/models/host-target.js.map +1 -0
- package/models/parser-variant.js +16 -0
- package/models/parser-variant.js.map +1 -0
- package/models/postgresql-session.js +6 -8
- package/models/postgresql-session.js.map +1 -1
- package/models/postgresql-socket.js +17 -20
- package/models/postgresql-socket.js.map +1 -1
- package/models/result.js +1 -1
- package/models/result.js.map +1 -1
- package/models/started-session.js +1 -1
- package/models/started-session.js.map +1 -1
- package/models/type-registry.js +19 -26
- package/models/type-registry.js.map +1 -1
- package/package.json +6 -6
- package/resources.js +3 -0
- package/resources.js.map +1 -1
- package/services/authenticator.js +7 -1
- package/services/authenticator.js.map +1 -1
- package/services/client/connection-lease.js.map +1 -1
- package/services/client/file-query-handler.js.map +1 -1
- package/services/client/row.reader.js +13 -20
- package/services/client/row.reader.js.map +1 -1
- package/services/client/type-loader-events.js.map +1 -1
- package/services/client-options.parser.js +12 -11
- package/services/client-options.parser.js.map +1 -1
- package/services/parameter-rewriter.js +22 -17
- package/services/parameter-rewriter.js.map +1 -1
- package/services/protocol/backend.js +0 -19
- package/services/protocol/backend.js.map +1 -1
- package/services/protocol/frame.reader.js +21 -37
- package/services/protocol/frame.reader.js.map +1 -1
- package/services/protocol/frontend.js +2 -2
- package/services/protocol/frontend.js.map +1 -1
- package/services/session-starter.js +15 -8
- package/services/session-starter.js.map +1 -1
- package/services/tls-options.reader.js +6 -6
- package/services/tls-options.reader.js.map +1 -1
- package/services/types/array-serializer.js +9 -3
- package/services/types/array-serializer.js.map +1 -1
- package/services/types/array.parser.js +23 -10
- package/services/types/array.parser.js.map +1 -1
- package/services/types/binary-array.reader.js +69 -0
- package/services/types/binary-array.reader.js.map +1 -0
- package/services/types/binary-readers.js +1 -60
- package/services/types/binary-readers.js.map +1 -1
- package/services/types/date.parser.js +7 -11
- package/services/types/date.parser.js.map +1 -1
- package/services/value-converter.js +3 -1
- package/services/value-converter.js.map +1 -1
- package/types/column-transform.js +9 -0
- package/types/column-transform.js.map +1 -0
- package/types/{host-target.js → row-transform.js} +1 -1
- package/types/row-transform.js.map +1 -0
- package/types/value-transform.js +9 -0
- package/types/value-transform.js.map +1 -0
- package/models/row-column.js.map +0 -1
- 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
|
-
}
|
|
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
|
|
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
|
|
232
|
+
const waiting = this.pending.get(index);
|
|
230
233
|
if (!Object.isUndefined(waiting)) {
|
|
231
|
-
this.pending.
|
|
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.
|
|
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.
|
|
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
|
|
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 (
|
|
409
|
-
exchange.own = PostgreSQLConnection.toError(
|
|
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
|
|
563
|
+
const item = this.sent.get(index);
|
|
561
564
|
if (!Object.isUndefined(item) && item.batch === batch) {
|
|
562
|
-
this.sent.
|
|
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
|
|
575
|
+
const item = this.pending.get(index);
|
|
573
576
|
if (!Object.isUndefined(item) && item.batch === batch) {
|
|
574
|
-
this.pending.
|
|
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 (
|
|
722
|
+
catch (exception) {
|
|
720
723
|
this.out.truncate(mark);
|
|
721
|
-
throw
|
|
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 (
|
|
789
|
-
exchange.own = PostgreSQLConnection.toError(
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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 (
|
|
983
|
-
if (
|
|
984
|
-
this.fatal =
|
|
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
|
|
992
|
+
const head = this.sent.peek();
|
|
990
993
|
if (Object.isUndefined(head))
|
|
991
|
-
this.destroy(PostgreSQLConnection.toError(
|
|
994
|
+
this.destroy(PostgreSQLConnection.toError(exception));
|
|
992
995
|
else
|
|
993
|
-
this.fail(head, PostgreSQLConnection.toError(
|
|
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
|
-
|
|
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
|
|
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
|
|
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 (
|
|
1239
|
+
catch (exception) {
|
|
1235
1240
|
exchange.awaiting = false;
|
|
1236
|
-
if (!Object.isNull(this.closedError) || exchange.synced || this.sent
|
|
1241
|
+
if (!Object.isNull(this.closedError) || exchange.synced || this.sent.peek() !== exchange)
|
|
1237
1242
|
return;
|
|
1238
|
-
this.fail(exchange, PostgreSQLConnection.toError(
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
}
|