@replit/river 0.13.4 → 0.13.6

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 (37) hide show
  1. package/dist/{builder-6f4630d0.d.ts → builder-533e1324.d.ts} +1 -1
  2. package/dist/{chunk-5V6B7TM3.js → chunk-3LGEBL5F.js} +1 -1
  3. package/dist/{chunk-ASZ3VDCS.js → chunk-E2CP4UWB.js} +2 -2
  4. package/dist/{chunk-FIX2F6VT.js → chunk-WCSTFZOJ.js} +1 -1
  5. package/dist/{chunk-MCTB3NYK.js → chunk-YXVFITRS.js} +21 -21
  6. package/dist/{connection-8d0efae0.d.ts → connection-1f994b63.d.ts} +1 -1
  7. package/dist/{connection-fe33e684.d.ts → connection-f46114a1.d.ts} +1 -1
  8. package/dist/{index-5c55c0d3.d.ts → index-2154021c.d.ts} +3 -5
  9. package/dist/router/index.cjs +2 -2
  10. package/dist/router/index.d.cts +3 -3
  11. package/dist/router/index.d.ts +3 -3
  12. package/dist/router/index.js +1 -1
  13. package/dist/transport/impls/uds/client.cjs +16 -21
  14. package/dist/transport/impls/uds/client.d.cts +2 -2
  15. package/dist/transport/impls/uds/client.d.ts +2 -2
  16. package/dist/transport/impls/uds/client.js +2 -2
  17. package/dist/transport/impls/uds/server.cjs +19 -24
  18. package/dist/transport/impls/uds/server.d.cts +2 -2
  19. package/dist/transport/impls/uds/server.d.ts +2 -2
  20. package/dist/transport/impls/uds/server.js +2 -5
  21. package/dist/transport/impls/ws/client.cjs +16 -21
  22. package/dist/transport/impls/ws/client.d.cts +2 -2
  23. package/dist/transport/impls/ws/client.d.ts +2 -2
  24. package/dist/transport/impls/ws/client.js +2 -2
  25. package/dist/transport/impls/ws/server.cjs +22 -27
  26. package/dist/transport/impls/ws/server.d.cts +2 -2
  27. package/dist/transport/impls/ws/server.d.ts +2 -2
  28. package/dist/transport/impls/ws/server.js +3 -8
  29. package/dist/transport/index.cjs +21 -21
  30. package/dist/transport/index.d.cts +1 -1
  31. package/dist/transport/index.d.ts +1 -1
  32. package/dist/transport/index.js +1 -1
  33. package/dist/util/testHelpers.cjs +14 -21
  34. package/dist/util/testHelpers.d.cts +2 -2
  35. package/dist/util/testHelpers.d.ts +2 -2
  36. package/dist/util/testHelpers.js +2 -2
  37. package/package.json +1 -1
@@ -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, d as Session, C as Connection } from './index-5c55c0d3.js';
3
+ import { b as TransportClientId, d as Session, C as Connection } from './index-2154021c.js';
4
4
 
5
5
  /**
6
6
  * The context for services/procedures. This is used only on
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-MCTB3NYK.js";
3
+ } from "./chunk-YXVFITRS.js";
4
4
 
5
5
  // transport/impls/ws/connection.ts
6
6
  var WebSocketConnection = class extends Connection {
@@ -770,8 +770,8 @@ var RiverServer = class {
770
770
  }
771
771
  createNewProcStream(message) {
772
772
  if (!isStreamOpen(message.controlFlags)) {
773
- log?.warn(
774
- `${this.transport.clientId} -- couldn't find a matching procedure stream for ${message.serviceName}.${message.procedureName}:${message.streamId}`
773
+ log?.error(
774
+ `${this.transport.clientId} -- can't create a new procedure stream from a message that doesn't have the stream open bit set`
775
775
  );
776
776
  return;
777
777
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-MCTB3NYK.js";
3
+ } from "./chunk-YXVFITRS.js";
4
4
 
5
5
  // transport/transforms/messageFraming.ts
6
6
  import { Transform } from "node:stream";
@@ -118,31 +118,24 @@ var Session = class {
118
118
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
119
119
  *
120
120
  * @param msg The partial message to be sent, which will be constructed into a full message.
121
- * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
122
- * ack hearbeats, which contain information that can already be found in the other buffered messages.
121
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
123
122
  * @returns The full transport ID of the message that was attempted to be sent.
124
123
  */
125
- send(msg, skipRetry) {
126
- const fullMsg = this.constructMsg(msg);
124
+ send(msg, addToSendBuff = true) {
125
+ const fullMsg = this.constructMsg(msg, addToSendBuff);
127
126
  log?.debug(`${this.from} -- sending ${JSON.stringify(fullMsg)}`);
128
127
  if (this.connection) {
129
128
  const ok = this.connection.send(this.codec.toBuffer(fullMsg));
130
129
  if (ok)
131
130
  return fullMsg.id;
132
131
  log?.info(
133
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
132
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
134
133
  );
135
134
  } else {
136
135
  log?.info(
137
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection not ready yet`
136
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection not ready yet`
138
137
  );
139
138
  }
140
- if (skipRetry)
141
- return fullMsg.id;
142
- this.addToSendBuff(fullMsg);
143
- log?.info(
144
- `${this.from} -- buffering msg ${fullMsg.id} until connection is healthy again`
145
- );
146
139
  return fullMsg.id;
147
140
  }
148
141
  sendHeartbeat() {
@@ -163,7 +156,7 @@ var Session = class {
163
156
  type: "ACK"
164
157
  }
165
158
  },
166
- true
159
+ false
167
160
  );
168
161
  this.heartbeatMisses++;
169
162
  }
@@ -178,8 +171,11 @@ var Session = class {
178
171
  log?.error(msg);
179
172
  throw new Error(msg);
180
173
  }
174
+ log?.info(
175
+ `${this.from} -- resending ${this.sendBuffer.length} buffered messages`
176
+ );
181
177
  for (const msg of this.sendBuffer) {
182
- log?.debug(`${this.from} -- resending ${JSON.stringify(msg)}`);
178
+ log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
183
179
  const ok = this.connection.send(this.codec.toBuffer(msg));
184
180
  if (!ok) {
185
181
  const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.debugId}) (if you hit this code path something is seriously wrong)`;
@@ -192,12 +188,6 @@ var Session = class {
192
188
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
193
189
  this.ack = seq + 1;
194
190
  }
195
- addToSendBuff(msg) {
196
- this.sendBuffer.push(msg);
197
- log?.debug(
198
- `${this.from} -- send buff to ${this.to} now tracking ${this.sendBuffer.length} messages`
199
- );
200
- }
201
191
  closeStaleConnection(conn) {
202
192
  if (!this.connection || this.connection !== conn)
203
193
  return;
@@ -240,7 +230,7 @@ var Session = class {
240
230
  get nextExpectedSeq() {
241
231
  return this.ack;
242
232
  }
243
- constructMsg(partialMsg) {
233
+ constructMsg(partialMsg, addToSendBuff = true) {
244
234
  const msg = {
245
235
  ...partialMsg,
246
236
  id: unsafeId(),
@@ -250,6 +240,9 @@ var Session = class {
250
240
  ack: this.ack
251
241
  };
252
242
  this.seq++;
243
+ if (addToSendBuff) {
244
+ this.sendBuffer.push(msg);
245
+ }
253
246
  return msg;
254
247
  }
255
248
  inspectSendBuffer() {
@@ -549,6 +542,8 @@ var ClientTransport = class extends Transport {
549
542
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
550
543
  }
551
544
  handleConnection(conn, to) {
545
+ if (this.state !== "open")
546
+ return;
552
547
  let session = void 0;
553
548
  const handshakeHandler = (data) => {
554
549
  const handshake = this.receiveHandshakeResponseMessage(data);
@@ -667,6 +662,11 @@ var ServerTransport = class extends Transport {
667
662
  );
668
663
  }
669
664
  handleConnection(conn) {
665
+ if (this.state !== "open")
666
+ return;
667
+ log?.info(
668
+ `${this.clientId} -- new incoming connection (id: ${conn.debugId})`
669
+ );
670
670
  let session = void 0;
671
671
  const client = () => session?.to ?? "unknown";
672
672
  const handshakeHandler = (data) => {
@@ -1,4 +1,4 @@
1
- import { C as Connection } from './index-5c55c0d3.js';
1
+ import { C as Connection } from './index-2154021c.js';
2
2
  import { Socket } from 'node:net';
3
3
  import stream, { Transform, TransformCallback, TransformOptions } from 'node:stream';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { C as Connection } from './index-5c55c0d3.js';
2
+ import { C as Connection } from './index-2154021c.js';
3
3
 
4
4
  declare class WebSocketConnection extends Connection {
5
5
  ws: WebSocket;
@@ -185,16 +185,14 @@ declare class Session<ConnType extends Connection> {
185
185
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
186
186
  *
187
187
  * @param msg The partial message to be sent, which will be constructed into a full message.
188
- * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
189
- * ack hearbeats, which contain information that can already be found in the other buffered messages.
188
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
190
189
  * @returns The full transport ID of the message that was attempted to be sent.
191
190
  */
192
- send(msg: PartialTransportMessage, skipRetry?: boolean): string;
191
+ send(msg: PartialTransportMessage, addToSendBuff?: boolean): string;
193
192
  sendHeartbeat(): void;
194
193
  resetBufferedMessages(): void;
195
194
  sendBufferedMessages(): void;
196
195
  updateBookkeeping(ack: number, seq: number): void;
197
- addToSendBuff(msg: TransportMessage): void;
198
196
  closeStaleConnection(conn?: ConnType): void;
199
197
  replaceWithNewConnection(newConn: ConnType): void;
200
198
  beginGrace(cb: () => void): void;
@@ -202,7 +200,7 @@ declare class Session<ConnType extends Connection> {
202
200
  close(): void;
203
201
  get connected(): boolean;
204
202
  get nextExpectedSeq(): number;
205
- constructMsg<Payload extends Record<string, unknown>>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
203
+ constructMsg<Payload extends Record<string, unknown>>(partialMsg: PartialTransportMessage<Payload>, addToSendBuff?: boolean): TransportMessage<Payload>;
206
204
  inspectSendBuffer(): ReadonlyArray<OpaqueTransportMessage>;
207
205
  }
208
206
 
@@ -866,8 +866,8 @@ var RiverServer = class {
866
866
  }
867
867
  createNewProcStream(message) {
868
868
  if (!isStreamOpen(message.controlFlags)) {
869
- log?.warn(
870
- `${this.transport.clientId} -- couldn't find a matching procedure stream for ${message.serviceName}.${message.procedureName}:${message.streamId}`
869
+ log?.error(
870
+ `${this.transport.clientId} -- can't create a new procedure stream from a message that doesn't have the stream open bit set`
871
871
  );
872
872
  return;
873
873
  }
@@ -1,6 +1,6 @@
1
- import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-6f4630d0.js';
2
- export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-6f4630d0.js';
3
- import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-5c55c0d3.js';
1
+ import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-533e1324.js';
2
+ export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-533e1324.js';
3
+ import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-2154021c.js';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
6
6
  import '../types-3e5768ec.js';
@@ -1,6 +1,6 @@
1
- import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-6f4630d0.js';
2
- export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-6f4630d0.js';
3
- import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-5c55c0d3.js';
1
+ import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-533e1324.js';
2
+ export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-533e1324.js';
3
+ import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-2154021c.js';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
6
6
  import '../types-3e5768ec.js';
@@ -8,7 +8,7 @@ import {
8
8
  createClient,
9
9
  createServer,
10
10
  serializeService
11
- } from "../chunk-ASZ3VDCS.js";
11
+ } from "../chunk-E2CP4UWB.js";
12
12
  import "../chunk-GFRAOY75.js";
13
13
  import "../chunk-H4BYJELI.js";
14
14
  export {
@@ -226,31 +226,24 @@ var Session = class {
226
226
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
227
227
  *
228
228
  * @param msg The partial message to be sent, which will be constructed into a full message.
229
- * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
230
- * ack hearbeats, which contain information that can already be found in the other buffered messages.
229
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
231
230
  * @returns The full transport ID of the message that was attempted to be sent.
232
231
  */
233
- send(msg, skipRetry) {
234
- const fullMsg = this.constructMsg(msg);
232
+ send(msg, addToSendBuff = true) {
233
+ const fullMsg = this.constructMsg(msg, addToSendBuff);
235
234
  log?.debug(`${this.from} -- sending ${JSON.stringify(fullMsg)}`);
236
235
  if (this.connection) {
237
236
  const ok = this.connection.send(this.codec.toBuffer(fullMsg));
238
237
  if (ok)
239
238
  return fullMsg.id;
240
239
  log?.info(
241
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
240
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
242
241
  );
243
242
  } else {
244
243
  log?.info(
245
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection not ready yet`
244
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection not ready yet`
246
245
  );
247
246
  }
248
- if (skipRetry)
249
- return fullMsg.id;
250
- this.addToSendBuff(fullMsg);
251
- log?.info(
252
- `${this.from} -- buffering msg ${fullMsg.id} until connection is healthy again`
253
- );
254
247
  return fullMsg.id;
255
248
  }
256
249
  sendHeartbeat() {
@@ -271,7 +264,7 @@ var Session = class {
271
264
  type: "ACK"
272
265
  }
273
266
  },
274
- true
267
+ false
275
268
  );
276
269
  this.heartbeatMisses++;
277
270
  }
@@ -286,8 +279,11 @@ var Session = class {
286
279
  log?.error(msg);
287
280
  throw new Error(msg);
288
281
  }
282
+ log?.info(
283
+ `${this.from} -- resending ${this.sendBuffer.length} buffered messages`
284
+ );
289
285
  for (const msg of this.sendBuffer) {
290
- log?.debug(`${this.from} -- resending ${JSON.stringify(msg)}`);
286
+ log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
291
287
  const ok = this.connection.send(this.codec.toBuffer(msg));
292
288
  if (!ok) {
293
289
  const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.debugId}) (if you hit this code path something is seriously wrong)`;
@@ -300,12 +296,6 @@ var Session = class {
300
296
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
301
297
  this.ack = seq + 1;
302
298
  }
303
- addToSendBuff(msg) {
304
- this.sendBuffer.push(msg);
305
- log?.debug(
306
- `${this.from} -- send buff to ${this.to} now tracking ${this.sendBuffer.length} messages`
307
- );
308
- }
309
299
  closeStaleConnection(conn) {
310
300
  if (!this.connection || this.connection !== conn)
311
301
  return;
@@ -348,7 +338,7 @@ var Session = class {
348
338
  get nextExpectedSeq() {
349
339
  return this.ack;
350
340
  }
351
- constructMsg(partialMsg) {
341
+ constructMsg(partialMsg, addToSendBuff = true) {
352
342
  const msg = {
353
343
  ...partialMsg,
354
344
  id: unsafeId(),
@@ -358,6 +348,9 @@ var Session = class {
358
348
  ack: this.ack
359
349
  };
360
350
  this.seq++;
351
+ if (addToSendBuff) {
352
+ this.sendBuffer.push(msg);
353
+ }
361
354
  return msg;
362
355
  }
363
356
  inspectSendBuffer() {
@@ -790,6 +783,8 @@ var ClientTransport = class extends Transport {
790
783
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
791
784
  }
792
785
  handleConnection(conn, to) {
786
+ if (this.state !== "open")
787
+ return;
793
788
  let session = void 0;
794
789
  const handshakeHandler = (data) => {
795
790
  const handshake = this.receiveHandshakeResponseMessage(data);
@@ -1,5 +1,5 @@
1
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
2
- import { U as UdsConnection } from '../../../connection-8d0efae0.js';
1
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-2154021c.js';
2
+ import { U as UdsConnection } from '../../../connection-1f994b63.js';
3
3
  import '../../../types-3e5768ec.js';
4
4
  import '@sinclair/typebox';
5
5
  import 'node:net';
@@ -1,5 +1,5 @@
1
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
2
- import { U as UdsConnection } from '../../../connection-8d0efae0.js';
1
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-2154021c.js';
2
+ import { U as UdsConnection } from '../../../connection-1f994b63.js';
3
3
  import '../../../types-3e5768ec.js';
4
4
  import '@sinclair/typebox';
5
5
  import 'node:net';
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  UdsConnection
3
- } from "../../../chunk-FIX2F6VT.js";
3
+ } from "../../../chunk-WCSTFZOJ.js";
4
4
  import {
5
5
  ClientTransport
6
- } from "../../../chunk-MCTB3NYK.js";
6
+ } from "../../../chunk-YXVFITRS.js";
7
7
  import "../../../chunk-GFRAOY75.js";
8
8
  import {
9
9
  log
@@ -264,31 +264,24 @@ var Session = class {
264
264
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
265
265
  *
266
266
  * @param msg The partial message to be sent, which will be constructed into a full message.
267
- * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
268
- * ack hearbeats, which contain information that can already be found in the other buffered messages.
267
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
269
268
  * @returns The full transport ID of the message that was attempted to be sent.
270
269
  */
271
- send(msg, skipRetry) {
272
- const fullMsg = this.constructMsg(msg);
270
+ send(msg, addToSendBuff = true) {
271
+ const fullMsg = this.constructMsg(msg, addToSendBuff);
273
272
  log?.debug(`${this.from} -- sending ${JSON.stringify(fullMsg)}`);
274
273
  if (this.connection) {
275
274
  const ok = this.connection.send(this.codec.toBuffer(fullMsg));
276
275
  if (ok)
277
276
  return fullMsg.id;
278
277
  log?.info(
279
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
278
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
280
279
  );
281
280
  } else {
282
281
  log?.info(
283
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection not ready yet`
282
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection not ready yet`
284
283
  );
285
284
  }
286
- if (skipRetry)
287
- return fullMsg.id;
288
- this.addToSendBuff(fullMsg);
289
- log?.info(
290
- `${this.from} -- buffering msg ${fullMsg.id} until connection is healthy again`
291
- );
292
285
  return fullMsg.id;
293
286
  }
294
287
  sendHeartbeat() {
@@ -309,7 +302,7 @@ var Session = class {
309
302
  type: "ACK"
310
303
  }
311
304
  },
312
- true
305
+ false
313
306
  );
314
307
  this.heartbeatMisses++;
315
308
  }
@@ -324,8 +317,11 @@ var Session = class {
324
317
  log?.error(msg);
325
318
  throw new Error(msg);
326
319
  }
320
+ log?.info(
321
+ `${this.from} -- resending ${this.sendBuffer.length} buffered messages`
322
+ );
327
323
  for (const msg of this.sendBuffer) {
328
- log?.debug(`${this.from} -- resending ${JSON.stringify(msg)}`);
324
+ log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
329
325
  const ok = this.connection.send(this.codec.toBuffer(msg));
330
326
  if (!ok) {
331
327
  const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.debugId}) (if you hit this code path something is seriously wrong)`;
@@ -338,12 +334,6 @@ var Session = class {
338
334
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
339
335
  this.ack = seq + 1;
340
336
  }
341
- addToSendBuff(msg) {
342
- this.sendBuffer.push(msg);
343
- log?.debug(
344
- `${this.from} -- send buff to ${this.to} now tracking ${this.sendBuffer.length} messages`
345
- );
346
- }
347
337
  closeStaleConnection(conn) {
348
338
  if (!this.connection || this.connection !== conn)
349
339
  return;
@@ -386,7 +376,7 @@ var Session = class {
386
376
  get nextExpectedSeq() {
387
377
  return this.ack;
388
378
  }
389
- constructMsg(partialMsg) {
379
+ constructMsg(partialMsg, addToSendBuff = true) {
390
380
  const msg = {
391
381
  ...partialMsg,
392
382
  id: unsafeId(),
@@ -396,6 +386,9 @@ var Session = class {
396
386
  ack: this.ack
397
387
  };
398
388
  this.seq++;
389
+ if (addToSendBuff) {
390
+ this.sendBuffer.push(msg);
391
+ }
399
392
  return msg;
400
393
  }
401
394
  inspectSendBuffer() {
@@ -699,6 +692,11 @@ var ServerTransport = class extends Transport {
699
692
  );
700
693
  }
701
694
  handleConnection(conn) {
695
+ if (this.state !== "open")
696
+ return;
697
+ log?.info(
698
+ `${this.clientId} -- new incoming connection (id: ${conn.debugId})`
699
+ );
702
700
  let session = void 0;
703
701
  const client = () => session?.to ?? "unknown";
704
702
  const handshakeHandler = (data) => {
@@ -890,9 +888,6 @@ var UnixDomainSocketServerTransport = class extends ServerTransport {
890
888
  connectionHandler = (sock) => {
891
889
  const conn = new UdsConnection(sock);
892
890
  this.handleConnection(conn);
893
- log?.info(
894
- `${this.clientId} -- new incoming uds connection (id: ${conn.debugId})`
895
- );
896
891
  };
897
892
  close() {
898
893
  super.close();
@@ -1,6 +1,6 @@
1
1
  import { Server, Socket } from 'node:net';
2
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
3
- import { U as UdsConnection } from '../../../connection-8d0efae0.js';
2
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-2154021c.js';
3
+ import { U as UdsConnection } from '../../../connection-1f994b63.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'node:stream';
@@ -1,6 +1,6 @@
1
1
  import { Server, Socket } from 'node:net';
2
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
3
- import { U as UdsConnection } from '../../../connection-8d0efae0.js';
2
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-2154021c.js';
3
+ import { U as UdsConnection } from '../../../connection-1f994b63.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'node:stream';
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  UdsConnection
3
- } from "../../../chunk-FIX2F6VT.js";
3
+ } from "../../../chunk-WCSTFZOJ.js";
4
4
  import {
5
5
  ServerTransport
6
- } from "../../../chunk-MCTB3NYK.js";
6
+ } from "../../../chunk-YXVFITRS.js";
7
7
  import "../../../chunk-GFRAOY75.js";
8
8
  import {
9
9
  log
@@ -24,9 +24,6 @@ var UnixDomainSocketServerTransport = class extends ServerTransport {
24
24
  connectionHandler = (sock) => {
25
25
  const conn = new UdsConnection(sock);
26
26
  this.handleConnection(conn);
27
- log?.info(
28
- `${this.clientId} -- new incoming uds connection (id: ${conn.debugId})`
29
- );
30
27
  };
31
28
  close() {
32
29
  super.close();
@@ -256,31 +256,24 @@ var Session = class {
256
256
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
257
257
  *
258
258
  * @param msg The partial message to be sent, which will be constructed into a full message.
259
- * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
260
- * ack hearbeats, which contain information that can already be found in the other buffered messages.
259
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
261
260
  * @returns The full transport ID of the message that was attempted to be sent.
262
261
  */
263
- send(msg, skipRetry) {
264
- const fullMsg = this.constructMsg(msg);
262
+ send(msg, addToSendBuff = true) {
263
+ const fullMsg = this.constructMsg(msg, addToSendBuff);
265
264
  log?.debug(`${this.from} -- sending ${JSON.stringify(fullMsg)}`);
266
265
  if (this.connection) {
267
266
  const ok = this.connection.send(this.codec.toBuffer(fullMsg));
268
267
  if (ok)
269
268
  return fullMsg.id;
270
269
  log?.info(
271
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
270
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
272
271
  );
273
272
  } else {
274
273
  log?.info(
275
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection not ready yet`
274
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection not ready yet`
276
275
  );
277
276
  }
278
- if (skipRetry)
279
- return fullMsg.id;
280
- this.addToSendBuff(fullMsg);
281
- log?.info(
282
- `${this.from} -- buffering msg ${fullMsg.id} until connection is healthy again`
283
- );
284
277
  return fullMsg.id;
285
278
  }
286
279
  sendHeartbeat() {
@@ -301,7 +294,7 @@ var Session = class {
301
294
  type: "ACK"
302
295
  }
303
296
  },
304
- true
297
+ false
305
298
  );
306
299
  this.heartbeatMisses++;
307
300
  }
@@ -316,8 +309,11 @@ var Session = class {
316
309
  log?.error(msg);
317
310
  throw new Error(msg);
318
311
  }
312
+ log?.info(
313
+ `${this.from} -- resending ${this.sendBuffer.length} buffered messages`
314
+ );
319
315
  for (const msg of this.sendBuffer) {
320
- log?.debug(`${this.from} -- resending ${JSON.stringify(msg)}`);
316
+ log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
321
317
  const ok = this.connection.send(this.codec.toBuffer(msg));
322
318
  if (!ok) {
323
319
  const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.debugId}) (if you hit this code path something is seriously wrong)`;
@@ -330,12 +326,6 @@ var Session = class {
330
326
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
331
327
  this.ack = seq + 1;
332
328
  }
333
- addToSendBuff(msg) {
334
- this.sendBuffer.push(msg);
335
- log?.debug(
336
- `${this.from} -- send buff to ${this.to} now tracking ${this.sendBuffer.length} messages`
337
- );
338
- }
339
329
  closeStaleConnection(conn) {
340
330
  if (!this.connection || this.connection !== conn)
341
331
  return;
@@ -378,7 +368,7 @@ var Session = class {
378
368
  get nextExpectedSeq() {
379
369
  return this.ack;
380
370
  }
381
- constructMsg(partialMsg) {
371
+ constructMsg(partialMsg, addToSendBuff = true) {
382
372
  const msg = {
383
373
  ...partialMsg,
384
374
  id: unsafeId(),
@@ -388,6 +378,9 @@ var Session = class {
388
378
  ack: this.ack
389
379
  };
390
380
  this.seq++;
381
+ if (addToSendBuff) {
382
+ this.sendBuffer.push(msg);
383
+ }
391
384
  return msg;
392
385
  }
393
386
  inspectSendBuffer() {
@@ -696,6 +689,8 @@ var ClientTransport = class extends Transport {
696
689
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
697
690
  }
698
691
  handleConnection(conn, to) {
692
+ if (this.state !== "open")
693
+ return;
699
694
  let session = void 0;
700
695
  const handshakeHandler = (data) => {
701
696
  const handshake = this.receiveHandshakeResponseMessage(data);
@@ -1,6 +1,6 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
3
- import { W as WebSocketConnection } from '../../../connection-fe33e684.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-2154021c.js';
3
+ import { W as WebSocketConnection } from '../../../connection-f46114a1.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 TransportOptions } from '../../../index-5c55c0d3.js';
3
- import { W as WebSocketConnection } from '../../../connection-fe33e684.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-2154021c.js';
3
+ import { W as WebSocketConnection } from '../../../connection-f46114a1.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-5V6B7TM3.js";
3
+ } from "../../../chunk-3LGEBL5F.js";
4
4
  import {
5
5
  ClientTransport
6
- } from "../../../chunk-MCTB3NYK.js";
6
+ } from "../../../chunk-YXVFITRS.js";
7
7
  import "../../../chunk-GFRAOY75.js";
8
8
  import {
9
9
  log
@@ -24,9 +24,6 @@ __export(server_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(server_exports);
26
26
 
27
- // logging/index.ts
28
- var log;
29
-
30
27
  // transport/transport.ts
31
28
  var import_value = require("@sinclair/typebox/value");
32
29
 
@@ -107,6 +104,9 @@ function isAck(controlFlag) {
107
104
  return (controlFlag & 1 /* AckBit */) === 1 /* AckBit */;
108
105
  }
109
106
 
107
+ // logging/index.ts
108
+ var log;
109
+
110
110
  // transport/events.ts
111
111
  var EventDispatcher = class {
112
112
  eventListeners = {};
@@ -264,31 +264,24 @@ var Session = class {
264
264
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
265
265
  *
266
266
  * @param msg The partial message to be sent, which will be constructed into a full message.
267
- * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
268
- * ack hearbeats, which contain information that can already be found in the other buffered messages.
267
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
269
268
  * @returns The full transport ID of the message that was attempted to be sent.
270
269
  */
271
- send(msg, skipRetry) {
272
- const fullMsg = this.constructMsg(msg);
270
+ send(msg, addToSendBuff = true) {
271
+ const fullMsg = this.constructMsg(msg, addToSendBuff);
273
272
  log?.debug(`${this.from} -- sending ${JSON.stringify(fullMsg)}`);
274
273
  if (this.connection) {
275
274
  const ok = this.connection.send(this.codec.toBuffer(fullMsg));
276
275
  if (ok)
277
276
  return fullMsg.id;
278
277
  log?.info(
279
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
278
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
280
279
  );
281
280
  } else {
282
281
  log?.info(
283
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection not ready yet`
282
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection not ready yet`
284
283
  );
285
284
  }
286
- if (skipRetry)
287
- return fullMsg.id;
288
- this.addToSendBuff(fullMsg);
289
- log?.info(
290
- `${this.from} -- buffering msg ${fullMsg.id} until connection is healthy again`
291
- );
292
285
  return fullMsg.id;
293
286
  }
294
287
  sendHeartbeat() {
@@ -309,7 +302,7 @@ var Session = class {
309
302
  type: "ACK"
310
303
  }
311
304
  },
312
- true
305
+ false
313
306
  );
314
307
  this.heartbeatMisses++;
315
308
  }
@@ -324,8 +317,11 @@ var Session = class {
324
317
  log?.error(msg);
325
318
  throw new Error(msg);
326
319
  }
320
+ log?.info(
321
+ `${this.from} -- resending ${this.sendBuffer.length} buffered messages`
322
+ );
327
323
  for (const msg of this.sendBuffer) {
328
- log?.debug(`${this.from} -- resending ${JSON.stringify(msg)}`);
324
+ log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
329
325
  const ok = this.connection.send(this.codec.toBuffer(msg));
330
326
  if (!ok) {
331
327
  const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.debugId}) (if you hit this code path something is seriously wrong)`;
@@ -338,12 +334,6 @@ var Session = class {
338
334
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
339
335
  this.ack = seq + 1;
340
336
  }
341
- addToSendBuff(msg) {
342
- this.sendBuffer.push(msg);
343
- log?.debug(
344
- `${this.from} -- send buff to ${this.to} now tracking ${this.sendBuffer.length} messages`
345
- );
346
- }
347
337
  closeStaleConnection(conn) {
348
338
  if (!this.connection || this.connection !== conn)
349
339
  return;
@@ -386,7 +376,7 @@ var Session = class {
386
376
  get nextExpectedSeq() {
387
377
  return this.ack;
388
378
  }
389
- constructMsg(partialMsg) {
379
+ constructMsg(partialMsg, addToSendBuff = true) {
390
380
  const msg = {
391
381
  ...partialMsg,
392
382
  id: unsafeId(),
@@ -396,6 +386,9 @@ var Session = class {
396
386
  ack: this.ack
397
387
  };
398
388
  this.seq++;
389
+ if (addToSendBuff) {
390
+ this.sendBuffer.push(msg);
391
+ }
399
392
  return msg;
400
393
  }
401
394
  inspectSendBuffer() {
@@ -699,6 +692,11 @@ var ServerTransport = class extends Transport {
699
692
  );
700
693
  }
701
694
  handleConnection(conn) {
695
+ if (this.state !== "open")
696
+ return;
697
+ log?.info(
698
+ `${this.clientId} -- new incoming connection (id: ${conn.debugId})`
699
+ );
702
700
  let session = void 0;
703
701
  const client = () => session?.to ?? "unknown";
704
702
  const handshakeHandler = (data) => {
@@ -826,9 +824,6 @@ var WebSocketServerTransport = class extends ServerTransport {
826
824
  }
827
825
  connectionHandler = (ws) => {
828
826
  const conn = new WebSocketConnection(ws);
829
- log?.info(
830
- `${this.clientId} -- new incoming ws connection (id: ${conn.debugId})`
831
- );
832
827
  this.handleConnection(conn);
833
828
  };
834
829
  close() {
@@ -1,7 +1,7 @@
1
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
1
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-2154021c.js';
2
2
  import { WebSocketServer } from 'ws';
3
3
  import { WebSocket } from 'isomorphic-ws';
4
- import { W as WebSocketConnection } from '../../../connection-fe33e684.js';
4
+ import { W as WebSocketConnection } from '../../../connection-f46114a1.js';
5
5
  import '../../../types-3e5768ec.js';
6
6
  import '@sinclair/typebox';
7
7
 
@@ -1,7 +1,7 @@
1
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-5c55c0d3.js';
1
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-2154021c.js';
2
2
  import { WebSocketServer } from 'ws';
3
3
  import { WebSocket } from 'isomorphic-ws';
4
- import { W as WebSocketConnection } from '../../../connection-fe33e684.js';
4
+ import { W as WebSocketConnection } from '../../../connection-f46114a1.js';
5
5
  import '../../../types-3e5768ec.js';
6
6
  import '@sinclair/typebox';
7
7
 
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-5V6B7TM3.js";
3
+ } from "../../../chunk-3LGEBL5F.js";
4
4
  import {
5
5
  ServerTransport
6
- } from "../../../chunk-MCTB3NYK.js";
6
+ } from "../../../chunk-YXVFITRS.js";
7
7
  import "../../../chunk-GFRAOY75.js";
8
- import {
9
- log
10
- } from "../../../chunk-H4BYJELI.js";
8
+ import "../../../chunk-H4BYJELI.js";
11
9
  import "../../../chunk-GZ7HCLLM.js";
12
10
 
13
11
  // transport/impls/ws/server.ts
@@ -20,9 +18,6 @@ var WebSocketServerTransport = class extends ServerTransport {
20
18
  }
21
19
  connectionHandler = (ws) => {
22
20
  const conn = new WebSocketConnection(ws);
23
- log?.info(
24
- `${this.clientId} -- new incoming ws connection (id: ${conn.debugId})`
25
- );
26
21
  this.handleConnection(conn);
27
22
  };
28
23
  close() {
@@ -286,31 +286,24 @@ var Session = class {
286
286
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
287
287
  *
288
288
  * @param msg The partial message to be sent, which will be constructed into a full message.
289
- * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
290
- * ack hearbeats, which contain information that can already be found in the other buffered messages.
289
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
291
290
  * @returns The full transport ID of the message that was attempted to be sent.
292
291
  */
293
- send(msg, skipRetry) {
294
- const fullMsg = this.constructMsg(msg);
292
+ send(msg, addToSendBuff = true) {
293
+ const fullMsg = this.constructMsg(msg, addToSendBuff);
295
294
  log?.debug(`${this.from} -- sending ${JSON.stringify(fullMsg)}`);
296
295
  if (this.connection) {
297
296
  const ok = this.connection.send(this.codec.toBuffer(fullMsg));
298
297
  if (ok)
299
298
  return fullMsg.id;
300
299
  log?.info(
301
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
300
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
302
301
  );
303
302
  } else {
304
303
  log?.info(
305
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection not ready yet`
304
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection not ready yet`
306
305
  );
307
306
  }
308
- if (skipRetry)
309
- return fullMsg.id;
310
- this.addToSendBuff(fullMsg);
311
- log?.info(
312
- `${this.from} -- buffering msg ${fullMsg.id} until connection is healthy again`
313
- );
314
307
  return fullMsg.id;
315
308
  }
316
309
  sendHeartbeat() {
@@ -331,7 +324,7 @@ var Session = class {
331
324
  type: "ACK"
332
325
  }
333
326
  },
334
- true
327
+ false
335
328
  );
336
329
  this.heartbeatMisses++;
337
330
  }
@@ -346,8 +339,11 @@ var Session = class {
346
339
  log?.error(msg);
347
340
  throw new Error(msg);
348
341
  }
342
+ log?.info(
343
+ `${this.from} -- resending ${this.sendBuffer.length} buffered messages`
344
+ );
349
345
  for (const msg of this.sendBuffer) {
350
- log?.debug(`${this.from} -- resending ${JSON.stringify(msg)}`);
346
+ log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
351
347
  const ok = this.connection.send(this.codec.toBuffer(msg));
352
348
  if (!ok) {
353
349
  const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.debugId}) (if you hit this code path something is seriously wrong)`;
@@ -360,12 +356,6 @@ var Session = class {
360
356
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
361
357
  this.ack = seq + 1;
362
358
  }
363
- addToSendBuff(msg) {
364
- this.sendBuffer.push(msg);
365
- log?.debug(
366
- `${this.from} -- send buff to ${this.to} now tracking ${this.sendBuffer.length} messages`
367
- );
368
- }
369
359
  closeStaleConnection(conn) {
370
360
  if (!this.connection || this.connection !== conn)
371
361
  return;
@@ -408,7 +398,7 @@ var Session = class {
408
398
  get nextExpectedSeq() {
409
399
  return this.ack;
410
400
  }
411
- constructMsg(partialMsg) {
401
+ constructMsg(partialMsg, addToSendBuff = true) {
412
402
  const msg = {
413
403
  ...partialMsg,
414
404
  id: unsafeId(),
@@ -418,6 +408,9 @@ var Session = class {
418
408
  ack: this.ack
419
409
  };
420
410
  this.seq++;
411
+ if (addToSendBuff) {
412
+ this.sendBuffer.push(msg);
413
+ }
421
414
  return msg;
422
415
  }
423
416
  inspectSendBuffer() {
@@ -726,6 +719,8 @@ var ClientTransport = class extends Transport {
726
719
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
727
720
  }
728
721
  handleConnection(conn, to) {
722
+ if (this.state !== "open")
723
+ return;
729
724
  let session = void 0;
730
725
  const handshakeHandler = (data) => {
731
726
  const handshake = this.receiveHandshakeResponseMessage(data);
@@ -844,6 +839,11 @@ var ServerTransport = class extends Transport {
844
839
  );
845
840
  }
846
841
  handleConnection(conn) {
842
+ if (this.state !== "open")
843
+ return;
844
+ log?.info(
845
+ `${this.clientId} -- new incoming connection (id: ${conn.debugId})`
846
+ );
847
847
  let session = void 0;
848
848
  const client = () => session?.to ?? "unknown";
849
849
  const handshakeHandler = (data) => {
@@ -1,3 +1,3 @@
1
- export { a as ClientTransport, C as Connection, l as EventHandler, E as EventMap, k as EventTypes, O as OpaqueTransportMessage, g as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, h as TransportMessage, f as TransportMessageSchema, c as TransportOptions, e as TransportStatus, j as isStreamClose, i as isStreamOpen } from '../index-5c55c0d3.js';
1
+ export { a as ClientTransport, C as Connection, l as EventHandler, E as EventMap, k as EventTypes, O as OpaqueTransportMessage, g as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, h as TransportMessage, f as TransportMessageSchema, c as TransportOptions, e as TransportStatus, j as isStreamClose, i as isStreamOpen } from '../index-2154021c.js';
2
2
  import '../types-3e5768ec.js';
3
3
  import '@sinclair/typebox';
@@ -1,3 +1,3 @@
1
- export { a as ClientTransport, C as Connection, l as EventHandler, E as EventMap, k as EventTypes, O as OpaqueTransportMessage, g as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, h as TransportMessage, f as TransportMessageSchema, c as TransportOptions, e as TransportStatus, j as isStreamClose, i as isStreamOpen } from '../index-5c55c0d3.js';
1
+ export { a as ClientTransport, C as Connection, l as EventHandler, E as EventMap, k as EventTypes, O as OpaqueTransportMessage, g as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, h as TransportMessage, f as TransportMessageSchema, c as TransportOptions, e as TransportStatus, j as isStreamClose, i as isStreamOpen } from '../index-2154021c.js';
2
2
  import '../types-3e5768ec.js';
3
3
  import '@sinclair/typebox';
@@ -5,7 +5,7 @@ import {
5
5
  ServerTransport,
6
6
  Session,
7
7
  Transport
8
- } from "../chunk-MCTB3NYK.js";
8
+ } from "../chunk-YXVFITRS.js";
9
9
  import {
10
10
  OpaqueTransportMessageSchema,
11
11
  TransportMessageSchema
@@ -174,31 +174,24 @@ var Session = class {
174
174
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
175
175
  *
176
176
  * @param msg The partial message to be sent, which will be constructed into a full message.
177
- * @param skipRetry Optional. If true, the message will not be buffered for retry on failure. This should only be used for
178
- * ack hearbeats, which contain information that can already be found in the other buffered messages.
177
+ * @param addToSendBuff Whether to add the message to the send buffer for retry.
179
178
  * @returns The full transport ID of the message that was attempted to be sent.
180
179
  */
181
- send(msg, skipRetry) {
182
- const fullMsg = this.constructMsg(msg);
180
+ send(msg, addToSendBuff = true) {
181
+ const fullMsg = this.constructMsg(msg, addToSendBuff);
183
182
  log?.debug(`${this.from} -- sending ${JSON.stringify(fullMsg)}`);
184
183
  if (this.connection) {
185
184
  const ok = this.connection.send(this.codec.toBuffer(fullMsg));
186
185
  if (ok)
187
186
  return fullMsg.id;
188
187
  log?.info(
189
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
188
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection (id: ${this.connection.debugId}) is probably dead`
190
189
  );
191
190
  } else {
192
191
  log?.info(
193
- `${this.from} -- failed to send ${fullMsg.id} to ${fullMsg.to}, connection not ready yet`
192
+ `${this.from} -- failed to send ${fullMsg.id} (seq: ${fullMsg.seq}) to ${fullMsg.to}, connection not ready yet`
194
193
  );
195
194
  }
196
- if (skipRetry)
197
- return fullMsg.id;
198
- this.addToSendBuff(fullMsg);
199
- log?.info(
200
- `${this.from} -- buffering msg ${fullMsg.id} until connection is healthy again`
201
- );
202
195
  return fullMsg.id;
203
196
  }
204
197
  sendHeartbeat() {
@@ -219,7 +212,7 @@ var Session = class {
219
212
  type: "ACK"
220
213
  }
221
214
  },
222
- true
215
+ false
223
216
  );
224
217
  this.heartbeatMisses++;
225
218
  }
@@ -234,8 +227,11 @@ var Session = class {
234
227
  log?.error(msg);
235
228
  throw new Error(msg);
236
229
  }
230
+ log?.info(
231
+ `${this.from} -- resending ${this.sendBuffer.length} buffered messages`
232
+ );
237
233
  for (const msg of this.sendBuffer) {
238
- log?.debug(`${this.from} -- resending ${JSON.stringify(msg)}`);
234
+ log?.debug(`${this.from} -- resending ${msg.id} (seq: ${msg.seq})`);
239
235
  const ok = this.connection.send(this.codec.toBuffer(msg));
240
236
  if (!ok) {
241
237
  const msg2 = `${this.from} -- failed to send buffered message to ${this.to} in session (id: ${this.debugId}) (if you hit this code path something is seriously wrong)`;
@@ -248,12 +244,6 @@ var Session = class {
248
244
  this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
249
245
  this.ack = seq + 1;
250
246
  }
251
- addToSendBuff(msg) {
252
- this.sendBuffer.push(msg);
253
- log?.debug(
254
- `${this.from} -- send buff to ${this.to} now tracking ${this.sendBuffer.length} messages`
255
- );
256
- }
257
247
  closeStaleConnection(conn) {
258
248
  if (!this.connection || this.connection !== conn)
259
249
  return;
@@ -296,7 +286,7 @@ var Session = class {
296
286
  get nextExpectedSeq() {
297
287
  return this.ack;
298
288
  }
299
- constructMsg(partialMsg) {
289
+ constructMsg(partialMsg, addToSendBuff = true) {
300
290
  const msg = {
301
291
  ...partialMsg,
302
292
  id: unsafeId(),
@@ -306,6 +296,9 @@ var Session = class {
306
296
  ack: this.ack
307
297
  };
308
298
  this.seq++;
299
+ if (addToSendBuff) {
300
+ this.sendBuffer.push(msg);
301
+ }
309
302
  return msg;
310
303
  }
311
304
  inspectSendBuffer() {
@@ -1,8 +1,8 @@
1
1
  import * as it_pushable from 'it-pushable';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
  import http from 'node:http';
4
- import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-5c55c0d3.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-6f4630d0.js';
4
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-2154021c.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-533e1324.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -1,8 +1,8 @@
1
1
  import * as it_pushable from 'it-pushable';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
  import http from 'node:http';
4
- import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-5c55c0d3.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-6f4630d0.js';
4
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-2154021c.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-533e1324.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  UNCAUGHT_ERROR,
3
3
  pushable
4
- } from "../chunk-ASZ3VDCS.js";
4
+ } from "../chunk-E2CP4UWB.js";
5
5
  import "../chunk-5IZ2UHWV.js";
6
6
  import {
7
7
  Session,
8
8
  defaultSessionOptions
9
- } from "../chunk-MCTB3NYK.js";
9
+ } from "../chunk-YXVFITRS.js";
10
10
  import {
11
11
  coerceErrorString
12
12
  } from "../chunk-GFRAOY75.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@replit/river",
3
3
  "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4
- "version": "0.13.4",
4
+ "version": "0.13.6",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {