@replit/river 0.215.1 → 0.216.0

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 (70) hide show
  1. package/README.md +47 -0
  2. package/dist/{adapter-Dtt4bYL-.d.ts → adapter-BXCk-dmy.d.ts} +3 -21
  3. package/dist/{adapter-CjgmjtUJ.d.cts → adapter-D5X11kmP.d.cts} +3 -21
  4. package/dist/{chunk-3DDZCLJM.js → chunk-75ZMPCKC.js} +22 -6
  5. package/dist/{chunk-3DDZCLJM.js.map → chunk-75ZMPCKC.js.map} +1 -1
  6. package/dist/chunk-SHND2JG6.js +86 -0
  7. package/dist/chunk-SHND2JG6.js.map +1 -0
  8. package/dist/{chunk-NUGV5QWU.js → chunk-ZLMQQI43.js} +12 -2
  9. package/dist/chunk-ZLMQQI43.js.map +1 -0
  10. package/dist/{client-BOc8blGj.d.ts → client-BNc5Pj_4.d.ts} +2 -2
  11. package/dist/{client-B9aKi9Li.d.cts → client-BZUvFL6B.d.cts} +2 -2
  12. package/dist/codec/index.cjs.map +1 -1
  13. package/dist/codec/index.d.cts +3 -3
  14. package/dist/codec/index.d.ts +3 -3
  15. package/dist/codec/index.js +2 -2
  16. package/dist/{connection-DnMYvolf.d.ts → connection-ou9w2dSY.d.ts} +3 -3
  17. package/dist/{connection-1hFoyxuX.d.cts → connection-xxgJHs2o.d.cts} +3 -3
  18. package/dist/{index-Bf9PGbS4.d.cts → index-BAGGleT3.d.cts} +1 -1
  19. package/dist/{index-DiAq34gk.d.ts → index-ZWkoesQD.d.ts} +1 -1
  20. package/dist/logging/index.d.cts +2 -2
  21. package/dist/logging/index.d.ts +2 -2
  22. package/dist/{message-DL74OqsX.d.cts → message-CpXWqmJw.d.cts} +1 -1
  23. package/dist/{message-DL74OqsX.d.ts → message-CpXWqmJw.d.ts} +1 -1
  24. package/dist/protobuf/codec.cjs +107 -0
  25. package/dist/protobuf/codec.cjs.map +1 -0
  26. package/dist/protobuf/codec.d.cts +13 -0
  27. package/dist/protobuf/codec.d.ts +13 -0
  28. package/dist/protobuf/codec.js +7 -0
  29. package/dist/protobuf/codec.js.map +1 -0
  30. package/dist/protobuf/index.cjs +1877 -0
  31. package/dist/protobuf/index.cjs.map +1 -0
  32. package/dist/protobuf/index.d.cts +488 -0
  33. package/dist/protobuf/index.d.ts +488 -0
  34. package/dist/protobuf/index.js +1260 -0
  35. package/dist/protobuf/index.js.map +1 -0
  36. package/dist/router/index.cjs +1 -1
  37. package/dist/router/index.cjs.map +1 -1
  38. package/dist/router/index.d.cts +11 -10
  39. package/dist/router/index.d.ts +11 -10
  40. package/dist/router/index.js +1 -1
  41. package/dist/{server-_bfE7LYc.d.ts → server-BPu7Td80.d.ts} +4 -4
  42. package/dist/{server-BkEzDYIv.d.cts → server-JdnoVO11.d.cts} +4 -4
  43. package/dist/{services-KdKBWdJr.d.ts → services-BrTFTO5Q.d.ts} +104 -93
  44. package/dist/{services-zaansuuR.d.cts → services-cwGAC2rB.d.cts} +104 -93
  45. package/dist/testUtil/index.cjs +21 -5
  46. package/dist/testUtil/index.cjs.map +1 -1
  47. package/dist/testUtil/index.d.cts +8 -7
  48. package/dist/testUtil/index.d.ts +8 -7
  49. package/dist/testUtil/index.js +2 -2
  50. package/dist/transport/impls/ws/client.cjs +1 -1
  51. package/dist/transport/impls/ws/client.cjs.map +1 -1
  52. package/dist/transport/impls/ws/client.d.cts +7 -6
  53. package/dist/transport/impls/ws/client.d.ts +7 -6
  54. package/dist/transport/impls/ws/client.js +2 -2
  55. package/dist/transport/impls/ws/server.cjs +21 -5
  56. package/dist/transport/impls/ws/server.cjs.map +1 -1
  57. package/dist/transport/impls/ws/server.d.cts +7 -6
  58. package/dist/transport/impls/ws/server.d.ts +7 -6
  59. package/dist/transport/impls/ws/server.js +2 -2
  60. package/dist/transport/index.cjs +21 -5
  61. package/dist/transport/index.cjs.map +1 -1
  62. package/dist/transport/index.d.cts +8 -7
  63. package/dist/transport/index.d.ts +8 -7
  64. package/dist/transport/index.js +2 -2
  65. package/dist/{transport-CCBNESLA.d.cts → transport-B1MUtXL7.d.ts} +5 -4
  66. package/dist/{transport-kW92H6x-.d.ts → transport-BnU3Zb0Q.d.cts} +5 -4
  67. package/dist/types-BGGvYIJM.d.cts +20 -0
  68. package/dist/types-BGGvYIJM.d.ts +20 -0
  69. package/package.json +12 -1
  70. package/dist/chunk-NUGV5QWU.js.map +0 -1
package/README.md CHANGED
@@ -713,6 +713,53 @@ async handler(ctx, ...args) {
713
713
  }
714
714
  ```
715
715
 
716
+ ## Protobuf Services (Experimental)
717
+
718
+ River also supports defining services using Protocol Buffers. Instead of TypeBox schemas, you define your service in a `.proto` file and use the generated descriptors directly.
719
+
720
+ ```protobuf
721
+ // greeter.proto
722
+ syntax = "proto3";
723
+ package myapp;
724
+
725
+ service Greeter {
726
+ rpc SayHello(HelloRequest) returns (HelloResponse);
727
+ rpc ServerStream(HelloRequest) returns (stream HelloResponse);
728
+ }
729
+
730
+ message HelloRequest { string name = 1; }
731
+ message HelloResponse { string message = 1; }
732
+ ```
733
+
734
+ ```ts
735
+ import {
736
+ createProtoService,
737
+ createServer,
738
+ createClient,
739
+ Ok,
740
+ ProtoCodec,
741
+ } from '@replit/river/protobuf';
742
+ import { Greeter } from './gen/greeter_pb';
743
+
744
+ const ProtoService = createProtoService();
745
+
746
+ const greeterSvc = ProtoService.define(Greeter, {
747
+ sayHello: (request, ctx) => Ok({ message: `Hello, ${request.name}!` }),
748
+ // serverStream left unimplemented → returns UNIMPLEMENTED at runtime
749
+ });
750
+
751
+ // server
752
+ const server = createServer(transport, [greeterSvc]);
753
+
754
+ // client
755
+ const client = createClient(Greeter, clientTransport, serverId);
756
+ const result = await client.sayHello({ name: 'World' });
757
+ ```
758
+
759
+ The protobuf router uses `ProtoCodec` for wire encoding (protobuf envelopes with msgpack fallback for control payloads) and supports the same features as the TypeBox router: context, disposable state, middleware, handshakes, and OpenTelemetry tracing.
760
+
761
+ > **Note:** The protobuf router is experimental and its API may change.
762
+
716
763
  ### Further examples
717
764
 
718
765
  We've also provided an end-to-end testing environment using `Next.js`, and a simple backend connected with the WebSocket transport that you can [play with on Replit](https://replit.com/@jzhao-replit/riverbed).
@@ -1,23 +1,5 @@
1
- import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-DL74OqsX.js';
2
-
3
- /**
4
- * Codec interface for encoding and decoding objects to and from Uint8 buffers.
5
- * Used to prepare messages for use by the transport layer.
6
- */
7
- interface Codec {
8
- /**
9
- * Encodes an object to a Uint8 buffer.
10
- * @param obj - The object to encode.
11
- * @returns The encoded Uint8 buffer.
12
- */
13
- toBuffer(obj: object): Uint8Array;
14
- /**
15
- * Decodes an object from a Uint8 buffer.
16
- * @param buf - The Uint8 buffer to decode.
17
- * @returns The decoded object, or null if decoding failed.
18
- */
19
- fromBuffer(buf: Uint8Array): object;
20
- }
1
+ import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-CpXWqmJw.js';
2
+ import { C as Codec } from './types-BGGvYIJM.js';
21
3
 
22
4
  type SessionApiResult<T> = {
23
5
  ok: true;
@@ -44,4 +26,4 @@ declare class CodecMessageAdapter {
44
26
  fromBuffer(buf: Uint8Array): DeserializeResult;
45
27
  }
46
28
 
47
- export { type Codec as C, type EncodeResult as E, type SendResult as S, CodecMessageAdapter as a, type SendBufferResult as b };
29
+ export { CodecMessageAdapter as C, type EncodeResult as E, type SendResult as S, type SendBufferResult as a };
@@ -1,23 +1,5 @@
1
- import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-DL74OqsX.cjs';
2
-
3
- /**
4
- * Codec interface for encoding and decoding objects to and from Uint8 buffers.
5
- * Used to prepare messages for use by the transport layer.
6
- */
7
- interface Codec {
8
- /**
9
- * Encodes an object to a Uint8 buffer.
10
- * @param obj - The object to encode.
11
- * @returns The encoded Uint8 buffer.
12
- */
13
- toBuffer(obj: object): Uint8Array;
14
- /**
15
- * Decodes an object from a Uint8 buffer.
16
- * @param buf - The Uint8 buffer to decode.
17
- * @returns The decoded object, or null if decoding failed.
18
- */
19
- fromBuffer(buf: Uint8Array): object;
20
- }
1
+ import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-CpXWqmJw.cjs';
2
+ import { C as Codec } from './types-BGGvYIJM.cjs';
21
3
 
22
4
  type SessionApiResult<T> = {
23
5
  ok: true;
@@ -44,4 +26,4 @@ declare class CodecMessageAdapter {
44
26
  fromBuffer(buf: Uint8Array): DeserializeResult;
45
27
  }
46
28
 
47
- export { type Codec as C, type EncodeResult as E, type SendResult as S, CodecMessageAdapter as a, type SendBufferResult as b };
29
+ export { CodecMessageAdapter as C, type EncodeResult as E, type SendResult as S, type SendBufferResult as a };
@@ -20,7 +20,7 @@ import {
20
20
  handshakeResponseMessage,
21
21
  isAcceptedProtocolVersion,
22
22
  isAck
23
- } from "./chunk-NUGV5QWU.js";
23
+ } from "./chunk-ZLMQQI43.js";
24
24
 
25
25
  // transport/events.ts
26
26
  var ProtocolError = {
@@ -2124,10 +2124,26 @@ var ServerTransport = class extends Transport {
2124
2124
  const previousParsedMetadata = this.sessionHandshakeMetadata.get(
2125
2125
  msg.from
2126
2126
  );
2127
- const parsedMetadataOrFailureCode = await this.handshakeExtensions.validate(
2128
- msg.payload.metadata,
2129
- previousParsedMetadata
2130
- );
2127
+ let parsedMetadataOrFailureCode;
2128
+ try {
2129
+ parsedMetadataOrFailureCode = await this.handshakeExtensions.validate(
2130
+ msg.payload.metadata,
2131
+ previousParsedMetadata
2132
+ );
2133
+ } catch (err) {
2134
+ this.rejectHandshakeRequest(
2135
+ session,
2136
+ msg.from,
2137
+ `handshake validation threw: ${coerceErrorString(err)}`,
2138
+ "REJECTED_BY_CUSTOM_HANDLER",
2139
+ {
2140
+ ...session.loggingMetadata,
2141
+ connectedTo: msg.from,
2142
+ clientId: this.clientId
2143
+ }
2144
+ );
2145
+ return;
2146
+ }
2131
2147
  if (session._isConsumed) {
2132
2148
  return;
2133
2149
  }
@@ -2473,4 +2489,4 @@ export {
2473
2489
  WebSocketConnection,
2474
2490
  CodecMessageAdapter
2475
2491
  };
2476
- //# sourceMappingURL=chunk-3DDZCLJM.js.map
2492
+ //# sourceMappingURL=chunk-75ZMPCKC.js.map