@replit/river 0.200.0-rc.6 → 0.200.0-rc.7

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 (68) hide show
  1. package/README.md +2 -2
  2. package/dist/{chunk-TMNVRR5R.js → chunk-3XKJOFZA.js} +193 -90
  3. package/dist/chunk-3XKJOFZA.js.map +1 -0
  4. package/dist/{chunk-IGNFE3QW.js → chunk-BZBEE2VR.js} +2 -2
  5. package/dist/chunk-BZBEE2VR.js.map +1 -0
  6. package/dist/{chunk-WE2PAPNC.js → chunk-CXPZSAU4.js} +102 -95
  7. package/dist/chunk-CXPZSAU4.js.map +1 -0
  8. package/dist/{chunk-WF3AW2CB.js → chunk-F2E7ILHW.js} +41 -45
  9. package/dist/chunk-F2E7ILHW.js.map +1 -0
  10. package/dist/{chunk-NOLXEIRP.js → chunk-U4W75CMT.js} +3 -3
  11. package/dist/chunk-U4W75CMT.js.map +1 -0
  12. package/dist/{chunk-GXRIBO3N.js → chunk-VLW5OKZG.js} +2 -2
  13. package/dist/{chunk-MXU6DJVG.js → chunk-XIJVDPYY.js} +161 -159
  14. package/dist/chunk-XIJVDPYY.js.map +1 -0
  15. package/dist/{client-f56a6da3.d.ts → client-829bf1f9.d.ts} +3 -1
  16. package/dist/{connection-6031a354.d.ts → connection-5e67d641.d.ts} +1 -1
  17. package/dist/{context-73df8978.d.ts → context-9eabf54f.d.ts} +132 -81
  18. package/dist/router/index.cjs +162 -160
  19. package/dist/router/index.cjs.map +1 -1
  20. package/dist/router/index.d.cts +7 -7
  21. package/dist/router/index.d.ts +7 -7
  22. package/dist/router/index.js +6 -6
  23. package/dist/{server-9f31d98f.d.ts → server-d82a2d9b.d.ts} +8 -3
  24. package/dist/{services-69d72cd5.d.ts → services-6a446f04.d.ts} +157 -139
  25. package/dist/transport/impls/ws/client.cjs +285 -178
  26. package/dist/transport/impls/ws/client.cjs.map +1 -1
  27. package/dist/transport/impls/ws/client.d.cts +3 -3
  28. package/dist/transport/impls/ws/client.d.ts +3 -3
  29. package/dist/transport/impls/ws/client.js +7 -7
  30. package/dist/transport/impls/ws/server.cjs +224 -128
  31. package/dist/transport/impls/ws/server.cjs.map +1 -1
  32. package/dist/transport/impls/ws/server.d.cts +3 -3
  33. package/dist/transport/impls/ws/server.d.ts +3 -3
  34. package/dist/transport/impls/ws/server.js +5 -5
  35. package/dist/transport/index.cjs +322 -218
  36. package/dist/transport/index.cjs.map +1 -1
  37. package/dist/transport/index.d.cts +3 -3
  38. package/dist/transport/index.d.ts +3 -3
  39. package/dist/transport/index.js +7 -7
  40. package/dist/util/testHelpers.cjs +227 -133
  41. package/dist/util/testHelpers.cjs.map +1 -1
  42. package/dist/util/testHelpers.d.cts +15 -12
  43. package/dist/util/testHelpers.d.ts +15 -12
  44. package/dist/util/testHelpers.js +41 -43
  45. package/dist/util/testHelpers.js.map +1 -1
  46. package/package.json +1 -1
  47. package/dist/chunk-IGNFE3QW.js.map +0 -1
  48. package/dist/chunk-MU25KVV7.js +0 -112
  49. package/dist/chunk-MU25KVV7.js.map +0 -1
  50. package/dist/chunk-MXU6DJVG.js.map +0 -1
  51. package/dist/chunk-NOLXEIRP.js.map +0 -1
  52. package/dist/chunk-TMNVRR5R.js.map +0 -1
  53. package/dist/chunk-WE2PAPNC.js.map +0 -1
  54. package/dist/chunk-WF3AW2CB.js.map +0 -1
  55. package/dist/connection-11991b13.d.ts +0 -31
  56. package/dist/transport/impls/uds/client.cjs +0 -1696
  57. package/dist/transport/impls/uds/client.cjs.map +0 -1
  58. package/dist/transport/impls/uds/client.d.cts +0 -18
  59. package/dist/transport/impls/uds/client.d.ts +0 -18
  60. package/dist/transport/impls/uds/client.js +0 -38
  61. package/dist/transport/impls/uds/client.js.map +0 -1
  62. package/dist/transport/impls/uds/server.cjs +0 -1663
  63. package/dist/transport/impls/uds/server.cjs.map +0 -1
  64. package/dist/transport/impls/uds/server.d.cts +0 -19
  65. package/dist/transport/impls/uds/server.d.ts +0 -19
  66. package/dist/transport/impls/uds/server.js +0 -33
  67. package/dist/transport/impls/uds/server.js.map +0 -1
  68. /package/dist/{chunk-GXRIBO3N.js.map → chunk-VLW5OKZG.js.map} +0 -0
@@ -41,12 +41,11 @@ __export(testHelpers_exports, {
41
41
  dummySession: () => dummySession,
42
42
  getIteratorFromStream: () => getIteratorFromStream,
43
43
  getTransportConnections: () => getTransportConnections,
44
- getUnixSocketPath: () => getUnixSocketPath,
45
44
  iterNext: () => iterNext,
46
45
  numberOfConnections: () => numberOfConnections,
47
- onUdsServeReady: () => onUdsServeReady,
48
46
  onWsServerReady: () => onWsServerReady,
49
47
  payloadToTransportMessage: () => payloadToTransportMessage,
48
+ testingClientSessionOptions: () => testingClientSessionOptions,
50
49
  testingSessionOptions: () => testingSessionOptions,
51
50
  waitForMessage: () => waitForMessage
52
51
  });
@@ -359,7 +358,7 @@ var UNCAUGHT_ERROR_CODE = "UNCAUGHT_ERROR";
359
358
  var UNEXPECTED_DISCONNECT_CODE = "UNEXPECTED_DISCONNECT";
360
359
  var INVALID_REQUEST_CODE = "INVALID_REQUEST";
361
360
  var ABORT_CODE = "ABORT";
362
- var OutputReaderErrorSchema = import_typebox2.Type.Object({
361
+ var ResponseReaderErrorSchema = import_typebox2.Type.Object({
363
362
  code: import_typebox2.Type.Union([
364
363
  import_typebox2.Type.Literal(INTERNAL_RIVER_ERROR_CODE),
365
364
  import_typebox2.Type.Literal(UNCAUGHT_ERROR_CODE),
@@ -369,7 +368,7 @@ var OutputReaderErrorSchema = import_typebox2.Type.Object({
369
368
  ]),
370
369
  message: import_typebox2.Type.String()
371
370
  });
372
- var InputReaderErrorSchema = import_typebox2.Type.Object({
371
+ var RequestReaderErrorSchema = import_typebox2.Type.Object({
373
372
  code: import_typebox2.Type.Union([
374
373
  import_typebox2.Type.Literal(UNCAUGHT_ERROR_CODE),
375
374
  import_typebox2.Type.Literal(UNEXPECTED_DISCONNECT_CODE),
@@ -480,7 +479,7 @@ function isAck(controlFlag) {
480
479
  var import_api = require("@opentelemetry/api");
481
480
 
482
481
  // package.json
483
- var version = "0.200.0-rc.6";
482
+ var version = "0.200.0-rc.7";
484
483
 
485
484
  // tracing/index.ts
486
485
  function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
@@ -510,9 +509,6 @@ function coerceErrorString(err) {
510
509
  return `[coerced to error] ${String(err)}`;
511
510
  }
512
511
 
513
- // util/testHelpers.ts
514
- var import_nanoid2 = require("nanoid");
515
-
516
512
  // codec/json.ts
517
513
  var encoder = new TextEncoder();
518
514
  var decoder = new TextDecoder();
@@ -575,7 +571,7 @@ var defaultTransportOptions = {
575
571
  codec: NaiveJsonCodec
576
572
  };
577
573
  var defaultConnectionRetryOptions = {
578
- baseIntervalMs: 250,
574
+ baseIntervalMs: 150,
579
575
  maxJitterMs: 200,
580
576
  maxBackoffMs: 32e3,
581
577
  attemptBudgetCapacity: 5,
@@ -642,7 +638,7 @@ var CommonSession = class extends StateMachineState {
642
638
  from;
643
639
  options;
644
640
  log;
645
- constructor(from, options, log) {
641
+ constructor({ from, options, log }) {
646
642
  super();
647
643
  this.from = from;
648
644
  this.options = options;
@@ -684,8 +680,9 @@ var IdentifiedSession = class extends CommonSession {
684
680
  */
685
681
  ack;
686
682
  sendBuffer;
687
- constructor(id, from, to, seq, ack, sendBuffer, telemetry, options, protocolVersion, log) {
688
- super(from, options, log);
683
+ constructor(props) {
684
+ const { id, to, seq, ack, sendBuffer, telemetry, log, protocolVersion } = props;
685
+ super(props);
689
686
  this.id = id;
690
687
  this.to = to;
691
688
  this.seq = seq;
@@ -741,23 +738,23 @@ var SessionConnecting = class extends IdentifiedSession {
741
738
  connPromise;
742
739
  listeners;
743
740
  connectionTimeout;
744
- constructor(connPromise, listeners, ...args) {
745
- super(...args);
746
- this.connPromise = connPromise;
747
- this.listeners = listeners;
741
+ constructor(props) {
742
+ super(props);
743
+ this.connPromise = props.connPromise;
744
+ this.listeners = props.listeners;
748
745
  this.connectionTimeout = setTimeout(() => {
749
- listeners.onConnectionTimeout();
746
+ this.listeners.onConnectionTimeout();
750
747
  }, this.options.connectionTimeoutMs);
751
- connPromise.then(
748
+ this.connPromise.then(
752
749
  (conn) => {
753
750
  if (this._isConsumed)
754
751
  return;
755
- listeners.onConnectionEstablished(conn);
752
+ this.listeners.onConnectionEstablished(conn);
756
753
  },
757
754
  (err) => {
758
755
  if (this._isConsumed)
759
756
  return;
760
- listeners.onConnectionFailed(err);
757
+ this.listeners.onConnectionFailed(err);
761
758
  }
762
759
  );
763
760
  }
@@ -783,9 +780,9 @@ var SessionNoConnection = class extends IdentifiedSession {
783
780
  state = "NoConnection" /* NoConnection */;
784
781
  listeners;
785
782
  gracePeriodTimeout;
786
- constructor(listeners, ...args) {
787
- super(...args);
788
- this.listeners = listeners;
783
+ constructor(props) {
784
+ super(props);
785
+ this.listeners = props.listeners;
789
786
  this.gracePeriodTimeout = setTimeout(() => {
790
787
  this.listeners.onSessionGracePeriodElapsed();
791
788
  }, this.options.sessionDisconnectGraceMs);
@@ -808,16 +805,16 @@ var SessionWaitingForHandshake = class extends CommonSession {
808
805
  conn;
809
806
  listeners;
810
807
  handshakeTimeout;
811
- constructor(conn, listeners, ...args) {
812
- super(...args);
813
- this.conn = conn;
814
- this.listeners = listeners;
808
+ constructor(props) {
809
+ super(props);
810
+ this.conn = props.conn;
811
+ this.listeners = props.listeners;
815
812
  this.handshakeTimeout = setTimeout(() => {
816
- listeners.onHandshakeTimeout();
813
+ this.listeners.onHandshakeTimeout();
817
814
  }, this.options.handshakeTimeoutMs);
818
815
  this.conn.addDataListener(this.onHandshakeData);
819
- this.conn.addErrorListener(listeners.onConnectionErrored);
820
- this.conn.addCloseListener(listeners.onConnectionClosed);
816
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
817
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
821
818
  }
822
819
  onHandshakeData = (msg) => {
823
820
  const parsedMsg = this.parseMsg(msg);
@@ -854,16 +851,16 @@ var SessionHandshaking = class extends IdentifiedSession {
854
851
  conn;
855
852
  listeners;
856
853
  handshakeTimeout;
857
- constructor(conn, listeners, ...args) {
858
- super(...args);
859
- this.conn = conn;
860
- this.listeners = listeners;
854
+ constructor(props) {
855
+ super(props);
856
+ this.conn = props.conn;
857
+ this.listeners = props.listeners;
861
858
  this.handshakeTimeout = setTimeout(() => {
862
- listeners.onHandshakeTimeout();
859
+ this.listeners.onHandshakeTimeout();
863
860
  }, this.options.handshakeTimeoutMs);
864
861
  this.conn.addDataListener(this.onHandshakeData);
865
- this.conn.addErrorListener(listeners.onConnectionErrored);
866
- this.conn.addCloseListener(listeners.onConnectionClosed);
862
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
863
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
867
864
  }
868
865
  onHandshakeData = (msg) => {
869
866
  const parsedMsg = this.parseMsg(msg);
@@ -897,9 +894,7 @@ var SessionConnected = class extends IdentifiedSession {
897
894
  listeners;
898
895
  heartbeatHandle;
899
896
  heartbeatMisses = 0;
900
- get isActivelyHeartbeating() {
901
- return this.heartbeatHandle !== void 0;
902
- }
897
+ isActivelyHeartbeating;
903
898
  updateBookkeeping(ack, seq) {
904
899
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq >= ack);
905
900
  this.ack = seq + 1;
@@ -911,13 +906,13 @@ var SessionConnected = class extends IdentifiedSession {
911
906
  this.conn.send(this.options.codec.toBuffer(constructedMsg));
912
907
  return constructedMsg.id;
913
908
  }
914
- constructor(conn, listeners, ...args) {
915
- super(...args);
916
- this.conn = conn;
917
- this.listeners = listeners;
909
+ constructor(props) {
910
+ super(props);
911
+ this.conn = props.conn;
912
+ this.listeners = props.listeners;
918
913
  this.conn.addDataListener(this.onMessageData);
919
- this.conn.addCloseListener(listeners.onConnectionClosed);
920
- this.conn.addErrorListener(listeners.onConnectionErrored);
914
+ this.conn.addCloseListener(this.listeners.onConnectionClosed);
915
+ this.conn.addErrorListener(this.listeners.onConnectionErrored);
921
916
  if (this.sendBuffer.length > 0) {
922
917
  this.log?.debug(
923
918
  `sending ${this.sendBuffer.length} buffered messages`,
@@ -925,10 +920,9 @@ var SessionConnected = class extends IdentifiedSession {
925
920
  );
926
921
  }
927
922
  for (const msg of this.sendBuffer) {
928
- conn.send(this.options.codec.toBuffer(msg));
923
+ this.conn.send(this.options.codec.toBuffer(msg));
929
924
  }
930
- }
931
- startActiveHeartbeat() {
925
+ this.isActivelyHeartbeating = false;
932
926
  this.heartbeatHandle = setInterval(() => {
933
927
  const misses = this.heartbeatMisses;
934
928
  const missDuration = misses * this.options.heartbeatIntervalMs;
@@ -943,11 +937,17 @@ var SessionConnected = class extends IdentifiedSession {
943
937
  this.heartbeatHandle = void 0;
944
938
  return;
945
939
  }
946
- this.sendHeartbeat();
940
+ if (this.isActivelyHeartbeating) {
941
+ this.sendHeartbeat();
942
+ }
947
943
  this.heartbeatMisses++;
948
944
  }, this.options.heartbeatIntervalMs);
949
945
  }
946
+ startActiveHeartbeat() {
947
+ this.isActivelyHeartbeating = true;
948
+ }
950
949
  sendHeartbeat() {
950
+ this.log?.debug("sending heartbeat", this.loggingMetadata);
951
951
  this.send({
952
952
  streamId: "heartbeat",
953
953
  controlFlags: 1 /* AckBit */,
@@ -1015,54 +1015,78 @@ var SessionConnected = class extends IdentifiedSession {
1015
1015
  }
1016
1016
  };
1017
1017
 
1018
+ // transport/sessionStateMachine/SessionBackingOff.ts
1019
+ var SessionBackingOff = class extends IdentifiedSession {
1020
+ state = "BackingOff" /* BackingOff */;
1021
+ listeners;
1022
+ backoffTimeout;
1023
+ constructor(props) {
1024
+ super(props);
1025
+ this.listeners = props.listeners;
1026
+ this.backoffTimeout = setTimeout(() => {
1027
+ this.listeners.onBackoffFinished();
1028
+ }, props.backoffMs);
1029
+ }
1030
+ _handleClose() {
1031
+ super._handleClose();
1032
+ }
1033
+ _handleStateExit() {
1034
+ super._handleStateExit();
1035
+ if (this.backoffTimeout) {
1036
+ clearTimeout(this.backoffTimeout);
1037
+ this.backoffTimeout = void 0;
1038
+ }
1039
+ }
1040
+ };
1041
+
1018
1042
  // transport/sessionStateMachine/transitions.ts
1019
1043
  function inheritSharedSession(session) {
1020
- return [
1021
- session.id,
1022
- session.from,
1023
- session.to,
1024
- session.seq,
1025
- session.ack,
1026
- session.sendBuffer,
1027
- session.telemetry,
1028
- session.options,
1029
- session.protocolVersion,
1030
- session.log
1031
- ];
1044
+ return {
1045
+ id: session.id,
1046
+ from: session.from,
1047
+ to: session.to,
1048
+ seq: session.seq,
1049
+ ack: session.ack,
1050
+ sendBuffer: session.sendBuffer,
1051
+ telemetry: session.telemetry,
1052
+ options: session.options,
1053
+ log: session.log,
1054
+ protocolVersion: session.protocolVersion
1055
+ };
1032
1056
  }
1033
1057
  var SessionStateGraph = {
1034
1058
  entrypoints: {
1035
- NoConnection(to, from, listeners, options, protocolVersion, log) {
1059
+ NoConnection: (to, from, listeners, options, protocolVersion, log) => {
1036
1060
  const id = `session-${generateId()}`;
1037
1061
  const telemetry = createSessionTelemetryInfo(id, to, from);
1038
1062
  const sendBuffer = [];
1039
- const session = new SessionNoConnection(
1063
+ const session = new SessionNoConnection({
1040
1064
  listeners,
1041
1065
  id,
1042
1066
  from,
1043
1067
  to,
1044
- 0,
1045
- 0,
1068
+ seq: 0,
1069
+ ack: 0,
1046
1070
  sendBuffer,
1047
1071
  telemetry,
1048
1072
  options,
1049
1073
  protocolVersion,
1050
1074
  log
1051
- );
1075
+ });
1052
1076
  session.log?.info(`session ${session.id} created in NoConnection state`, {
1053
1077
  ...session.loggingMetadata,
1054
1078
  tags: ["state-transition"]
1055
1079
  });
1056
1080
  return session;
1057
1081
  },
1058
- WaitingForHandshake(from, conn, listeners, options, log) {
1059
- const session = new SessionWaitingForHandshake(
1082
+ WaitingForHandshake: (from, conn, listeners, options, log) => {
1083
+ const session = new SessionWaitingForHandshake({
1060
1084
  conn,
1061
1085
  listeners,
1062
1086
  from,
1063
1087
  options,
1064
1088
  log
1065
- );
1089
+ });
1066
1090
  session.log?.info(`session created in WaitingForHandshake state`, {
1067
1091
  ...session.loggingMetadata,
1068
1092
  tags: ["state-transition"]
@@ -1074,16 +1098,33 @@ var SessionStateGraph = {
1074
1098
  // After a session is transitioned, any usage of the old session will throw.
1075
1099
  transition: {
1076
1100
  // happy path transitions
1077
- NoConnectionToConnecting(oldSession, connPromise, listeners) {
1101
+ NoConnectionToBackingOff: (oldSession, backoffMs, listeners) => {
1078
1102
  const carriedState = inheritSharedSession(oldSession);
1079
1103
  oldSession._handleStateExit();
1080
- const session = new SessionConnecting(
1081
- connPromise,
1104
+ const session = new SessionBackingOff({
1105
+ backoffMs,
1082
1106
  listeners,
1083
1107
  ...carriedState
1108
+ });
1109
+ session.log?.info(
1110
+ `session ${session.id} transition from NoConnection to BackingOff`,
1111
+ {
1112
+ ...session.loggingMetadata,
1113
+ tags: ["state-transition"]
1114
+ }
1084
1115
  );
1116
+ return session;
1117
+ },
1118
+ BackingOffToConnecting: (oldSession, connPromise, listeners) => {
1119
+ const carriedState = inheritSharedSession(oldSession);
1120
+ oldSession._handleStateExit();
1121
+ const session = new SessionConnecting({
1122
+ connPromise,
1123
+ listeners,
1124
+ ...carriedState
1125
+ });
1085
1126
  session.log?.info(
1086
- `session ${session.id} transition from NoConnection to Connecting`,
1127
+ `session ${session.id} transition from BackingOff to Connecting`,
1087
1128
  {
1088
1129
  ...session.loggingMetadata,
1089
1130
  tags: ["state-transition"]
@@ -1091,10 +1132,14 @@ var SessionStateGraph = {
1091
1132
  );
1092
1133
  return session;
1093
1134
  },
1094
- ConnectingToHandshaking(oldSession, conn, listeners) {
1135
+ ConnectingToHandshaking: (oldSession, conn, listeners) => {
1095
1136
  const carriedState = inheritSharedSession(oldSession);
1096
1137
  oldSession._handleStateExit();
1097
- const session = new SessionHandshaking(conn, listeners, ...carriedState);
1138
+ const session = new SessionHandshaking({
1139
+ conn,
1140
+ listeners,
1141
+ ...carriedState
1142
+ });
1098
1143
  session.log?.info(
1099
1144
  `session ${session.id} transition from Connecting to Handshaking`,
1100
1145
  {
@@ -1104,11 +1149,15 @@ var SessionStateGraph = {
1104
1149
  );
1105
1150
  return session;
1106
1151
  },
1107
- HandshakingToConnected(oldSession, listeners) {
1152
+ HandshakingToConnected: (oldSession, listeners) => {
1108
1153
  const carriedState = inheritSharedSession(oldSession);
1109
1154
  const conn = oldSession.conn;
1110
1155
  oldSession._handleStateExit();
1111
- const session = new SessionConnected(conn, listeners, ...carriedState);
1156
+ const session = new SessionConnected({
1157
+ conn,
1158
+ listeners,
1159
+ ...carriedState
1160
+ });
1112
1161
  session.log?.info(
1113
1162
  `session ${session.id} transition from Handshaking to Connected`,
1114
1163
  {
@@ -1118,7 +1167,7 @@ var SessionStateGraph = {
1118
1167
  );
1119
1168
  return session;
1120
1169
  },
1121
- WaitingForHandshakeToConnected(pendingSession, oldSession, sessionId, to, propagationCtx, listeners, protocolVersion) {
1170
+ WaitingForHandshakeToConnected: (pendingSession, oldSession, sessionId, to, propagationCtx, listeners, protocolVersion) => {
1122
1171
  const conn = pendingSession.conn;
1123
1172
  const { from, options } = pendingSession;
1124
1173
  const carriedState = oldSession ? (
@@ -1126,22 +1175,31 @@ var SessionStateGraph = {
1126
1175
  inheritSharedSession(oldSession)
1127
1176
  ) : (
1128
1177
  // old session does not exist, create new state
1129
- [
1130
- sessionId,
1178
+ {
1179
+ id: sessionId,
1131
1180
  from,
1132
1181
  to,
1133
- 0,
1134
- 0,
1135
- [],
1136
- createSessionTelemetryInfo(sessionId, to, from, propagationCtx),
1182
+ seq: 0,
1183
+ ack: 0,
1184
+ sendBuffer: [],
1185
+ telemetry: createSessionTelemetryInfo(
1186
+ sessionId,
1187
+ to,
1188
+ from,
1189
+ propagationCtx
1190
+ ),
1137
1191
  options,
1138
- protocolVersion,
1139
- pendingSession.log
1140
- ]
1192
+ log: pendingSession.log,
1193
+ protocolVersion
1194
+ }
1141
1195
  );
1142
1196
  pendingSession._handleStateExit();
1143
1197
  oldSession?._handleStateExit();
1144
- const session = new SessionConnected(conn, listeners, ...carriedState);
1198
+ const session = new SessionConnected({
1199
+ conn,
1200
+ listeners,
1201
+ ...carriedState
1202
+ });
1145
1203
  session.log?.info(
1146
1204
  `session ${session.id} transition from WaitingForHandshake to Connected`,
1147
1205
  {
@@ -1152,11 +1210,24 @@ var SessionStateGraph = {
1152
1210
  return session;
1153
1211
  },
1154
1212
  // disconnect paths
1155
- ConnectingToNoConnection(oldSession, listeners) {
1213
+ BackingOffToNoConnection: (oldSession, listeners) => {
1214
+ const carriedState = inheritSharedSession(oldSession);
1215
+ oldSession._handleStateExit();
1216
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1217
+ session.log?.info(
1218
+ `session ${session.id} transition from BackingOff to NoConnection`,
1219
+ {
1220
+ ...session.loggingMetadata,
1221
+ tags: ["state-transition"]
1222
+ }
1223
+ );
1224
+ return session;
1225
+ },
1226
+ ConnectingToNoConnection: (oldSession, listeners) => {
1156
1227
  const carriedState = inheritSharedSession(oldSession);
1157
1228
  oldSession.bestEffortClose();
1158
1229
  oldSession._handleStateExit();
1159
- const session = new SessionNoConnection(listeners, ...carriedState);
1230
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1160
1231
  session.log?.info(
1161
1232
  `session ${session.id} transition from Connecting to NoConnection`,
1162
1233
  {
@@ -1166,11 +1237,11 @@ var SessionStateGraph = {
1166
1237
  );
1167
1238
  return session;
1168
1239
  },
1169
- HandshakingToNoConnection(oldSession, listeners) {
1240
+ HandshakingToNoConnection: (oldSession, listeners) => {
1170
1241
  const carriedState = inheritSharedSession(oldSession);
1171
1242
  oldSession.conn.close();
1172
1243
  oldSession._handleStateExit();
1173
- const session = new SessionNoConnection(listeners, ...carriedState);
1244
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1174
1245
  session.log?.info(
1175
1246
  `session ${session.id} transition from Handshaking to NoConnection`,
1176
1247
  {
@@ -1180,11 +1251,11 @@ var SessionStateGraph = {
1180
1251
  );
1181
1252
  return session;
1182
1253
  },
1183
- ConnectedToNoConnection(oldSession, listeners) {
1254
+ ConnectedToNoConnection: (oldSession, listeners) => {
1184
1255
  const carriedState = inheritSharedSession(oldSession);
1185
1256
  oldSession.conn.close();
1186
1257
  oldSession._handleStateExit();
1187
- const session = new SessionNoConnection(listeners, ...carriedState);
1258
+ const session = new SessionNoConnection({ listeners, ...carriedState });
1188
1259
  session.log?.info(
1189
1260
  `session ${session.id} transition from Connected to NoConnection`,
1190
1261
  {
@@ -1196,6 +1267,31 @@ var SessionStateGraph = {
1196
1267
  }
1197
1268
  }
1198
1269
  };
1270
+ var transitions = SessionStateGraph.transition;
1271
+ var ClientSessionStateGraph = {
1272
+ entrypoint: SessionStateGraph.entrypoints.NoConnection,
1273
+ transition: {
1274
+ // happy paths
1275
+ NoConnectionToBackingOff: transitions.NoConnectionToBackingOff,
1276
+ BackingOffToConnecting: transitions.BackingOffToConnecting,
1277
+ ConnectingToHandshaking: transitions.ConnectingToHandshaking,
1278
+ HandshakingToConnected: transitions.HandshakingToConnected,
1279
+ // disconnect paths
1280
+ BackingOffToNoConnection: transitions.BackingOffToNoConnection,
1281
+ ConnectingToNoConnection: transitions.ConnectingToNoConnection,
1282
+ HandshakingToNoConnection: transitions.HandshakingToNoConnection,
1283
+ ConnectedToNoConnection: transitions.ConnectedToNoConnection
1284
+ }
1285
+ };
1286
+ var ServerSessionStateGraph = {
1287
+ entrypoint: SessionStateGraph.entrypoints.WaitingForHandshake,
1288
+ transition: {
1289
+ // happy paths
1290
+ WaitingForHandshakeToConnected: transitions.WaitingForHandshakeToConnected,
1291
+ // disconnect paths
1292
+ ConnectedToNoConnection: transitions.ConnectedToNoConnection
1293
+ }
1294
+ };
1199
1295
 
1200
1296
  // util/testHelpers.ts
1201
1297
  function createLocalWebSocketClient(port) {
@@ -1218,11 +1314,6 @@ function onWsServerReady(server) {
1218
1314
  });
1219
1315
  });
1220
1316
  }
1221
- function onUdsServeReady(server, path) {
1222
- return new Promise((resolve) => {
1223
- server.listen(path, resolve);
1224
- });
1225
- }
1226
1317
  function getIteratorFromStream(readStream) {
1227
1318
  return readStream[Symbol.asyncIterator]();
1228
1319
  }
@@ -1264,6 +1355,7 @@ function catchProcError(err) {
1264
1355
  return Err({ code: UNCAUGHT_ERROR_CODE, message: errorMsg });
1265
1356
  }
1266
1357
  var testingSessionOptions = defaultTransportOptions;
1358
+ var testingClientSessionOptions = defaultClientTransportOptions;
1267
1359
  function dummySession() {
1268
1360
  return SessionStateGraph.entrypoints.NoConnection(
1269
1361
  "client",
@@ -1290,10 +1382,13 @@ function dummyCtx(state, session, extendedContext) {
1290
1382
  }
1291
1383
  function asClientRpc(state, proc, extendedContext, session = dummySession()) {
1292
1384
  return async (msg) => {
1293
- return proc.handler(dummyCtx(state, session, extendedContext), msg).catch(catchProcError);
1385
+ return proc.handler({
1386
+ ctx: dummyCtx(state, session, extendedContext),
1387
+ reqInit: msg
1388
+ }).catch(catchProcError);
1294
1389
  };
1295
1390
  }
1296
- function createOutputPipe() {
1391
+ function createResponsePipe() {
1297
1392
  const reader = new ReadStreamImpl(() => {
1298
1393
  void Promise.resolve().then(() => {
1299
1394
  writer.triggerCloseRequest();
@@ -1311,7 +1406,7 @@ function createOutputPipe() {
1311
1406
  });
1312
1407
  return { reader, writer };
1313
1408
  }
1314
- function createInputPipe() {
1409
+ function createRequestPipe() {
1315
1410
  const reader = new ReadStreamImpl(() => {
1316
1411
  void Promise.resolve().then(() => {
1317
1412
  writer.triggerCloseRequest();
@@ -1327,40 +1422,40 @@ function createInputPipe() {
1327
1422
  });
1328
1423
  return { reader, writer };
1329
1424
  }
1330
- function asClientStream(state, proc, init, extendedContext, session = dummySession()) {
1331
- const inputPipe = createInputPipe();
1332
- const outputPipe = createOutputPipe();
1333
- void proc.handler(
1334
- dummyCtx(state, session, extendedContext),
1335
- init ?? {},
1336
- inputPipe.reader,
1337
- outputPipe.writer
1338
- ).catch((err) => outputPipe.writer.write(catchProcError(err)));
1339
- return [inputPipe.writer, outputPipe.reader];
1425
+ function asClientStream(state, proc, reqInit, extendedContext, session = dummySession()) {
1426
+ const requestPipe = createRequestPipe();
1427
+ const responsePipe = createResponsePipe();
1428
+ void proc.handler({
1429
+ ctx: dummyCtx(state, session, extendedContext),
1430
+ reqInit: reqInit ?? {},
1431
+ reqReader: requestPipe.reader,
1432
+ resWriter: responsePipe.writer
1433
+ }).catch((err) => responsePipe.writer.write(catchProcError(err)));
1434
+ return {
1435
+ reqWriter: requestPipe.writer,
1436
+ resReader: responsePipe.reader
1437
+ };
1340
1438
  }
1341
1439
  function asClientSubscription(state, proc, extendedContext, session = dummySession()) {
1342
- const outputPipe = createOutputPipe();
1440
+ const responsePipe = createResponsePipe();
1343
1441
  return (msg) => {
1344
- void proc.handler(
1345
- dummyCtx(state, session, extendedContext),
1346
- msg,
1347
- outputPipe.writer
1348
- ).catch((err) => outputPipe.writer.write(catchProcError(err)));
1349
- return outputPipe.reader;
1442
+ void proc.handler({
1443
+ ctx: dummyCtx(state, session, extendedContext),
1444
+ reqInit: msg,
1445
+ resWriter: responsePipe.writer
1446
+ }).catch((err) => responsePipe.writer.write(catchProcError(err)));
1447
+ return { resReader: responsePipe.reader };
1350
1448
  };
1351
1449
  }
1352
- function asClientUpload(state, proc, init, extendedContext, session = dummySession()) {
1353
- const inputPipe = createInputPipe();
1354
- const result = proc.handler(
1355
- dummyCtx(state, session, extendedContext),
1356
- init ?? {},
1357
- inputPipe.reader
1358
- ).catch(catchProcError);
1359
- return [inputPipe.writer, () => result];
1450
+ function asClientUpload(state, proc, reqInit, extendedContext, session = dummySession()) {
1451
+ const requestPipe = createRequestPipe();
1452
+ const result = proc.handler({
1453
+ ctx: dummyCtx(state, session, extendedContext),
1454
+ reqInit: reqInit ?? {},
1455
+ reqReader: requestPipe.reader
1456
+ }).catch(catchProcError);
1457
+ return [requestPipe.writer, () => result];
1360
1458
  }
1361
- var getUnixSocketPath = () => {
1362
- return `/tmp/${(0, import_nanoid2.nanoid)()}.sock`;
1363
- };
1364
1459
  function getTransportConnections(transport) {
1365
1460
  const connections = [];
1366
1461
  for (const session of transport.sessions.values()) {
@@ -1391,12 +1486,11 @@ function closeAllConnections(transport) {
1391
1486
  dummySession,
1392
1487
  getIteratorFromStream,
1393
1488
  getTransportConnections,
1394
- getUnixSocketPath,
1395
1489
  iterNext,
1396
1490
  numberOfConnections,
1397
- onUdsServeReady,
1398
1491
  onWsServerReady,
1399
1492
  payloadToTransportMessage,
1493
+ testingClientSessionOptions,
1400
1494
  testingSessionOptions,
1401
1495
  waitForMessage
1402
1496
  });