@trpc/server 11.24.1-canary.7.8ff8793e9 → 11.25.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 +1 -1
- package/dist/adapters/aws-lambda/index.cjs +1 -1
- package/dist/adapters/aws-lambda/index.d.cts +1 -1
- package/dist/adapters/aws-lambda/index.d.mts +1 -1
- package/dist/adapters/aws-lambda/index.mjs +1 -1
- package/dist/adapters/express.cjs +1 -1
- package/dist/adapters/express.d.cts +2 -2
- package/dist/adapters/express.d.mts +2 -2
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/index.cjs +3 -3
- package/dist/adapters/fastify/index.d.cts +3 -3
- package/dist/adapters/fastify/index.d.mts +3 -3
- package/dist/adapters/fastify/index.mjs +3 -3
- package/dist/adapters/fetch/index.cjs +1 -1
- package/dist/adapters/fetch/index.d.cts +1 -1
- package/dist/adapters/fetch/index.d.mts +1 -1
- package/dist/adapters/fetch/index.mjs +1 -1
- package/dist/adapters/next-app-dir.d.cts +1 -1
- package/dist/adapters/next-app-dir.d.mts +1 -1
- package/dist/adapters/next.cjs +1 -1
- package/dist/adapters/next.d.cts +2 -2
- package/dist/adapters/next.d.mts +2 -2
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/index.cjs +1 -1
- package/dist/adapters/node-http/index.d.cts +1 -1
- package/dist/adapters/node-http/index.d.mts +1 -1
- package/dist/adapters/node-http/index.mjs +1 -1
- package/dist/adapters/standalone.cjs +1 -1
- package/dist/adapters/standalone.d.cts +2 -2
- package/dist/adapters/standalone.d.mts +2 -2
- package/dist/adapters/standalone.mjs +1 -1
- package/dist/adapters/ws.cjs +1 -1
- package/dist/adapters/ws.d.cts +2 -2
- package/dist/adapters/ws.d.mts +2 -2
- package/dist/adapters/ws.mjs +1 -1
- package/dist/http.cjs +1 -1
- package/dist/http.d.cts +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-Bdq70sid.d.cts → index-CFQnkrGZ.d.cts} +6 -3
- package/dist/{index-Bdq70sid.d.cts.map → index-CFQnkrGZ.d.cts.map} +1 -1
- package/dist/{index-Bdq70sid.d.mts → index-CFQnkrGZ.d.mts} +6 -3
- package/dist/{index-Bdq70sid.d.mts.map → index-CFQnkrGZ.d.mts.map} +1 -1
- package/dist/{index-C8o7kgHD.d.mts → index-DVmu6VtT.d.mts} +2 -2
- package/dist/{index-C8o7kgHD.d.mts.map → index-DVmu6VtT.d.mts.map} +1 -1
- package/dist/{index-mlF5Hred.d.cts → index-Dn1ucZS5.d.cts} +2 -2
- package/dist/{index-mlF5Hred.d.cts.map → index-Dn1ucZS5.d.cts.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{initTRPC-BHFhyRlq.mjs → initTRPC-DPoVGUwX.mjs} +2 -2
- package/dist/{initTRPC-BHFhyRlq.mjs.map → initTRPC-DPoVGUwX.mjs.map} +1 -1
- package/dist/{initTRPC-Cqhzvadj.cjs → initTRPC-yeYwDikA.cjs} +1 -1
- package/dist/{node-http-CgxAZYco.mjs → node-http-Df_b1FfK.mjs} +33 -10
- package/dist/{node-http-CgxAZYco.mjs.map → node-http-Df_b1FfK.mjs.map} +1 -1
- package/dist/{node-http-zAXiTJ5z.cjs → node-http-vS2eeV-2.cjs} +31 -8
- package/dist/observable/index.cjs +2 -2
- package/dist/observable/index.d.cts +1 -1
- package/dist/observable/index.d.mts +1 -1
- package/dist/observable/index.mjs +2 -2
- package/dist/{observable-DvS5lN8Q.cjs → observable-1zKJIeLl.cjs} +27 -9
- package/dist/{observable-YaZmQKBm.mjs → observable-Cmd1MFy3.mjs} +17 -3
- package/dist/{observable-YaZmQKBm.mjs.map → observable-Cmd1MFy3.mjs.map} +1 -1
- package/dist/{observable-C__NrSHz.cjs → observable-CtU0hoef.cjs} +16 -2
- package/dist/{observable-Crotwz1G.mjs → observable-kpFFzvou.mjs} +28 -10
- package/dist/observable-kpFFzvou.mjs.map +1 -0
- package/dist/{resolveResponse-KsaMasi_.mjs → resolveResponse-C3K3zKPn.mjs} +2 -2
- package/dist/{resolveResponse-KsaMasi_.mjs.map → resolveResponse-C3K3zKPn.mjs.map} +1 -1
- package/dist/{resolveResponse-BiNVUUPp.cjs → resolveResponse-CoiQ9diV.cjs} +1 -1
- package/dist/rpc.d.cts +1 -1
- package/dist/rpc.d.mts +1 -1
- package/dist/shared.d.cts +1 -1
- package/dist/shared.d.mts +1 -1
- package/dist/{unstable-core-do-not-import-Dwco_7Rh.d.mts → unstable-core-do-not-import-CzDUc5m2.d.mts} +2 -2
- package/dist/{unstable-core-do-not-import-Dwco_7Rh.d.mts.map → unstable-core-do-not-import-CzDUc5m2.d.mts.map} +1 -1
- package/dist/{unstable-core-do-not-import-BSR46h1T.d.cts → unstable-core-do-not-import-Db2TnFh8.d.cts} +2 -2
- package/dist/{unstable-core-do-not-import-BSR46h1T.d.cts.map → unstable-core-do-not-import-Db2TnFh8.d.cts.map} +1 -1
- package/dist/unstable-core-do-not-import.cjs +2 -2
- package/dist/unstable-core-do-not-import.d.cts +1 -1
- package/dist/unstable-core-do-not-import.d.mts +1 -1
- package/dist/unstable-core-do-not-import.mjs +2 -2
- package/dist/{ws-DISNGMFd.mjs → ws-BqEmiHOX.mjs} +348 -195
- package/dist/ws-BqEmiHOX.mjs.map +1 -0
- package/dist/{ws-DFpyRwue.d.cts → ws-D-DF_k_T.d.cts} +3 -3
- package/dist/ws-D-DF_k_T.d.cts.map +1 -0
- package/dist/{ws-CO1rjQdN.d.mts → ws-lJRDMspc.d.mts} +3 -3
- package/dist/ws-lJRDMspc.d.mts.map +1 -0
- package/dist/{ws-BefV3QoE.cjs → ws-zjwsyre9.cjs} +346 -193
- package/package.json +9 -11
- package/skills/adapter-aws-lambda/SKILL.md +1 -1
- package/skills/adapter-express/SKILL.md +1 -1
- package/skills/adapter-fastify/SKILL.md +1 -1
- package/skills/adapter-fetch/SKILL.md +1 -1
- package/skills/adapter-standalone/SKILL.md +1 -1
- package/skills/auth/SKILL.md +1 -1
- package/skills/caching/SKILL.md +1 -1
- package/skills/error-handling/SKILL.md +1 -1
- package/skills/middlewares/SKILL.md +1 -1
- package/skills/non-json-content-types/SKILL.md +1 -1
- package/skills/server-setup/SKILL.md +1 -1
- package/skills/server-side-calls/SKILL.md +1 -1
- package/skills/service-oriented-architecture/SKILL.md +1 -1
- package/skills/subscriptions/SKILL.md +11 -3
- package/skills/trpc-router/SKILL.md +1 -1
- package/skills/validators/SKILL.md +1 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +37 -8
- package/src/adapters/ws.ts +333 -123
- package/src/observable/behaviorSubject.ts +20 -2
- package/src/observable/observable.ts +26 -11
- package/dist/observable-Crotwz1G.mjs.map +0 -1
- package/dist/ws-CO1rjQdN.d.mts.map +0 -1
- package/dist/ws-DFpyRwue.d.cts.map +0 -1
- package/dist/ws-DISNGMFd.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@trpc/server",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "11.
|
|
5
|
+
"version": "11.25.0",
|
|
6
6
|
"description": "The tRPC server library",
|
|
7
7
|
"author": "KATT",
|
|
8
8
|
"license": "MIT",
|
|
@@ -15,14 +15,6 @@
|
|
|
15
15
|
"url": "git+https://github.com/trpc/trpc.git",
|
|
16
16
|
"directory": "packages/server"
|
|
17
17
|
},
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "tsdown",
|
|
20
|
-
"prepack": "node ../../www/build/skills.ts --package .",
|
|
21
|
-
"dev": "tsdown --watch",
|
|
22
|
-
"benchmark": "tsc --project tsconfig.benchmark.json",
|
|
23
|
-
"lint": "oxlint src",
|
|
24
|
-
"typecheck": "tsc --noEmit --preserveWatchOutput --pretty"
|
|
25
|
-
},
|
|
26
18
|
"exports": {
|
|
27
19
|
"./package.json": "./package.json",
|
|
28
20
|
".": {
|
|
@@ -257,5 +249,11 @@
|
|
|
257
249
|
"keywords": [
|
|
258
250
|
"tanstack-intent"
|
|
259
251
|
],
|
|
260
|
-
"
|
|
261
|
-
|
|
252
|
+
"scripts": {
|
|
253
|
+
"build": "tsdown",
|
|
254
|
+
"dev": "tsdown --watch",
|
|
255
|
+
"benchmark": "tsc --project tsconfig.benchmark.json",
|
|
256
|
+
"lint": "oxlint src",
|
|
257
|
+
"typecheck": "tsc --noEmit --preserveWatchOutput --pretty"
|
|
258
|
+
}
|
|
259
|
+
}
|
package/skills/auth/SKILL.md
CHANGED
package/skills/caching/SKILL.md
CHANGED
|
@@ -10,7 +10,7 @@ sources:
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: composition
|
|
12
12
|
library: trpc
|
|
13
|
-
library_version: 11.
|
|
13
|
+
library_version: 11.25.0
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
<!-- Generated from www/v11/docs/server/service-oriented-architecture.md by www/build/skills.ts. Edit the docs instead. -->
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: subscriptions
|
|
3
|
-
description: "Set up real-time event streams with async generator subscriptions using .subscription(async function*() { yield }). SSE via httpSubscriptionLink is recommended over WebSocket. Use tracked(id, data) from @trpc/server for reconnection recovery with lastEventId. WebSocket via wsLink and createWSClient from @trpc/client, applyWSSHandler from @trpc/server/adapters/ws. Configure SSE ping with initTRPC.create({ sse: { ping: { enabled, intervalMs } } }). AbortSignal via opts.signal for cleanup. splitLink to route subscriptions. Consume them with the client's .subscribe(input, { onData, onError }) and .unsubscribe()."
|
|
3
|
+
description: "Set up real-time event streams with async generator subscriptions using .subscription(async function*() { yield }). SSE via httpSubscriptionLink is recommended over WebSocket. Use tracked(id, data) from @trpc/server for reconnection recovery with lastEventId. WebSocket via wsLink and createWSClient from @trpc/client, applyWSSHandler from @trpc/server/adapters/ws. Configure SSE ping with initTRPC.create({ sse: { ping: { enabled, intervalMs } } }). AbortSignal via opts.signal for cleanup. splitLink to route subscriptions. Consume them with the client's .subscribe(input, { onData, onError }) and .unsubscribe(), or without callbacks iterate the returned async iterator with for await, stopping it with break or an AbortSignal."
|
|
4
4
|
requires:
|
|
5
5
|
- server-setup
|
|
6
6
|
- links
|
|
@@ -12,7 +12,7 @@ sources:
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: core
|
|
14
14
|
library: trpc
|
|
15
|
-
library_version: 11.
|
|
15
|
+
library_version: 11.25.0
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
<!-- Generated from www/v11/docs/server/subscriptions.md by www/build/skills.ts. Edit the docs instead. -->
|
|
@@ -180,6 +180,14 @@ const subscription = client.onPostAdd.subscribe(
|
|
|
180
180
|
subscription.unsubscribe();
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
+
Without callbacks, `.subscribe()` returns an async iterator, so you can consume the subscription with `for await` instead. It has no `unsubscribe()`: leaving the loop or aborting the `signal` you passed unsubscribes, and errors are thrown from the loop. See [the vanilla client](https://trpc.io/docs/client/vanilla/setup#5-use-subscriptions) for the details.
|
|
184
|
+
|
|
185
|
+
```ts no-check title="client.ts"
|
|
186
|
+
for await (const event of client.onPostAdd.subscribe({ lastEventId: null })) {
|
|
187
|
+
console.log(event.id, event.data.title);
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
183
191
|
For React, see [`subscriptionOptions`](https://trpc.io/docs/client/tanstack-react-query/usage#subscriptionOptions) with TanStack React Query, or the classic [`useSubscription()`](https://trpc.io/docs/client/react/useSubscription).
|
|
184
192
|
|
|
185
193
|
## Pull data in a loop
|
|
@@ -262,7 +270,7 @@ export const subRouter = router({
|
|
|
262
270
|
});
|
|
263
271
|
```
|
|
264
272
|
|
|
265
|
-
On the client, you just `.unsubscribe()` the subscription.
|
|
273
|
+
On the client, you just `.unsubscribe()` the subscription, or leave the `for await` loop.
|
|
266
274
|
|
|
267
275
|
## Cleanup of side effects
|
|
268
276
|
|
|
@@ -18,7 +18,12 @@ import {
|
|
|
18
18
|
import type { ResolveHTTPRequestOptionsContextFn } from '../../@trpc/server/http';
|
|
19
19
|
import { resolveResponse } from '../../@trpc/server/http';
|
|
20
20
|
// oxlint-disable-next-line no-restricted-imports
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
getErrorShape,
|
|
23
|
+
run,
|
|
24
|
+
TRPC_ERROR_CODES_BY_KEY,
|
|
25
|
+
type TRPCErrorShape,
|
|
26
|
+
} from '../../unstable-core-do-not-import';
|
|
22
27
|
import { incomingMessageToRequest } from './incomingMessageToRequest';
|
|
23
28
|
import type {
|
|
24
29
|
NodeHTTPRequest,
|
|
@@ -27,6 +32,16 @@ import type {
|
|
|
27
32
|
} from './types';
|
|
28
33
|
import { writeResponse } from './writeResponse';
|
|
29
34
|
|
|
35
|
+
/**
|
|
36
|
+
* What the client gets when its error can't be formatted. It says nothing
|
|
37
|
+
* about the error, which is what `errorFormatter` would have hidden.
|
|
38
|
+
*/
|
|
39
|
+
const fallbackErrorShape: TRPCErrorShape = {
|
|
40
|
+
code: TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR,
|
|
41
|
+
message: 'Internal server error',
|
|
42
|
+
data: { code: 'INTERNAL_SERVER_ERROR', httpStatus: 500 },
|
|
43
|
+
};
|
|
44
|
+
|
|
30
45
|
/**
|
|
31
46
|
* Answers with an error response when handling a request throws.
|
|
32
47
|
* @internal
|
|
@@ -40,13 +55,21 @@ export function internal_exceptionHandler<
|
|
|
40
55
|
const { res, req } = opts;
|
|
41
56
|
const error = getTRPCErrorFromUnknown(cause);
|
|
42
57
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
const config = opts.router._def._config;
|
|
59
|
+
const shape = run(() => {
|
|
60
|
+
try {
|
|
61
|
+
return getErrorShape({
|
|
62
|
+
config,
|
|
63
|
+
error,
|
|
64
|
+
type: 'unknown',
|
|
65
|
+
path: undefined,
|
|
66
|
+
input: undefined,
|
|
67
|
+
ctx: undefined,
|
|
68
|
+
});
|
|
69
|
+
} catch {
|
|
70
|
+
// a throwing `errorFormatter` must not stop the response
|
|
71
|
+
return fallbackErrorShape;
|
|
72
|
+
}
|
|
50
73
|
});
|
|
51
74
|
|
|
52
75
|
opts.onError?.({
|
|
@@ -58,6 +81,12 @@ export function internal_exceptionHandler<
|
|
|
58
81
|
ctx: undefined,
|
|
59
82
|
});
|
|
60
83
|
|
|
84
|
+
if (res.headersSent) {
|
|
85
|
+
// a body that failed while streaming; writing again would throw
|
|
86
|
+
res.end();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
61
90
|
const transformed = transformTRPCResponse(opts.router._def._config, {
|
|
62
91
|
error: shape,
|
|
63
92
|
});
|