@replit/river 0.12.6 → 0.13.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.
Files changed (51) hide show
  1. package/README.md +4 -1
  2. package/dist/{builder-c593de11.d.ts → builder-169fbf7f.d.ts} +16 -7
  3. package/dist/{chunk-AFLZ6INU.js → chunk-CBRQM65K.js} +29 -10
  4. package/dist/{chunk-IIBVKYDB.js → chunk-CDH7QSB4.js} +39 -1
  5. package/dist/{chunk-XFFS4UOD.js → chunk-MGGIUH5O.js} +7 -7
  6. package/dist/{chunk-VLBVQX5H.js → chunk-NPXAAD7M.js} +1 -1
  7. package/dist/{chunk-4SDJ5VN4.js → chunk-R2IMXRVU.js} +150 -116
  8. package/dist/{connection-ba37d174.d.ts → connection-ab681c08.d.ts} +1 -1
  9. package/dist/{messageFraming-b200ef25.d.ts → connection-dd789651.d.ts} +17 -2
  10. package/dist/{index-54e0f99c.d.ts → index-21c1b21d.d.ts} +29 -13
  11. package/dist/router/index.cjs +31 -13
  12. package/dist/router/index.d.cts +5 -5
  13. package/dist/router/index.d.ts +5 -5
  14. package/dist/router/index.js +2 -2
  15. package/dist/transport/impls/uds/client.cjs +143 -121
  16. package/dist/transport/impls/uds/client.d.cts +2 -3
  17. package/dist/transport/impls/uds/client.d.ts +2 -3
  18. package/dist/transport/impls/uds/client.js +5 -6
  19. package/dist/transport/impls/uds/server.cjs +151 -127
  20. package/dist/transport/impls/uds/server.d.cts +2 -3
  21. package/dist/transport/impls/uds/server.d.ts +2 -3
  22. package/dist/transport/impls/uds/server.js +4 -5
  23. package/dist/transport/impls/ws/client.cjs +147 -123
  24. package/dist/transport/impls/ws/client.d.cts +4 -4
  25. package/dist/transport/impls/ws/client.d.ts +4 -4
  26. package/dist/transport/impls/ws/client.js +7 -7
  27. package/dist/transport/impls/ws/server.cjs +151 -127
  28. package/dist/transport/impls/ws/server.d.cts +2 -2
  29. package/dist/transport/impls/ws/server.d.ts +2 -2
  30. package/dist/transport/impls/ws/server.js +4 -4
  31. package/dist/transport/index.cjs +202 -167
  32. package/dist/transport/index.d.cts +1 -1
  33. package/dist/transport/index.d.ts +1 -1
  34. package/dist/transport/index.js +3 -3
  35. package/dist/util/testHelpers.cjs +294 -16
  36. package/dist/util/testHelpers.d.cts +2 -2
  37. package/dist/util/testHelpers.d.ts +2 -2
  38. package/dist/util/testHelpers.js +30 -8
  39. package/package.json +1 -9
  40. package/dist/chunk-PBPXYLI6.js +0 -44
  41. package/dist/chunk-Q7GL34DZ.js +0 -47
  42. package/dist/connection-1f9971d8.d.ts +0 -17
  43. package/dist/connection-24d878ac.d.ts +0 -18
  44. package/dist/transport/impls/stdio/client.cjs +0 -904
  45. package/dist/transport/impls/stdio/client.d.cts +0 -27
  46. package/dist/transport/impls/stdio/client.d.ts +0 -27
  47. package/dist/transport/impls/stdio/client.js +0 -42
  48. package/dist/transport/impls/stdio/server.cjs +0 -879
  49. package/dist/transport/impls/stdio/server.d.cts +0 -25
  50. package/dist/transport/impls/stdio/server.d.ts +0 -25
  51. package/dist/transport/impls/stdio/server.js +0 -33
@@ -1,19 +1,19 @@
1
- import {
2
- NaiveJsonCodec
3
- } from "./chunk-GZ7HCLLM.js";
4
1
  import {
5
2
  ControlMessageHandshakeRequestSchema,
6
3
  ControlMessageHandshakeResponseSchema,
7
4
  OpaqueTransportMessageSchema,
8
5
  PROTOCOL_VERSION,
9
- bootRequestMessage,
10
- bootResponseMessage,
11
6
  coerceErrorString,
7
+ handshakeRequestMessage,
8
+ handshakeResponseMessage,
12
9
  isAck
13
- } from "./chunk-XFFS4UOD.js";
10
+ } from "./chunk-MGGIUH5O.js";
14
11
  import {
15
12
  log
16
13
  } from "./chunk-H4BYJELI.js";
14
+ import {
15
+ NaiveJsonCodec
16
+ } from "./chunk-GZ7HCLLM.js";
17
17
 
18
18
  // transport/events.ts
19
19
  var EventDispatcher = class {
@@ -56,8 +56,15 @@ var Connection = class {
56
56
  var HEARTBEAT_INTERVAL_MS = 1e3;
57
57
  var HEARTBEATS_TILL_DEAD = 2;
58
58
  var SESSION_DISCONNECT_GRACE_MS = 5e3;
59
+ var defaultSessionOptions = {
60
+ heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
61
+ heartbeatsUntilDead: HEARTBEATS_TILL_DEAD,
62
+ sessionDisconnectGraceMs: SESSION_DISCONNECT_GRACE_MS,
63
+ codec: NaiveJsonCodec
64
+ };
59
65
  var Session = class {
60
66
  codec;
67
+ options;
61
68
  /**
62
69
  * The buffer of messages that have been sent but not yet acknowledged.
63
70
  */
@@ -93,16 +100,17 @@ var Session = class {
93
100
  * The interval for sending heartbeats.
94
101
  */
95
102
  heartbeat;
96
- constructor(codec, from, connectedTo, conn) {
103
+ constructor(from, connectedTo, conn, options) {
104
+ this.options = options;
97
105
  this.debugId = `sess-${unsafeId()}`;
98
106
  this.from = from;
99
107
  this.to = connectedTo;
100
108
  this.connection = conn;
101
- this.codec = codec;
109
+ this.codec = options.codec;
102
110
  this.heartbeatMisses = 0;
103
111
  this.heartbeat = setInterval(
104
112
  () => this.sendHeartbeat(),
105
- HEARTBEAT_INTERVAL_MS
113
+ options.heartbeatIntervalMs
106
114
  );
107
115
  }
108
116
  /**
@@ -138,7 +146,7 @@ var Session = class {
138
146
  return fullMsg.id;
139
147
  }
140
148
  sendHeartbeat() {
141
- if (this.heartbeatMisses >= HEARTBEATS_TILL_DEAD) {
149
+ if (this.heartbeatMisses >= this.options.heartbeatsUntilDead) {
142
150
  if (this.connection) {
143
151
  log?.info(
144
152
  `${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
@@ -208,7 +216,7 @@ var Session = class {
208
216
  this.disconnectionGrace = setTimeout(() => {
209
217
  this.close();
210
218
  cb();
211
- }, SESSION_DISCONNECT_GRACE_MS);
219
+ }, this.options.sessionDisconnectGraceMs);
212
220
  }
213
221
  // called on reconnect of the underlying session
214
222
  cancelGrace() {
@@ -249,13 +257,13 @@ var Session = class {
249
257
  // transport/transport.ts
250
258
  import { Value } from "@sinclair/typebox/value";
251
259
  import { nanoid as nanoid2 } from "nanoid";
252
- var DEFAULT_RECONNECT_JITTER_MAX_MS = 500;
253
- var DEFAULT_RECONNECT_INTERVAL_MS = 250;
260
+ var RECONNECT_JITTER_MAX_MS = 500;
261
+ var RECONNECT_INTERVAL_MS = 250;
254
262
  var defaultTransportOptions = {
255
- retryIntervalMs: DEFAULT_RECONNECT_INTERVAL_MS,
256
- retryJitterMs: DEFAULT_RECONNECT_JITTER_MAX_MS,
263
+ retryIntervalMs: RECONNECT_INTERVAL_MS,
264
+ retryJitterMs: RECONNECT_JITTER_MAX_MS,
257
265
  retryAttemptsMax: 5,
258
- codec: NaiveJsonCodec
266
+ ...defaultSessionOptions
259
267
  };
260
268
  var Transport = class {
261
269
  /**
@@ -326,7 +334,7 @@ var Transport = class {
326
334
  const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
327
335
  if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
328
336
  log?.warn(
329
- `${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
337
+ `${this.clientId} -- connection from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
330
338
  );
331
339
  oldSession.close();
332
340
  this.deleteSession(oldSession);
@@ -349,10 +357,10 @@ var Transport = class {
349
357
  }
350
358
  createSession(connectedTo, conn) {
351
359
  const session = new Session(
352
- this.codec,
353
360
  this.clientId,
354
361
  connectedTo,
355
- conn
362
+ conn,
363
+ this.options
356
364
  );
357
365
  this.sessions.set(session.to, session);
358
366
  this.eventDispatcher.dispatchEvent("sessionStatus", {
@@ -395,7 +403,7 @@ var Transport = class {
395
403
  parseMsg(msg) {
396
404
  const parsedMsg = this.codec.fromBuffer(msg);
397
405
  if (parsedMsg === null) {
398
- const decodedBuffer = new TextDecoder().decode(msg);
406
+ const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
399
407
  log?.error(
400
408
  `${this.clientId} -- received malformed msg, killing conn: ${decodedBuffer}`
401
409
  );
@@ -409,11 +417,7 @@ var Transport = class {
409
417
  );
410
418
  return null;
411
419
  }
412
- return {
413
- ...parsedMsg,
414
- serviceName: parsedMsg.serviceName === null ? void 0 : parsedMsg.serviceName,
415
- procedureName: parsedMsg.procedureName === null ? void 0 : parsedMsg.procedureName
416
- };
420
+ return parsedMsg;
417
421
  }
418
422
  /**
419
423
  * Called when a message is received by this transport.
@@ -432,11 +436,18 @@ var Transport = class {
432
436
  session.cancelGrace();
433
437
  log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
434
438
  if (msg.seq !== session.nextExpectedSeq) {
435
- log?.warn(
436
- `${this.clientId} -- received out-of-order msg (got: ${msg.seq}, wanted: ${session.nextExpectedSeq}), discarding: ${JSON.stringify(
437
- msg
438
- )}`
439
- );
439
+ if (msg.seq < session.nextExpectedSeq) {
440
+ log?.debug(
441
+ `${this.clientId} -- received duplicate msg (got: ${msg.seq}, wanted: ${session.nextExpectedSeq}), discarding: ${JSON.stringify(
442
+ msg
443
+ )}`
444
+ );
445
+ } else {
446
+ log?.error(
447
+ `${this.clientId} -- received out-of-order msg (got: ${msg.seq}, wanted: ${session.nextExpectedSeq}), marking connection as dead: ${JSON.stringify(msg)}`
448
+ );
449
+ session.closeStaleConnection(session.connection);
450
+ }
440
451
  return;
441
452
  }
442
453
  if (!isAck(msg.controlFlags)) {
@@ -454,7 +465,7 @@ var Transport = class {
454
465
  }
455
466
  /**
456
467
  * Removes a listener from this transport.
457
- * @param the type of event to unlisten on
468
+ * @param the type of event to un-listen on
458
469
  * @param handler The message handler to remove.
459
470
  */
460
471
  removeEventListener(type, handler) {
@@ -531,23 +542,31 @@ var ClientTransport = class extends Transport {
531
542
  */
532
543
  inflightConnectionPromises;
533
544
  tryReconnecting = true;
534
- constructor(clientId, providedOptions) {
545
+ connectedTo;
546
+ constructor(clientId, connectedTo, providedOptions) {
535
547
  super(clientId, providedOptions);
548
+ this.connectedTo = connectedTo;
536
549
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
537
550
  }
538
551
  handleConnection(conn, to) {
539
- const bootHandler = this.receiveWithBootSequence(conn, () => {
540
- conn.removeDataListener(bootHandler);
541
- conn.addDataListener((data) => {
542
- const parsed = this.parseMsg(data);
552
+ const handshakeHandler = (data) => {
553
+ const handshake = this.receiveHandshakeResponseMessage(data);
554
+ if (!handshake) {
555
+ conn.close();
556
+ return;
557
+ }
558
+ this.onConnect(conn, handshake.from, handshake.instanceId);
559
+ conn.removeDataListener(handshakeHandler);
560
+ conn.addDataListener((data2) => {
561
+ const parsed = this.parseMsg(data2);
543
562
  if (!parsed) {
544
563
  conn.close();
545
564
  return;
546
565
  }
547
566
  this.handleMsg(parsed);
548
567
  });
549
- });
550
- conn.addDataListener(bootHandler);
568
+ };
569
+ conn.addDataListener(handshakeHandler);
551
570
  conn.addCloseListener(() => {
552
571
  this.onDisconnect(conn, to);
553
572
  void this.connect(to);
@@ -558,6 +577,32 @@ var ClientTransport = class extends Transport {
558
577
  );
559
578
  });
560
579
  }
580
+ receiveHandshakeResponseMessage(data) {
581
+ const parsed = this.parseMsg(data);
582
+ if (!parsed)
583
+ return false;
584
+ if (!Value.Check(ControlMessageHandshakeResponseSchema, parsed.payload)) {
585
+ log?.warn(
586
+ `${this.clientId} -- received invalid handshake resp: ${JSON.stringify(
587
+ parsed
588
+ )}`
589
+ );
590
+ return false;
591
+ }
592
+ if (!parsed.payload.status.ok) {
593
+ log?.warn(
594
+ `${this.clientId} -- received failed handshake resp: ${JSON.stringify(
595
+ parsed
596
+ )}`
597
+ );
598
+ return false;
599
+ }
600
+ const instanceId = parsed.payload.status.instanceId;
601
+ log?.debug(
602
+ `${this.clientId} -- handshake from ${parsed.from} ok (instance: ${instanceId})`
603
+ );
604
+ return { instanceId, from: parsed.from };
605
+ }
561
606
  /**
562
607
  * Manually attempts to connect to a client.
563
608
  * @param to The client ID of the node to connect to.
@@ -576,10 +621,7 @@ var ClientTransport = class extends Transport {
576
621
  }
577
622
  try {
578
623
  const conn = await reconnectPromise;
579
- this.state = "open";
580
- const requestMsg = bootRequestMessage(this.clientId, to, this.instanceId);
581
- log?.debug(`${this.clientId} -- sending boot handshake to ${to}`);
582
- conn.send(this.codec.toBuffer(requestMsg));
624
+ this.sendHandshake(to, conn);
583
625
  } catch (error) {
584
626
  const errStr = coerceErrorString(error);
585
627
  this.inflightConnectionPromises.delete(to);
@@ -597,34 +639,14 @@ var ClientTransport = class extends Transport {
597
639
  }
598
640
  }
599
641
  }
600
- receiveWithBootSequence(conn, sessionCb) {
601
- const bootHandler = (data) => {
602
- const parsed = this.parseMsg(data);
603
- if (!parsed) {
604
- conn.close();
605
- return;
606
- }
607
- if (!Value.Check(ControlMessageHandshakeResponseSchema, parsed.payload)) {
608
- log?.warn(
609
- `${this.clientId} -- received invalid handshake resp: ${JSON.stringify(parsed)}`
610
- );
611
- return;
612
- }
613
- if (!parsed.payload.status.ok) {
614
- log?.warn(
615
- `${this.clientId} -- received failed handshake resp: ${JSON.stringify(
616
- parsed
617
- )}`
618
- );
619
- return;
620
- }
621
- const serverInstanceId = parsed.payload.status.instanceId;
622
- log?.debug(
623
- `${this.clientId} -- handshake from ${parsed.from} ok (server instance: ${serverInstanceId})`
624
- );
625
- sessionCb(this.onConnect(conn, parsed.from, serverInstanceId));
626
- };
627
- return bootHandler;
642
+ sendHandshake(to, conn) {
643
+ const requestMsg = handshakeRequestMessage(
644
+ this.clientId,
645
+ to,
646
+ this.instanceId
647
+ );
648
+ log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
649
+ conn.send(this.codec.toBuffer(requestMsg));
628
650
  }
629
651
  onDisconnect(conn, connectedTo) {
630
652
  this.inflightConnectionPromises.delete(connectedTo);
@@ -641,22 +663,24 @@ var ServerTransport = class extends Transport {
641
663
  handleConnection(conn) {
642
664
  let session = void 0;
643
665
  const client = () => session?.to ?? "unknown";
644
- const bootHandler = this.receiveWithBootSequence(
645
- conn,
646
- (establishedSession) => {
647
- session = establishedSession;
648
- conn.removeDataListener(bootHandler);
649
- conn.addDataListener((data) => {
650
- const parsed = this.parseMsg(data);
651
- if (!parsed) {
652
- conn.close();
653
- return;
654
- }
655
- this.handleMsg(parsed);
656
- });
666
+ const handshakeHandler = (data) => {
667
+ const handshake = this.receiveHandshakeRequestMessage(data, conn);
668
+ if (!handshake) {
669
+ conn.close();
670
+ return;
657
671
  }
658
- );
659
- conn.addDataListener(bootHandler);
672
+ session = this.onConnect(conn, handshake.from, handshake.instanceId);
673
+ conn.removeDataListener(handshakeHandler);
674
+ conn.addDataListener((data2) => {
675
+ const parsed = this.parseMsg(data2);
676
+ if (!parsed) {
677
+ conn.close();
678
+ return;
679
+ }
680
+ this.handleMsg(parsed);
681
+ });
682
+ };
683
+ conn.addDataListener(handshakeHandler);
660
684
  conn.addCloseListener(() => {
661
685
  if (!session)
662
686
  return;
@@ -673,47 +697,57 @@ var ServerTransport = class extends Transport {
673
697
  );
674
698
  });
675
699
  }
676
- receiveWithBootSequence(conn, sessionCb) {
677
- const bootHandler = (data) => {
678
- const parsed = this.parseMsg(data);
679
- if (!parsed) {
680
- conn.close();
681
- return;
682
- }
683
- if (!Value.Check(ControlMessageHandshakeRequestSchema, parsed.payload)) {
684
- const responseMsg2 = bootResponseMessage(
685
- this.clientId,
686
- this.instanceId,
687
- parsed.from,
688
- false
689
- );
690
- conn.send(this.codec.toBuffer(responseMsg2));
691
- log?.warn(
692
- `${this.clientId} -- received invalid handshake msg: ${JSON.stringify(
693
- parsed
694
- )}`
695
- );
696
- return;
697
- }
698
- const instanceId = parsed.payload.instanceId;
699
- log?.debug(
700
- `${this.clientId} -- handshake from ${parsed.from} ok (instance id: ${instanceId}), responding with handshake success`
700
+ receiveHandshakeRequestMessage(data, conn) {
701
+ const parsed = this.parseMsg(data);
702
+ if (!parsed)
703
+ return false;
704
+ if (!Value.Check(ControlMessageHandshakeRequestSchema, parsed.payload)) {
705
+ const responseMsg2 = handshakeResponseMessage(
706
+ this.clientId,
707
+ this.instanceId,
708
+ parsed.from,
709
+ false
710
+ );
711
+ conn.send(this.codec.toBuffer(responseMsg2));
712
+ log?.warn(
713
+ `${this.clientId} -- received invalid handshake msg: ${JSON.stringify(
714
+ parsed
715
+ )}`
701
716
  );
702
- const responseMsg = bootResponseMessage(
717
+ return false;
718
+ }
719
+ const gotVersion = parsed.payload.protocolVersion;
720
+ if (gotVersion !== PROTOCOL_VERSION) {
721
+ const responseMsg2 = handshakeResponseMessage(
703
722
  this.clientId,
704
723
  this.instanceId,
705
724
  parsed.from,
706
- true
725
+ false
707
726
  );
708
- conn.send(this.codec.toBuffer(responseMsg));
709
- sessionCb(this.onConnect(conn, parsed.from, instanceId));
710
- };
711
- return bootHandler;
727
+ conn.send(this.codec.toBuffer(responseMsg2));
728
+ log?.warn(
729
+ `${this.clientId} -- received handshake msg with incompatible protocol version (got: ${gotVersion}, expected: ${PROTOCOL_VERSION})`
730
+ );
731
+ return false;
732
+ }
733
+ const instanceId = parsed.payload.instanceId;
734
+ log?.debug(
735
+ `${this.clientId} -- handshake from ${parsed.from} ok (instance id: ${instanceId}), responding with handshake success`
736
+ );
737
+ const responseMsg = handshakeResponseMessage(
738
+ this.clientId,
739
+ this.instanceId,
740
+ parsed.from,
741
+ true
742
+ );
743
+ conn.send(this.codec.toBuffer(responseMsg));
744
+ return { instanceId, from: parsed.from };
712
745
  }
713
746
  };
714
747
 
715
748
  export {
716
749
  Connection,
750
+ defaultSessionOptions,
717
751
  Session,
718
752
  Transport,
719
753
  ClientTransport,
@@ -1,5 +1,5 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { C as Connection } from './index-54e0f99c.js';
2
+ import { C as Connection } from './index-21c1b21d.js';
3
3
 
4
4
  declare class WebSocketConnection extends Connection {
5
5
  ws: WebSocket;
@@ -1,4 +1,6 @@
1
- import { Transform, TransformCallback, TransformOptions } from 'node:stream';
1
+ import { C as Connection } from './index-21c1b21d.js';
2
+ import { Socket } from 'node:net';
3
+ import stream, { Transform, TransformCallback, TransformOptions } from 'node:stream';
2
4
 
3
5
  interface LengthEncodedOptions extends TransformOptions {
4
6
  /** Maximum in-memory buffer size before we throw */
@@ -17,4 +19,17 @@ declare class Uint32LengthPrefixFraming extends Transform {
17
19
  _destroy(error: Error | null, callback: (error: Error | null) => void): void;
18
20
  }
19
21
 
20
- export { Uint32LengthPrefixFraming as U };
22
+ declare class UdsConnection extends Connection {
23
+ sock: Socket;
24
+ input: stream.Readable;
25
+ framer: Uint32LengthPrefixFraming;
26
+ constructor(sock: Socket);
27
+ addDataListener(cb: (msg: Uint8Array) => void): void;
28
+ removeDataListener(cb: (msg: Uint8Array) => void): void;
29
+ addCloseListener(cb: () => void): void;
30
+ addErrorListener(cb: (err: Error) => void): void;
31
+ send(payload: Uint8Array): boolean;
32
+ close(): void;
33
+ }
34
+
35
+ export { UdsConnection as U };
@@ -14,8 +14,8 @@ declare const TransportMessageSchema: <T extends TSchema>(t: T) => _sinclair_typ
14
14
  to: _sinclair_typebox.TString;
15
15
  seq: _sinclair_typebox.TInteger;
16
16
  ack: _sinclair_typebox.TInteger;
17
- serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>>;
18
- procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>>;
17
+ serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
18
+ procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
19
19
  streamId: _sinclair_typebox.TString;
20
20
  controlFlags: _sinclair_typebox.TInteger;
21
21
  payload: T;
@@ -31,8 +31,8 @@ declare const OpaqueTransportMessageSchema: _sinclair_typebox.TObject<{
31
31
  to: _sinclair_typebox.TString;
32
32
  seq: _sinclair_typebox.TInteger;
33
33
  ack: _sinclair_typebox.TInteger;
34
- serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>>;
35
- procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>>;
34
+ serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
35
+ procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
36
36
  streamId: _sinclair_typebox.TString;
37
37
  controlFlags: _sinclair_typebox.TInteger;
38
38
  payload: _sinclair_typebox.TUnknown;
@@ -48,6 +48,8 @@ declare const OpaqueTransportMessageSchema: _sinclair_typebox.TObject<{
48
48
  * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `serviceName` and `procedureName` must be set.
49
49
  * * If `controlFlags & StreamClosedBit == StreamClosedBit` and the kind is `stream` or `subscription`,
50
50
  * `payload` should be discarded (usually contains a control message).
51
+ * * If `controlFlags & AckBit == AckBit`, the message is an explicit acknowledgement message and doesn't
52
+ * contain any payload that is relevant to the application so should not be delivered.
51
53
  * @template Payload The type of the payload.
52
54
  */
53
55
  interface TransportMessage<Payload = Record<string, unknown>> {
@@ -126,6 +128,12 @@ declare abstract class Connection {
126
128
  */
127
129
  abstract close(): void;
128
130
  }
131
+ interface SessionOptions {
132
+ heartbeatIntervalMs: number;
133
+ heartbeatsUntilDead: number;
134
+ sessionDisconnectGraceMs: number;
135
+ codec: Codec;
136
+ }
129
137
  /**
130
138
  * A session is a higher-level abstraction that operates over the span of potentially multiple transport-level connections
131
139
  * - It’s responsible for tracking any metadata for a particular client that might need to be persisted across connections (i.e. the sendBuffer, ack, seq)
@@ -161,6 +169,7 @@ declare abstract class Connection {
161
169
  */
162
170
  declare class Session<ConnType extends Connection> {
163
171
  private codec;
172
+ private options;
164
173
  /**
165
174
  * The buffer of messages that have been sent but not yet acknowledged.
166
175
  */
@@ -196,7 +205,7 @@ declare class Session<ConnType extends Connection> {
196
205
  * The interval for sending heartbeats.
197
206
  */
198
207
  private heartbeat?;
199
- constructor(codec: Codec, from: TransportClientId, connectedTo: TransportClientId, conn: ConnType | undefined);
208
+ constructor(from: TransportClientId, connectedTo: TransportClientId, conn: ConnType | undefined, options: SessionOptions);
200
209
  /**
201
210
  * Sends a message over the session's connection.
202
211
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
@@ -252,12 +261,11 @@ declare class EventDispatcher<T extends EventTypes> {
252
261
  * @property {'destroyed'} destroyed - The transport is permanently destroyed and cannot be reopened.
253
262
  */
254
263
  type TransportStatus = 'open' | 'closed' | 'destroyed';
255
- interface TransportOptions {
264
+ type TransportOptions = {
256
265
  retryIntervalMs: number;
257
266
  retryJitterMs: number;
258
267
  retryAttemptsMax: number;
259
- codec: Codec;
260
- }
268
+ } & SessionOptions;
261
269
  /**
262
270
  * Transports manage the lifecycle (creation/deletion) of sessions and connections. Its responsibilities include:
263
271
  *
@@ -324,7 +332,7 @@ declare abstract class Transport<ConnType extends Connection> {
324
332
  /**
325
333
  * The options for this transport.
326
334
  */
327
- options: TransportOptions;
335
+ protected options: TransportOptions;
328
336
  /**
329
337
  * Creates a new Transport instance.
330
338
  * This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
@@ -375,7 +383,7 @@ declare abstract class Transport<ConnType extends Connection> {
375
383
  addEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
376
384
  /**
377
385
  * Removes a listener from this transport.
378
- * @param the type of event to unlisten on
386
+ * @param the type of event to un-listen on
379
387
  * @param handler The message handler to remove.
380
388
  */
381
389
  removeEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
@@ -406,8 +414,13 @@ declare abstract class ClientTransport<ConnType extends Connection> extends Tran
406
414
  */
407
415
  inflightConnectionPromises: Map<TransportClientId, Promise<ConnType>>;
408
416
  tryReconnecting: boolean;
409
- constructor(clientId: TransportClientId, providedOptions?: Partial<TransportOptions>);
417
+ connectedTo: TransportClientId;
418
+ constructor(clientId: TransportClientId, connectedTo: TransportClientId, providedOptions?: Partial<TransportOptions>);
410
419
  protected handleConnection(conn: ConnType, to: TransportClientId): void;
420
+ receiveHandshakeResponseMessage(data: Uint8Array): false | {
421
+ instanceId: string;
422
+ from: string;
423
+ };
411
424
  /**
412
425
  * Abstract method that creates a new {@link Connection} object.
413
426
  * This should call {@link handleConnection} when the connection is created.
@@ -422,13 +435,16 @@ declare abstract class ClientTransport<ConnType extends Connection> extends Tran
422
435
  * @param to The client ID of the node to connect to.
423
436
  */
424
437
  connect(to: TransportClientId, attempt?: number): Promise<void>;
425
- private receiveWithBootSequence;
438
+ protected sendHandshake(to: TransportClientId, conn: ConnType): void;
426
439
  protected onDisconnect(conn: ConnType, connectedTo: string): void;
427
440
  }
428
441
  declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
429
442
  constructor(clientId: TransportClientId, providedOptions?: Partial<TransportOptions>);
430
443
  protected handleConnection(conn: ConnType): void;
431
- protected receiveWithBootSequence(conn: ConnType, sessionCb: (sess: Session<ConnType>) => void): (data: Uint8Array) => void;
444
+ receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType): false | {
445
+ instanceId: string;
446
+ from: string;
447
+ };
432
448
  }
433
449
 
434
450
  export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, ServerTransport as S, Transport as T, ClientTransport as a, TransportClientId as b, TransportOptions as c, Session as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, TransportMessage as g, isStreamClose as h, isStreamOpen as i, EventTypes as j, EventHandler as k };