@replit/river 0.215.0 → 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.
- package/README.md +47 -0
- package/dist/adapter-BXCk-dmy.d.ts +29 -0
- package/dist/adapter-D5X11kmP.d.cts +29 -0
- package/dist/{chunk-VXRAFUA3.js → chunk-75ZMPCKC.js} +26 -6
- package/dist/{chunk-VXRAFUA3.js.map → chunk-75ZMPCKC.js.map} +1 -1
- package/dist/chunk-SHND2JG6.js +86 -0
- package/dist/chunk-SHND2JG6.js.map +1 -0
- package/dist/{chunk-RDTQZ7HO.js → chunk-ZLMQQI43.js} +12 -2
- package/dist/chunk-ZLMQQI43.js.map +1 -0
- package/dist/{client-BhwlY0-L.d.ts → client-BNc5Pj_4.d.ts} +2 -2
- package/dist/{client-Dk4H7qeg.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-DU9v3y8a.d.ts → connection-ou9w2dSY.d.ts} +3 -3
- package/dist/{connection-CS00EWuS.d.cts → connection-xxgJHs2o.d.cts} +3 -3
- package/dist/{index-CHCzvZ9D.d.cts → index-BAGGleT3.d.cts} +1 -1
- package/dist/{index-uF0cBM7z.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-aABg0s5M.d.cts → message-CpXWqmJw.d.cts} +1 -1
- package/dist/{message-aABg0s5M.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 +1 -1
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +12 -11
- package/dist/router/index.d.ts +12 -11
- package/dist/router/index.js +1 -1
- package/dist/{server-uNzkzIRh.d.ts → server-BPu7Td80.d.ts} +4 -4
- package/dist/{server-BR0DZaWi.d.cts → server-JdnoVO11.d.cts} +4 -4
- package/dist/{services-B5SY771g.d.ts → services-BrTFTO5Q.d.ts} +104 -93
- package/dist/{services-DBv2nmly.d.cts → services-cwGAC2rB.d.cts} +104 -93
- package/dist/testUtil/index.cjs +25 -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 +5 -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 +25 -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-BOL2p5s-.d.ts → transport-B1MUtXL7.d.ts} +7 -5
- package/dist/{transport-D3jzhFSi.d.cts → transport-BnU3Zb0Q.d.cts} +7 -5
- package/dist/types-BGGvYIJM.d.cts +20 -0
- package/dist/types-BGGvYIJM.d.ts +20 -0
- package/package.json +12 -1
- package/dist/adapter-CgF7vQPu.d.ts +0 -47
- package/dist/adapter-IGrG4KLL.d.cts +0 -47
- package/dist/chunk-RDTQZ7HO.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).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-CpXWqmJw.js';
|
|
2
|
+
import { C as Codec } from './types-BGGvYIJM.js';
|
|
3
|
+
|
|
4
|
+
type SessionApiResult<T> = {
|
|
5
|
+
ok: true;
|
|
6
|
+
value: T;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
11
|
+
type SendResult = SessionApiResult<string>;
|
|
12
|
+
type SendBufferResult = SessionApiResult<undefined>;
|
|
13
|
+
type EncodeResult = SessionApiResult<EncodedTransportMessage>;
|
|
14
|
+
type SerializeResult = SessionApiResult<Uint8Array>;
|
|
15
|
+
type DeserializeResult = SessionApiResult<OpaqueTransportMessage>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Adapts a {@link Codec} to the {@link OpaqueTransportMessage} format,
|
|
19
|
+
* accounting for fallibility of toBuffer and fromBuffer and wrapping
|
|
20
|
+
* it with a Result type.
|
|
21
|
+
*/
|
|
22
|
+
declare class CodecMessageAdapter {
|
|
23
|
+
private readonly codec;
|
|
24
|
+
constructor(codec: Codec);
|
|
25
|
+
toBuffer(msg: OpaqueTransportMessage): SerializeResult;
|
|
26
|
+
fromBuffer(buf: Uint8Array): DeserializeResult;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { CodecMessageAdapter as C, type EncodeResult as E, type SendResult as S, type SendBufferResult as a };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-CpXWqmJw.cjs';
|
|
2
|
+
import { C as Codec } from './types-BGGvYIJM.cjs';
|
|
3
|
+
|
|
4
|
+
type SessionApiResult<T> = {
|
|
5
|
+
ok: true;
|
|
6
|
+
value: T;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
11
|
+
type SendResult = SessionApiResult<string>;
|
|
12
|
+
type SendBufferResult = SessionApiResult<undefined>;
|
|
13
|
+
type EncodeResult = SessionApiResult<EncodedTransportMessage>;
|
|
14
|
+
type SerializeResult = SessionApiResult<Uint8Array>;
|
|
15
|
+
type DeserializeResult = SessionApiResult<OpaqueTransportMessage>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Adapts a {@link Codec} to the {@link OpaqueTransportMessage} format,
|
|
19
|
+
* accounting for fallibility of toBuffer and fromBuffer and wrapping
|
|
20
|
+
* it with a Result type.
|
|
21
|
+
*/
|
|
22
|
+
declare class CodecMessageAdapter {
|
|
23
|
+
private readonly codec;
|
|
24
|
+
constructor(codec: Codec);
|
|
25
|
+
toBuffer(msg: OpaqueTransportMessage): SerializeResult;
|
|
26
|
+
fromBuffer(buf: Uint8Array): DeserializeResult;
|
|
27
|
+
}
|
|
28
|
+
|
|
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-ZLMQQI43.js";
|
|
24
24
|
|
|
25
25
|
// transport/events.ts
|
|
26
26
|
var ProtocolError = {
|
|
@@ -1469,6 +1469,10 @@ var LeakyBucketRateLimit = class {
|
|
|
1469
1469
|
clearInterval(this.intervalHandle);
|
|
1470
1470
|
this.intervalHandle = void 0;
|
|
1471
1471
|
}
|
|
1472
|
+
resetBudget() {
|
|
1473
|
+
this.stopLeak();
|
|
1474
|
+
this.budgetConsumed = 0;
|
|
1475
|
+
}
|
|
1472
1476
|
close() {
|
|
1473
1477
|
this.stopLeak();
|
|
1474
1478
|
}
|
|
@@ -2120,10 +2124,26 @@ var ServerTransport = class extends Transport {
|
|
|
2120
2124
|
const previousParsedMetadata = this.sessionHandshakeMetadata.get(
|
|
2121
2125
|
msg.from
|
|
2122
2126
|
);
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
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
|
+
}
|
|
2127
2147
|
if (session._isConsumed) {
|
|
2128
2148
|
return;
|
|
2129
2149
|
}
|
|
@@ -2469,4 +2489,4 @@ export {
|
|
|
2469
2489
|
WebSocketConnection,
|
|
2470
2490
|
CodecMessageAdapter
|
|
2471
2491
|
};
|
|
2472
|
-
//# sourceMappingURL=chunk-
|
|
2492
|
+
//# sourceMappingURL=chunk-75ZMPCKC.js.map
|