@trevrpc/effect 1.7.0 → 1.8.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 +3 -3
- package/package.json +3 -3
- package/src/index.js +20 -4
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
[Effect](https://effect.website) adapter for the TrevRPC browser client, [`@trevrpc/trevrpc-js`](https://www.npmjs.com/package/@trevrpc/trevrpc-js): it makes clients whose calls are effects and streams.
|
|
4
4
|
|
|
5
5
|
> **Compatibility:** every TrevRPC package shares one version, and packages of the same version are compatible
|
|
6
|
-
> with each other: `trevrpc-rust` 1.
|
|
7
|
-
> 1.
|
|
6
|
+
> with each other: `trevrpc-rust` 1.8.0 works with `trevrpc-go` 1.8.0, `trevrpc-js` 1.8.0, and `trevrpc-kotlin`
|
|
7
|
+
> 1.8.0. Compatibility across different versions isn't guaranteed yet; that's a milestone for 2.0.
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
npm install @trevrpc/effect @trevrpc/trevrpc-js @bufbuild/protobuf effect
|
|
@@ -44,7 +44,7 @@ const replies = greeter.chat(
|
|
|
44
44
|
`options` are the usual [call options](https://trev.zip/llc/TrevRPC/wiki/JavaScript-Guide#call-options).
|
|
45
45
|
|
|
46
46
|
- **Cancellation.** Interrupting an effect or stream cancels its call, which the server sees as `CANCELLED`; so does taking part of a response stream (`Stream.take`) or a failure elsewhere in the program. A `signal` in the call options also cancels the call.
|
|
47
|
-
- **Request streams.** Client-streaming and bidirectional calls pull their requests from the stream as the transport accepts them, so a request stream is only consumed as fast as the server reads it. When the server ends the call first, the rest of the stream is not pulled, and the server's outcome is the result: its response or response stream if it succeeded, or its `TrevRpcError`. A request stream that fails cancels the call, and the call fails with the request stream's error.
|
|
47
|
+
- **Request streams.** Client-streaming and bidirectional calls pull their requests from the stream as the transport accepts them, so a request stream is only consumed as fast as the server reads it. When the server ends the call first, the rest of the stream is not pulled, and the server's outcome is the result: its response or response stream if it succeeded, or its `TrevRpcError`. A request stream that fails cancels the call, and the call fails with the request stream's error. So does a request that does not encode or that the client's [validator](https://trev.zip/llc/TrevRPC/wiki/JavaScript-Guide#request-validation) rejects: the call fails with its `TrevRpcError`.
|
|
48
48
|
- **Errors.** Calls fail with the `TrevRpcError` of the [client](https://trev.zip/llc/TrevRPC/wiki/JavaScript-Guide#errors-cancellation-and-streams), whose `_tag` is `"TrevRpcError"`, so `Effect.catchTag("TrevRpcError", ...)` handles it. Anything else a call rejects with becomes a `TrevRpcError` with `Code.Unknown` and the original as `cause`, as `toTrevRpcError(error)` does.
|
|
49
49
|
- **Rendering.** Response streams deliver buffered messages without returning to the event loop, as the client does; see [Rendering long streams](https://trev.zip/llc/TrevRPC/wiki/JavaScript-Guide#rendering-long-streams) before rendering a long stream message by message.
|
|
50
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trevrpc/effect",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Effect adapter for TrevRPC browser clients",
|
|
5
5
|
"homepage": "https://trev.zip/llc/TrevRPC",
|
|
6
6
|
"bugs": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"@bufbuild/protobuf": "^2.17.0",
|
|
43
43
|
"@bufbuild/protoc-gen-es": "^2.17.0",
|
|
44
44
|
"@trevrpc/trevrpc-js": "file:..",
|
|
45
|
-
"effect": "^4.1.
|
|
45
|
+
"effect": "^4.1.3",
|
|
46
46
|
"typescript": "^7.0.2"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@bufbuild/protobuf": "^2.17.0",
|
|
50
|
-
"@trevrpc/trevrpc-js": "^1.
|
|
50
|
+
"@trevrpc/trevrpc-js": "^1.8.0",
|
|
51
51
|
"effect": "^4.1.2"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
package/src/index.js
CHANGED
|
@@ -118,12 +118,29 @@ function withSignal(options, signal) {
|
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
120
|
* Sends each request of `requests`, waiting for the transport to accept it. Stops without an error
|
|
121
|
-
* at the first
|
|
122
|
-
*
|
|
121
|
+
* at the first send rejected because the call ended; the call reports its outcome. A send rejected
|
|
122
|
+
* while the call goes on, for a request that does not encode or that the client's validator
|
|
123
|
+
* rejects, fails with its error, as a failing request stream does with its own; the caller's scope
|
|
124
|
+
* then cancels the call.
|
|
123
125
|
*/
|
|
124
126
|
function upload(stream, requests) {
|
|
127
|
+
// The call settles its status as it ends, before the sends that its end rejects fail.
|
|
128
|
+
let ended = false;
|
|
129
|
+
const end = () => {
|
|
130
|
+
ended = true;
|
|
131
|
+
};
|
|
132
|
+
stream.status.then(end, end);
|
|
125
133
|
return Stream.runForEachWhile(requests, (request) =>
|
|
126
|
-
Effect.
|
|
134
|
+
Effect.tryPromise({
|
|
135
|
+
try: () =>
|
|
136
|
+
stream.send(request).then(accepted, (error) => {
|
|
137
|
+
if (ended) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}),
|
|
142
|
+
catch: toTrevRpcError,
|
|
143
|
+
}),
|
|
127
144
|
);
|
|
128
145
|
}
|
|
129
146
|
|
|
@@ -133,5 +150,4 @@ function settled(promise) {
|
|
|
133
150
|
}
|
|
134
151
|
|
|
135
152
|
const accepted = () => true;
|
|
136
|
-
const rejected = () => false;
|
|
137
153
|
const ignore = () => {};
|