@replit/river 0.12.2 → 0.12.4

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 (45) hide show
  1. package/dist/{chunk-CT57CKBS.js → chunk-2PKONGC3.js} +34 -31
  2. package/dist/{chunk-NHSJ4RDY.js → chunk-6OAKPO5R.js} +1 -1
  3. package/dist/{chunk-PIF32FUL.js → chunk-7J66WOIC.js} +1 -1
  4. package/dist/{chunk-55XUAPC6.js → chunk-AFLZ6INU.js} +1 -1
  5. package/dist/{chunk-R6YJHJV7.js → chunk-H4QR2K3T.js} +1 -1
  6. package/dist/{connection-eb10d250.d.ts → connection-4a839b9a.d.ts} +1 -1
  7. package/dist/{connection-bf7811aa.d.ts → connection-64b9e0ff.d.ts} +1 -1
  8. package/dist/{connection-d880aa4a.d.ts → connection-a6cc48e8.d.ts} +1 -1
  9. package/dist/{index-0c0a69f6.d.ts → index-1afc5580.d.ts} +5 -9
  10. package/dist/router/index.cjs +1 -1
  11. package/dist/router/index.d.cts +1 -1
  12. package/dist/router/index.d.ts +1 -1
  13. package/dist/router/index.js +1 -1
  14. package/dist/transport/impls/stdio/client.cjs +34 -31
  15. package/dist/transport/impls/stdio/client.d.cts +2 -2
  16. package/dist/transport/impls/stdio/client.d.ts +2 -2
  17. package/dist/transport/impls/stdio/client.js +2 -2
  18. package/dist/transport/impls/stdio/server.cjs +33 -29
  19. package/dist/transport/impls/stdio/server.d.cts +2 -2
  20. package/dist/transport/impls/stdio/server.d.ts +2 -2
  21. package/dist/transport/impls/stdio/server.js +2 -2
  22. package/dist/transport/impls/uds/client.cjs +34 -31
  23. package/dist/transport/impls/uds/client.d.cts +2 -2
  24. package/dist/transport/impls/uds/client.d.ts +2 -2
  25. package/dist/transport/impls/uds/client.js +2 -2
  26. package/dist/transport/impls/uds/server.cjs +33 -29
  27. package/dist/transport/impls/uds/server.d.cts +2 -2
  28. package/dist/transport/impls/uds/server.d.ts +2 -2
  29. package/dist/transport/impls/uds/server.js +2 -2
  30. package/dist/transport/impls/ws/client.cjs +38 -32
  31. package/dist/transport/impls/ws/client.d.cts +2 -2
  32. package/dist/transport/impls/ws/client.d.ts +2 -2
  33. package/dist/transport/impls/ws/client.js +9 -4
  34. package/dist/transport/impls/ws/server.cjs +33 -29
  35. package/dist/transport/impls/ws/server.d.cts +2 -2
  36. package/dist/transport/impls/ws/server.d.ts +2 -2
  37. package/dist/transport/impls/ws/server.js +2 -2
  38. package/dist/transport/index.cjs +34 -31
  39. package/dist/transport/index.d.cts +1 -1
  40. package/dist/transport/index.d.ts +1 -1
  41. package/dist/transport/index.js +1 -1
  42. package/dist/util/testHelpers.d.cts +1 -1
  43. package/dist/util/testHelpers.d.ts +1 -1
  44. package/dist/util/testHelpers.js +1 -1
  45. package/package.json +1 -1
@@ -260,17 +260,27 @@ var Session = class {
260
260
  this.cancelGrace();
261
261
  this.connection = newConn;
262
262
  }
263
+ graceCb;
263
264
  beginGrace(cb) {
265
+ this.graceCb = cb;
264
266
  this.disconnectionGrace = setTimeout(() => {
265
- this.resetBufferedMessages();
266
- clearInterval(this.heartbeat);
267
+ this.close();
267
268
  cb();
268
269
  }, SESSION_DISCONNECT_GRACE_MS);
269
270
  }
271
+ // called on reconnect of the underlying session
270
272
  cancelGrace() {
271
273
  this.heartbeatMisses = 0;
272
274
  clearTimeout(this.disconnectionGrace);
273
275
  }
276
+ // closed when we want to discard the whole session
277
+ // (i.e. shutdown or session disconnect)
278
+ close() {
279
+ this.closeStaleConnection(this.connection);
280
+ this.cancelGrace();
281
+ clearInterval(this.heartbeat);
282
+ this.resetBufferedMessages();
283
+ }
274
284
  get connected() {
275
285
  return this.connection !== void 0;
276
286
  }
@@ -289,16 +299,6 @@ var Session = class {
289
299
  this.seq++;
290
300
  return msg;
291
301
  }
292
- /**
293
- * Closes the out-going connection but doesn't remove the listeners
294
- * for incoming messages. The connection will eventually call onClose
295
- * when it is ready to be cleaned up and only then will {@link connection} be set back
296
- * to undefined
297
- */
298
- halfCloseConnection() {
299
- this.connection?.close();
300
- clearInterval(this.heartbeat);
301
- }
302
302
  inspectSendBuffer() {
303
303
  return this.sendBuffer;
304
304
  }
@@ -574,19 +574,18 @@ var Transport = class {
574
574
  status: "connect",
575
575
  conn
576
576
  });
577
- let session = this.sessions.get(connectedTo);
577
+ let oldSession = this.sessions.get(connectedTo);
578
578
  const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
579
- if (session && lastInstanceId !== instanceId && lastInstanceId !== void 0) {
579
+ if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
580
580
  log?.warn(
581
- `${this.clientId} -- handshake from ${connectedTo} has different server instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
581
+ `${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
582
582
  );
583
- session.resetBufferedMessages();
584
- session.closeStaleConnection(conn);
585
- this.deleteSession(session);
586
- session = void 0;
583
+ oldSession.close();
584
+ this.deleteSession(oldSession);
585
+ oldSession = void 0;
587
586
  }
588
587
  this.connectedInstanceIds.set(connectedTo, instanceId);
589
- if (session === void 0) {
588
+ if (oldSession === void 0) {
590
589
  const newSession = this.createSession(connectedTo, conn);
591
590
  log?.info(
592
591
  `${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
@@ -594,11 +593,11 @@ var Transport = class {
594
593
  return newSession;
595
594
  }
596
595
  log?.info(
597
- `${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${session.debugId}) to ${connectedTo}`
596
+ `${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.debugId}) to ${connectedTo}`
598
597
  );
599
- session.replaceWithNewConnection(conn);
600
- session.sendBufferedMessages();
601
- return session;
598
+ oldSession.replaceWithNewConnection(conn);
599
+ oldSession.sendBufferedMessages();
600
+ return oldSession;
602
601
  }
603
602
  createSession(connectedTo, conn) {
604
603
  const session = new Session(
@@ -627,13 +626,14 @@ var Transport = class {
627
626
  /**
628
627
  * The downstream implementation needs to call this when a connection is closed.
629
628
  * @param conn The connection object.
629
+ * @param connectedTo The peer we are connected to.
630
630
  */
631
631
  onDisconnect(conn, connectedTo) {
632
632
  this.eventDispatcher.dispatchEvent("connectionStatus", {
633
633
  status: "disconnect",
634
634
  conn
635
635
  });
636
- if (!connectedTo)
636
+ if (this.state !== "open")
637
637
  return;
638
638
  const session = this.sessionByClientId(connectedTo);
639
639
  log?.info(
@@ -676,6 +676,8 @@ var Transport = class {
676
676
  * @param msg The received message.
677
677
  */
678
678
  handleMsg(msg) {
679
+ if (this.state !== "open")
680
+ return;
679
681
  const session = this.sessionByClientId(msg.from);
680
682
  session.cancelGrace();
681
683
  log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
@@ -752,10 +754,11 @@ var Transport = class {
752
754
  * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
753
755
  */
754
756
  close() {
757
+ this.state = "closed";
755
758
  for (const session of this.sessions.values()) {
756
- session.halfCloseConnection();
759
+ session.close();
760
+ this.deleteSession(session);
757
761
  }
758
- this.state = "closed";
759
762
  log?.info(`${this.clientId} -- manually closed transport`);
760
763
  }
761
764
  /**
@@ -764,10 +767,11 @@ var Transport = class {
764
767
  * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
765
768
  */
766
769
  destroy() {
770
+ this.state = "destroyed";
767
771
  for (const session of this.sessions.values()) {
768
- session.closeStaleConnection(session.connection);
772
+ session.close();
773
+ this.deleteSession(session);
769
774
  }
770
- this.state = "destroyed";
771
775
  log?.info(`${this.clientId} -- manually destroyed transport`);
772
776
  }
773
777
  };
@@ -873,8 +877,7 @@ var ClientTransport = class extends Transport {
873
877
  return bootHandler;
874
878
  }
875
879
  onDisconnect(conn, connectedTo) {
876
- if (connectedTo)
877
- this.inflightConnectionPromises.delete(connectedTo);
880
+ this.inflightConnectionPromises.delete(connectedTo);
878
881
  super.onDisconnect(conn, connectedTo);
879
882
  }
880
883
  };
@@ -1,5 +1,5 @@
1
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-0c0a69f6.js';
2
- import { U as UdsConnection } from '../../../connection-d880aa4a.js';
1
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
2
+ import { U as UdsConnection } from '../../../connection-a6cc48e8.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-0c0a69f6.js';
2
- import { U as UdsConnection } from '../../../connection-d880aa4a.js';
1
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
2
+ import { U as UdsConnection } from '../../../connection-a6cc48e8.js';
3
3
  import '../../../types-3e5768ec.js';
4
4
  import '@sinclair/typebox';
5
5
  import 'node:net';
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  UdsConnection
3
- } from "../../../chunk-PIF32FUL.js";
3
+ } from "../../../chunk-7J66WOIC.js";
4
4
  import "../../../chunk-IIBVKYDB.js";
5
5
  import {
6
6
  ClientTransport
7
- } from "../../../chunk-CT57CKBS.js";
7
+ } from "../../../chunk-2PKONGC3.js";
8
8
  import "../../../chunk-GZ7HCLLM.js";
9
9
  import "../../../chunk-XFFS4UOD.js";
10
10
  import {
@@ -296,17 +296,27 @@ var Session = class {
296
296
  this.cancelGrace();
297
297
  this.connection = newConn;
298
298
  }
299
+ graceCb;
299
300
  beginGrace(cb) {
301
+ this.graceCb = cb;
300
302
  this.disconnectionGrace = setTimeout(() => {
301
- this.resetBufferedMessages();
302
- clearInterval(this.heartbeat);
303
+ this.close();
303
304
  cb();
304
305
  }, SESSION_DISCONNECT_GRACE_MS);
305
306
  }
307
+ // called on reconnect of the underlying session
306
308
  cancelGrace() {
307
309
  this.heartbeatMisses = 0;
308
310
  clearTimeout(this.disconnectionGrace);
309
311
  }
312
+ // closed when we want to discard the whole session
313
+ // (i.e. shutdown or session disconnect)
314
+ close() {
315
+ this.closeStaleConnection(this.connection);
316
+ this.cancelGrace();
317
+ clearInterval(this.heartbeat);
318
+ this.resetBufferedMessages();
319
+ }
310
320
  get connected() {
311
321
  return this.connection !== void 0;
312
322
  }
@@ -325,16 +335,6 @@ var Session = class {
325
335
  this.seq++;
326
336
  return msg;
327
337
  }
328
- /**
329
- * Closes the out-going connection but doesn't remove the listeners
330
- * for incoming messages. The connection will eventually call onClose
331
- * when it is ready to be cleaned up and only then will {@link connection} be set back
332
- * to undefined
333
- */
334
- halfCloseConnection() {
335
- this.connection?.close();
336
- clearInterval(this.heartbeat);
337
- }
338
338
  inspectSendBuffer() {
339
339
  return this.sendBuffer;
340
340
  }
@@ -486,19 +486,18 @@ var Transport = class {
486
486
  status: "connect",
487
487
  conn
488
488
  });
489
- let session = this.sessions.get(connectedTo);
489
+ let oldSession = this.sessions.get(connectedTo);
490
490
  const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
491
- if (session && lastInstanceId !== instanceId && lastInstanceId !== void 0) {
491
+ if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
492
492
  log?.warn(
493
- `${this.clientId} -- handshake from ${connectedTo} has different server instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
493
+ `${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
494
494
  );
495
- session.resetBufferedMessages();
496
- session.closeStaleConnection(conn);
497
- this.deleteSession(session);
498
- session = void 0;
495
+ oldSession.close();
496
+ this.deleteSession(oldSession);
497
+ oldSession = void 0;
499
498
  }
500
499
  this.connectedInstanceIds.set(connectedTo, instanceId);
501
- if (session === void 0) {
500
+ if (oldSession === void 0) {
502
501
  const newSession = this.createSession(connectedTo, conn);
503
502
  log?.info(
504
503
  `${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
@@ -506,11 +505,11 @@ var Transport = class {
506
505
  return newSession;
507
506
  }
508
507
  log?.info(
509
- `${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${session.debugId}) to ${connectedTo}`
508
+ `${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.debugId}) to ${connectedTo}`
510
509
  );
511
- session.replaceWithNewConnection(conn);
512
- session.sendBufferedMessages();
513
- return session;
510
+ oldSession.replaceWithNewConnection(conn);
511
+ oldSession.sendBufferedMessages();
512
+ return oldSession;
514
513
  }
515
514
  createSession(connectedTo, conn) {
516
515
  const session = new Session(
@@ -539,13 +538,14 @@ var Transport = class {
539
538
  /**
540
539
  * The downstream implementation needs to call this when a connection is closed.
541
540
  * @param conn The connection object.
541
+ * @param connectedTo The peer we are connected to.
542
542
  */
543
543
  onDisconnect(conn, connectedTo) {
544
544
  this.eventDispatcher.dispatchEvent("connectionStatus", {
545
545
  status: "disconnect",
546
546
  conn
547
547
  });
548
- if (!connectedTo)
548
+ if (this.state !== "open")
549
549
  return;
550
550
  const session = this.sessionByClientId(connectedTo);
551
551
  log?.info(
@@ -588,6 +588,8 @@ var Transport = class {
588
588
  * @param msg The received message.
589
589
  */
590
590
  handleMsg(msg) {
591
+ if (this.state !== "open")
592
+ return;
591
593
  const session = this.sessionByClientId(msg.from);
592
594
  session.cancelGrace();
593
595
  log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
@@ -664,10 +666,11 @@ var Transport = class {
664
666
  * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
665
667
  */
666
668
  close() {
669
+ this.state = "closed";
667
670
  for (const session of this.sessions.values()) {
668
- session.halfCloseConnection();
671
+ session.close();
672
+ this.deleteSession(session);
669
673
  }
670
- this.state = "closed";
671
674
  log?.info(`${this.clientId} -- manually closed transport`);
672
675
  }
673
676
  /**
@@ -676,10 +679,11 @@ var Transport = class {
676
679
  * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
677
680
  */
678
681
  destroy() {
682
+ this.state = "destroyed";
679
683
  for (const session of this.sessions.values()) {
680
- session.closeStaleConnection(session.connection);
684
+ session.close();
685
+ this.deleteSession(session);
681
686
  }
682
- this.state = "destroyed";
683
687
  log?.info(`${this.clientId} -- manually destroyed transport`);
684
688
  }
685
689
  };
@@ -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-0c0a69f6.js';
3
- import { U as UdsConnection } from '../../../connection-d880aa4a.js';
2
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
3
+ import { U as UdsConnection } from '../../../connection-a6cc48e8.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import '../../../messageFraming-b200ef25.js';
@@ -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-0c0a69f6.js';
3
- import { U as UdsConnection } from '../../../connection-d880aa4a.js';
2
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
3
+ import { U as UdsConnection } from '../../../connection-a6cc48e8.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import '../../../messageFraming-b200ef25.js';
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  UdsConnection
3
- } from "../../../chunk-PIF32FUL.js";
3
+ } from "../../../chunk-7J66WOIC.js";
4
4
  import "../../../chunk-IIBVKYDB.js";
5
5
  import {
6
6
  ServerTransport
7
- } from "../../../chunk-CT57CKBS.js";
7
+ } from "../../../chunk-2PKONGC3.js";
8
8
  import "../../../chunk-GZ7HCLLM.js";
9
9
  import "../../../chunk-XFFS4UOD.js";
10
10
  import {
@@ -288,17 +288,27 @@ var Session = class {
288
288
  this.cancelGrace();
289
289
  this.connection = newConn;
290
290
  }
291
+ graceCb;
291
292
  beginGrace(cb) {
293
+ this.graceCb = cb;
292
294
  this.disconnectionGrace = setTimeout(() => {
293
- this.resetBufferedMessages();
294
- clearInterval(this.heartbeat);
295
+ this.close();
295
296
  cb();
296
297
  }, SESSION_DISCONNECT_GRACE_MS);
297
298
  }
299
+ // called on reconnect of the underlying session
298
300
  cancelGrace() {
299
301
  this.heartbeatMisses = 0;
300
302
  clearTimeout(this.disconnectionGrace);
301
303
  }
304
+ // closed when we want to discard the whole session
305
+ // (i.e. shutdown or session disconnect)
306
+ close() {
307
+ this.closeStaleConnection(this.connection);
308
+ this.cancelGrace();
309
+ clearInterval(this.heartbeat);
310
+ this.resetBufferedMessages();
311
+ }
302
312
  get connected() {
303
313
  return this.connection !== void 0;
304
314
  }
@@ -317,16 +327,6 @@ var Session = class {
317
327
  this.seq++;
318
328
  return msg;
319
329
  }
320
- /**
321
- * Closes the out-going connection but doesn't remove the listeners
322
- * for incoming messages. The connection will eventually call onClose
323
- * when it is ready to be cleaned up and only then will {@link connection} be set back
324
- * to undefined
325
- */
326
- halfCloseConnection() {
327
- this.connection?.close();
328
- clearInterval(this.heartbeat);
329
- }
330
330
  inspectSendBuffer() {
331
331
  return this.sendBuffer;
332
332
  }
@@ -478,19 +478,18 @@ var Transport = class {
478
478
  status: "connect",
479
479
  conn
480
480
  });
481
- let session = this.sessions.get(connectedTo);
481
+ let oldSession = this.sessions.get(connectedTo);
482
482
  const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
483
- if (session && lastInstanceId !== instanceId && lastInstanceId !== void 0) {
483
+ if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
484
484
  log?.warn(
485
- `${this.clientId} -- handshake from ${connectedTo} has different server instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
485
+ `${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
486
486
  );
487
- session.resetBufferedMessages();
488
- session.closeStaleConnection(conn);
489
- this.deleteSession(session);
490
- session = void 0;
487
+ oldSession.close();
488
+ this.deleteSession(oldSession);
489
+ oldSession = void 0;
491
490
  }
492
491
  this.connectedInstanceIds.set(connectedTo, instanceId);
493
- if (session === void 0) {
492
+ if (oldSession === void 0) {
494
493
  const newSession = this.createSession(connectedTo, conn);
495
494
  log?.info(
496
495
  `${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
@@ -498,11 +497,11 @@ var Transport = class {
498
497
  return newSession;
499
498
  }
500
499
  log?.info(
501
- `${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${session.debugId}) to ${connectedTo}`
500
+ `${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.debugId}) to ${connectedTo}`
502
501
  );
503
- session.replaceWithNewConnection(conn);
504
- session.sendBufferedMessages();
505
- return session;
502
+ oldSession.replaceWithNewConnection(conn);
503
+ oldSession.sendBufferedMessages();
504
+ return oldSession;
506
505
  }
507
506
  createSession(connectedTo, conn) {
508
507
  const session = new Session(
@@ -531,13 +530,14 @@ var Transport = class {
531
530
  /**
532
531
  * The downstream implementation needs to call this when a connection is closed.
533
532
  * @param conn The connection object.
533
+ * @param connectedTo The peer we are connected to.
534
534
  */
535
535
  onDisconnect(conn, connectedTo) {
536
536
  this.eventDispatcher.dispatchEvent("connectionStatus", {
537
537
  status: "disconnect",
538
538
  conn
539
539
  });
540
- if (!connectedTo)
540
+ if (this.state !== "open")
541
541
  return;
542
542
  const session = this.sessionByClientId(connectedTo);
543
543
  log?.info(
@@ -580,6 +580,8 @@ var Transport = class {
580
580
  * @param msg The received message.
581
581
  */
582
582
  handleMsg(msg) {
583
+ if (this.state !== "open")
584
+ return;
583
585
  const session = this.sessionByClientId(msg.from);
584
586
  session.cancelGrace();
585
587
  log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
@@ -656,10 +658,11 @@ var Transport = class {
656
658
  * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
657
659
  */
658
660
  close() {
661
+ this.state = "closed";
659
662
  for (const session of this.sessions.values()) {
660
- session.halfCloseConnection();
663
+ session.close();
664
+ this.deleteSession(session);
661
665
  }
662
- this.state = "closed";
663
666
  log?.info(`${this.clientId} -- manually closed transport`);
664
667
  }
665
668
  /**
@@ -668,10 +671,11 @@ var Transport = class {
668
671
  * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
669
672
  */
670
673
  destroy() {
674
+ this.state = "destroyed";
671
675
  for (const session of this.sessions.values()) {
672
- session.closeStaleConnection(session.connection);
676
+ session.close();
677
+ this.deleteSession(session);
673
678
  }
674
- this.state = "destroyed";
675
679
  log?.info(`${this.clientId} -- manually destroyed transport`);
676
680
  }
677
681
  };
@@ -777,8 +781,7 @@ var ClientTransport = class extends Transport {
777
781
  return bootHandler;
778
782
  }
779
783
  onDisconnect(conn, connectedTo) {
780
- if (connectedTo)
781
- this.inflightConnectionPromises.delete(connectedTo);
784
+ this.inflightConnectionPromises.delete(connectedTo);
782
785
  super.onDisconnect(conn, connectedTo);
783
786
  }
784
787
  };
@@ -864,9 +867,12 @@ var WebSocketClientTransport = class extends ClientTransport {
864
867
  resolve({ err: evt.reason });
865
868
  };
866
869
  const onError = (evt) => {
870
+ const err = evt.error;
867
871
  ws.removeEventListener("error", onError);
868
872
  ws.removeEventListener("close", onClose);
869
- resolve({ err: evt.message });
873
+ resolve({
874
+ err: err?.code ?? coerceErrorString(err)
875
+ });
870
876
  };
871
877
  ws.addEventListener("open", onOpen);
872
878
  ws.addEventListener("close", onClose);
@@ -1,6 +1,6 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-0c0a69f6.js';
3
- import { W as WebSocketConnection } from '../../../connection-eb10d250.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
3
+ import { W as WebSocketConnection } from '../../../connection-4a839b9a.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-0c0a69f6.js';
3
- import { W as WebSocketConnection } from '../../../connection-eb10d250.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
3
+ import { W as WebSocketConnection } from '../../../connection-4a839b9a.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-NHSJ4RDY.js";
3
+ } from "../../../chunk-6OAKPO5R.js";
4
4
  import {
5
5
  ClientTransport
6
- } from "../../../chunk-CT57CKBS.js";
6
+ } from "../../../chunk-2PKONGC3.js";
7
7
  import "../../../chunk-GZ7HCLLM.js";
8
- import "../../../chunk-XFFS4UOD.js";
8
+ import {
9
+ coerceErrorString
10
+ } from "../../../chunk-XFFS4UOD.js";
9
11
  import {
10
12
  log
11
13
  } from "../../../chunk-H4BYJELI.js";
@@ -58,9 +60,12 @@ var WebSocketClientTransport = class extends ClientTransport {
58
60
  resolve({ err: evt.reason });
59
61
  };
60
62
  const onError = (evt) => {
63
+ const err = evt.error;
61
64
  ws.removeEventListener("error", onError);
62
65
  ws.removeEventListener("close", onClose);
63
- resolve({ err: evt.message });
66
+ resolve({
67
+ err: err?.code ?? coerceErrorString(err)
68
+ });
64
69
  };
65
70
  ws.addEventListener("open", onOpen);
66
71
  ws.addEventListener("close", onClose);