@replit/river 0.25.1 → 0.26.0
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-D5O3ERJU.js → chunk-5FDAIAQ5.js} +3 -3
- package/dist/chunk-5FDAIAQ5.js.map +1 -0
- package/dist/{chunk-5CNNIOAO.js → chunk-5S64PXTU.js} +102 -95
- package/dist/chunk-5S64PXTU.js.map +1 -0
- package/dist/{chunk-PCBPPTXH.js → chunk-7ETNUCOL.js} +54 -62
- package/dist/chunk-7ETNUCOL.js.map +1 -0
- package/dist/{chunk-SGSRNAWJ.js → chunk-BNNELZM4.js} +2 -2
- package/dist/{chunk-SGSRNAWJ.js.map → chunk-BNNELZM4.js.map} +1 -1
- package/dist/{chunk-SZ5NBBX7.js → chunk-CCUYKR5C.js} +14 -4
- package/dist/chunk-CCUYKR5C.js.map +1 -0
- package/dist/{chunk-YM5Y4NAT.js → chunk-JSU2KACV.js} +199 -117
- package/dist/chunk-JSU2KACV.js.map +1 -0
- package/dist/{chunk-MBMEJIPU.js → chunk-KP4UB5NW.js} +2 -2
- package/dist/{client-1321630c.d.ts → client-162c509c.d.ts} +4 -2
- package/dist/{connection-bd907ca6.d.ts → connection-6a404bb8.d.ts} +1 -1
- package/dist/{handshake-3772d7ca.d.ts → handshake-3342bb94.d.ts} +132 -84
- package/dist/logging/index.d.cts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/{message-e6c560fd.d.ts → message-1a434848.d.ts} +2 -1
- package/dist/router/index.cjs +12 -3
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +8 -8
- package/dist/router/index.d.ts +8 -8
- package/dist/router/index.js +2 -2
- package/dist/{server-f0fd2b98.d.ts → server-1b695374.d.ts} +9 -4
- package/dist/{services-8d14ae16.d.ts → services-c17f7eff.d.ts} +3 -3
- package/dist/transport/impls/ws/client.cjs +302 -207
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +4 -4
- package/dist/transport/impls/ws/client.d.ts +4 -4
- package/dist/transport/impls/ws/client.js +5 -5
- package/dist/transport/impls/ws/server.cjs +253 -174
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +4 -4
- package/dist/transport/impls/ws/server.d.ts +4 -4
- package/dist/transport/impls/ws/server.js +5 -5
- package/dist/transport/index.cjs +351 -264
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +4 -4
- package/dist/transport/index.d.ts +4 -4
- package/dist/transport/index.js +5 -5
- package/dist/util/testHelpers.cjs +208 -117
- package/dist/util/testHelpers.cjs.map +1 -1
- package/dist/util/testHelpers.d.cts +6 -5
- package/dist/util/testHelpers.d.ts +6 -5
- package/dist/util/testHelpers.js +6 -3
- package/dist/util/testHelpers.js.map +1 -1
- package/package.json +14 -13
- package/dist/chunk-5CNNIOAO.js.map +0 -1
- package/dist/chunk-D5O3ERJU.js.map +0 -1
- package/dist/chunk-PCBPPTXH.js.map +0 -1
- package/dist/chunk-SZ5NBBX7.js.map +0 -1
- package/dist/chunk-YM5Y4NAT.js.map +0 -1
- /package/dist/{chunk-MBMEJIPU.js.map → chunk-KP4UB5NW.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-
|
|
2
|
-
export { C as ClientTransport } from '../client-
|
|
3
|
-
export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-
|
|
4
|
-
export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-
|
|
1
|
+
export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-3342bb94.js';
|
|
2
|
+
export { C as ClientTransport } from '../client-162c509c.js';
|
|
3
|
+
export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-1b695374.js';
|
|
4
|
+
export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-1a434848.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import '../types-3e5768ec.js';
|
|
7
7
|
import '@sinclair/typebox/value';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-
|
|
2
|
-
export { C as ClientTransport } from '../client-
|
|
3
|
-
export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-
|
|
4
|
-
export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-
|
|
1
|
+
export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../handshake-3342bb94.js';
|
|
2
|
+
export { C as ClientTransport } from '../client-162c509c.js';
|
|
3
|
+
export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-1b695374.js';
|
|
4
|
+
export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-1a434848.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import '../types-3e5768ec.js';
|
|
7
7
|
import '@sinclair/typebox/value';
|
package/dist/transport/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientTransport
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-5S64PXTU.js";
|
|
4
4
|
import {
|
|
5
5
|
ServerTransport
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-7ETNUCOL.js";
|
|
7
7
|
import {
|
|
8
8
|
Connection,
|
|
9
9
|
ProtocolError,
|
|
10
10
|
Transport
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-5FDAIAQ5.js";
|
|
12
12
|
import "../chunk-TAH2GVTJ.js";
|
|
13
13
|
import {
|
|
14
14
|
SessionState
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-JSU2KACV.js";
|
|
16
16
|
import {
|
|
17
17
|
OpaqueTransportMessageSchema,
|
|
18
18
|
TransportMessageSchema
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-CCUYKR5C.js";
|
|
20
20
|
import "../chunk-4PVU7J25.js";
|
|
21
21
|
export {
|
|
22
22
|
ClientTransport,
|
|
@@ -44,6 +44,7 @@ __export(testHelpers_exports, {
|
|
|
44
44
|
numberOfConnections: () => numberOfConnections,
|
|
45
45
|
onWsServerReady: () => onWsServerReady,
|
|
46
46
|
payloadToTransportMessage: () => payloadToTransportMessage,
|
|
47
|
+
testingClientSessionOptions: () => testingClientSessionOptions,
|
|
47
48
|
testingSessionOptions: () => testingSessionOptions,
|
|
48
49
|
waitForMessage: () => waitForMessage
|
|
49
50
|
});
|
|
@@ -389,11 +390,20 @@ var ControlMessageHandshakeRequestSchema = import_typebox.Type.Object({
|
|
|
389
390
|
var HandshakeErrorRetriableResponseCodes = import_typebox.Type.Union([
|
|
390
391
|
import_typebox.Type.Literal("SESSION_STATE_MISMATCH")
|
|
391
392
|
]);
|
|
393
|
+
var HandshakeErrorCustomHandlerFatalResponseCodes = import_typebox.Type.Union([
|
|
394
|
+
// The custom validation handler rejected the handler because the client is unsupported.
|
|
395
|
+
import_typebox.Type.Literal("REJECTED_UNSUPPORTED_CLIENT"),
|
|
396
|
+
// The custom validation handler rejected the handshake.
|
|
397
|
+
import_typebox.Type.Literal("REJECTED_BY_CUSTOM_HANDLER")
|
|
398
|
+
]);
|
|
392
399
|
var HandshakeErrorFatalResponseCodes = import_typebox.Type.Union([
|
|
400
|
+
HandshakeErrorCustomHandlerFatalResponseCodes,
|
|
401
|
+
// The ciient sent a handshake that doesn't comply with the extended handshake metadata.
|
|
393
402
|
import_typebox.Type.Literal("MALFORMED_HANDSHAKE_META"),
|
|
403
|
+
// The ciient sent a handshake that doesn't comply with ControlMessageHandshakeRequestSchema.
|
|
394
404
|
import_typebox.Type.Literal("MALFORMED_HANDSHAKE"),
|
|
395
|
-
|
|
396
|
-
import_typebox.Type.Literal("
|
|
405
|
+
// The client's protocol version does not match the server's.
|
|
406
|
+
import_typebox.Type.Literal("PROTOCOL_VERSION_MISMATCH")
|
|
397
407
|
]);
|
|
398
408
|
var HandshakeErrorResponseCodes = import_typebox.Type.Union([
|
|
399
409
|
HandshakeErrorRetriableResponseCodes,
|
|
@@ -450,7 +460,7 @@ function Err(error) {
|
|
|
450
460
|
var import_api = require("@opentelemetry/api");
|
|
451
461
|
|
|
452
462
|
// package.json
|
|
453
|
-
var version = "0.
|
|
463
|
+
var version = "0.26.0";
|
|
454
464
|
|
|
455
465
|
// tracing/index.ts
|
|
456
466
|
function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
|
|
@@ -542,7 +552,7 @@ var defaultTransportOptions = {
|
|
|
542
552
|
codec: NaiveJsonCodec
|
|
543
553
|
};
|
|
544
554
|
var defaultConnectionRetryOptions = {
|
|
545
|
-
baseIntervalMs:
|
|
555
|
+
baseIntervalMs: 150,
|
|
546
556
|
maxJitterMs: 200,
|
|
547
557
|
maxBackoffMs: 32e3,
|
|
548
558
|
attemptBudgetCapacity: 5,
|
|
@@ -609,7 +619,7 @@ var CommonSession = class extends StateMachineState {
|
|
|
609
619
|
from;
|
|
610
620
|
options;
|
|
611
621
|
log;
|
|
612
|
-
constructor(from, options, log) {
|
|
622
|
+
constructor({ from, options, log }) {
|
|
613
623
|
super();
|
|
614
624
|
this.from = from;
|
|
615
625
|
this.options = options;
|
|
@@ -650,8 +660,9 @@ var IdentifiedSession = class extends CommonSession {
|
|
|
650
660
|
*/
|
|
651
661
|
ack;
|
|
652
662
|
sendBuffer;
|
|
653
|
-
constructor(
|
|
654
|
-
|
|
663
|
+
constructor(props) {
|
|
664
|
+
const { id, to, seq, ack, sendBuffer, telemetry, log } = props;
|
|
665
|
+
super(props);
|
|
655
666
|
this.id = id;
|
|
656
667
|
this.to = to;
|
|
657
668
|
this.seq = seq;
|
|
@@ -706,23 +717,23 @@ var SessionConnecting = class extends IdentifiedSession {
|
|
|
706
717
|
connPromise;
|
|
707
718
|
listeners;
|
|
708
719
|
connectionTimeout;
|
|
709
|
-
constructor(
|
|
710
|
-
super(
|
|
711
|
-
this.connPromise = connPromise;
|
|
712
|
-
this.listeners = listeners;
|
|
720
|
+
constructor(props) {
|
|
721
|
+
super(props);
|
|
722
|
+
this.connPromise = props.connPromise;
|
|
723
|
+
this.listeners = props.listeners;
|
|
713
724
|
this.connectionTimeout = setTimeout(() => {
|
|
714
|
-
listeners.onConnectionTimeout();
|
|
725
|
+
this.listeners.onConnectionTimeout();
|
|
715
726
|
}, this.options.connectionTimeoutMs);
|
|
716
|
-
connPromise.then(
|
|
727
|
+
this.connPromise.then(
|
|
717
728
|
(conn) => {
|
|
718
729
|
if (this._isConsumed)
|
|
719
730
|
return;
|
|
720
|
-
listeners.onConnectionEstablished(conn);
|
|
731
|
+
this.listeners.onConnectionEstablished(conn);
|
|
721
732
|
},
|
|
722
733
|
(err) => {
|
|
723
734
|
if (this._isConsumed)
|
|
724
735
|
return;
|
|
725
|
-
listeners.onConnectionFailed(err);
|
|
736
|
+
this.listeners.onConnectionFailed(err);
|
|
726
737
|
}
|
|
727
738
|
);
|
|
728
739
|
}
|
|
@@ -748,9 +759,9 @@ var SessionNoConnection = class extends IdentifiedSession {
|
|
|
748
759
|
state = "NoConnection" /* NoConnection */;
|
|
749
760
|
listeners;
|
|
750
761
|
gracePeriodTimeout;
|
|
751
|
-
constructor(
|
|
752
|
-
super(
|
|
753
|
-
this.listeners = listeners;
|
|
762
|
+
constructor(props) {
|
|
763
|
+
super(props);
|
|
764
|
+
this.listeners = props.listeners;
|
|
754
765
|
this.gracePeriodTimeout = setTimeout(() => {
|
|
755
766
|
this.listeners.onSessionGracePeriodElapsed();
|
|
756
767
|
}, this.options.sessionDisconnectGraceMs);
|
|
@@ -773,16 +784,16 @@ var SessionWaitingForHandshake = class extends CommonSession {
|
|
|
773
784
|
conn;
|
|
774
785
|
listeners;
|
|
775
786
|
handshakeTimeout;
|
|
776
|
-
constructor(
|
|
777
|
-
super(
|
|
778
|
-
this.conn = conn;
|
|
779
|
-
this.listeners = listeners;
|
|
787
|
+
constructor(props) {
|
|
788
|
+
super(props);
|
|
789
|
+
this.conn = props.conn;
|
|
790
|
+
this.listeners = props.listeners;
|
|
780
791
|
this.handshakeTimeout = setTimeout(() => {
|
|
781
|
-
listeners.onHandshakeTimeout();
|
|
792
|
+
this.listeners.onHandshakeTimeout();
|
|
782
793
|
}, this.options.handshakeTimeoutMs);
|
|
783
794
|
this.conn.addDataListener(this.onHandshakeData);
|
|
784
|
-
this.conn.addErrorListener(listeners.onConnectionErrored);
|
|
785
|
-
this.conn.addCloseListener(listeners.onConnectionClosed);
|
|
795
|
+
this.conn.addErrorListener(this.listeners.onConnectionErrored);
|
|
796
|
+
this.conn.addCloseListener(this.listeners.onConnectionClosed);
|
|
786
797
|
}
|
|
787
798
|
onHandshakeData = (msg) => {
|
|
788
799
|
const parsedMsg = this.parseMsg(msg);
|
|
@@ -819,16 +830,16 @@ var SessionHandshaking = class extends IdentifiedSession {
|
|
|
819
830
|
conn;
|
|
820
831
|
listeners;
|
|
821
832
|
handshakeTimeout;
|
|
822
|
-
constructor(
|
|
823
|
-
super(
|
|
824
|
-
this.conn = conn;
|
|
825
|
-
this.listeners = listeners;
|
|
833
|
+
constructor(props) {
|
|
834
|
+
super(props);
|
|
835
|
+
this.conn = props.conn;
|
|
836
|
+
this.listeners = props.listeners;
|
|
826
837
|
this.handshakeTimeout = setTimeout(() => {
|
|
827
|
-
listeners.onHandshakeTimeout();
|
|
838
|
+
this.listeners.onHandshakeTimeout();
|
|
828
839
|
}, this.options.handshakeTimeoutMs);
|
|
829
840
|
this.conn.addDataListener(this.onHandshakeData);
|
|
830
|
-
this.conn.addErrorListener(listeners.onConnectionErrored);
|
|
831
|
-
this.conn.addCloseListener(listeners.onConnectionClosed);
|
|
841
|
+
this.conn.addErrorListener(this.listeners.onConnectionErrored);
|
|
842
|
+
this.conn.addCloseListener(this.listeners.onConnectionClosed);
|
|
832
843
|
}
|
|
833
844
|
onHandshakeData = (msg) => {
|
|
834
845
|
const parsedMsg = this.parseMsg(msg);
|
|
@@ -860,16 +871,13 @@ var SessionConnected = class extends IdentifiedSession {
|
|
|
860
871
|
state = "Connected" /* Connected */;
|
|
861
872
|
conn;
|
|
862
873
|
listeners;
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
get isActivelyHeartbeating() {
|
|
867
|
-
return this.activeHeartbeatHandle !== void 0;
|
|
868
|
-
}
|
|
874
|
+
heartbeatHandle;
|
|
875
|
+
heartbeatMisses = 0;
|
|
876
|
+
isActivelyHeartbeating;
|
|
869
877
|
updateBookkeeping(ack, seq) {
|
|
870
878
|
this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq >= ack);
|
|
871
879
|
this.ack = seq + 1;
|
|
872
|
-
this.
|
|
880
|
+
this.heartbeatMisses = 0;
|
|
873
881
|
}
|
|
874
882
|
send(msg) {
|
|
875
883
|
const constructedMsg = this.constructMsg(msg);
|
|
@@ -877,13 +885,13 @@ var SessionConnected = class extends IdentifiedSession {
|
|
|
877
885
|
this.conn.send(this.options.codec.toBuffer(constructedMsg));
|
|
878
886
|
return constructedMsg.id;
|
|
879
887
|
}
|
|
880
|
-
constructor(
|
|
881
|
-
super(
|
|
882
|
-
this.conn = conn;
|
|
883
|
-
this.listeners = listeners;
|
|
888
|
+
constructor(props) {
|
|
889
|
+
super(props);
|
|
890
|
+
this.conn = props.conn;
|
|
891
|
+
this.listeners = props.listeners;
|
|
884
892
|
this.conn.addDataListener(this.onMessageData);
|
|
885
|
-
this.conn.addCloseListener(listeners.onConnectionClosed);
|
|
886
|
-
this.conn.addErrorListener(listeners.onConnectionErrored);
|
|
893
|
+
this.conn.addCloseListener(this.listeners.onConnectionClosed);
|
|
894
|
+
this.conn.addErrorListener(this.listeners.onConnectionErrored);
|
|
887
895
|
if (this.sendBuffer.length > 0) {
|
|
888
896
|
this.log?.debug(
|
|
889
897
|
`sending ${this.sendBuffer.length} buffered messages`,
|
|
@@ -891,12 +899,11 @@ var SessionConnected = class extends IdentifiedSession {
|
|
|
891
899
|
);
|
|
892
900
|
}
|
|
893
901
|
for (const msg of this.sendBuffer) {
|
|
894
|
-
conn.send(this.options.codec.toBuffer(msg));
|
|
902
|
+
this.conn.send(this.options.codec.toBuffer(msg));
|
|
895
903
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
const misses = this.activeHeartbeatMisses;
|
|
904
|
+
this.isActivelyHeartbeating = false;
|
|
905
|
+
this.heartbeatHandle = setInterval(() => {
|
|
906
|
+
const misses = this.heartbeatMisses;
|
|
900
907
|
const missDuration = misses * this.options.heartbeatIntervalMs;
|
|
901
908
|
if (misses >= this.options.heartbeatsUntilDead) {
|
|
902
909
|
this.log?.info(
|
|
@@ -905,29 +912,18 @@ var SessionConnected = class extends IdentifiedSession {
|
|
|
905
912
|
);
|
|
906
913
|
this.telemetry.span.addEvent("closing connection due to inactivity");
|
|
907
914
|
this.conn.close();
|
|
908
|
-
clearInterval(this.
|
|
909
|
-
this.
|
|
915
|
+
clearInterval(this.heartbeatHandle);
|
|
916
|
+
this.heartbeatHandle = void 0;
|
|
910
917
|
return;
|
|
911
918
|
}
|
|
912
|
-
this.
|
|
913
|
-
|
|
919
|
+
if (this.isActivelyHeartbeating) {
|
|
920
|
+
this.sendHeartbeat();
|
|
921
|
+
}
|
|
922
|
+
this.heartbeatMisses++;
|
|
914
923
|
}, this.options.heartbeatIntervalMs);
|
|
915
924
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
if (this.passiveHeartbeatHandle) {
|
|
919
|
-
clearTimeout(this.passiveHeartbeatHandle);
|
|
920
|
-
this.passiveHeartbeatHandle = void 0;
|
|
921
|
-
}
|
|
922
|
-
this.passiveHeartbeatHandle = setTimeout(() => {
|
|
923
|
-
this.log?.info(
|
|
924
|
-
`closing connection to ${this.to} due to not receiving a heartbeat in the last ${duration}ms`,
|
|
925
|
-
this.loggingMetadata
|
|
926
|
-
);
|
|
927
|
-
this.telemetry.span.addEvent("closing connection due to inactivity");
|
|
928
|
-
this.conn.close();
|
|
929
|
-
this.passiveHeartbeatHandle = void 0;
|
|
930
|
-
}, duration);
|
|
925
|
+
startActiveHeartbeat() {
|
|
926
|
+
this.isActivelyHeartbeating = true;
|
|
931
927
|
}
|
|
932
928
|
sendHeartbeat() {
|
|
933
929
|
this.log?.debug("sending heartbeat", this.loggingMetadata);
|
|
@@ -982,7 +978,6 @@ var SessionConnected = class extends IdentifiedSession {
|
|
|
982
978
|
});
|
|
983
979
|
if (!this.isActivelyHeartbeating) {
|
|
984
980
|
this.sendHeartbeat();
|
|
985
|
-
this.waitForNextHeartbeat();
|
|
986
981
|
}
|
|
987
982
|
};
|
|
988
983
|
_handleStateExit() {
|
|
@@ -990,10 +985,8 @@ var SessionConnected = class extends IdentifiedSession {
|
|
|
990
985
|
this.conn.removeDataListener(this.onMessageData);
|
|
991
986
|
this.conn.removeCloseListener(this.listeners.onConnectionClosed);
|
|
992
987
|
this.conn.removeErrorListener(this.listeners.onConnectionErrored);
|
|
993
|
-
clearInterval(this.
|
|
994
|
-
|
|
995
|
-
this.activeHeartbeatHandle = void 0;
|
|
996
|
-
this.passiveHeartbeatHandle = void 0;
|
|
988
|
+
clearInterval(this.heartbeatHandle);
|
|
989
|
+
this.heartbeatHandle = void 0;
|
|
997
990
|
}
|
|
998
991
|
_handleClose() {
|
|
999
992
|
super._handleClose();
|
|
@@ -1001,52 +994,76 @@ var SessionConnected = class extends IdentifiedSession {
|
|
|
1001
994
|
}
|
|
1002
995
|
};
|
|
1003
996
|
|
|
997
|
+
// transport/sessionStateMachine/SessionBackingOff.ts
|
|
998
|
+
var SessionBackingOff = class extends IdentifiedSession {
|
|
999
|
+
state = "BackingOff" /* BackingOff */;
|
|
1000
|
+
listeners;
|
|
1001
|
+
backoffTimeout;
|
|
1002
|
+
constructor(props) {
|
|
1003
|
+
super(props);
|
|
1004
|
+
this.listeners = props.listeners;
|
|
1005
|
+
this.backoffTimeout = setTimeout(() => {
|
|
1006
|
+
this.listeners.onBackoffFinished();
|
|
1007
|
+
}, props.backoffMs);
|
|
1008
|
+
}
|
|
1009
|
+
_handleClose() {
|
|
1010
|
+
super._handleClose();
|
|
1011
|
+
}
|
|
1012
|
+
_handleStateExit() {
|
|
1013
|
+
super._handleStateExit();
|
|
1014
|
+
if (this.backoffTimeout) {
|
|
1015
|
+
clearTimeout(this.backoffTimeout);
|
|
1016
|
+
this.backoffTimeout = void 0;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1004
1021
|
// transport/sessionStateMachine/transitions.ts
|
|
1005
1022
|
function inheritSharedSession(session) {
|
|
1006
|
-
return
|
|
1007
|
-
session.id,
|
|
1008
|
-
session.from,
|
|
1009
|
-
session.to,
|
|
1010
|
-
session.seq,
|
|
1011
|
-
session.ack,
|
|
1012
|
-
session.sendBuffer,
|
|
1013
|
-
session.telemetry,
|
|
1014
|
-
session.options,
|
|
1015
|
-
session.log
|
|
1016
|
-
|
|
1023
|
+
return {
|
|
1024
|
+
id: session.id,
|
|
1025
|
+
from: session.from,
|
|
1026
|
+
to: session.to,
|
|
1027
|
+
seq: session.seq,
|
|
1028
|
+
ack: session.ack,
|
|
1029
|
+
sendBuffer: session.sendBuffer,
|
|
1030
|
+
telemetry: session.telemetry,
|
|
1031
|
+
options: session.options,
|
|
1032
|
+
log: session.log
|
|
1033
|
+
};
|
|
1017
1034
|
}
|
|
1018
1035
|
var SessionStateGraph = {
|
|
1019
1036
|
entrypoints: {
|
|
1020
|
-
NoConnection(to, from, listeners, options, log) {
|
|
1037
|
+
NoConnection: (to, from, listeners, options, log) => {
|
|
1021
1038
|
const id = `session-${generateId()}`;
|
|
1022
1039
|
const telemetry = createSessionTelemetryInfo(id, to, from);
|
|
1023
1040
|
const sendBuffer = [];
|
|
1024
|
-
const session = new SessionNoConnection(
|
|
1041
|
+
const session = new SessionNoConnection({
|
|
1025
1042
|
listeners,
|
|
1026
1043
|
id,
|
|
1027
1044
|
from,
|
|
1028
1045
|
to,
|
|
1029
|
-
0,
|
|
1030
|
-
0,
|
|
1046
|
+
seq: 0,
|
|
1047
|
+
ack: 0,
|
|
1031
1048
|
sendBuffer,
|
|
1032
1049
|
telemetry,
|
|
1033
1050
|
options,
|
|
1034
1051
|
log
|
|
1035
|
-
);
|
|
1052
|
+
});
|
|
1036
1053
|
session.log?.info(`session ${session.id} created in NoConnection state`, {
|
|
1037
1054
|
...session.loggingMetadata,
|
|
1038
1055
|
tags: ["state-transition"]
|
|
1039
1056
|
});
|
|
1040
1057
|
return session;
|
|
1041
1058
|
},
|
|
1042
|
-
WaitingForHandshake(from, conn, listeners, options, log) {
|
|
1043
|
-
const session = new SessionWaitingForHandshake(
|
|
1059
|
+
WaitingForHandshake: (from, conn, listeners, options, log) => {
|
|
1060
|
+
const session = new SessionWaitingForHandshake({
|
|
1044
1061
|
conn,
|
|
1045
1062
|
listeners,
|
|
1046
1063
|
from,
|
|
1047
1064
|
options,
|
|
1048
1065
|
log
|
|
1049
|
-
);
|
|
1066
|
+
});
|
|
1050
1067
|
session.log?.info(`session created in WaitingForHandshake state`, {
|
|
1051
1068
|
...session.loggingMetadata,
|
|
1052
1069
|
tags: ["state-transition"]
|
|
@@ -1058,16 +1075,33 @@ var SessionStateGraph = {
|
|
|
1058
1075
|
// After a session is transitioned, any usage of the old session will throw.
|
|
1059
1076
|
transition: {
|
|
1060
1077
|
// happy path transitions
|
|
1061
|
-
|
|
1078
|
+
NoConnectionToBackingOff: (oldSession, backoffMs, listeners) => {
|
|
1062
1079
|
const carriedState = inheritSharedSession(oldSession);
|
|
1063
1080
|
oldSession._handleStateExit();
|
|
1064
|
-
const session = new
|
|
1065
|
-
|
|
1081
|
+
const session = new SessionBackingOff({
|
|
1082
|
+
backoffMs,
|
|
1066
1083
|
listeners,
|
|
1067
1084
|
...carriedState
|
|
1085
|
+
});
|
|
1086
|
+
session.log?.info(
|
|
1087
|
+
`session ${session.id} transition from NoConnection to BackingOff`,
|
|
1088
|
+
{
|
|
1089
|
+
...session.loggingMetadata,
|
|
1090
|
+
tags: ["state-transition"]
|
|
1091
|
+
}
|
|
1068
1092
|
);
|
|
1093
|
+
return session;
|
|
1094
|
+
},
|
|
1095
|
+
BackingOffToConnecting: (oldSession, connPromise, listeners) => {
|
|
1096
|
+
const carriedState = inheritSharedSession(oldSession);
|
|
1097
|
+
oldSession._handleStateExit();
|
|
1098
|
+
const session = new SessionConnecting({
|
|
1099
|
+
connPromise,
|
|
1100
|
+
listeners,
|
|
1101
|
+
...carriedState
|
|
1102
|
+
});
|
|
1069
1103
|
session.log?.info(
|
|
1070
|
-
`session ${session.id} transition from
|
|
1104
|
+
`session ${session.id} transition from BackingOff to Connecting`,
|
|
1071
1105
|
{
|
|
1072
1106
|
...session.loggingMetadata,
|
|
1073
1107
|
tags: ["state-transition"]
|
|
@@ -1075,10 +1109,14 @@ var SessionStateGraph = {
|
|
|
1075
1109
|
);
|
|
1076
1110
|
return session;
|
|
1077
1111
|
},
|
|
1078
|
-
ConnectingToHandshaking(oldSession, conn, listeners) {
|
|
1112
|
+
ConnectingToHandshaking: (oldSession, conn, listeners) => {
|
|
1079
1113
|
const carriedState = inheritSharedSession(oldSession);
|
|
1080
1114
|
oldSession._handleStateExit();
|
|
1081
|
-
const session = new SessionHandshaking(
|
|
1115
|
+
const session = new SessionHandshaking({
|
|
1116
|
+
conn,
|
|
1117
|
+
listeners,
|
|
1118
|
+
...carriedState
|
|
1119
|
+
});
|
|
1082
1120
|
session.log?.info(
|
|
1083
1121
|
`session ${session.id} transition from Connecting to Handshaking`,
|
|
1084
1122
|
{
|
|
@@ -1088,11 +1126,15 @@ var SessionStateGraph = {
|
|
|
1088
1126
|
);
|
|
1089
1127
|
return session;
|
|
1090
1128
|
},
|
|
1091
|
-
HandshakingToConnected(oldSession, listeners) {
|
|
1129
|
+
HandshakingToConnected: (oldSession, listeners) => {
|
|
1092
1130
|
const carriedState = inheritSharedSession(oldSession);
|
|
1093
1131
|
const conn = oldSession.conn;
|
|
1094
1132
|
oldSession._handleStateExit();
|
|
1095
|
-
const session = new SessionConnected(
|
|
1133
|
+
const session = new SessionConnected({
|
|
1134
|
+
conn,
|
|
1135
|
+
listeners,
|
|
1136
|
+
...carriedState
|
|
1137
|
+
});
|
|
1096
1138
|
session.log?.info(
|
|
1097
1139
|
`session ${session.id} transition from Handshaking to Connected`,
|
|
1098
1140
|
{
|
|
@@ -1102,7 +1144,7 @@ var SessionStateGraph = {
|
|
|
1102
1144
|
);
|
|
1103
1145
|
return session;
|
|
1104
1146
|
},
|
|
1105
|
-
WaitingForHandshakeToConnected(pendingSession, oldSession, sessionId, to, propagationCtx, listeners) {
|
|
1147
|
+
WaitingForHandshakeToConnected: (pendingSession, oldSession, sessionId, to, propagationCtx, listeners) => {
|
|
1106
1148
|
const conn = pendingSession.conn;
|
|
1107
1149
|
const { from, options } = pendingSession;
|
|
1108
1150
|
const carriedState = oldSession ? (
|
|
@@ -1110,21 +1152,30 @@ var SessionStateGraph = {
|
|
|
1110
1152
|
inheritSharedSession(oldSession)
|
|
1111
1153
|
) : (
|
|
1112
1154
|
// old session does not exist, create new state
|
|
1113
|
-
|
|
1114
|
-
sessionId,
|
|
1155
|
+
{
|
|
1156
|
+
id: sessionId,
|
|
1115
1157
|
from,
|
|
1116
1158
|
to,
|
|
1117
|
-
0,
|
|
1118
|
-
0,
|
|
1119
|
-
[],
|
|
1120
|
-
createSessionTelemetryInfo(
|
|
1159
|
+
seq: 0,
|
|
1160
|
+
ack: 0,
|
|
1161
|
+
sendBuffer: [],
|
|
1162
|
+
telemetry: createSessionTelemetryInfo(
|
|
1163
|
+
sessionId,
|
|
1164
|
+
to,
|
|
1165
|
+
from,
|
|
1166
|
+
propagationCtx
|
|
1167
|
+
),
|
|
1121
1168
|
options,
|
|
1122
|
-
pendingSession.log
|
|
1123
|
-
|
|
1169
|
+
log: pendingSession.log
|
|
1170
|
+
}
|
|
1124
1171
|
);
|
|
1125
1172
|
pendingSession._handleStateExit();
|
|
1126
1173
|
oldSession?._handleStateExit();
|
|
1127
|
-
const session = new SessionConnected(
|
|
1174
|
+
const session = new SessionConnected({
|
|
1175
|
+
conn,
|
|
1176
|
+
listeners,
|
|
1177
|
+
...carriedState
|
|
1178
|
+
});
|
|
1128
1179
|
session.log?.info(
|
|
1129
1180
|
`session ${session.id} transition from WaitingForHandshake to Connected`,
|
|
1130
1181
|
{
|
|
@@ -1135,11 +1186,24 @@ var SessionStateGraph = {
|
|
|
1135
1186
|
return session;
|
|
1136
1187
|
},
|
|
1137
1188
|
// disconnect paths
|
|
1138
|
-
|
|
1189
|
+
BackingOffToNoConnection: (oldSession, listeners) => {
|
|
1190
|
+
const carriedState = inheritSharedSession(oldSession);
|
|
1191
|
+
oldSession._handleStateExit();
|
|
1192
|
+
const session = new SessionNoConnection({ listeners, ...carriedState });
|
|
1193
|
+
session.log?.info(
|
|
1194
|
+
`session ${session.id} transition from BackingOff to NoConnection`,
|
|
1195
|
+
{
|
|
1196
|
+
...session.loggingMetadata,
|
|
1197
|
+
tags: ["state-transition"]
|
|
1198
|
+
}
|
|
1199
|
+
);
|
|
1200
|
+
return session;
|
|
1201
|
+
},
|
|
1202
|
+
ConnectingToNoConnection: (oldSession, listeners) => {
|
|
1139
1203
|
const carriedState = inheritSharedSession(oldSession);
|
|
1140
1204
|
oldSession.bestEffortClose();
|
|
1141
1205
|
oldSession._handleStateExit();
|
|
1142
|
-
const session = new SessionNoConnection(listeners, ...carriedState);
|
|
1206
|
+
const session = new SessionNoConnection({ listeners, ...carriedState });
|
|
1143
1207
|
session.log?.info(
|
|
1144
1208
|
`session ${session.id} transition from Connecting to NoConnection`,
|
|
1145
1209
|
{
|
|
@@ -1149,11 +1213,11 @@ var SessionStateGraph = {
|
|
|
1149
1213
|
);
|
|
1150
1214
|
return session;
|
|
1151
1215
|
},
|
|
1152
|
-
HandshakingToNoConnection(oldSession, listeners) {
|
|
1216
|
+
HandshakingToNoConnection: (oldSession, listeners) => {
|
|
1153
1217
|
const carriedState = inheritSharedSession(oldSession);
|
|
1154
1218
|
oldSession.conn.close();
|
|
1155
1219
|
oldSession._handleStateExit();
|
|
1156
|
-
const session = new SessionNoConnection(listeners, ...carriedState);
|
|
1220
|
+
const session = new SessionNoConnection({ listeners, ...carriedState });
|
|
1157
1221
|
session.log?.info(
|
|
1158
1222
|
`session ${session.id} transition from Handshaking to NoConnection`,
|
|
1159
1223
|
{
|
|
@@ -1163,11 +1227,11 @@ var SessionStateGraph = {
|
|
|
1163
1227
|
);
|
|
1164
1228
|
return session;
|
|
1165
1229
|
},
|
|
1166
|
-
ConnectedToNoConnection(oldSession, listeners) {
|
|
1230
|
+
ConnectedToNoConnection: (oldSession, listeners) => {
|
|
1167
1231
|
const carriedState = inheritSharedSession(oldSession);
|
|
1168
1232
|
oldSession.conn.close();
|
|
1169
1233
|
oldSession._handleStateExit();
|
|
1170
|
-
const session = new SessionNoConnection(listeners, ...carriedState);
|
|
1234
|
+
const session = new SessionNoConnection({ listeners, ...carriedState });
|
|
1171
1235
|
session.log?.info(
|
|
1172
1236
|
`session ${session.id} transition from Connected to NoConnection`,
|
|
1173
1237
|
{
|
|
@@ -1179,6 +1243,31 @@ var SessionStateGraph = {
|
|
|
1179
1243
|
}
|
|
1180
1244
|
}
|
|
1181
1245
|
};
|
|
1246
|
+
var transitions = SessionStateGraph.transition;
|
|
1247
|
+
var ClientSessionStateGraph = {
|
|
1248
|
+
entrypoint: SessionStateGraph.entrypoints.NoConnection,
|
|
1249
|
+
transition: {
|
|
1250
|
+
// happy paths
|
|
1251
|
+
NoConnectionToBackingOff: transitions.NoConnectionToBackingOff,
|
|
1252
|
+
BackingOffToConnecting: transitions.BackingOffToConnecting,
|
|
1253
|
+
ConnectingToHandshaking: transitions.ConnectingToHandshaking,
|
|
1254
|
+
HandshakingToConnected: transitions.HandshakingToConnected,
|
|
1255
|
+
// disconnect paths
|
|
1256
|
+
BackingOffToNoConnection: transitions.BackingOffToNoConnection,
|
|
1257
|
+
ConnectingToNoConnection: transitions.ConnectingToNoConnection,
|
|
1258
|
+
HandshakingToNoConnection: transitions.HandshakingToNoConnection,
|
|
1259
|
+
ConnectedToNoConnection: transitions.ConnectedToNoConnection
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
var ServerSessionStateGraph = {
|
|
1263
|
+
entrypoint: SessionStateGraph.entrypoints.WaitingForHandshake,
|
|
1264
|
+
transition: {
|
|
1265
|
+
// happy paths
|
|
1266
|
+
WaitingForHandshakeToConnected: transitions.WaitingForHandshakeToConnected,
|
|
1267
|
+
// disconnect paths
|
|
1268
|
+
ConnectedToNoConnection: transitions.ConnectedToNoConnection
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1182
1271
|
|
|
1183
1272
|
// util/testHelpers.ts
|
|
1184
1273
|
function createLocalWebSocketClient(port) {
|
|
@@ -1239,6 +1328,7 @@ function catchProcError(err) {
|
|
|
1239
1328
|
return Err({ code: UNCAUGHT_ERROR, message: errorMsg });
|
|
1240
1329
|
}
|
|
1241
1330
|
var testingSessionOptions = defaultTransportOptions;
|
|
1331
|
+
var testingClientSessionOptions = defaultClientTransportOptions;
|
|
1242
1332
|
function dummySession() {
|
|
1243
1333
|
return SessionStateGraph.entrypoints.NoConnection(
|
|
1244
1334
|
"client",
|
|
@@ -1338,6 +1428,7 @@ function closeAllConnections(transport) {
|
|
|
1338
1428
|
numberOfConnections,
|
|
1339
1429
|
onWsServerReady,
|
|
1340
1430
|
payloadToTransportMessage,
|
|
1431
|
+
testingClientSessionOptions,
|
|
1341
1432
|
testingSessionOptions,
|
|
1342
1433
|
waitForMessage
|
|
1343
1434
|
});
|