@replit/river 0.23.8 → 0.23.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-WQRQFAP6.js → chunk-B323CECK.js} +473 -15
- package/dist/chunk-B323CECK.js.map +1 -0
- package/dist/{chunk-ELZRZNA5.js → chunk-FRICSBDW.js} +2 -2
- package/dist/chunk-FRICSBDW.js.map +1 -0
- package/dist/{chunk-RJ6CXPBM.js → chunk-KBAZ5TWE.js} +129 -65
- package/dist/chunk-KBAZ5TWE.js.map +1 -0
- package/dist/{chunk-DXTG3E3B.js → chunk-UXQMGZKP.js} +2 -2
- package/dist/{chunk-CBNCT4B3.js → chunk-Z4G27Y2I.js} +2 -2
- package/dist/{connection-6ce35bd5.d.ts → connection-700340c4.d.ts} +1 -1
- package/dist/{connection-a3fdfa3a.d.ts → connection-efcd4e1a.d.ts} +1 -1
- package/dist/router/index.cjs +473 -14
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +41 -7
- package/dist/router/index.d.ts +41 -7
- package/dist/router/index.js +4 -2
- package/dist/{services-fd8a9894.d.ts → services-409c5545.d.ts} +10 -9
- package/dist/transport/impls/uds/client.cjs +122 -58
- package/dist/transport/impls/uds/client.cjs.map +1 -1
- package/dist/transport/impls/uds/client.d.cts +2 -2
- package/dist/transport/impls/uds/client.d.ts +2 -2
- package/dist/transport/impls/uds/client.js +3 -3
- package/dist/transport/impls/uds/server.cjs +103 -47
- package/dist/transport/impls/uds/server.cjs.map +1 -1
- package/dist/transport/impls/uds/server.d.cts +2 -2
- package/dist/transport/impls/uds/server.d.ts +2 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +125 -58
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +2 -2
- package/dist/transport/impls/ws/client.d.ts +2 -2
- package/dist/transport/impls/ws/client.js +6 -3
- package/dist/transport/impls/ws/client.js.map +1 -1
- package/dist/transport/impls/ws/server.cjs +103 -47
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +2 -2
- package/dist/transport/impls/ws/server.d.ts +2 -2
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +128 -64
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +2 -2
- package/dist/{transport-3d34f714.d.ts → transport-cf856c41.d.ts} +46 -24
- package/dist/util/testHelpers.cjs +46 -4
- package/dist/util/testHelpers.cjs.map +1 -1
- package/dist/util/testHelpers.d.cts +2 -2
- package/dist/util/testHelpers.d.ts +2 -2
- package/dist/util/testHelpers.js +3 -3
- package/package.json +3 -3
- package/dist/chunk-ELZRZNA5.js.map +0 -1
- package/dist/chunk-RJ6CXPBM.js.map +0 -1
- package/dist/chunk-WQRQFAP6.js.map +0 -1
- /package/dist/{chunk-DXTG3E3B.js.map → chunk-UXQMGZKP.js.map} +0 -0
- /package/dist/{chunk-CBNCT4B3.js.map → chunk-Z4G27Y2I.js.map} +0 -0
|
@@ -159,11 +159,13 @@ var createLogProxy = (log) => ({
|
|
|
159
159
|
var ProtocolError = {
|
|
160
160
|
RetriesExceeded: "conn_retry_exceeded",
|
|
161
161
|
HandshakeFailed: "handshake_failed",
|
|
162
|
-
UseAfterDestroy: "use_after_destroy",
|
|
163
162
|
MessageOrderingViolated: "message_ordering_violated"
|
|
164
163
|
};
|
|
165
164
|
var EventDispatcher = class {
|
|
166
165
|
eventListeners = {};
|
|
166
|
+
removeAllListeners() {
|
|
167
|
+
this.eventListeners = {};
|
|
168
|
+
}
|
|
167
169
|
numberOfListeners(eventType) {
|
|
168
170
|
return this.eventListeners[eventType]?.size ?? 0;
|
|
169
171
|
}
|
|
@@ -182,7 +184,8 @@ var EventDispatcher = class {
|
|
|
182
184
|
dispatchEvent(eventType, event) {
|
|
183
185
|
const handlers = this.eventListeners[eventType];
|
|
184
186
|
if (handlers) {
|
|
185
|
-
|
|
187
|
+
const copy = [...handlers];
|
|
188
|
+
for (const handler of copy) {
|
|
186
189
|
handler(event);
|
|
187
190
|
}
|
|
188
191
|
}
|
|
@@ -196,7 +199,7 @@ var import_nanoid2 = require("nanoid");
|
|
|
196
199
|
var import_api = require("@opentelemetry/api");
|
|
197
200
|
|
|
198
201
|
// package.json
|
|
199
|
-
var version = "0.23.
|
|
202
|
+
var version = "0.23.10";
|
|
200
203
|
|
|
201
204
|
// tracing/index.ts
|
|
202
205
|
function createSessionTelemetryInfo(session, propagationCtx) {
|
|
@@ -246,7 +249,7 @@ var Connection = class {
|
|
|
246
249
|
get loggingMetadata() {
|
|
247
250
|
const metadata = { connId: this.id };
|
|
248
251
|
const spanContext = this.telemetry?.span.spanContext();
|
|
249
|
-
if (spanContext) {
|
|
252
|
+
if (this.telemetry?.span.isRecording() && spanContext) {
|
|
250
253
|
metadata.telemetry = {
|
|
251
254
|
traceId: spanContext.traceId,
|
|
252
255
|
spanId: spanContext.spanId
|
|
@@ -267,6 +270,11 @@ var Session = class {
|
|
|
267
270
|
* The active connection associated with this session
|
|
268
271
|
*/
|
|
269
272
|
connection;
|
|
273
|
+
/**
|
|
274
|
+
* A connection that is currently undergoing handshaking. Used to distinguish between the active
|
|
275
|
+
* connection, but still be able to close it if needed.
|
|
276
|
+
*/
|
|
277
|
+
handshakingConnection;
|
|
270
278
|
from;
|
|
271
279
|
to;
|
|
272
280
|
/**
|
|
@@ -446,23 +454,60 @@ var Session = class {
|
|
|
446
454
|
this.cancelGrace();
|
|
447
455
|
this.sendBufferedMessages(newConn);
|
|
448
456
|
this.connection = newConn;
|
|
457
|
+
this.handshakingConnection = void 0;
|
|
458
|
+
}
|
|
459
|
+
replaceWithNewHandshakingConnection(newConn) {
|
|
460
|
+
this.handshakingConnection = newConn;
|
|
449
461
|
}
|
|
450
462
|
beginGrace(cb) {
|
|
451
463
|
this.log?.info(
|
|
452
464
|
`starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
|
|
453
465
|
this.loggingMetadata
|
|
454
466
|
);
|
|
467
|
+
this.cancelGrace({ keepHeartbeatMisses: true });
|
|
455
468
|
this.disconnectionGrace = setTimeout(() => {
|
|
456
|
-
this.
|
|
469
|
+
if (this.connection !== void 0) {
|
|
470
|
+
this.log?.warn(
|
|
471
|
+
`grace period for ${this.to} elapsed while connected. not calling callback`,
|
|
472
|
+
{
|
|
473
|
+
...this.loggingMetadata,
|
|
474
|
+
connId: this.connection.id,
|
|
475
|
+
tags: ["invariant-violation"]
|
|
476
|
+
}
|
|
477
|
+
);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
this.log?.info(
|
|
481
|
+
`grace period for ${this.to} elapsed`,
|
|
482
|
+
this.loggingMetadata
|
|
483
|
+
);
|
|
457
484
|
cb();
|
|
458
485
|
}, this.options.sessionDisconnectGraceMs);
|
|
459
486
|
}
|
|
460
487
|
// called on reconnect of the underlying session
|
|
461
|
-
cancelGrace(
|
|
462
|
-
|
|
488
|
+
cancelGrace({ keepHeartbeatMisses } = {
|
|
489
|
+
keepHeartbeatMisses: false
|
|
490
|
+
}) {
|
|
491
|
+
if (!keepHeartbeatMisses) {
|
|
492
|
+
this.heartbeatMisses = 0;
|
|
493
|
+
}
|
|
494
|
+
if (this.disconnectionGrace === void 0)
|
|
495
|
+
return;
|
|
463
496
|
clearTimeout(this.disconnectionGrace);
|
|
464
497
|
this.disconnectionGrace = void 0;
|
|
465
498
|
}
|
|
499
|
+
/**
|
|
500
|
+
* Used to close the handshaking connection, if set.
|
|
501
|
+
*/
|
|
502
|
+
closeHandshakingConnection(expectedHandshakingConn) {
|
|
503
|
+
if (this.handshakingConnection === void 0)
|
|
504
|
+
return;
|
|
505
|
+
if (expectedHandshakingConn !== void 0 && this.handshakingConnection === expectedHandshakingConn) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
this.handshakingConnection.close();
|
|
509
|
+
this.handshakingConnection = void 0;
|
|
510
|
+
}
|
|
466
511
|
// closed when we want to discard the whole session
|
|
467
512
|
// (i.e. shutdown or session disconnect)
|
|
468
513
|
close() {
|
|
@@ -579,10 +624,9 @@ var defaultServerTransportOptions = {
|
|
|
579
624
|
};
|
|
580
625
|
var Transport = class {
|
|
581
626
|
/**
|
|
582
|
-
*
|
|
583
|
-
* A destroyed transport will not attempt to reconnect and cannot be used again.
|
|
627
|
+
* The status of the transport.
|
|
584
628
|
*/
|
|
585
|
-
|
|
629
|
+
status;
|
|
586
630
|
/**
|
|
587
631
|
* The {@link Codec} used to encode and decode messages.
|
|
588
632
|
*/
|
|
@@ -624,7 +668,7 @@ var Transport = class {
|
|
|
624
668
|
this.sessions = /* @__PURE__ */ new Map();
|
|
625
669
|
this.codec = this.options.codec;
|
|
626
670
|
this.clientId = clientId;
|
|
627
|
-
this.
|
|
671
|
+
this.status = "open";
|
|
628
672
|
}
|
|
629
673
|
bindLogger(fn, level) {
|
|
630
674
|
if (typeof fn === "function") {
|
|
@@ -672,7 +716,13 @@ var Transport = class {
|
|
|
672
716
|
});
|
|
673
717
|
return session;
|
|
674
718
|
}
|
|
675
|
-
getOrCreateSession(
|
|
719
|
+
getOrCreateSession({
|
|
720
|
+
to,
|
|
721
|
+
conn,
|
|
722
|
+
handshakingConn,
|
|
723
|
+
sessionId,
|
|
724
|
+
propagationCtx
|
|
725
|
+
}) {
|
|
676
726
|
let session = this.sessions.get(to);
|
|
677
727
|
let isReconnect = session !== void 0;
|
|
678
728
|
if (session?.advertisedSessionId !== void 0 && sessionId !== void 0 && session.advertisedSessionId !== sessionId) {
|
|
@@ -680,7 +730,11 @@ var Transport = class {
|
|
|
680
730
|
`session for ${to} already exists but has a different session id (expected: ${session.advertisedSessionId}, got: ${sessionId}), creating a new one`,
|
|
681
731
|
session.loggingMetadata
|
|
682
732
|
);
|
|
683
|
-
this.deleteSession(
|
|
733
|
+
this.deleteSession({
|
|
734
|
+
session,
|
|
735
|
+
closeHandshakingConnection: handshakingConn !== void 0,
|
|
736
|
+
handshakingConn
|
|
737
|
+
});
|
|
684
738
|
isReconnect = false;
|
|
685
739
|
session = void 0;
|
|
686
740
|
}
|
|
@@ -694,9 +748,19 @@ var Transport = class {
|
|
|
694
748
|
if (sessionId !== void 0) {
|
|
695
749
|
session.advertisedSessionId = sessionId;
|
|
696
750
|
}
|
|
751
|
+
if (handshakingConn !== void 0) {
|
|
752
|
+
session.replaceWithNewHandshakingConnection(handshakingConn);
|
|
753
|
+
}
|
|
697
754
|
return { session, isReconnect };
|
|
698
755
|
}
|
|
699
|
-
deleteSession(
|
|
756
|
+
deleteSession({
|
|
757
|
+
session,
|
|
758
|
+
closeHandshakingConnection,
|
|
759
|
+
handshakingConn
|
|
760
|
+
}) {
|
|
761
|
+
if (closeHandshakingConnection) {
|
|
762
|
+
session.closeHandshakingConnection(handshakingConn);
|
|
763
|
+
}
|
|
700
764
|
session.close();
|
|
701
765
|
session.telemetry.span.end();
|
|
702
766
|
this.sessions.delete(session.to);
|
|
@@ -723,7 +787,11 @@ var Transport = class {
|
|
|
723
787
|
session.connection = void 0;
|
|
724
788
|
session.beginGrace(() => {
|
|
725
789
|
session.telemetry.span.addEvent("session grace period expired");
|
|
726
|
-
this.deleteSession(
|
|
790
|
+
this.deleteSession({
|
|
791
|
+
session,
|
|
792
|
+
closeHandshakingConnection: true,
|
|
793
|
+
handshakingConn: conn
|
|
794
|
+
});
|
|
727
795
|
});
|
|
728
796
|
}
|
|
729
797
|
/**
|
|
@@ -762,7 +830,7 @@ var Transport = class {
|
|
|
762
830
|
* @param msg The received message.
|
|
763
831
|
*/
|
|
764
832
|
handleMsg(msg, conn) {
|
|
765
|
-
if (this.
|
|
833
|
+
if (this.getStatus() !== "open")
|
|
766
834
|
return;
|
|
767
835
|
const session = this.sessions.get(msg.from);
|
|
768
836
|
if (!session) {
|
|
@@ -803,7 +871,7 @@ var Transport = class {
|
|
|
803
871
|
code: import_api3.SpanStatusCode.ERROR,
|
|
804
872
|
message: "message order violated"
|
|
805
873
|
});
|
|
806
|
-
|
|
874
|
+
this.deleteSession({ session, closeHandshakingConnection: true });
|
|
807
875
|
}
|
|
808
876
|
return;
|
|
809
877
|
}
|
|
@@ -841,23 +909,16 @@ var Transport = class {
|
|
|
841
909
|
* @returns The ID of the sent message or undefined if it wasn't sent
|
|
842
910
|
*/
|
|
843
911
|
send(to, msg) {
|
|
844
|
-
if (this.
|
|
845
|
-
const err = "transport is
|
|
912
|
+
if (this.getStatus() === "closed") {
|
|
913
|
+
const err = "transport is closed, cant send";
|
|
846
914
|
this.log?.error(err, {
|
|
847
915
|
clientId: this.clientId,
|
|
848
916
|
transportMessage: msg,
|
|
849
917
|
tags: ["invariant-violation"]
|
|
850
918
|
});
|
|
851
|
-
|
|
852
|
-
return void 0;
|
|
853
|
-
} else if (this.state === "closed") {
|
|
854
|
-
this.log?.info(`transport closed when sending, discarding`, {
|
|
855
|
-
clientId: this.clientId,
|
|
856
|
-
transportMessage: msg
|
|
857
|
-
});
|
|
858
|
-
return void 0;
|
|
919
|
+
throw new Error(err);
|
|
859
920
|
}
|
|
860
|
-
return this.getOrCreateSession(to).session.send(msg);
|
|
921
|
+
return this.getOrCreateSession({ to }).session.send(msg);
|
|
861
922
|
}
|
|
862
923
|
// control helpers
|
|
863
924
|
sendCloseStream(to, streamId) {
|
|
@@ -878,23 +939,18 @@ var Transport = class {
|
|
|
878
939
|
* Closes the transport. Any messages sent while the transport is closed will be silently discarded.
|
|
879
940
|
*/
|
|
880
941
|
close() {
|
|
881
|
-
this.
|
|
942
|
+
this.status = "closed";
|
|
882
943
|
for (const session of this.sessions.values()) {
|
|
883
|
-
this.deleteSession(session);
|
|
944
|
+
this.deleteSession({ session, closeHandshakingConnection: true });
|
|
884
945
|
}
|
|
946
|
+
this.eventDispatcher.dispatchEvent("transportStatus", {
|
|
947
|
+
status: this.status
|
|
948
|
+
});
|
|
949
|
+
this.eventDispatcher.removeAllListeners();
|
|
885
950
|
this.log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
886
951
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
* implementation if you need to do any additional cleanup and call super.destroy() at the end.
|
|
890
|
-
* Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
|
|
891
|
-
*/
|
|
892
|
-
destroy() {
|
|
893
|
-
this.state = "destroyed";
|
|
894
|
-
for (const session of this.sessions.values()) {
|
|
895
|
-
this.deleteSession(session);
|
|
896
|
-
}
|
|
897
|
-
this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
952
|
+
getStatus() {
|
|
953
|
+
return this.status;
|
|
898
954
|
}
|
|
899
955
|
};
|
|
900
956
|
var ServerTransport = class extends Transport {
|
|
@@ -926,7 +982,7 @@ var ServerTransport = class extends Transport {
|
|
|
926
982
|
this.handshakeExtensions = options;
|
|
927
983
|
}
|
|
928
984
|
handleConnection(conn) {
|
|
929
|
-
if (this.
|
|
985
|
+
if (this.getStatus() !== "open")
|
|
930
986
|
return;
|
|
931
987
|
this.log?.info(`new incoming connection`, {
|
|
932
988
|
...conn.loggingMetadata,
|
|
@@ -1126,12 +1182,12 @@ var ServerTransport = class extends Transport {
|
|
|
1126
1182
|
if (parsedMetadata === false) {
|
|
1127
1183
|
return false;
|
|
1128
1184
|
}
|
|
1129
|
-
const { session, isReconnect } = this.getOrCreateSession(
|
|
1130
|
-
parsed.from,
|
|
1185
|
+
const { session, isReconnect } = this.getOrCreateSession({
|
|
1186
|
+
to: parsed.from,
|
|
1131
1187
|
conn,
|
|
1132
|
-
parsed.payload.sessionId,
|
|
1133
|
-
parsed.tracing
|
|
1134
|
-
);
|
|
1188
|
+
sessionId: parsed.payload.sessionId,
|
|
1189
|
+
propagationCtx: parsed.tracing
|
|
1190
|
+
});
|
|
1135
1191
|
this.sessionHandshakeMetadata.set(session, parsedMetadata);
|
|
1136
1192
|
this.log?.debug(
|
|
1137
1193
|
`handshake from ${parsed.from} ok, responding with handshake success`,
|