@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
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
handshakeRequestMessage,
|
|
8
8
|
handshakeResponseMessage,
|
|
9
9
|
isAck
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-VH3NGOXQ.js";
|
|
11
11
|
import {
|
|
12
12
|
log
|
|
13
13
|
} from "./chunk-H4BYJELI.js";
|
|
@@ -75,7 +75,12 @@ var Session = class {
|
|
|
75
75
|
/**
|
|
76
76
|
* The unique ID of this session.
|
|
77
77
|
*/
|
|
78
|
-
|
|
78
|
+
id;
|
|
79
|
+
/**
|
|
80
|
+
* What the other side advertised as their session ID
|
|
81
|
+
* for this session.
|
|
82
|
+
*/
|
|
83
|
+
advertisedSessionId;
|
|
79
84
|
/**
|
|
80
85
|
* Number of messages we've sent along this session (excluding handshake and acks)
|
|
81
86
|
*/
|
|
@@ -97,11 +102,11 @@ var Session = class {
|
|
|
97
102
|
* The interval for sending heartbeats.
|
|
98
103
|
*/
|
|
99
104
|
heartbeat;
|
|
100
|
-
constructor(
|
|
105
|
+
constructor(conn, from, to, options) {
|
|
106
|
+
this.id = `session-${nanoid(12)}`;
|
|
101
107
|
this.options = options;
|
|
102
|
-
this.debugId = `sess-${unsafeId()}`;
|
|
103
108
|
this.from = from;
|
|
104
|
-
this.to =
|
|
109
|
+
this.to = to;
|
|
105
110
|
this.connection = conn;
|
|
106
111
|
this.codec = options.codec;
|
|
107
112
|
this.heartbeatMisses = 0;
|
|
@@ -141,7 +146,7 @@ var Session = class {
|
|
|
141
146
|
log?.info(
|
|
142
147
|
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
143
148
|
);
|
|
144
|
-
this.closeStaleConnection(
|
|
149
|
+
this.closeStaleConnection();
|
|
145
150
|
}
|
|
146
151
|
return;
|
|
147
152
|
}
|
|
@@ -172,33 +177,37 @@ var Session = class {
|
|
|
172
177
|
log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
|
|
173
178
|
const ok = this.connection.send(this.codec.toBuffer(msg));
|
|
174
179
|
if (!ok) {
|
|
175
|
-
const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.
|
|
180
|
+
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)`;
|
|
176
181
|
log?.error(msg2);
|
|
177
182
|
throw new Error(msg2);
|
|
178
183
|
}
|
|
179
184
|
}
|
|
180
185
|
}
|
|
181
186
|
updateBookkeeping(ack, seq) {
|
|
187
|
+
if (seq + 1 < this.ack) {
|
|
188
|
+
log?.error(`${this.from} -- received stale seq ${seq} + 1 < ${this.ack}`);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
182
191
|
this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
|
|
183
192
|
this.ack = seq + 1;
|
|
184
193
|
}
|
|
185
194
|
closeStaleConnection(conn) {
|
|
186
|
-
if (
|
|
195
|
+
if (this.connection === void 0 || this.connection === conn)
|
|
187
196
|
return;
|
|
188
197
|
log?.info(
|
|
189
|
-
`${this.from} -- closing old inner connection (id: ${this.connection.debugId}) from session (id: ${this.
|
|
198
|
+
`${this.from} -- closing old inner connection (id: ${this.connection.debugId}) from session (id: ${this.id}) to ${this.to}`
|
|
190
199
|
);
|
|
191
200
|
this.connection.close();
|
|
192
201
|
this.connection = void 0;
|
|
193
202
|
}
|
|
194
203
|
replaceWithNewConnection(newConn) {
|
|
195
|
-
this.closeStaleConnection(
|
|
204
|
+
this.closeStaleConnection(newConn);
|
|
196
205
|
this.cancelGrace();
|
|
197
206
|
this.connection = newConn;
|
|
198
207
|
}
|
|
199
208
|
beginGrace(cb) {
|
|
200
209
|
log?.info(
|
|
201
|
-
`${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.
|
|
210
|
+
`${this.from} -- starting ${this.options.sessionDisconnectGraceMs}ms grace period until session (id: ${this.id}) to ${this.to} is closed`
|
|
202
211
|
);
|
|
203
212
|
this.disconnectionGrace = setTimeout(() => {
|
|
204
213
|
this.close();
|
|
@@ -209,11 +218,12 @@ var Session = class {
|
|
|
209
218
|
cancelGrace() {
|
|
210
219
|
this.heartbeatMisses = 0;
|
|
211
220
|
clearTimeout(this.disconnectionGrace);
|
|
221
|
+
this.disconnectionGrace = void 0;
|
|
212
222
|
}
|
|
213
223
|
// closed when we want to discard the whole session
|
|
214
224
|
// (i.e. shutdown or session disconnect)
|
|
215
225
|
close() {
|
|
216
|
-
this.closeStaleConnection(
|
|
226
|
+
this.closeStaleConnection();
|
|
217
227
|
this.cancelGrace();
|
|
218
228
|
this.resetBufferedMessages();
|
|
219
229
|
clearInterval(this.heartbeat);
|
|
@@ -244,7 +254,6 @@ var Session = class {
|
|
|
244
254
|
|
|
245
255
|
// transport/transport.ts
|
|
246
256
|
import { Value } from "@sinclair/typebox/value";
|
|
247
|
-
import { nanoid as nanoid2 } from "nanoid";
|
|
248
257
|
|
|
249
258
|
// transport/rateLimit.ts
|
|
250
259
|
var LeakyBucketRateLimit = class {
|
|
@@ -336,13 +345,6 @@ var defaultClientTransportOptions = {
|
|
|
336
345
|
...defaultConnectionRetryOptions
|
|
337
346
|
};
|
|
338
347
|
var Transport = class {
|
|
339
|
-
/**
|
|
340
|
-
* Unique per instance of the transport.
|
|
341
|
-
* This allows us to distinguish reconnects to different
|
|
342
|
-
* transports.
|
|
343
|
-
*/
|
|
344
|
-
instanceId = nanoid2();
|
|
345
|
-
connectedInstanceIds = /* @__PURE__ */ new Map();
|
|
346
348
|
/**
|
|
347
349
|
* A flag indicating whether the transport has been destroyed.
|
|
348
350
|
* A destroyed transport will not attempt to reconnect and cannot be used again.
|
|
@@ -395,41 +397,41 @@ var Transport = class {
|
|
|
395
397
|
* and we know the identity of the connected client.
|
|
396
398
|
* @param conn The connection object.
|
|
397
399
|
*/
|
|
398
|
-
onConnect(conn, connectedTo,
|
|
400
|
+
onConnect(conn, connectedTo, advertisedSessionId) {
|
|
399
401
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
400
402
|
status: "connect",
|
|
401
403
|
conn
|
|
402
404
|
});
|
|
403
405
|
let oldSession = this.sessions.get(connectedTo);
|
|
404
|
-
|
|
405
|
-
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
406
|
+
if (oldSession?.advertisedSessionId && oldSession.advertisedSessionId !== advertisedSessionId) {
|
|
406
407
|
log?.warn(
|
|
407
|
-
`${this.clientId} -- connection from ${connectedTo} is a different
|
|
408
|
+
`${this.clientId} -- connection from ${connectedTo} is a different session (id: ${advertisedSessionId}, last connected to: ${oldSession.advertisedSessionId}), starting a new session`
|
|
408
409
|
);
|
|
409
410
|
oldSession.close();
|
|
410
411
|
this.deleteSession(oldSession);
|
|
411
412
|
oldSession = void 0;
|
|
412
413
|
}
|
|
413
|
-
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
414
414
|
if (oldSession === void 0) {
|
|
415
415
|
const newSession = this.createSession(connectedTo, conn);
|
|
416
|
+
newSession.advertisedSessionId = advertisedSessionId;
|
|
416
417
|
log?.info(
|
|
417
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.
|
|
418
|
+
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.id}) to ${connectedTo}`
|
|
418
419
|
);
|
|
419
420
|
return newSession;
|
|
420
421
|
}
|
|
421
422
|
log?.info(
|
|
422
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.
|
|
423
|
+
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.id}) to ${connectedTo}`
|
|
423
424
|
);
|
|
424
425
|
oldSession.replaceWithNewConnection(conn);
|
|
425
426
|
oldSession.sendBufferedMessages();
|
|
427
|
+
oldSession.advertisedSessionId = advertisedSessionId;
|
|
426
428
|
return oldSession;
|
|
427
429
|
}
|
|
428
|
-
createSession(
|
|
430
|
+
createSession(to, conn) {
|
|
429
431
|
const session = new Session(
|
|
430
|
-
this.clientId,
|
|
431
|
-
connectedTo,
|
|
432
432
|
conn,
|
|
433
|
+
this.clientId,
|
|
434
|
+
to,
|
|
433
435
|
this.options
|
|
434
436
|
);
|
|
435
437
|
this.sessions.set(session.to, session);
|
|
@@ -439,10 +441,20 @@ var Transport = class {
|
|
|
439
441
|
});
|
|
440
442
|
return session;
|
|
441
443
|
}
|
|
444
|
+
getOrCreateSession(to, conn) {
|
|
445
|
+
let session = this.sessions.get(to);
|
|
446
|
+
if (!session) {
|
|
447
|
+
session = this.createSession(to, conn);
|
|
448
|
+
log?.info(
|
|
449
|
+
`${this.clientId} -- no session for ${to}, created a new one (id: ${session.id})`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
return session;
|
|
453
|
+
}
|
|
442
454
|
deleteSession(session) {
|
|
443
455
|
this.sessions.delete(session.to);
|
|
444
456
|
log?.info(
|
|
445
|
-
`${this.clientId} -- session ${session.
|
|
457
|
+
`${this.clientId} -- session ${session.id} disconnect from ${session.to}`
|
|
446
458
|
);
|
|
447
459
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
448
460
|
status: "disconnect",
|
|
@@ -512,9 +524,12 @@ var Transport = class {
|
|
|
512
524
|
} else {
|
|
513
525
|
const errMsg = `received out-of-order msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq})`;
|
|
514
526
|
log?.error(
|
|
515
|
-
`${this.clientId} -- ${errMsg}, marking connection as dead: ${JSON.stringify(
|
|
527
|
+
`${this.clientId} -- fatal: ${errMsg}, marking connection as dead: ${JSON.stringify(
|
|
528
|
+
msg
|
|
529
|
+
)}`
|
|
516
530
|
);
|
|
517
531
|
this.protocolError(ProtocolError.MessageOrderingViolated, errMsg);
|
|
532
|
+
session.close();
|
|
518
533
|
}
|
|
519
534
|
return;
|
|
520
535
|
}
|
|
@@ -561,14 +576,7 @@ var Transport = class {
|
|
|
561
576
|
);
|
|
562
577
|
return void 0;
|
|
563
578
|
}
|
|
564
|
-
|
|
565
|
-
if (!session) {
|
|
566
|
-
session = this.createSession(to, void 0);
|
|
567
|
-
log?.info(
|
|
568
|
-
`${this.clientId} -- no session for ${to}, created a new one (id: ${session.debugId})`
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
return session.send(msg);
|
|
579
|
+
return this.getOrCreateSession(to).send(msg);
|
|
572
580
|
}
|
|
573
581
|
// control helpers
|
|
574
582
|
sendCloseStream(to, streamId) {
|
|
@@ -641,12 +649,13 @@ var ClientTransport = class extends Transport {
|
|
|
641
649
|
return;
|
|
642
650
|
let session = void 0;
|
|
643
651
|
const handshakeHandler = (data) => {
|
|
644
|
-
const
|
|
645
|
-
if (!
|
|
652
|
+
const maybeSession = this.receiveHandshakeResponseMessage(data, conn);
|
|
653
|
+
if (!maybeSession) {
|
|
646
654
|
conn.close();
|
|
647
655
|
return;
|
|
656
|
+
} else {
|
|
657
|
+
session = maybeSession;
|
|
648
658
|
}
|
|
649
|
-
session = this.onConnect(conn, handshake.from, handshake.instanceId);
|
|
650
659
|
conn.removeDataListener(handshakeHandler);
|
|
651
660
|
conn.addDataListener((data2) => {
|
|
652
661
|
const parsed = this.parseMsg(data2);
|
|
@@ -676,7 +685,7 @@ var ClientTransport = class extends Transport {
|
|
|
676
685
|
);
|
|
677
686
|
});
|
|
678
687
|
}
|
|
679
|
-
receiveHandshakeResponseMessage(data) {
|
|
688
|
+
receiveHandshakeResponseMessage(data, conn) {
|
|
680
689
|
const parsed = this.parseMsg(data);
|
|
681
690
|
if (!parsed) {
|
|
682
691
|
this.protocolError(
|
|
@@ -709,12 +718,14 @@ var ClientTransport = class extends Transport {
|
|
|
709
718
|
);
|
|
710
719
|
return false;
|
|
711
720
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
721
|
+
log?.debug(`${this.clientId} -- handshake from ${parsed.from} ok`);
|
|
722
|
+
const session = this.onConnect(
|
|
723
|
+
conn,
|
|
724
|
+
parsed.from,
|
|
725
|
+
parsed.payload.status.sessionId
|
|
715
726
|
);
|
|
716
727
|
this.retryBudget.startRestoringBudget(parsed.from);
|
|
717
|
-
return
|
|
728
|
+
return session;
|
|
718
729
|
}
|
|
719
730
|
/**
|
|
720
731
|
* Manually attempts to connect to a client.
|
|
@@ -783,11 +794,8 @@ var ClientTransport = class extends Transport {
|
|
|
783
794
|
}
|
|
784
795
|
}
|
|
785
796
|
sendHandshake(to, conn) {
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
to,
|
|
789
|
-
this.instanceId
|
|
790
|
-
);
|
|
797
|
+
const session = this.getOrCreateSession(to, conn);
|
|
798
|
+
const requestMsg = handshakeRequestMessage(this.clientId, to, session.id);
|
|
791
799
|
log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
|
|
792
800
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
793
801
|
}
|
|
@@ -800,7 +808,7 @@ var ServerTransport = class extends Transport {
|
|
|
800
808
|
constructor(clientId, providedOptions) {
|
|
801
809
|
super(clientId, providedOptions);
|
|
802
810
|
log?.info(
|
|
803
|
-
`${this.clientId} -- initiated server transport (
|
|
811
|
+
`${this.clientId} -- initiated server transport (protocol: ${PROTOCOL_VERSION})`
|
|
804
812
|
);
|
|
805
813
|
}
|
|
806
814
|
handleConnection(conn) {
|
|
@@ -812,12 +820,13 @@ var ServerTransport = class extends Transport {
|
|
|
812
820
|
let session = void 0;
|
|
813
821
|
const client = () => session?.to ?? "unknown";
|
|
814
822
|
const handshakeHandler = (data) => {
|
|
815
|
-
const
|
|
816
|
-
if (!
|
|
823
|
+
const maybeSession = this.receiveHandshakeRequestMessage(data, conn);
|
|
824
|
+
if (!maybeSession) {
|
|
817
825
|
conn.close();
|
|
818
826
|
return;
|
|
827
|
+
} else {
|
|
828
|
+
session = maybeSession;
|
|
819
829
|
}
|
|
820
|
-
session = this.onConnect(conn, handshake.from, handshake.instanceId);
|
|
821
830
|
conn.removeDataListener(handshakeHandler);
|
|
822
831
|
conn.addDataListener((data2) => {
|
|
823
832
|
const parsed = this.parseMsg(data2);
|
|
@@ -855,18 +864,13 @@ var ServerTransport = class extends Transport {
|
|
|
855
864
|
return false;
|
|
856
865
|
}
|
|
857
866
|
if (!Value.Check(ControlMessageHandshakeRequestSchema, parsed.payload)) {
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
);
|
|
867
|
+
const reason = "received invalid handshake msg";
|
|
868
|
+
const responseMsg2 = handshakeResponseMessage(this.clientId, parsed.from, {
|
|
869
|
+
ok: false,
|
|
870
|
+
reason
|
|
871
|
+
});
|
|
864
872
|
conn.send(this.codec.toBuffer(responseMsg2));
|
|
865
|
-
log?.warn(
|
|
866
|
-
`${this.clientId} -- received invalid handshake msg: ${JSON.stringify(
|
|
867
|
-
parsed
|
|
868
|
-
)}`
|
|
869
|
-
);
|
|
873
|
+
log?.warn(`${this.clientId} -- ${reason}: ${JSON.stringify(parsed)}`);
|
|
870
874
|
this.protocolError(
|
|
871
875
|
ProtocolError.HandshakeFailed,
|
|
872
876
|
"invalid handshake request"
|
|
@@ -875,34 +879,28 @@ var ServerTransport = class extends Transport {
|
|
|
875
879
|
}
|
|
876
880
|
const gotVersion = parsed.payload.protocolVersion;
|
|
877
881
|
if (gotVersion !== PROTOCOL_VERSION) {
|
|
878
|
-
const
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
);
|
|
882
|
+
const reason = `incorrect version (got: ${gotVersion} wanted ${PROTOCOL_VERSION})`;
|
|
883
|
+
const responseMsg2 = handshakeResponseMessage(this.clientId, parsed.from, {
|
|
884
|
+
ok: false,
|
|
885
|
+
reason
|
|
886
|
+
});
|
|
884
887
|
conn.send(this.codec.toBuffer(responseMsg2));
|
|
885
888
|
log?.warn(
|
|
886
889
|
`${this.clientId} -- received handshake msg with incompatible protocol version (got: ${gotVersion}, expected: ${PROTOCOL_VERSION})`
|
|
887
890
|
);
|
|
888
|
-
this.protocolError(
|
|
889
|
-
ProtocolError.HandshakeFailed,
|
|
890
|
-
`incorrect version (got: ${gotVersion} wanted ${PROTOCOL_VERSION})`
|
|
891
|
-
);
|
|
891
|
+
this.protocolError(ProtocolError.HandshakeFailed, reason);
|
|
892
892
|
return false;
|
|
893
893
|
}
|
|
894
|
-
const
|
|
894
|
+
const session = this.getOrCreateSession(parsed.from, conn);
|
|
895
895
|
log?.debug(
|
|
896
|
-
`${this.clientId} -- handshake from ${parsed.from} ok
|
|
897
|
-
);
|
|
898
|
-
const responseMsg = handshakeResponseMessage(
|
|
899
|
-
this.clientId,
|
|
900
|
-
this.instanceId,
|
|
901
|
-
parsed.from,
|
|
902
|
-
true
|
|
896
|
+
`${this.clientId} -- handshake from ${parsed.from} ok, responding with handshake success`
|
|
903
897
|
);
|
|
898
|
+
const responseMsg = handshakeResponseMessage(this.clientId, parsed.from, {
|
|
899
|
+
ok: true,
|
|
900
|
+
sessionId: session.id
|
|
901
|
+
});
|
|
904
902
|
conn.send(this.codec.toBuffer(responseMsg));
|
|
905
|
-
return
|
|
903
|
+
return this.onConnect(conn, parsed.from, parsed.payload.sessionId);
|
|
906
904
|
}
|
|
907
905
|
};
|
|
908
906
|
|
|
@@ -910,6 +908,7 @@ export {
|
|
|
910
908
|
ProtocolError,
|
|
911
909
|
Connection,
|
|
912
910
|
Session,
|
|
911
|
+
defaultTransportOptions,
|
|
913
912
|
Transport,
|
|
914
913
|
ClientTransport,
|
|
915
914
|
ServerTransport
|
|
@@ -19,18 +19,18 @@ var ControlMessageAckSchema = Type.Object({
|
|
|
19
19
|
var ControlMessageCloseSchema = Type.Object({
|
|
20
20
|
type: Type.Literal("CLOSE")
|
|
21
21
|
});
|
|
22
|
-
var PROTOCOL_VERSION = "v1";
|
|
22
|
+
var PROTOCOL_VERSION = "v1.1";
|
|
23
23
|
var ControlMessageHandshakeRequestSchema = Type.Object({
|
|
24
24
|
type: Type.Literal("HANDSHAKE_REQ"),
|
|
25
25
|
protocolVersion: Type.String(),
|
|
26
|
-
|
|
26
|
+
sessionId: Type.String()
|
|
27
27
|
});
|
|
28
28
|
var ControlMessageHandshakeResponseSchema = Type.Object({
|
|
29
29
|
type: Type.Literal("HANDSHAKE_RESP"),
|
|
30
30
|
status: Type.Union([
|
|
31
31
|
Type.Object({
|
|
32
32
|
ok: Type.Literal(true),
|
|
33
|
-
|
|
33
|
+
sessionId: Type.String()
|
|
34
34
|
}),
|
|
35
35
|
Type.Object({
|
|
36
36
|
ok: Type.Literal(false),
|
|
@@ -47,7 +47,7 @@ var ControlMessagePayloadSchema = Type.Union([
|
|
|
47
47
|
var OpaqueTransportMessageSchema = TransportMessageSchema(
|
|
48
48
|
Type.Unknown()
|
|
49
49
|
);
|
|
50
|
-
function handshakeRequestMessage(from, to,
|
|
50
|
+
function handshakeRequestMessage(from, to, sessionId) {
|
|
51
51
|
return {
|
|
52
52
|
id: nanoid(),
|
|
53
53
|
from,
|
|
@@ -59,11 +59,11 @@ function handshakeRequestMessage(from, to, instanceId) {
|
|
|
59
59
|
payload: {
|
|
60
60
|
type: "HANDSHAKE_REQ",
|
|
61
61
|
protocolVersion: PROTOCOL_VERSION,
|
|
62
|
-
|
|
62
|
+
sessionId
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
function handshakeResponseMessage(from,
|
|
66
|
+
function handshakeResponseMessage(from, to, status) {
|
|
67
67
|
return {
|
|
68
68
|
id: nanoid(),
|
|
69
69
|
from,
|
|
@@ -72,18 +72,9 @@ function handshakeResponseMessage(from, instanceId, to, ok, reason) {
|
|
|
72
72
|
ack: 0,
|
|
73
73
|
streamId: nanoid(),
|
|
74
74
|
controlFlags: 0,
|
|
75
|
-
payload:
|
|
76
|
-
type: "HANDSHAKE_RESP",
|
|
77
|
-
status: {
|
|
78
|
-
ok: true,
|
|
79
|
-
instanceId
|
|
80
|
-
}
|
|
81
|
-
} : {
|
|
75
|
+
payload: {
|
|
82
76
|
type: "HANDSHAKE_RESP",
|
|
83
|
-
status
|
|
84
|
-
ok: false,
|
|
85
|
-
reason: reason ?? "Unknown reason"
|
|
86
|
-
}
|
|
77
|
+
status
|
|
87
78
|
}
|
|
88
79
|
};
|
|
89
80
|
}
|
|
@@ -170,7 +170,12 @@ declare class Session<ConnType extends Connection> {
|
|
|
170
170
|
/**
|
|
171
171
|
* The unique ID of this session.
|
|
172
172
|
*/
|
|
173
|
-
|
|
173
|
+
id: string;
|
|
174
|
+
/**
|
|
175
|
+
* What the other side advertised as their session ID
|
|
176
|
+
* for this session.
|
|
177
|
+
*/
|
|
178
|
+
advertisedSessionId?: string;
|
|
174
179
|
/**
|
|
175
180
|
* Number of messages we've sent along this session (excluding handshake and acks)
|
|
176
181
|
*/
|
|
@@ -191,8 +196,8 @@ declare class Session<ConnType extends Connection> {
|
|
|
191
196
|
/**
|
|
192
197
|
* The interval for sending heartbeats.
|
|
193
198
|
*/
|
|
194
|
-
private heartbeat
|
|
195
|
-
constructor(
|
|
199
|
+
private heartbeat;
|
|
200
|
+
constructor(conn: ConnType | undefined, from: TransportClientId, to: TransportClientId, options: SessionOptions);
|
|
196
201
|
/**
|
|
197
202
|
* Sends a message over the session's connection.
|
|
198
203
|
* If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
|
|
@@ -344,13 +349,6 @@ type ClientTransportOptions = SessionOptions & ConnectionRetryOptions;
|
|
|
344
349
|
* @abstract
|
|
345
350
|
*/
|
|
346
351
|
declare abstract class Transport<ConnType extends Connection> {
|
|
347
|
-
/**
|
|
348
|
-
* Unique per instance of the transport.
|
|
349
|
-
* This allows us to distinguish reconnects to different
|
|
350
|
-
* transports.
|
|
351
|
-
*/
|
|
352
|
-
instanceId: string;
|
|
353
|
-
connectedInstanceIds: Map<string, string>;
|
|
354
352
|
/**
|
|
355
353
|
* A flag indicating whether the transport has been destroyed.
|
|
356
354
|
* A destroyed transport will not attempt to reconnect and cannot be used again.
|
|
@@ -401,8 +399,9 @@ declare abstract class Transport<ConnType extends Connection> {
|
|
|
401
399
|
* and we know the identity of the connected client.
|
|
402
400
|
* @param conn The connection object.
|
|
403
401
|
*/
|
|
404
|
-
protected onConnect(conn: ConnType, connectedTo: TransportClientId,
|
|
405
|
-
|
|
402
|
+
protected onConnect(conn: ConnType, connectedTo: TransportClientId, advertisedSessionId: string): Session<ConnType>;
|
|
403
|
+
protected createSession(to: TransportClientId, conn?: ConnType): Session<ConnType>;
|
|
404
|
+
protected getOrCreateSession(to: TransportClientId, conn?: ConnType): Session<ConnType>;
|
|
406
405
|
protected deleteSession(session: Session<ConnType>): void;
|
|
407
406
|
/**
|
|
408
407
|
* The downstream implementation needs to call this when a connection is closed.
|
|
@@ -475,10 +474,7 @@ declare abstract class ClientTransport<ConnType extends Connection> extends Tran
|
|
|
475
474
|
reconnectOnConnectionDrop: boolean;
|
|
476
475
|
constructor(clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
|
|
477
476
|
protected handleConnection(conn: ConnType, to: TransportClientId): void;
|
|
478
|
-
receiveHandshakeResponseMessage(data: Uint8Array):
|
|
479
|
-
instanceId: string;
|
|
480
|
-
from: string;
|
|
481
|
-
};
|
|
477
|
+
receiveHandshakeResponseMessage(data: Uint8Array, conn: ConnType): Session<ConnType> | false;
|
|
482
478
|
/**
|
|
483
479
|
* Abstract method that creates a new {@link Connection} object.
|
|
484
480
|
* This should call {@link handleConnection} when the connection is created.
|
|
@@ -499,10 +495,7 @@ declare abstract class ClientTransport<ConnType extends Connection> extends Tran
|
|
|
499
495
|
declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
|
|
500
496
|
constructor(clientId: TransportClientId, providedOptions?: ProvidedTransportOptions);
|
|
501
497
|
protected handleConnection(conn: ConnType): void;
|
|
502
|
-
receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType):
|
|
503
|
-
instanceId: string;
|
|
504
|
-
from: string;
|
|
505
|
-
};
|
|
498
|
+
receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType): Session<ConnType> | false;
|
|
506
499
|
}
|
|
507
500
|
|
|
508
|
-
export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P,
|
|
501
|
+
export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, SessionOptions as S, Transport as T, ClientTransport as a, TransportClientId as b, ProvidedClientTransportOptions as c, ServerTransport as d, ProvidedTransportOptions as e, Session as f, TransportStatus as g, TransportMessageSchema as h, OpaqueTransportMessageSchema as i, TransportMessage as j, isStreamOpen as k, isStreamClose as l, EventTypes as m, EventHandler as n, ProtocolError as o, ProtocolErrorType as p };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TObject, TUnion, TString, TSchema, TNever, TLiteral, Static } from '@sinclair/typebox';
|
|
2
2
|
import { Pushable } from 'it-pushable';
|
|
3
|
-
import { b as TransportClientId,
|
|
3
|
+
import { b as TransportClientId, f as Session, C as Connection } from './index-8df0bdfb.js';
|
|
4
4
|
|
|
5
5
|
type TLiteralString = TLiteral<string>;
|
|
6
6
|
type RiverErrorSchema = TObject<{
|
package/dist/router/index.cjs
CHANGED
|
@@ -567,14 +567,14 @@ var ControlMessageCloseSchema = import_typebox3.Type.Object({
|
|
|
567
567
|
var ControlMessageHandshakeRequestSchema = import_typebox3.Type.Object({
|
|
568
568
|
type: import_typebox3.Type.Literal("HANDSHAKE_REQ"),
|
|
569
569
|
protocolVersion: import_typebox3.Type.String(),
|
|
570
|
-
|
|
570
|
+
sessionId: import_typebox3.Type.String()
|
|
571
571
|
});
|
|
572
572
|
var ControlMessageHandshakeResponseSchema = import_typebox3.Type.Object({
|
|
573
573
|
type: import_typebox3.Type.Literal("HANDSHAKE_RESP"),
|
|
574
574
|
status: import_typebox3.Type.Union([
|
|
575
575
|
import_typebox3.Type.Object({
|
|
576
576
|
ok: import_typebox3.Type.Literal(true),
|
|
577
|
-
|
|
577
|
+
sessionId: import_typebox3.Type.String()
|
|
578
578
|
}),
|
|
579
579
|
import_typebox3.Type.Object({
|
|
580
580
|
ok: import_typebox3.Type.Literal(false),
|
package/dist/router/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TObject, TUnion, Static } from '@sinclair/typebox';
|
|
2
|
-
import { e as ProcedureMap, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../procedures-
|
|
3
|
-
export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-
|
|
4
|
-
import {
|
|
2
|
+
import { e as ProcedureMap, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../procedures-b5ddb54d.js';
|
|
3
|
+
export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-b5ddb54d.js';
|
|
4
|
+
import { d as ServerTransport, C as Connection, a as ClientTransport, b as TransportClientId } from '../index-8df0bdfb.js';
|
|
5
5
|
import { Pushable } from 'it-pushable';
|
|
6
6
|
import '../types-3e5768ec.js';
|
|
7
7
|
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TObject, TUnion, Static } from '@sinclair/typebox';
|
|
2
|
-
import { e as ProcedureMap, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../procedures-
|
|
3
|
-
export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-
|
|
4
|
-
import {
|
|
2
|
+
import { e as ProcedureMap, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../procedures-b5ddb54d.js';
|
|
3
|
+
export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-b5ddb54d.js';
|
|
4
|
+
import { d as ServerTransport, C as Connection, a as ClientTransport, b as TransportClientId } from '../index-8df0bdfb.js';
|
|
5
5
|
import { Pushable } from 'it-pushable';
|
|
6
6
|
import '../types-3e5768ec.js';
|
|
7
7
|
|
package/dist/router/index.js
CHANGED