@replit/river 0.13.0 → 0.13.1

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 (38) hide show
  1. package/README.md +2 -0
  2. package/dist/{builder-169fbf7f.d.ts → builder-eef3b061.d.ts} +1 -1
  3. package/dist/{chunk-CBRQM65K.js → chunk-JXKTY3GQ.js} +49 -40
  4. package/dist/{chunk-CDH7QSB4.js → chunk-JXO2SCQB.js} +1 -1
  5. package/dist/{chunk-R2IMXRVU.js → chunk-LDUFHGZU.js} +1 -1
  6. package/dist/{chunk-NPXAAD7M.js → chunk-Q7AWJYDQ.js} +1 -1
  7. package/dist/{chunk-MGGIUH5O.js → chunk-SCG5S2EC.js} +3 -3
  8. package/dist/{connection-dd789651.d.ts → connection-03e650c8.d.ts} +1 -1
  9. package/dist/{connection-ab681c08.d.ts → connection-d052d027.d.ts} +1 -1
  10. package/dist/{index-21c1b21d.d.ts → index-9aa0aabb.d.ts} +0 -26
  11. package/dist/router/index.cjs +52 -43
  12. package/dist/router/index.d.cts +3 -3
  13. package/dist/router/index.d.ts +3 -3
  14. package/dist/router/index.js +2 -2
  15. package/dist/transport/impls/uds/client.cjs +1 -1
  16. package/dist/transport/impls/uds/client.d.cts +2 -2
  17. package/dist/transport/impls/uds/client.d.ts +2 -2
  18. package/dist/transport/impls/uds/client.js +3 -3
  19. package/dist/transport/impls/uds/server.cjs +3 -3
  20. package/dist/transport/impls/uds/server.d.cts +2 -2
  21. package/dist/transport/impls/uds/server.d.ts +2 -2
  22. package/dist/transport/impls/uds/server.js +3 -3
  23. package/dist/transport/impls/ws/client.cjs +4 -11
  24. package/dist/transport/impls/ws/client.d.cts +2 -2
  25. package/dist/transport/impls/ws/client.d.ts +2 -2
  26. package/dist/transport/impls/ws/client.js +6 -13
  27. package/dist/transport/impls/ws/server.cjs +3 -3
  28. package/dist/transport/impls/ws/server.d.cts +2 -2
  29. package/dist/transport/impls/ws/server.d.ts +2 -2
  30. package/dist/transport/impls/ws/server.js +3 -3
  31. package/dist/transport/index.cjs +3 -3
  32. package/dist/transport/index.d.cts +1 -1
  33. package/dist/transport/index.d.ts +1 -1
  34. package/dist/transport/index.js +2 -2
  35. package/dist/util/testHelpers.d.cts +2 -2
  36. package/dist/util/testHelpers.d.ts +2 -2
  37. package/dist/util/testHelpers.js +3 -3
  38. package/package.json +1 -1
package/README.md CHANGED
@@ -10,6 +10,8 @@ It's like tRPC/gRPC but with
10
10
  - transparent reconnect support for long-lived sessions
11
11
  - over any transport (WebSockets and Unix Domain Socket out of the box)
12
12
 
13
+ See [PROTOCOL.md](./PROTOCOL.md) for more information on the protocol.
14
+
13
15
  ## Installation
14
16
 
15
17
  To use River, you must be on least Typescript 5 with `"moduleResolution": "bundler"`.
@@ -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-21c1b21d.js';
3
+ import { b as TransportClientId, d as Session, C as Connection } from './index-9aa0aabb.js';
4
4
 
5
5
  /**
6
6
  * The context for services/procedures. This is used only on
@@ -3,7 +3,7 @@ import {
3
3
  coerceErrorString,
4
4
  isStreamClose,
5
5
  isStreamOpen
6
- } from "./chunk-MGGIUH5O.js";
6
+ } from "./chunk-SCG5S2EC.js";
7
7
  import {
8
8
  log
9
9
  } from "./chunk-H4BYJELI.js";
@@ -438,6 +438,11 @@ var createClient = (transport) => _createRecursiveProxy(async (opts) => {
438
438
  );
439
439
  }
440
440
  const [input] = opts.args;
441
+ log?.info(
442
+ `${transport.clientId} -- invoked ${procType}: ${serviceName}.${procName} with args: ${JSON.stringify(
443
+ input
444
+ )}`
445
+ );
441
446
  if (procType === "rpc") {
442
447
  return handleRpc(
443
448
  transport,
@@ -505,16 +510,12 @@ function handleRpc(transport, serverId, input, serviceName, procedureName) {
505
510
  transport.removeEventListener("sessionStatus", onSessionStatus);
506
511
  }
507
512
  function onMessage(msg) {
508
- if (msg.streamId !== streamId) {
513
+ if (msg.streamId !== streamId)
509
514
  return;
510
- }
511
- if (msg.to !== transport.clientId) {
515
+ if (msg.to !== transport.clientId)
512
516
  return;
513
- }
514
- if (msg.streamId === streamId) {
515
- cleanup();
516
- resolve(msg.payload);
517
- }
517
+ cleanup();
518
+ resolve(msg.payload);
518
519
  }
519
520
  transport.addEventListener("message", onMessage);
520
521
  transport.addEventListener("sessionStatus", onSessionStatus);
@@ -558,12 +559,10 @@ function handleStream(transport, serverId, init, serviceName, procedureName) {
558
559
  };
559
560
  void pipeInputToTransport();
560
561
  function onMessage(msg) {
561
- if (msg.streamId !== streamId) {
562
+ if (msg.streamId !== streamId)
562
563
  return;
563
- }
564
- if (msg.to !== transport.clientId) {
564
+ if (msg.to !== transport.clientId)
565
565
  return;
566
- }
567
566
  if (isStreamClose(msg.controlFlags)) {
568
567
  cleanup();
569
568
  } else {
@@ -602,12 +601,10 @@ function handleSubscribe(transport, serverId, input, serviceName, procedureName)
602
601
  let healthyClose = true;
603
602
  const outputStream = pushable({ objectMode: true });
604
603
  function onMessage(msg) {
605
- if (msg.streamId !== streamId) {
604
+ if (msg.streamId !== streamId)
606
605
  return;
607
- }
608
- if (msg.to !== transport.clientId) {
606
+ if (msg.to !== transport.clientId)
609
607
  return;
610
- }
611
608
  if (isStreamClose(msg.controlFlags)) {
612
609
  cleanup();
613
610
  } else {
@@ -691,13 +688,12 @@ function handleUpload(transport, serverId, init, serviceName, procedureName) {
691
688
  transport.removeEventListener("sessionStatus", onSessionStatus);
692
689
  }
693
690
  function onMessage(msg) {
694
- if (msg.to !== transport.clientId) {
691
+ if (msg.streamId !== streamId)
695
692
  return;
696
- }
697
- if (msg.streamId === streamId) {
698
- cleanup();
699
- resolve(msg.payload);
700
- }
693
+ if (msg.to !== transport.clientId)
694
+ return;
695
+ cleanup();
696
+ resolve(msg.payload);
701
697
  }
702
698
  transport.addEventListener("message", onMessage);
703
699
  transport.addEventListener("sessionStatus", onSessionStatus);
@@ -752,17 +748,15 @@ var RiverServer = class {
752
748
  };
753
749
  // cleanup streams on session close
754
750
  onSessionStatus = async (evt) => {
755
- if (evt.status !== "disconnect") {
751
+ if (evt.status !== "disconnect")
756
752
  return;
757
- }
758
753
  const disconnectedClientId = evt.session.to;
759
754
  log?.info(
760
755
  `${this.transport.clientId} -- got session disconnect from ${disconnectedClientId}, cleaning up streams`
761
756
  );
762
757
  const streamsFromThisClient = this.clientStreams.get(disconnectedClientId);
763
- if (!streamsFromThisClient) {
758
+ if (!streamsFromThisClient)
764
759
  return;
765
- }
766
760
  this.disconnectedSessions.add(disconnectedClientId);
767
761
  await Promise.all(
768
762
  Array.from(streamsFromThisClient).map(this.cleanupStream)
@@ -812,21 +806,36 @@ var RiverServer = class {
812
806
  const procedure = service.procedures[message.procedureName];
813
807
  const incoming = pushable({ objectMode: true });
814
808
  const outgoing = pushable({ objectMode: true });
809
+ const needsClose = procedure.type === "subscription" || procedure.type === "stream";
815
810
  const outputHandler = (
816
811
  // sending outgoing messages back to client
817
- (async () => {
818
- for await (const response of outgoing) {
819
- this.transport.send(session.to, {
820
- streamId: message.streamId,
821
- controlFlags: 0,
822
- payload: response
823
- });
824
- }
825
- const needsClose = procedure.type === "subscription" || procedure.type === "stream";
826
- if (needsClose && !this.disconnectedSessions.has(message.from)) {
827
- this.transport.sendCloseStream(session.to, message.streamId);
828
- }
829
- })()
812
+ needsClose ? (
813
+ // subscription and stream case, we need to send a close bit after the response stream
814
+ (async () => {
815
+ for await (const response of outgoing) {
816
+ this.transport.send(session.to, {
817
+ streamId: message.streamId,
818
+ controlFlags: 0,
819
+ payload: response
820
+ });
821
+ }
822
+ if (!this.disconnectedSessions.has(message.from)) {
823
+ this.transport.sendCloseStream(session.to, message.streamId);
824
+ }
825
+ })()
826
+ ) : (
827
+ // rpc and upload case, we just send the response back with close bit
828
+ (async () => {
829
+ const response = await outgoing.next().then((res) => res.value);
830
+ if (response) {
831
+ this.transport.send(session.to, {
832
+ streamId: message.streamId,
833
+ controlFlags: 4 /* StreamClosedBit */,
834
+ payload: response
835
+ });
836
+ }
837
+ })()
838
+ )
830
839
  );
831
840
  const errorHandler = (err) => {
832
841
  const errorMsg = coerceErrorString(err);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-R2IMXRVU.js";
3
+ } from "./chunk-LDUFHGZU.js";
4
4
 
5
5
  // transport/transforms/messageFraming.ts
6
6
  import { Transform } from "node:stream";
@@ -7,7 +7,7 @@ import {
7
7
  handshakeRequestMessage,
8
8
  handshakeResponseMessage,
9
9
  isAck
10
- } from "./chunk-MGGIUH5O.js";
10
+ } from "./chunk-SCG5S2EC.js";
11
11
  import {
12
12
  log
13
13
  } from "./chunk-H4BYJELI.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-R2IMXRVU.js";
3
+ } from "./chunk-LDUFHGZU.js";
4
4
 
5
5
  // transport/impls/ws/connection.ts
6
6
  var WebSocketConnection = class extends Connection {
@@ -34,7 +34,7 @@ var ControlMessageHandshakeResponseSchema = Type.Object({
34
34
  }),
35
35
  Type.Object({
36
36
  ok: Type.Literal(false),
37
- reason: Type.Union([Type.Literal("VERSION_MISMATCH")])
37
+ reason: Type.String()
38
38
  })
39
39
  ])
40
40
  });
@@ -63,7 +63,7 @@ function handshakeRequestMessage(from, to, instanceId) {
63
63
  }
64
64
  };
65
65
  }
66
- function handshakeResponseMessage(from, instanceId, to, ok) {
66
+ function handshakeResponseMessage(from, instanceId, to, ok, reason) {
67
67
  return {
68
68
  id: nanoid(),
69
69
  from,
@@ -82,7 +82,7 @@ function handshakeResponseMessage(from, instanceId, to, ok) {
82
82
  type: "HANDSHAKE_RESP",
83
83
  status: {
84
84
  ok: false,
85
- reason: "VERSION_MISMATCH"
85
+ reason: reason ?? "Unknown reason"
86
86
  }
87
87
  }
88
88
  };
@@ -1,4 +1,4 @@
1
- import { C as Connection } from './index-21c1b21d.js';
1
+ import { C as Connection } from './index-9aa0aabb.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-21c1b21d.js';
2
+ import { C as Connection } from './index-9aa0aabb.js';
3
3
 
4
4
  declare class WebSocketConnection extends Connection {
5
5
  ws: WebSocket;
@@ -140,32 +140,6 @@ interface SessionOptions {
140
140
  * - This will only be considered disconnected if
141
141
  * - the server tells the client that we’ve reconnected but it doesn’t recognize us anymore (server definitely died) or
142
142
  * - we hit a grace period after a connection disconnect
143
- *
144
- * Here's a legend for what each of the numbers means. A '-' indicates the
145
- * session/connection is connected and ' ' means it is disconnected.
146
- *
147
- * 1. connectionStatus :: connect
148
- * 2. sessionStatus :: connect
149
- * 3. connectionStatus :: disconnect
150
- * 4. sessionStatus :: disconnect
151
- *
152
- * From the server's perspective:
153
- * ```plaintext
154
- * session 2-----------------------4
155
- * connection ----1---------3 1-------3
156
- * ^-^ grace period
157
- * ^---^ connection is created
158
- * before connectionStatus event is fired
159
- * ```
160
- *
161
- * From the client's perspective:
162
- * ```plaintext
163
- * session 2---------------------------4
164
- * connection 1---------3 1-------3
165
- * ^-^ grace period
166
- * ^---^ session is created as soon
167
- * as we send an outgoing message
168
- * ```
169
143
  */
170
144
  declare class Session<ConnType extends Connection> {
171
145
  private codec;
@@ -438,7 +438,7 @@ var ControlMessageHandshakeResponseSchema = import_typebox2.Type.Object({
438
438
  }),
439
439
  import_typebox2.Type.Object({
440
440
  ok: import_typebox2.Type.Literal(false),
441
- reason: import_typebox2.Type.Union([import_typebox2.Type.Literal("VERSION_MISMATCH")])
441
+ reason: import_typebox2.Type.String()
442
442
  })
443
443
  ])
444
444
  });
@@ -491,6 +491,9 @@ function Err(error) {
491
491
  };
492
492
  }
493
493
 
494
+ // logging/index.ts
495
+ var log;
496
+
494
497
  // router/client.ts
495
498
  var noop = () => {
496
499
  };
@@ -521,6 +524,11 @@ var createClient = (transport) => _createRecursiveProxy(async (opts) => {
521
524
  );
522
525
  }
523
526
  const [input] = opts.args;
527
+ log?.info(
528
+ `${transport.clientId} -- invoked ${procType}: ${serviceName}.${procName} with args: ${JSON.stringify(
529
+ input
530
+ )}`
531
+ );
524
532
  if (procType === "rpc") {
525
533
  return handleRpc(
526
534
  transport,
@@ -588,16 +596,12 @@ function handleRpc(transport, serverId, input, serviceName, procedureName) {
588
596
  transport.removeEventListener("sessionStatus", onSessionStatus);
589
597
  }
590
598
  function onMessage(msg) {
591
- if (msg.streamId !== streamId) {
599
+ if (msg.streamId !== streamId)
592
600
  return;
593
- }
594
- if (msg.to !== transport.clientId) {
601
+ if (msg.to !== transport.clientId)
595
602
  return;
596
- }
597
- if (msg.streamId === streamId) {
598
- cleanup();
599
- resolve(msg.payload);
600
- }
603
+ cleanup();
604
+ resolve(msg.payload);
601
605
  }
602
606
  transport.addEventListener("message", onMessage);
603
607
  transport.addEventListener("sessionStatus", onSessionStatus);
@@ -641,12 +645,10 @@ function handleStream(transport, serverId, init, serviceName, procedureName) {
641
645
  };
642
646
  void pipeInputToTransport();
643
647
  function onMessage(msg) {
644
- if (msg.streamId !== streamId) {
648
+ if (msg.streamId !== streamId)
645
649
  return;
646
- }
647
- if (msg.to !== transport.clientId) {
650
+ if (msg.to !== transport.clientId)
648
651
  return;
649
- }
650
652
  if (isStreamClose(msg.controlFlags)) {
651
653
  cleanup();
652
654
  } else {
@@ -685,12 +687,10 @@ function handleSubscribe(transport, serverId, input, serviceName, procedureName)
685
687
  let healthyClose = true;
686
688
  const outputStream = pushable({ objectMode: true });
687
689
  function onMessage(msg) {
688
- if (msg.streamId !== streamId) {
690
+ if (msg.streamId !== streamId)
689
691
  return;
690
- }
691
- if (msg.to !== transport.clientId) {
692
+ if (msg.to !== transport.clientId)
692
693
  return;
693
- }
694
694
  if (isStreamClose(msg.controlFlags)) {
695
695
  cleanup();
696
696
  } else {
@@ -774,13 +774,12 @@ function handleUpload(transport, serverId, init, serviceName, procedureName) {
774
774
  transport.removeEventListener("sessionStatus", onSessionStatus);
775
775
  }
776
776
  function onMessage(msg) {
777
- if (msg.to !== transport.clientId) {
777
+ if (msg.streamId !== streamId)
778
778
  return;
779
- }
780
- if (msg.streamId === streamId) {
781
- cleanup();
782
- resolve(msg.payload);
783
- }
779
+ if (msg.to !== transport.clientId)
780
+ return;
781
+ cleanup();
782
+ resolve(msg.payload);
784
783
  }
785
784
  transport.addEventListener("message", onMessage);
786
785
  transport.addEventListener("sessionStatus", onSessionStatus);
@@ -788,9 +787,6 @@ function handleUpload(transport, serverId, init, serviceName, procedureName) {
788
787
  return [inputStream, responsePromise];
789
788
  }
790
789
 
791
- // logging/index.ts
792
- var log;
793
-
794
790
  // router/server.ts
795
791
  var import_value = require("@sinclair/typebox/value");
796
792
 
@@ -848,17 +844,15 @@ var RiverServer = class {
848
844
  };
849
845
  // cleanup streams on session close
850
846
  onSessionStatus = async (evt) => {
851
- if (evt.status !== "disconnect") {
847
+ if (evt.status !== "disconnect")
852
848
  return;
853
- }
854
849
  const disconnectedClientId = evt.session.to;
855
850
  log?.info(
856
851
  `${this.transport.clientId} -- got session disconnect from ${disconnectedClientId}, cleaning up streams`
857
852
  );
858
853
  const streamsFromThisClient = this.clientStreams.get(disconnectedClientId);
859
- if (!streamsFromThisClient) {
854
+ if (!streamsFromThisClient)
860
855
  return;
861
- }
862
856
  this.disconnectedSessions.add(disconnectedClientId);
863
857
  await Promise.all(
864
858
  Array.from(streamsFromThisClient).map(this.cleanupStream)
@@ -908,21 +902,36 @@ var RiverServer = class {
908
902
  const procedure = service.procedures[message.procedureName];
909
903
  const incoming = pushable({ objectMode: true });
910
904
  const outgoing = pushable({ objectMode: true });
905
+ const needsClose = procedure.type === "subscription" || procedure.type === "stream";
911
906
  const outputHandler = (
912
907
  // sending outgoing messages back to client
913
- (async () => {
914
- for await (const response of outgoing) {
915
- this.transport.send(session.to, {
916
- streamId: message.streamId,
917
- controlFlags: 0,
918
- payload: response
919
- });
920
- }
921
- const needsClose = procedure.type === "subscription" || procedure.type === "stream";
922
- if (needsClose && !this.disconnectedSessions.has(message.from)) {
923
- this.transport.sendCloseStream(session.to, message.streamId);
924
- }
925
- })()
908
+ needsClose ? (
909
+ // subscription and stream case, we need to send a close bit after the response stream
910
+ (async () => {
911
+ for await (const response of outgoing) {
912
+ this.transport.send(session.to, {
913
+ streamId: message.streamId,
914
+ controlFlags: 0,
915
+ payload: response
916
+ });
917
+ }
918
+ if (!this.disconnectedSessions.has(message.from)) {
919
+ this.transport.sendCloseStream(session.to, message.streamId);
920
+ }
921
+ })()
922
+ ) : (
923
+ // rpc and upload case, we just send the response back with close bit
924
+ (async () => {
925
+ const response = await outgoing.next().then((res) => res.value);
926
+ if (response) {
927
+ this.transport.send(session.to, {
928
+ streamId: message.streamId,
929
+ controlFlags: 4 /* StreamClosedBit */,
930
+ payload: response
931
+ });
932
+ }
933
+ })()
934
+ )
926
935
  );
927
936
  const errorHandler = (err) => {
928
937
  const errorMsg = coerceErrorString(err);
@@ -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-169fbf7f.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-169fbf7f.js';
3
- import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-21c1b21d.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-eef3b061.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-eef3b061.js';
3
+ import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-9aa0aabb.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-169fbf7f.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-169fbf7f.js';
3
- import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-21c1b21d.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-eef3b061.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-eef3b061.js';
3
+ import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-9aa0aabb.js';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
6
6
  import '../types-3e5768ec.js';
@@ -8,8 +8,8 @@ import {
8
8
  createClient,
9
9
  createServer,
10
10
  serializeService
11
- } from "../chunk-CBRQM65K.js";
12
- import "../chunk-MGGIUH5O.js";
11
+ } from "../chunk-JXKTY3GQ.js";
12
+ import "../chunk-SCG5S2EC.js";
13
13
  import "../chunk-H4BYJELI.js";
14
14
  export {
15
15
  Err,
@@ -67,7 +67,7 @@ var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
67
67
  }),
68
68
  import_typebox.Type.Object({
69
69
  ok: import_typebox.Type.Literal(false),
70
- reason: import_typebox.Type.Union([import_typebox.Type.Literal("VERSION_MISMATCH")])
70
+ reason: import_typebox.Type.String()
71
71
  })
72
72
  ])
73
73
  });
@@ -1,5 +1,5 @@
1
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js';
2
- import { U as UdsConnection } from '../../../connection-dd789651.js';
1
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
2
+ import { U as UdsConnection } from '../../../connection-03e650c8.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-21c1b21d.js';
2
- import { U as UdsConnection } from '../../../connection-dd789651.js';
1
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
2
+ import { U as UdsConnection } from '../../../connection-03e650c8.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-CDH7QSB4.js";
3
+ } from "../../../chunk-JXO2SCQB.js";
4
4
  import {
5
5
  ClientTransport
6
- } from "../../../chunk-R2IMXRVU.js";
7
- import "../../../chunk-MGGIUH5O.js";
6
+ } from "../../../chunk-LDUFHGZU.js";
7
+ import "../../../chunk-SCG5S2EC.js";
8
8
  import {
9
9
  log
10
10
  } from "../../../chunk-H4BYJELI.js";
@@ -66,7 +66,7 @@ var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
66
66
  }),
67
67
  import_typebox.Type.Object({
68
68
  ok: import_typebox.Type.Literal(false),
69
- reason: import_typebox.Type.Union([import_typebox.Type.Literal("VERSION_MISMATCH")])
69
+ reason: import_typebox.Type.String()
70
70
  })
71
71
  ])
72
72
  });
@@ -79,7 +79,7 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
79
79
  var OpaqueTransportMessageSchema = TransportMessageSchema(
80
80
  import_typebox.Type.Unknown()
81
81
  );
82
- function handshakeResponseMessage(from, instanceId, to, ok) {
82
+ function handshakeResponseMessage(from, instanceId, to, ok, reason) {
83
83
  return {
84
84
  id: (0, import_nanoid.nanoid)(),
85
85
  from,
@@ -98,7 +98,7 @@ function handshakeResponseMessage(from, instanceId, to, ok) {
98
98
  type: "HANDSHAKE_RESP",
99
99
  status: {
100
100
  ok: false,
101
- reason: "VERSION_MISMATCH"
101
+ reason: reason ?? "Unknown reason"
102
102
  }
103
103
  }
104
104
  };
@@ -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-21c1b21d.js';
3
- import { U as UdsConnection } from '../../../connection-dd789651.js';
2
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
3
+ import { U as UdsConnection } from '../../../connection-03e650c8.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-21c1b21d.js';
3
- import { U as UdsConnection } from '../../../connection-dd789651.js';
2
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
3
+ import { U as UdsConnection } from '../../../connection-03e650c8.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'node:stream';
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  UdsConnection
3
- } from "../../../chunk-CDH7QSB4.js";
3
+ } from "../../../chunk-JXO2SCQB.js";
4
4
  import {
5
5
  ServerTransport
6
- } from "../../../chunk-R2IMXRVU.js";
7
- import "../../../chunk-MGGIUH5O.js";
6
+ } from "../../../chunk-LDUFHGZU.js";
7
+ import "../../../chunk-SCG5S2EC.js";
8
8
  import {
9
9
  log
10
10
  } from "../../../chunk-H4BYJELI.js";
@@ -63,7 +63,7 @@ var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
63
63
  }),
64
64
  import_typebox.Type.Object({
65
65
  ok: import_typebox.Type.Literal(false),
66
- reason: import_typebox.Type.Union([import_typebox.Type.Literal("VERSION_MISMATCH")])
66
+ reason: import_typebox.Type.String()
67
67
  })
68
68
  ])
69
69
  });
@@ -873,25 +873,18 @@ var WebSocketClientTransport = class extends ClientTransport {
873
873
  resolve({ err: "ws is closing or closed" });
874
874
  return;
875
875
  }
876
- const onOpen = () => {
877
- ws.removeEventListener("open", onOpen);
876
+ ws.onopen = () => {
878
877
  resolve({ ws });
879
878
  };
880
- const onClose = (evt) => {
881
- ws.removeEventListener("close", onClose);
879
+ ws.onclose = (evt) => {
882
880
  resolve({ err: evt.reason });
883
881
  };
884
- const onError = (evt) => {
882
+ ws.onerror = (evt) => {
885
883
  const err = evt.error;
886
- ws.removeEventListener("error", onError);
887
- ws.removeEventListener("close", onClose);
888
884
  resolve({
889
885
  err: err?.code ?? "unexpected disconnect"
890
886
  });
891
887
  };
892
- ws.addEventListener("open", onOpen);
893
- ws.addEventListener("close", onClose);
894
- ws.addEventListener("error", onError);
895
888
  }).catch((e) => {
896
889
  const reason = e instanceof Error ? e.message : "unknown reason";
897
890
  resolve({ err: `couldn't get a new websocket: ${reason}` });
@@ -1,6 +1,6 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js';
3
- import { W as WebSocketConnection } from '../../../connection-ab681c08.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
3
+ import { W as WebSocketConnection } from '../../../connection-d052d027.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-21c1b21d.js';
3
- import { W as WebSocketConnection } from '../../../connection-ab681c08.js';
2
+ import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
3
+ import { W as WebSocketConnection } from '../../../connection-d052d027.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-NPXAAD7M.js";
3
+ } from "../../../chunk-Q7AWJYDQ.js";
4
4
  import {
5
5
  ClientTransport
6
- } from "../../../chunk-R2IMXRVU.js";
7
- import "../../../chunk-MGGIUH5O.js";
6
+ } from "../../../chunk-LDUFHGZU.js";
7
+ import "../../../chunk-SCG5S2EC.js";
8
8
  import {
9
9
  log
10
10
  } from "../../../chunk-H4BYJELI.js";
@@ -49,25 +49,18 @@ var WebSocketClientTransport = class extends ClientTransport {
49
49
  resolve({ err: "ws is closing or closed" });
50
50
  return;
51
51
  }
52
- const onOpen = () => {
53
- ws.removeEventListener("open", onOpen);
52
+ ws.onopen = () => {
54
53
  resolve({ ws });
55
54
  };
56
- const onClose = (evt) => {
57
- ws.removeEventListener("close", onClose);
55
+ ws.onclose = (evt) => {
58
56
  resolve({ err: evt.reason });
59
57
  };
60
- const onError = (evt) => {
58
+ ws.onerror = (evt) => {
61
59
  const err = evt.error;
62
- ws.removeEventListener("error", onError);
63
- ws.removeEventListener("close", onClose);
64
60
  resolve({
65
61
  err: err?.code ?? "unexpected disconnect"
66
62
  });
67
63
  };
68
- ws.addEventListener("open", onOpen);
69
- ws.addEventListener("close", onClose);
70
- ws.addEventListener("error", onError);
71
64
  }).catch((e) => {
72
65
  const reason = e instanceof Error ? e.message : "unknown reason";
73
66
  resolve({ err: `couldn't get a new websocket: ${reason}` });
@@ -66,7 +66,7 @@ var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
66
66
  }),
67
67
  import_typebox.Type.Object({
68
68
  ok: import_typebox.Type.Literal(false),
69
- reason: import_typebox.Type.Union([import_typebox.Type.Literal("VERSION_MISMATCH")])
69
+ reason: import_typebox.Type.String()
70
70
  })
71
71
  ])
72
72
  });
@@ -79,7 +79,7 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
79
79
  var OpaqueTransportMessageSchema = TransportMessageSchema(
80
80
  import_typebox.Type.Unknown()
81
81
  );
82
- function handshakeResponseMessage(from, instanceId, to, ok) {
82
+ function handshakeResponseMessage(from, instanceId, to, ok, reason) {
83
83
  return {
84
84
  id: (0, import_nanoid.nanoid)(),
85
85
  from,
@@ -98,7 +98,7 @@ function handshakeResponseMessage(from, instanceId, to, ok) {
98
98
  type: "HANDSHAKE_RESP",
99
99
  status: {
100
100
  ok: false,
101
- reason: "VERSION_MISMATCH"
101
+ reason: reason ?? "Unknown reason"
102
102
  }
103
103
  }
104
104
  };
@@ -1,7 +1,7 @@
1
- import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js';
1
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
2
2
  import { WebSocketServer } from 'ws';
3
3
  import { WebSocket } from 'isomorphic-ws';
4
- import { W as WebSocketConnection } from '../../../connection-ab681c08.js';
4
+ import { W as WebSocketConnection } from '../../../connection-d052d027.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-21c1b21d.js';
1
+ import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-9aa0aabb.js';
2
2
  import { WebSocketServer } from 'ws';
3
3
  import { WebSocket } from 'isomorphic-ws';
4
- import { W as WebSocketConnection } from '../../../connection-ab681c08.js';
4
+ import { W as WebSocketConnection } from '../../../connection-d052d027.js';
5
5
  import '../../../types-3e5768ec.js';
6
6
  import '@sinclair/typebox';
7
7
 
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-NPXAAD7M.js";
3
+ } from "../../../chunk-Q7AWJYDQ.js";
4
4
  import {
5
5
  ServerTransport
6
- } from "../../../chunk-R2IMXRVU.js";
7
- import "../../../chunk-MGGIUH5O.js";
6
+ } from "../../../chunk-LDUFHGZU.js";
7
+ import "../../../chunk-SCG5S2EC.js";
8
8
  import {
9
9
  log
10
10
  } from "../../../chunk-H4BYJELI.js";
@@ -69,7 +69,7 @@ var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
69
69
  }),
70
70
  import_typebox.Type.Object({
71
71
  ok: import_typebox.Type.Literal(false),
72
- reason: import_typebox.Type.Union([import_typebox.Type.Literal("VERSION_MISMATCH")])
72
+ reason: import_typebox.Type.String()
73
73
  })
74
74
  ])
75
75
  });
@@ -98,7 +98,7 @@ function handshakeRequestMessage(from, to, instanceId) {
98
98
  }
99
99
  };
100
100
  }
101
- function handshakeResponseMessage(from, instanceId, to, ok) {
101
+ function handshakeResponseMessage(from, instanceId, to, ok, reason) {
102
102
  return {
103
103
  id: (0, import_nanoid.nanoid)(),
104
104
  from,
@@ -117,7 +117,7 @@ function handshakeResponseMessage(from, instanceId, to, ok) {
117
117
  type: "HANDSHAKE_RESP",
118
118
  status: {
119
119
  ok: false,
120
- reason: "VERSION_MISMATCH"
120
+ reason: reason ?? "Unknown reason"
121
121
  }
122
122
  }
123
123
  };
@@ -1,3 +1,3 @@
1
- export { a as ClientTransport, C as Connection, k as EventHandler, E as EventMap, j as EventTypes, O as OpaqueTransportMessage, f as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, g as TransportMessage, e as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-21c1b21d.js';
1
+ export { a as ClientTransport, C as Connection, k as EventHandler, E as EventMap, j as EventTypes, O as OpaqueTransportMessage, f as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, g as TransportMessage, e as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-9aa0aabb.js';
2
2
  import '../types-3e5768ec.js';
3
3
  import '@sinclair/typebox';
@@ -1,3 +1,3 @@
1
- export { a as ClientTransport, C as Connection, k as EventHandler, E as EventMap, j as EventTypes, O as OpaqueTransportMessage, f as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, g as TransportMessage, e as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-21c1b21d.js';
1
+ export { a as ClientTransport, C as Connection, k as EventHandler, E as EventMap, j as EventTypes, O as OpaqueTransportMessage, f as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, g as TransportMessage, e as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-9aa0aabb.js';
2
2
  import '../types-3e5768ec.js';
3
3
  import '@sinclair/typebox';
@@ -5,11 +5,11 @@ import {
5
5
  ServerTransport,
6
6
  Session,
7
7
  Transport
8
- } from "../chunk-R2IMXRVU.js";
8
+ } from "../chunk-LDUFHGZU.js";
9
9
  import {
10
10
  OpaqueTransportMessageSchema,
11
11
  TransportMessageSchema
12
- } from "../chunk-MGGIUH5O.js";
12
+ } from "../chunk-SCG5S2EC.js";
13
13
  import "../chunk-H4BYJELI.js";
14
14
  import "../chunk-GZ7HCLLM.js";
15
15
  export {
@@ -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-21c1b21d.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-169fbf7f.js';
4
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-9aa0aabb.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-eef3b061.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-21c1b21d.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-169fbf7f.js';
4
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-9aa0aabb.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-eef3b061.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  UNCAUGHT_ERROR,
3
3
  pushable
4
- } from "../chunk-CBRQM65K.js";
4
+ } from "../chunk-JXKTY3GQ.js";
5
5
  import "../chunk-5IZ2UHWV.js";
6
6
  import {
7
7
  Session,
8
8
  defaultSessionOptions
9
- } from "../chunk-R2IMXRVU.js";
9
+ } from "../chunk-LDUFHGZU.js";
10
10
  import {
11
11
  coerceErrorString
12
- } from "../chunk-MGGIUH5O.js";
12
+ } from "../chunk-SCG5S2EC.js";
13
13
  import "../chunk-H4BYJELI.js";
14
14
  import "../chunk-GZ7HCLLM.js";
15
15
 
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.0",
4
+ "version": "0.13.1",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {