@replit/river 0.215.1 → 0.216.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.
- package/README.md +47 -0
- package/dist/{adapter-Dtt4bYL-.d.ts → adapter-BXCk-dmy.d.ts} +3 -21
- package/dist/{adapter-CjgmjtUJ.d.cts → adapter-D5X11kmP.d.cts} +3 -21
- package/dist/{chunk-3DDZCLJM.js → chunk-62BM2WOT.js} +22 -6
- package/dist/{chunk-3DDZCLJM.js.map → chunk-62BM2WOT.js.map} +1 -1
- package/dist/{chunk-NUGV5QWU.js → chunk-C4EPHIKQ.js} +21 -3
- package/dist/chunk-C4EPHIKQ.js.map +1 -0
- package/dist/chunk-SHND2JG6.js +86 -0
- package/dist/chunk-SHND2JG6.js.map +1 -0
- package/dist/{client-BOc8blGj.d.ts → client-BNc5Pj_4.d.ts} +2 -2
- package/dist/{client-B9aKi9Li.d.cts → client-BZUvFL6B.d.cts} +2 -2
- package/dist/codec/index.cjs.map +1 -1
- package/dist/codec/index.d.cts +3 -3
- package/dist/codec/index.d.ts +3 -3
- package/dist/codec/index.js +2 -2
- package/dist/{connection-DnMYvolf.d.ts → connection-ou9w2dSY.d.ts} +3 -3
- package/dist/{connection-1hFoyxuX.d.cts → connection-xxgJHs2o.d.cts} +3 -3
- package/dist/{index-Bf9PGbS4.d.cts → index-BAGGleT3.d.cts} +1 -1
- package/dist/{index-DiAq34gk.d.ts → index-ZWkoesQD.d.ts} +1 -1
- package/dist/logging/index.d.cts +2 -2
- package/dist/logging/index.d.ts +2 -2
- package/dist/{message-DL74OqsX.d.cts → message-CpXWqmJw.d.cts} +1 -1
- package/dist/{message-DL74OqsX.d.ts → message-CpXWqmJw.d.ts} +1 -1
- package/dist/protobuf/codec.cjs +107 -0
- package/dist/protobuf/codec.cjs.map +1 -0
- package/dist/protobuf/codec.d.cts +13 -0
- package/dist/protobuf/codec.d.ts +13 -0
- package/dist/protobuf/codec.js +7 -0
- package/dist/protobuf/codec.js.map +1 -0
- package/dist/protobuf/index.cjs +1877 -0
- package/dist/protobuf/index.cjs.map +1 -0
- package/dist/protobuf/index.d.cts +488 -0
- package/dist/protobuf/index.d.ts +488 -0
- package/dist/protobuf/index.js +1260 -0
- package/dist/protobuf/index.js.map +1 -0
- package/dist/router/index.cjs +10 -2
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +11 -10
- package/dist/router/index.d.ts +11 -10
- package/dist/router/index.js +1 -1
- package/dist/{server-_bfE7LYc.d.ts → server-BPu7Td80.d.ts} +4 -4
- package/dist/{server-BkEzDYIv.d.cts → server-JdnoVO11.d.cts} +4 -4
- package/dist/{services-zaansuuR.d.cts → services-CjigASqe.d.cts} +114 -93
- package/dist/{services-KdKBWdJr.d.ts → services-DpT2yNtt.d.ts} +114 -93
- package/dist/testUtil/index.cjs +21 -5
- package/dist/testUtil/index.cjs.map +1 -1
- package/dist/testUtil/index.d.cts +8 -7
- package/dist/testUtil/index.d.ts +8 -7
- package/dist/testUtil/index.js +2 -2
- package/dist/transport/impls/ws/client.cjs +1 -1
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +7 -6
- package/dist/transport/impls/ws/client.d.ts +7 -6
- package/dist/transport/impls/ws/client.js +2 -2
- package/dist/transport/impls/ws/server.cjs +21 -5
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +7 -6
- package/dist/transport/impls/ws/server.d.ts +7 -6
- package/dist/transport/impls/ws/server.js +2 -2
- package/dist/transport/index.cjs +21 -5
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +8 -7
- package/dist/transport/index.d.ts +8 -7
- package/dist/transport/index.js +2 -2
- package/dist/{transport-CCBNESLA.d.cts → transport-B1MUtXL7.d.ts} +5 -4
- package/dist/{transport-kW92H6x-.d.ts → transport-BnU3Zb0Q.d.cts} +5 -4
- package/dist/types-BGGvYIJM.d.cts +20 -0
- package/dist/types-BGGvYIJM.d.ts +20 -0
- package/package.json +12 -1
- 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-
|
|
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 {
|
|
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-
|
|
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 {
|
|
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-
|
|
23
|
+
} from "./chunk-C4EPHIKQ.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
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
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-
|
|
2492
|
+
//# sourceMappingURL=chunk-62BM2WOT.js.map
|