Skip to content

Commit 161d5f7

Browse files
authored
small type updates: unexport unwrapOrThrow, add regression test for ctx.cancel return (#298)
## Why - people kept misusing unwrapOrThrow in production procedures ## What changed - unexport unwrapOrThrow - add a simple regression test for ctx.cancel in a union-ed case <!-- Describe the changes you made in this pull request or pointers for the reviewer --> ## Versioning - [ ] Breaking protocol change - [x] Breaking ts/js API change <!-- Kind reminder to add tests and updated documentation if needed -->
1 parent 3b8bd94 commit 161d5f7

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

__tests__/typescript-stress.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,33 @@ const services = {
234234
requestInit: Type.Object({}),
235235
requestData: Type.Object({ n: Type.Number() }),
236236
responseData: Type.Object({ n: Type.Number() }),
237-
async handler() {
237+
responseError: flattenErrorType(
238+
Type.Union([
239+
Type.Object({
240+
code: Type.Literal('ERROR1'),
241+
message: Type.String(),
242+
}),
243+
Type.Object({
244+
code: Type.Literal('ERROR2'),
245+
message: Type.String(),
246+
}),
247+
]),
248+
),
249+
async handler({ ctx, reqReadable }) {
250+
for await (const { ok, payload } of reqReadable) {
251+
if (!ok) {
252+
return ctx.cancel();
253+
}
254+
255+
if (payload.n === 1) {
256+
return Err({ code: 'ERROR1', message: 'n is 1' });
257+
}
258+
259+
if (payload.n === 2) {
260+
return Err({ code: 'ERROR2', message: 'n is 2' });
261+
}
262+
}
263+
238264
return Ok({ n: 1 });
239265
},
240266
}),

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@replit/river",
33
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4-
"version": "0.206.0",
4+
"version": "0.207.0",
55
"type": "module",
66
"exports": {
77
".": {

router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type {
4949
ServiceContext,
5050
ProcedureHandlerContext,
5151
} from './context';
52-
export { Ok, Err, unwrapOrThrow } from './result';
52+
export { Ok, Err } from './result';
5353
export type {
5454
Result,
5555
ErrResult,

0 commit comments

Comments
 (0)