@replit/river 0.16.2 → 0.17.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-SKH3JYHN.js → chunk-7IQO434V.js} +1 -1
- package/dist/{chunk-CJGD7CNG.js → chunk-LQMPJI3S.js} +86 -87
- package/dist/{chunk-GFRAOY75.js → chunk-VH3NGOXQ.js} +8 -17
- package/dist/{chunk-HZWCU4ZI.js → chunk-VJRLJ3JU.js} +1 -1
- package/dist/{chunk-HKVP6XEL.js → chunk-Y6DLSCKU.js} +1 -1
- package/dist/{connection-2db95d74.d.ts → connection-0767dc6b.d.ts} +1 -1
- package/dist/{connection-c97da681.d.ts → connection-f31edbcd.d.ts} +1 -1
- package/dist/{index-c9e9977f.d.ts → index-8df0bdfb.d.ts} +14 -21
- package/dist/{procedures-d295c1a5.d.ts → procedures-b5ddb54d.d.ts} +1 -1
- package/dist/router/index.cjs +2 -2
- package/dist/router/index.d.cts +3 -3
- package/dist/router/index.d.ts +3 -3
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/uds/client.cjs +65 -59
- 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 +77 -90
- 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 +65 -59
- 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 +3 -3
- package/dist/transport/impls/ws/server.cjs +77 -90
- 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 +92 -105
- 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/util/testHelpers.cjs +45 -18
- package/dist/util/testHelpers.d.cts +4 -9
- package/dist/util/testHelpers.d.ts +4 -9
- package/dist/util/testHelpers.js +8 -14
- package/package.json +1 -1
|
@@ -48,18 +48,18 @@ var ControlMessageAckSchema = import_typebox.Type.Object({
|
|
|
48
48
|
var ControlMessageCloseSchema = import_typebox.Type.Object({
|
|
49
49
|
type: import_typebox.Type.Literal("CLOSE")
|
|
50
50
|
});
|
|
51
|
-
var PROTOCOL_VERSION = "v1";
|
|
51
|
+
var PROTOCOL_VERSION = "v1.1";
|
|
52
52
|
var ControlMessageHandshakeRequestSchema = import_typebox.Type.Object({
|
|
53
53
|
type: import_typebox.Type.Literal("HANDSHAKE_REQ"),
|
|
54
54
|
protocolVersion: import_typebox.Type.String(),
|
|
55
|
-
|
|
55
|
+
sessionId: import_typebox.Type.String()
|
|
56
56
|
});
|
|
57
57
|
var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
|
|
58
58
|
type: import_typebox.Type.Literal("HANDSHAKE_RESP"),
|
|
59
59
|
status: import_typebox.Type.Union([
|
|
60
60
|
import_typebox.Type.Object({
|
|
61
61
|
ok: import_typebox.Type.Literal(true),
|
|
62
|
-
|
|
62
|
+
sessionId: import_typebox.Type.String()
|
|
63
63
|
}),
|
|
64
64
|
import_typebox.Type.Object({
|
|
65
65
|
ok: import_typebox.Type.Literal(false),
|
|
@@ -76,7 +76,7 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
|
|
|
76
76
|
var OpaqueTransportMessageSchema = TransportMessageSchema(
|
|
77
77
|
import_typebox.Type.Unknown()
|
|
78
78
|
);
|
|
79
|
-
function handshakeRequestMessage(from, to,
|
|
79
|
+
function handshakeRequestMessage(from, to, sessionId) {
|
|
80
80
|
return {
|
|
81
81
|
id: (0, import_nanoid.nanoid)(),
|
|
82
82
|
from,
|
|
@@ -88,7 +88,7 @@ function handshakeRequestMessage(from, to, instanceId) {
|
|
|
88
88
|
payload: {
|
|
89
89
|
type: "HANDSHAKE_REQ",
|
|
90
90
|
protocolVersion: PROTOCOL_VERSION,
|
|
91
|
-
|
|
91
|
+
sessionId
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
}
|
|
@@ -159,7 +159,12 @@ var Session = class {
|
|
|
159
159
|
/**
|
|
160
160
|
* The unique ID of this session.
|
|
161
161
|
*/
|
|
162
|
-
|
|
162
|
+
id;
|
|
163
|
+
/**
|
|
164
|
+
* What the other side advertised as their session ID
|
|
165
|
+
* for this session.
|
|
166
|
+
*/
|
|
167
|
+
advertisedSessionId;
|
|
163
168
|
/**
|
|
164
169
|
* Number of messages we've sent along this session (excluding handshake and acks)
|
|
165
170
|
*/
|
|
@@ -181,11 +186,11 @@ var Session = class {
|
|
|
181
186
|
* The interval for sending heartbeats.
|
|
182
187
|
*/
|
|
183
188
|
heartbeat;
|
|
184
|
-
constructor(
|
|
189
|
+
constructor(conn, from, to, options) {
|
|
190
|
+
this.id = `session-${nanoid2(12)}`;
|
|
185
191
|
this.options = options;
|
|
186
|
-
this.debugId = `sess-${unsafeId()}`;
|
|
187
192
|
this.from = from;
|
|
188
|
-
this.to =
|
|
193
|
+
this.to = to;
|
|
189
194
|
this.connection = conn;
|
|
190
195
|
this.codec = options.codec;
|
|
191
196
|
this.heartbeatMisses = 0;
|
|
@@ -225,7 +230,7 @@ var Session = class {
|
|
|
225
230
|
log?.info(
|
|
226
231
|
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
227
232
|
);
|
|
228
|
-
this.closeStaleConnection(
|
|
233
|
+
this.closeStaleConnection();
|
|
229
234
|
}
|
|
230
235
|
return;
|
|
231
236
|
}
|
|
@@ -256,33 +261,37 @@ var Session = class {
|
|
|
256
261
|
log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
|
|
257
262
|
const ok = this.connection.send(this.codec.toBuffer(msg));
|
|
258
263
|
if (!ok) {
|
|
259
|
-
const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.
|
|
264
|
+
const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.id}) (if you hit this code path something is seriously wrong)`;
|
|
260
265
|
log?.error(msg2);
|
|
261
266
|
throw new Error(msg2);
|
|
262
267
|
}
|
|
263
268
|
}
|
|
264
269
|
}
|
|
265
270
|
updateBookkeeping(ack, seq) {
|
|
271
|
+
if (seq + 1 < this.ack) {
|
|
272
|
+
log?.error(`${this.from} -- received stale seq ${seq} + 1 < ${this.ack}`);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
266
275
|
this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
|
|
267
276
|
this.ack = seq + 1;
|
|
268
277
|
}
|
|
269
278
|
closeStaleConnection(conn) {
|
|
270
|
-
if (
|
|
279
|
+
if (this.connection === void 0 || this.connection === conn)
|
|
271
280
|
return;
|
|
272
281
|
log?.info(
|
|
273
|
-
`${this.from} -- closing old inner connection (id: ${this.connection.debugId}) from session (id: ${this.
|
|
282
|
+
`${this.from} -- closing old inner connection (id: ${this.connection.debugId}) from session (id: ${this.id}) to ${this.to}`
|
|
274
283
|
);
|
|
275
284
|
this.connection.close();
|
|
276
285
|
this.connection = void 0;
|
|
277
286
|
}
|
|
278
287
|
replaceWithNewConnection(newConn) {
|
|
279
|
-
this.closeStaleConnection(
|
|
288
|
+
this.closeStaleConnection(newConn);
|
|
280
289
|
this.cancelGrace();
|
|
281
290
|
this.connection = newConn;
|
|
282
291
|
}
|
|
283
292
|
beginGrace(cb) {
|
|
284
293
|
log?.info(
|
|
285
|
-
`${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.
|
|
294
|
+
`${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.id}) to ${this.to} is closed`
|
|
286
295
|
);
|
|
287
296
|
this.disconnectionGrace = setTimeout(() => {
|
|
288
297
|
this.close();
|
|
@@ -293,11 +302,12 @@ var Session = class {
|
|
|
293
302
|
cancelGrace() {
|
|
294
303
|
this.heartbeatMisses = 0;
|
|
295
304
|
clearTimeout(this.disconnectionGrace);
|
|
305
|
+
this.disconnectionGrace = void 0;
|
|
296
306
|
}
|
|
297
307
|
// closed when we want to discard the whole session
|
|
298
308
|
// (i.e. shutdown or session disconnect)
|
|
299
309
|
close() {
|
|
300
|
-
this.closeStaleConnection(
|
|
310
|
+
this.closeStaleConnection();
|
|
301
311
|
this.cancelGrace();
|
|
302
312
|
this.resetBufferedMessages();
|
|
303
313
|
clearInterval(this.heartbeat);
|
|
@@ -326,9 +336,6 @@ var Session = class {
|
|
|
326
336
|
}
|
|
327
337
|
};
|
|
328
338
|
|
|
329
|
-
// transport/transport.ts
|
|
330
|
-
var import_nanoid3 = require("nanoid");
|
|
331
|
-
|
|
332
339
|
// util/stringify.ts
|
|
333
340
|
function coerceErrorString(err) {
|
|
334
341
|
if (err instanceof Error) {
|
|
@@ -479,13 +486,6 @@ var defaultClientTransportOptions = {
|
|
|
479
486
|
...defaultConnectionRetryOptions
|
|
480
487
|
};
|
|
481
488
|
var Transport = class {
|
|
482
|
-
/**
|
|
483
|
-
* Unique per instance of the transport.
|
|
484
|
-
* This allows us to distinguish reconnects to different
|
|
485
|
-
* transports.
|
|
486
|
-
*/
|
|
487
|
-
instanceId = (0, import_nanoid3.nanoid)();
|
|
488
|
-
connectedInstanceIds = /* @__PURE__ */ new Map();
|
|
489
489
|
/**
|
|
490
490
|
* A flag indicating whether the transport has been destroyed.
|
|
491
491
|
* A destroyed transport will not attempt to reconnect and cannot be used again.
|
|
@@ -538,41 +538,41 @@ var Transport = class {
|
|
|
538
538
|
* and we know the identity of the connected client.
|
|
539
539
|
* @param conn The connection object.
|
|
540
540
|
*/
|
|
541
|
-
onConnect(conn, connectedTo,
|
|
541
|
+
onConnect(conn, connectedTo, advertisedSessionId) {
|
|
542
542
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
543
543
|
status: "connect",
|
|
544
544
|
conn
|
|
545
545
|
});
|
|
546
546
|
let oldSession = this.sessions.get(connectedTo);
|
|
547
|
-
|
|
548
|
-
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
547
|
+
if (oldSession?.advertisedSessionId && oldSession.advertisedSessionId !== advertisedSessionId) {
|
|
549
548
|
log?.warn(
|
|
550
|
-
`${this.clientId} -- connection from ${connectedTo} is a different
|
|
549
|
+
`${this.clientId} -- connection from ${connectedTo} is a different session (id: ${advertisedSessionId}, last connected to: ${oldSession.advertisedSessionId}), starting a new session`
|
|
551
550
|
);
|
|
552
551
|
oldSession.close();
|
|
553
552
|
this.deleteSession(oldSession);
|
|
554
553
|
oldSession = void 0;
|
|
555
554
|
}
|
|
556
|
-
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
557
555
|
if (oldSession === void 0) {
|
|
558
556
|
const newSession = this.createSession(connectedTo, conn);
|
|
557
|
+
newSession.advertisedSessionId = advertisedSessionId;
|
|
559
558
|
log?.info(
|
|
560
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.
|
|
559
|
+
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.id}) to ${connectedTo}`
|
|
561
560
|
);
|
|
562
561
|
return newSession;
|
|
563
562
|
}
|
|
564
563
|
log?.info(
|
|
565
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.
|
|
564
|
+
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.id}) to ${connectedTo}`
|
|
566
565
|
);
|
|
567
566
|
oldSession.replaceWithNewConnection(conn);
|
|
568
567
|
oldSession.sendBufferedMessages();
|
|
568
|
+
oldSession.advertisedSessionId = advertisedSessionId;
|
|
569
569
|
return oldSession;
|
|
570
570
|
}
|
|
571
|
-
createSession(
|
|
571
|
+
createSession(to, conn) {
|
|
572
572
|
const session = new Session(
|
|
573
|
-
this.clientId,
|
|
574
|
-
connectedTo,
|
|
575
573
|
conn,
|
|
574
|
+
this.clientId,
|
|
575
|
+
to,
|
|
576
576
|
this.options
|
|
577
577
|
);
|
|
578
578
|
this.sessions.set(session.to, session);
|
|
@@ -582,10 +582,20 @@ var Transport = class {
|
|
|
582
582
|
});
|
|
583
583
|
return session;
|
|
584
584
|
}
|
|
585
|
+
getOrCreateSession(to, conn) {
|
|
586
|
+
let session = this.sessions.get(to);
|
|
587
|
+
if (!session) {
|
|
588
|
+
session = this.createSession(to, conn);
|
|
589
|
+
log?.info(
|
|
590
|
+
`${this.clientId} -- no session for ${to}, created a new one (id: ${session.id})`
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
return session;
|
|
594
|
+
}
|
|
585
595
|
deleteSession(session) {
|
|
586
596
|
this.sessions.delete(session.to);
|
|
587
597
|
log?.info(
|
|
588
|
-
`${this.clientId} -- session ${session.
|
|
598
|
+
`${this.clientId} -- session ${session.id} disconnect from ${session.to}`
|
|
589
599
|
);
|
|
590
600
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
591
601
|
status: "disconnect",
|
|
@@ -655,9 +665,12 @@ var Transport = class {
|
|
|
655
665
|
} else {
|
|
656
666
|
const errMsg = `received out-of-order msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq})`;
|
|
657
667
|
log?.error(
|
|
658
|
-
`${this.clientId} -- ${errMsg}, marking connection as dead: ${JSON.stringify(
|
|
668
|
+
`${this.clientId} -- fatal: ${errMsg}, marking connection as dead: ${JSON.stringify(
|
|
669
|
+
msg
|
|
670
|
+
)}`
|
|
659
671
|
);
|
|
660
672
|
this.protocolError(ProtocolError.MessageOrderingViolated, errMsg);
|
|
673
|
+
session.close();
|
|
661
674
|
}
|
|
662
675
|
return;
|
|
663
676
|
}
|
|
@@ -704,14 +717,7 @@ var Transport = class {
|
|
|
704
717
|
);
|
|
705
718
|
return void 0;
|
|
706
719
|
}
|
|
707
|
-
|
|
708
|
-
if (!session) {
|
|
709
|
-
session = this.createSession(to, void 0);
|
|
710
|
-
log?.info(
|
|
711
|
-
`${this.clientId} -- no session for ${to}, created a new one (id: ${session.debugId})`
|
|
712
|
-
);
|
|
713
|
-
}
|
|
714
|
-
return session.send(msg);
|
|
720
|
+
return this.getOrCreateSession(to).send(msg);
|
|
715
721
|
}
|
|
716
722
|
// control helpers
|
|
717
723
|
sendCloseStream(to, streamId) {
|
|
@@ -784,12 +790,13 @@ var ClientTransport = class extends Transport {
|
|
|
784
790
|
return;
|
|
785
791
|
let session = void 0;
|
|
786
792
|
const handshakeHandler = (data) => {
|
|
787
|
-
const
|
|
788
|
-
if (!
|
|
793
|
+
const maybeSession = this.receiveHandshakeResponseMessage(data, conn);
|
|
794
|
+
if (!maybeSession) {
|
|
789
795
|
conn.close();
|
|
790
796
|
return;
|
|
797
|
+
} else {
|
|
798
|
+
session = maybeSession;
|
|
791
799
|
}
|
|
792
|
-
session = this.onConnect(conn, handshake.from, handshake.instanceId);
|
|
793
800
|
conn.removeDataListener(handshakeHandler);
|
|
794
801
|
conn.addDataListener((data2) => {
|
|
795
802
|
const parsed = this.parseMsg(data2);
|
|
@@ -819,7 +826,7 @@ var ClientTransport = class extends Transport {
|
|
|
819
826
|
);
|
|
820
827
|
});
|
|
821
828
|
}
|
|
822
|
-
receiveHandshakeResponseMessage(data) {
|
|
829
|
+
receiveHandshakeResponseMessage(data, conn) {
|
|
823
830
|
const parsed = this.parseMsg(data);
|
|
824
831
|
if (!parsed) {
|
|
825
832
|
this.protocolError(
|
|
@@ -852,12 +859,14 @@ var ClientTransport = class extends Transport {
|
|
|
852
859
|
);
|
|
853
860
|
return false;
|
|
854
861
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
862
|
+
log?.debug(`${this.clientId} -- handshake from ${parsed.from} ok`);
|
|
863
|
+
const session = this.onConnect(
|
|
864
|
+
conn,
|
|
865
|
+
parsed.from,
|
|
866
|
+
parsed.payload.status.sessionId
|
|
858
867
|
);
|
|
859
868
|
this.retryBudget.startRestoringBudget(parsed.from);
|
|
860
|
-
return
|
|
869
|
+
return session;
|
|
861
870
|
}
|
|
862
871
|
/**
|
|
863
872
|
* Manually attempts to connect to a client.
|
|
@@ -926,11 +935,8 @@ var ClientTransport = class extends Transport {
|
|
|
926
935
|
}
|
|
927
936
|
}
|
|
928
937
|
sendHandshake(to, conn) {
|
|
929
|
-
const
|
|
930
|
-
|
|
931
|
-
to,
|
|
932
|
-
this.instanceId
|
|
933
|
-
);
|
|
938
|
+
const session = this.getOrCreateSession(to, conn);
|
|
939
|
+
const requestMsg = handshakeRequestMessage(this.clientId, to, session.id);
|
|
934
940
|
log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
|
|
935
941
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
936
942
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { a as ClientTransport, b as TransportClientId, c as ProvidedClientTransportOptions } from '../../../index-
|
|
3
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
2
|
+
import { a as ClientTransport, b as TransportClientId, c as ProvidedClientTransportOptions } from '../../../index-8df0bdfb.js';
|
|
3
|
+
import { W as WebSocketConnection } from '../../../connection-f31edbcd.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { a as ClientTransport, b as TransportClientId, c as ProvidedClientTransportOptions } from '../../../index-
|
|
3
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
2
|
+
import { a as ClientTransport, b as TransportClientId, c as ProvidedClientTransportOptions } from '../../../index-8df0bdfb.js';
|
|
3
|
+
import { W as WebSocketConnection } from '../../../connection-f31edbcd.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebSocketConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-Y6DLSCKU.js";
|
|
4
4
|
import {
|
|
5
5
|
ClientTransport
|
|
6
|
-
} from "../../../chunk-
|
|
7
|
-
import "../../../chunk-
|
|
6
|
+
} from "../../../chunk-LQMPJI3S.js";
|
|
7
|
+
import "../../../chunk-VH3NGOXQ.js";
|
|
8
8
|
import {
|
|
9
9
|
log
|
|
10
10
|
} from "../../../chunk-H4BYJELI.js";
|