@replit/river 0.10.5 → 0.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,130 @@
1
1
  # river - Streaming Remote Procedure Calls
2
2
 
3
- It's like tRPC but...
3
+ It's like tRPC/gRPC but with
4
4
 
5
- - with JSON Schema Support
6
- - with full-duplex streaming
7
- - with support for service multiplexing
8
- - with Result types and error handling
9
- - over WebSockets
5
+ - JSON Schema Support + run-time schema validation
6
+ - full-duplex streaming
7
+ - service multiplexing
8
+ - result types and error handling
9
+ - snappy DX (no code-generation)
10
+ - over any transport (WebSockets, stdio, Unix Domain Socket out of the box)
11
+
12
+ ## Installation
10
13
 
11
14
  To use River, you must be on least Typescript 5 with `"moduleResolution": "bundler"`.
12
15
 
16
+ ```bash
17
+ npm i @replit/river @sinclair/typebox
18
+
19
+ # if you plan on using WebSocket for transport, also install
20
+ npm i ws isomorphic-ws
21
+ ```
22
+
23
+ ## Writing Services
24
+
25
+ ### Concepts
26
+
27
+ - Router: a collection of services, namespaced by service name.
28
+ - Service: a collection of procedures with shared state.
29
+ - Procedure: a single procedure. A procedure declares its type, an input message type, an output message type, optionally an error type, and the associated handler. Valid types are:
30
+ - `rpc` whose handler has a signature of `Input -> Result<Output, Error>`.
31
+ - `upload` whose handler has a signature of `AsyncIterableIterator<Input> -> Result<Output, Error>`.
32
+ - `subscription` whose handler has a signature of `Input -> Pushable<Result<Output, Error>>`.
33
+ - `stream` whose handler has a signature of `AsyncIterableIterator<Input> -> Pushable<Result<Output, Error>>`.
34
+ - Transport: manages the lifecycle (creation/deletion) of connections and multiplexing read/writes from clients. Both the client and the server must be passed in a subclass of `Transport` to work.
35
+ - Codec: encodes messages between clients/servers before the transport sends it across the wire.
36
+
37
+ ### A basic router
38
+
39
+ First, we create a service using the `ServiceBuilder`
40
+
41
+ ```ts
42
+ import { ServiceBuilder, Ok, buildServiceDefs } from '@replit/river';
43
+ import { Type } from '@sinclair/typebox';
44
+
45
+ export const ExampleServiceConstructor = () =>
46
+ ServiceBuilder.create('example')
47
+ .initialState({
48
+ count: 0,
49
+ })
50
+ .defineProcedure('add', {
51
+ type: 'rpc',
52
+ input: Type.Object({ n: Type.Number() }),
53
+ output: Type.Object({ result: Type.Number() }),
54
+ errors: Type.Never(),
55
+ async handler(ctx, { n }) {
56
+ ctx.state.count += n;
57
+ return Ok({ result: ctx.state.count });
58
+ },
59
+ })
60
+ .finalize();
61
+
62
+ // expore a listing of all the services that we have
63
+ export const serviceDefs = buildServiceDefs([ExampleServiceConstructor()]);
64
+ ```
65
+
66
+ Then, we create the server
67
+
68
+ ```ts
69
+ import http from 'http';
70
+ import { WebSocketServer } from 'ws';
71
+ import { WebSocketServerTransport } from '@replit/river/transport/ws/server';
72
+ import { createServer } from '@replit/river';
73
+
74
+ // start websocket server on port 3000
75
+ const httpServer = http.createServer();
76
+ const port = 3000;
77
+ const wss = new WebSocketServer({ server: httpServer });
78
+ const transport = new WebSocketServerTransport(wss, 'SERVER');
79
+
80
+ export const server = createServer(transport, serviceDefs);
81
+ export type ServiceSurface = typeof server;
82
+
83
+ httpServer.listen(port);
84
+ ```
85
+
86
+ In another file for the client (to create a separate entrypoint),
87
+
88
+ ```ts
89
+ import WebSocket from 'isomorphic-ws';
90
+ import { WebSocketClientTransport } from '@replit/river/transport/ws/client';
91
+ import { createClient } from '@replit/river';
92
+
93
+ const websocketUrl = `ws://localhost:3000`;
94
+ const transport = new WebSocketClientTransport(
95
+ async () => new WebSocket(websocketUrl),
96
+ 'my-client-id',
97
+ 'SERVER',
98
+ );
99
+
100
+ const client = createClient<ServiceSurface>(transport, 'SERVER');
101
+
102
+ // we get full type safety on `client`
103
+ // client.<service name>.<procedure name>.<procedure type>()
104
+ // e.g.
105
+ const result = await client.example.add.rpc({ n: 3 });
106
+ if (result.ok) {
107
+ const msg = result.payload;
108
+ console.log(msg.result); // 0 + 3 = 3
109
+ }
110
+ ```
111
+
112
+ To add logging,
113
+
114
+ ```ts
115
+ import { bindLogger, setLevel } from '@replit/river/logging';
116
+
117
+ bindLogger(console.log);
118
+ setLevel('info');
119
+ ```
120
+
121
+ ### Further examples
122
+
123
+ We've also provided an end-to-end testing environment using Next.js, and a simple backend connected
124
+ with the WebSocket transport that you can [play with on Replit](https://replit.com/@jzhao-replit/riverbed).
125
+
126
+ You can find more service examples in the [E2E test fixtures](https://github.com/replit/river/blob/main/__tests__/fixtures/services.ts)
127
+
13
128
  ## Developing
14
129
 
15
130
  [![Run on Repl.it](https://replit.com/badge/github/replit/river)](https://replit.com/new/github/replit/river)
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-ZE4MX7DF.js";
9
9
  import {
10
10
  log
11
- } from "./chunk-SLUSVGQH.js";
11
+ } from "./chunk-T7M7OKPE.js";
12
12
 
13
13
  // router/builder.ts
14
14
  import { Type } from "@sinclair/typebox";
@@ -515,6 +515,12 @@ function handleRpc(transport, serverId, input, serviceName, procName) {
515
515
  transport.removeEventListener("connectionStatus", onConnectionStatus);
516
516
  }
517
517
  function onMessage(msg2) {
518
+ if (msg2.streamId !== streamId) {
519
+ return;
520
+ }
521
+ if (msg2.to !== transport.clientId) {
522
+ return;
523
+ }
518
524
  if (msg2.streamId === streamId) {
519
525
  cleanup();
520
526
  resolve(msg2.payload);
@@ -560,6 +566,9 @@ function handleStream(transport, serverId, init, serviceName, procName) {
560
566
  if (msg2.streamId !== streamId) {
561
567
  return;
562
568
  }
569
+ if (msg2.to !== transport.clientId) {
570
+ return;
571
+ }
563
572
  if (isStreamClose(msg2.controlFlags)) {
564
573
  cleanup();
565
574
  } else {
@@ -606,6 +615,9 @@ function handleSubscribe(transport, serverId, input, serviceName, procName) {
606
615
  if (msg2.streamId !== streamId) {
607
616
  return;
608
617
  }
618
+ if (msg2.to !== transport.clientId) {
619
+ return;
620
+ }
609
621
  if (isStreamClose(msg2.controlFlags)) {
610
622
  cleanup();
611
623
  } else {
@@ -680,6 +692,9 @@ function handleUpload(transport, serverId, input, serviceName, procName) {
680
692
  transport.removeEventListener("connectionStatus", onConnectionStatus);
681
693
  }
682
694
  function onMessage(msg2) {
695
+ if (msg2.to !== transport.clientId) {
696
+ return;
697
+ }
683
698
  if (msg2.streamId === streamId) {
684
699
  cleanup();
685
700
  resolve(msg2.payload);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-V2YJRBRX.js";
3
+ } from "./chunk-LQXPKF3A.js";
4
4
 
5
5
  // transport/transforms/delim.ts
6
6
  import { Transform } from "node:stream";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "./chunk-SZTOUKL7.js";
3
+ } from "./chunk-L7D75G4K.js";
4
4
  import {
5
5
  NaiveJsonCodec
6
6
  } from "./chunk-R6H2BIMC.js";
7
7
  import {
8
8
  Transport
9
- } from "./chunk-V2YJRBRX.js";
9
+ } from "./chunk-LQXPKF3A.js";
10
10
  import {
11
11
  log
12
- } from "./chunk-SLUSVGQH.js";
12
+ } from "./chunk-T7M7OKPE.js";
13
13
 
14
14
  // transport/impls/ws/client.ts
15
15
  var defaultOptions = {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-V2YJRBRX.js";
3
+ } from "./chunk-LQXPKF3A.js";
4
4
 
5
5
  // transport/impls/ws/connection.ts
6
6
  var WebSocketConnection = class extends Connection {
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-ZE4MX7DF.js";
7
7
  import {
8
8
  log
9
- } from "./chunk-SLUSVGQH.js";
9
+ } from "./chunk-T7M7OKPE.js";
10
10
 
11
11
  // transport/transport.ts
12
12
  import { Value } from "@sinclair/typebox/value";
@@ -178,15 +178,12 @@ var Transport = class {
178
178
  return;
179
179
  }
180
180
  if (isAck(msg.controlFlags) && Value.Check(TransportAckSchema, msg)) {
181
- log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
181
+ log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
182
182
  if (this.sendBuffer.has(msg.payload.ack)) {
183
183
  this.sendBuffer.delete(msg.payload.ack);
184
184
  }
185
185
  } else {
186
- log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
187
- if (msg.to !== this.clientId) {
188
- return;
189
- }
186
+ log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
190
187
  this.eventDispatcher.dispatchEvent("message", msg);
191
188
  if (!isAck(msg.controlFlags)) {
192
189
  const ackMsg = reply(msg, { ack: msg.id });
@@ -236,7 +233,7 @@ var Transport = class {
236
233
  this.sendBuffer.set(msg.id, msg);
237
234
  }
238
235
  if (conn) {
239
- log?.info(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
236
+ log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
240
237
  const ok = conn.send(this.codec.toBuffer(msg));
241
238
  if (ok) {
242
239
  return msg.id;
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "./chunk-SZTOUKL7.js";
3
+ } from "./chunk-L7D75G4K.js";
4
4
  import {
5
5
  NaiveJsonCodec
6
6
  } from "./chunk-R6H2BIMC.js";
7
7
  import {
8
8
  Transport
9
- } from "./chunk-V2YJRBRX.js";
9
+ } from "./chunk-LQXPKF3A.js";
10
10
  import {
11
11
  log
12
- } from "./chunk-SLUSVGQH.js";
12
+ } from "./chunk-T7M7OKPE.js";
13
13
 
14
14
  // transport/impls/ws/server.ts
15
15
  var defaultOptions = {
@@ -1,5 +1,6 @@
1
1
  // logging/index.ts
2
2
  var LoggingLevels = {
3
+ debug: -1,
3
4
  info: 0,
4
5
  warn: 1,
5
6
  error: 2
@@ -7,10 +8,12 @@ var LoggingLevels = {
7
8
  var log;
8
9
  var defaultLoggingLevel = "warn";
9
10
  function bindLogger(write, color) {
11
+ const debug = color ? "\x1B[37mdebug\x1B[0m" : "debug";
10
12
  const info = color ? "\x1B[37minfo\x1B[0m" : "info";
11
13
  const warn = color ? "\x1B[33mwarn\x1B[0m" : "warn";
12
14
  const error = color ? "\x1B[31merr\x1B[0m" : "err";
13
15
  log = {
16
+ debug: (msg) => log && LoggingLevels[log.minLevel] <= -1 && write(`[river:${debug}] ${msg}`),
14
17
  info: (msg) => log && LoggingLevels[log.minLevel] <= 0 && write(`[river:${info}] ${msg}`),
15
18
  warn: (msg) => log && LoggingLevels[log.minLevel] <= 1 && write(`[river:${warn}] ${msg}`),
16
19
  error: (msg) => log && LoggingLevels[log.minLevel] <= 2 && write(`[river:${error}] ${msg}`),
@@ -26,6 +26,7 @@ __export(logging_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(logging_exports);
28
28
  var LoggingLevels = {
29
+ debug: -1,
29
30
  info: 0,
30
31
  warn: 1,
31
32
  error: 2
@@ -33,10 +34,12 @@ var LoggingLevels = {
33
34
  var log;
34
35
  var defaultLoggingLevel = "warn";
35
36
  function bindLogger(write, color) {
37
+ const debug = color ? "\x1B[37mdebug\x1B[0m" : "debug";
36
38
  const info = color ? "\x1B[37minfo\x1B[0m" : "info";
37
39
  const warn = color ? "\x1B[33mwarn\x1B[0m" : "warn";
38
40
  const error = color ? "\x1B[31merr\x1B[0m" : "err";
39
41
  log = {
42
+ debug: (msg) => log && LoggingLevels[log.minLevel] <= -1 && write(`[river:${debug}] ${msg}`),
40
43
  info: (msg) => log && LoggingLevels[log.minLevel] <= 0 && write(`[river:${info}] ${msg}`),
41
44
  warn: (msg) => log && LoggingLevels[log.minLevel] <= 1 && write(`[river:${warn}] ${msg}`),
42
45
  error: (msg) => log && LoggingLevels[log.minLevel] <= 2 && write(`[river:${error}] ${msg}`),
@@ -1,4 +1,5 @@
1
1
  declare const LoggingLevels: {
2
+ readonly debug: -1;
2
3
  readonly info: 0;
3
4
  readonly warn: 1;
4
5
  readonly error: 2;
@@ -1,4 +1,5 @@
1
1
  declare const LoggingLevels: {
2
+ readonly debug: -1;
2
3
  readonly info: 0;
3
4
  readonly warn: 1;
4
5
  readonly error: 2;
@@ -2,7 +2,7 @@ import {
2
2
  bindLogger,
3
3
  log,
4
4
  setLevel
5
- } from "../chunk-SLUSVGQH.js";
5
+ } from "../chunk-T7M7OKPE.js";
6
6
  export {
7
7
  bindLogger,
8
8
  log,
@@ -595,6 +595,12 @@ function handleRpc(transport, serverId, input, serviceName, procName) {
595
595
  transport.removeEventListener("connectionStatus", onConnectionStatus);
596
596
  }
597
597
  function onMessage(msg2) {
598
+ if (msg2.streamId !== streamId) {
599
+ return;
600
+ }
601
+ if (msg2.to !== transport.clientId) {
602
+ return;
603
+ }
598
604
  if (msg2.streamId === streamId) {
599
605
  cleanup();
600
606
  resolve(msg2.payload);
@@ -640,6 +646,9 @@ function handleStream(transport, serverId, init, serviceName, procName) {
640
646
  if (msg2.streamId !== streamId) {
641
647
  return;
642
648
  }
649
+ if (msg2.to !== transport.clientId) {
650
+ return;
651
+ }
643
652
  if (isStreamClose(msg2.controlFlags)) {
644
653
  cleanup();
645
654
  } else {
@@ -686,6 +695,9 @@ function handleSubscribe(transport, serverId, input, serviceName, procName) {
686
695
  if (msg2.streamId !== streamId) {
687
696
  return;
688
697
  }
698
+ if (msg2.to !== transport.clientId) {
699
+ return;
700
+ }
689
701
  if (isStreamClose(msg2.controlFlags)) {
690
702
  cleanup();
691
703
  } else {
@@ -760,6 +772,9 @@ function handleUpload(transport, serverId, input, serviceName, procName) {
760
772
  transport.removeEventListener("connectionStatus", onConnectionStatus);
761
773
  }
762
774
  function onMessage(msg2) {
775
+ if (msg2.to !== transport.clientId) {
776
+ return;
777
+ }
763
778
  if (msg2.streamId === streamId) {
764
779
  cleanup();
765
780
  resolve(msg2.payload);
@@ -8,9 +8,9 @@ import {
8
8
  createClient,
9
9
  createServer,
10
10
  serializeService
11
- } from "../chunk-IYRPZPSQ.js";
11
+ } from "../chunk-3JGVFWKQ.js";
12
12
  import "../chunk-ZE4MX7DF.js";
13
- import "../chunk-SLUSVGQH.js";
13
+ import "../chunk-T7M7OKPE.js";
14
14
  export {
15
15
  Err,
16
16
  Ok,
@@ -335,15 +335,12 @@ var Transport = class {
335
335
  return;
336
336
  }
337
337
  if (isAck(msg.controlFlags) && import_value.Value.Check(TransportAckSchema, msg)) {
338
- log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
338
+ log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
339
339
  if (this.sendBuffer.has(msg.payload.ack)) {
340
340
  this.sendBuffer.delete(msg.payload.ack);
341
341
  }
342
342
  } else {
343
- log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
344
- if (msg.to !== this.clientId) {
345
- return;
346
- }
343
+ log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
347
344
  this.eventDispatcher.dispatchEvent("message", msg);
348
345
  if (!isAck(msg.controlFlags)) {
349
346
  const ackMsg = reply(msg, { ack: msg.id });
@@ -393,7 +390,7 @@ var Transport = class {
393
390
  this.sendBuffer.set(msg.id, msg);
394
391
  }
395
392
  if (conn) {
396
- log?.info(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
393
+ log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
397
394
  const ok = conn.send(this.codec.toBuffer(msg));
398
395
  if (ok) {
399
396
  return msg.id;
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  StreamConnection,
3
3
  createDelimitedStream
4
- } from "../../../chunk-TZSX5KM2.js";
4
+ } from "../../../chunk-3MQETIGZ.js";
5
5
  import "../../../chunk-ORAG7IAU.js";
6
6
  import {
7
7
  NaiveJsonCodec
8
8
  } from "../../../chunk-R6H2BIMC.js";
9
9
  import {
10
10
  Transport
11
- } from "../../../chunk-V2YJRBRX.js";
11
+ } from "../../../chunk-LQXPKF3A.js";
12
12
  import "../../../chunk-ZE4MX7DF.js";
13
13
  import {
14
14
  log
15
- } from "../../../chunk-SLUSVGQH.js";
15
+ } from "../../../chunk-T7M7OKPE.js";
16
16
 
17
17
  // transport/impls/stdio/stdio.ts
18
18
  var defaultOptions = {
@@ -235,15 +235,12 @@ var Transport = class {
235
235
  return;
236
236
  }
237
237
  if (isAck(msg.controlFlags) && import_value.Value.Check(TransportAckSchema, msg)) {
238
- log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
238
+ log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
239
239
  if (this.sendBuffer.has(msg.payload.ack)) {
240
240
  this.sendBuffer.delete(msg.payload.ack);
241
241
  }
242
242
  } else {
243
- log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
244
- if (msg.to !== this.clientId) {
245
- return;
246
- }
243
+ log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
247
244
  this.eventDispatcher.dispatchEvent("message", msg);
248
245
  if (!isAck(msg.controlFlags)) {
249
246
  const ackMsg = reply(msg, { ack: msg.id });
@@ -293,7 +290,7 @@ var Transport = class {
293
290
  this.sendBuffer.set(msg.id, msg);
294
291
  }
295
292
  if (conn) {
296
- log?.info(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
293
+ log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
297
294
  const ok = conn.send(this.codec.toBuffer(msg));
298
295
  if (ok) {
299
296
  return msg.id;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  StreamConnection,
3
3
  createDelimitedStream
4
- } from "../../../chunk-TZSX5KM2.js";
4
+ } from "../../../chunk-3MQETIGZ.js";
5
5
  import "../../../chunk-ORAG7IAU.js";
6
6
  import "../../../chunk-WVT5QXMZ.js";
7
7
  import {
@@ -9,11 +9,11 @@ import {
9
9
  } from "../../../chunk-R6H2BIMC.js";
10
10
  import {
11
11
  Transport
12
- } from "../../../chunk-V2YJRBRX.js";
12
+ } from "../../../chunk-LQXPKF3A.js";
13
13
  import "../../../chunk-ZE4MX7DF.js";
14
14
  import {
15
15
  log
16
- } from "../../../chunk-SLUSVGQH.js";
16
+ } from "../../../chunk-T7M7OKPE.js";
17
17
 
18
18
  // transport/impls/unixsocket/client.ts
19
19
  import { createConnection } from "node:net";
@@ -235,15 +235,12 @@ var Transport = class {
235
235
  return;
236
236
  }
237
237
  if (isAck(msg.controlFlags) && import_value.Value.Check(TransportAckSchema, msg)) {
238
- log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
238
+ log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
239
239
  if (this.sendBuffer.has(msg.payload.ack)) {
240
240
  this.sendBuffer.delete(msg.payload.ack);
241
241
  }
242
242
  } else {
243
- log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
244
- if (msg.to !== this.clientId) {
245
- return;
246
- }
243
+ log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
247
244
  this.eventDispatcher.dispatchEvent("message", msg);
248
245
  if (!isAck(msg.controlFlags)) {
249
246
  const ackMsg = reply(msg, { ack: msg.id });
@@ -293,7 +290,7 @@ var Transport = class {
293
290
  this.sendBuffer.set(msg.id, msg);
294
291
  }
295
292
  if (conn) {
296
- log?.info(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
293
+ log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
297
294
  const ok = conn.send(this.codec.toBuffer(msg));
298
295
  if (ok) {
299
296
  return msg.id;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  StreamConnection,
3
3
  createDelimitedStream
4
- } from "../../../chunk-TZSX5KM2.js";
4
+ } from "../../../chunk-3MQETIGZ.js";
5
5
  import "../../../chunk-ORAG7IAU.js";
6
6
  import "../../../chunk-WVT5QXMZ.js";
7
7
  import {
@@ -9,11 +9,11 @@ import {
9
9
  } from "../../../chunk-R6H2BIMC.js";
10
10
  import {
11
11
  Transport
12
- } from "../../../chunk-V2YJRBRX.js";
12
+ } from "../../../chunk-LQXPKF3A.js";
13
13
  import "../../../chunk-ZE4MX7DF.js";
14
14
  import {
15
15
  log
16
- } from "../../../chunk-SLUSVGQH.js";
16
+ } from "../../../chunk-T7M7OKPE.js";
17
17
 
18
18
  // transport/impls/unixsocket/server.ts
19
19
  var defaultOptions = {
@@ -235,15 +235,12 @@ var Transport = class {
235
235
  return;
236
236
  }
237
237
  if (isAck(msg.controlFlags) && import_value.Value.Check(TransportAckSchema, msg)) {
238
- log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
238
+ log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
239
239
  if (this.sendBuffer.has(msg.payload.ack)) {
240
240
  this.sendBuffer.delete(msg.payload.ack);
241
241
  }
242
242
  } else {
243
- log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
244
- if (msg.to !== this.clientId) {
245
- return;
246
- }
243
+ log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
247
244
  this.eventDispatcher.dispatchEvent("message", msg);
248
245
  if (!isAck(msg.controlFlags)) {
249
246
  const ackMsg = reply(msg, { ack: msg.id });
@@ -293,7 +290,7 @@ var Transport = class {
293
290
  this.sendBuffer.set(msg.id, msg);
294
291
  }
295
292
  if (conn) {
296
- log?.info(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
293
+ log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
297
294
  const ok = conn.send(this.codec.toBuffer(msg));
298
295
  if (ok) {
299
296
  return msg.id;
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  WebSocketClientTransport
3
- } from "../../../chunk-IEU7OE5W.js";
4
- import "../../../chunk-SZTOUKL7.js";
3
+ } from "../../../chunk-6QJETGOD.js";
4
+ import "../../../chunk-L7D75G4K.js";
5
5
  import "../../../chunk-R6H2BIMC.js";
6
- import "../../../chunk-V2YJRBRX.js";
6
+ import "../../../chunk-LQXPKF3A.js";
7
7
  import "../../../chunk-ZE4MX7DF.js";
8
- import "../../../chunk-SLUSVGQH.js";
8
+ import "../../../chunk-T7M7OKPE.js";
9
9
  export {
10
10
  WebSocketClientTransport
11
11
  };
@@ -281,15 +281,12 @@ var Transport = class {
281
281
  return;
282
282
  }
283
283
  if (isAck(msg.controlFlags) && import_value.Value.Check(TransportAckSchema, msg)) {
284
- log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
284
+ log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg)}`);
285
285
  if (this.sendBuffer.has(msg.payload.ack)) {
286
286
  this.sendBuffer.delete(msg.payload.ack);
287
287
  }
288
288
  } else {
289
- log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
290
- if (msg.to !== this.clientId) {
291
- return;
292
- }
289
+ log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
293
290
  this.eventDispatcher.dispatchEvent("message", msg);
294
291
  if (!isAck(msg.controlFlags)) {
295
292
  const ackMsg = reply(msg, { ack: msg.id });
@@ -339,7 +336,7 @@ var Transport = class {
339
336
  this.sendBuffer.set(msg.id, msg);
340
337
  }
341
338
  if (conn) {
342
- log?.info(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
339
+ log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg)}`);
343
340
  const ok = conn.send(this.codec.toBuffer(msg));
344
341
  if (ok) {
345
342
  return msg.id;
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  WebSocketServerTransport
3
- } from "../../../chunk-PNZXYQME.js";
4
- import "../../../chunk-SZTOUKL7.js";
3
+ } from "../../../chunk-PJ2EUO7O.js";
4
+ import "../../../chunk-L7D75G4K.js";
5
5
  import "../../../chunk-WVT5QXMZ.js";
6
6
  import "../../../chunk-R6H2BIMC.js";
7
- import "../../../chunk-V2YJRBRX.js";
7
+ import "../../../chunk-LQXPKF3A.js";
8
8
  import "../../../chunk-ZE4MX7DF.js";
9
- import "../../../chunk-SLUSVGQH.js";
9
+ import "../../../chunk-T7M7OKPE.js";
10
10
  export {
11
11
  WebSocketServerTransport
12
12
  };
@@ -252,15 +252,12 @@ var Transport = class {
252
252
  return;
253
253
  }
254
254
  if (isAck(msg2.controlFlags) && import_value.Value.Check(TransportAckSchema, msg2)) {
255
- log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg2)}`);
255
+ log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg2)}`);
256
256
  if (this.sendBuffer.has(msg2.payload.ack)) {
257
257
  this.sendBuffer.delete(msg2.payload.ack);
258
258
  }
259
259
  } else {
260
- log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg2)}`);
261
- if (msg2.to !== this.clientId) {
262
- return;
263
- }
260
+ log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg2)}`);
264
261
  this.eventDispatcher.dispatchEvent("message", msg2);
265
262
  if (!isAck(msg2.controlFlags)) {
266
263
  const ackMsg = reply(msg2, { ack: msg2.id });
@@ -310,7 +307,7 @@ var Transport = class {
310
307
  this.sendBuffer.set(msg2.id, msg2);
311
308
  }
312
309
  if (conn) {
313
- log?.info(`${this.clientId} -- sending ${JSON.stringify(msg2)}`);
310
+ log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg2)}`);
314
311
  const ok = conn.send(this.codec.toBuffer(msg2));
315
312
  if (ok) {
316
313
  return msg2.id;
@@ -2,14 +2,14 @@ import "../chunk-ORAG7IAU.js";
2
2
  import {
3
3
  Connection,
4
4
  Transport
5
- } from "../chunk-V2YJRBRX.js";
5
+ } from "../chunk-LQXPKF3A.js";
6
6
  import {
7
7
  OpaqueTransportMessageSchema,
8
8
  TransportMessageSchema,
9
9
  msg,
10
10
  reply
11
11
  } from "../chunk-ZE4MX7DF.js";
12
- import "../chunk-SLUSVGQH.js";
12
+ import "../chunk-T7M7OKPE.js";
13
13
  export {
14
14
  Connection,
15
15
  OpaqueTransportMessageSchema,
@@ -272,15 +272,12 @@ var Transport = class {
272
272
  return;
273
273
  }
274
274
  if (isAck(msg2.controlFlags) && import_value.Value.Check(TransportAckSchema, msg2)) {
275
- log?.info(`${this.clientId} -- received ack: ${JSON.stringify(msg2)}`);
275
+ log?.debug(`${this.clientId} -- received ack: ${JSON.stringify(msg2)}`);
276
276
  if (this.sendBuffer.has(msg2.payload.ack)) {
277
277
  this.sendBuffer.delete(msg2.payload.ack);
278
278
  }
279
279
  } else {
280
- log?.info(`${this.clientId} -- received msg: ${JSON.stringify(msg2)}`);
281
- if (msg2.to !== this.clientId) {
282
- return;
283
- }
280
+ log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg2)}`);
284
281
  this.eventDispatcher.dispatchEvent("message", msg2);
285
282
  if (!isAck(msg2.controlFlags)) {
286
283
  const ackMsg = reply(msg2, { ack: msg2.id });
@@ -330,7 +327,7 @@ var Transport = class {
330
327
  this.sendBuffer.set(msg2.id, msg2);
331
328
  }
332
329
  if (conn) {
333
- log?.info(`${this.clientId} -- sending ${JSON.stringify(msg2)}`);
330
+ log?.debug(`${this.clientId} -- sending ${JSON.stringify(msg2)}`);
334
331
  const ok = conn.send(this.codec.toBuffer(msg2));
335
332
  if (ok) {
336
333
  return msg2.id;
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  UNCAUGHT_ERROR,
3
3
  pushable
4
- } from "../chunk-IYRPZPSQ.js";
4
+ } from "../chunk-3JGVFWKQ.js";
5
5
  import {
6
6
  WebSocketClientTransport
7
- } from "../chunk-IEU7OE5W.js";
7
+ } from "../chunk-6QJETGOD.js";
8
8
  import {
9
9
  WebSocketServerTransport
10
- } from "../chunk-PNZXYQME.js";
11
- import "../chunk-SZTOUKL7.js";
10
+ } from "../chunk-PJ2EUO7O.js";
11
+ import "../chunk-L7D75G4K.js";
12
12
  import "../chunk-ORAG7IAU.js";
13
13
  import "../chunk-WVT5QXMZ.js";
14
14
  import "../chunk-R6H2BIMC.js";
15
- import "../chunk-V2YJRBRX.js";
15
+ import "../chunk-LQXPKF3A.js";
16
16
  import {
17
17
  msg
18
18
  } from "../chunk-ZE4MX7DF.js";
19
- import "../chunk-SLUSVGQH.js";
19
+ import "../chunk-T7M7OKPE.js";
20
20
 
21
21
  // util/testHelpers.ts
22
22
  import WebSocket from "isomorphic-ws";
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.10.5",
4
+ "version": "0.10.7",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {