@trpc/server 11.24.1-canary.9.fb22efc0a → 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.
Files changed (114) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/aws-lambda/index.cjs +1 -1
  3. package/dist/adapters/aws-lambda/index.d.cts +1 -1
  4. package/dist/adapters/aws-lambda/index.d.mts +1 -1
  5. package/dist/adapters/aws-lambda/index.mjs +1 -1
  6. package/dist/adapters/express.cjs +1 -1
  7. package/dist/adapters/express.d.cts +2 -2
  8. package/dist/adapters/express.d.mts +2 -2
  9. package/dist/adapters/express.mjs +1 -1
  10. package/dist/adapters/fastify/index.cjs +3 -3
  11. package/dist/adapters/fastify/index.d.cts +3 -3
  12. package/dist/adapters/fastify/index.d.mts +3 -3
  13. package/dist/adapters/fastify/index.mjs +3 -3
  14. package/dist/adapters/fetch/index.cjs +1 -1
  15. package/dist/adapters/fetch/index.d.cts +1 -1
  16. package/dist/adapters/fetch/index.d.mts +1 -1
  17. package/dist/adapters/fetch/index.mjs +1 -1
  18. package/dist/adapters/next-app-dir.d.cts +1 -1
  19. package/dist/adapters/next-app-dir.d.mts +1 -1
  20. package/dist/adapters/next.cjs +1 -1
  21. package/dist/adapters/next.d.cts +2 -2
  22. package/dist/adapters/next.d.mts +2 -2
  23. package/dist/adapters/next.mjs +1 -1
  24. package/dist/adapters/node-http/index.cjs +1 -1
  25. package/dist/adapters/node-http/index.d.cts +1 -1
  26. package/dist/adapters/node-http/index.d.mts +1 -1
  27. package/dist/adapters/node-http/index.mjs +1 -1
  28. package/dist/adapters/standalone.cjs +1 -1
  29. package/dist/adapters/standalone.d.cts +2 -2
  30. package/dist/adapters/standalone.d.mts +2 -2
  31. package/dist/adapters/standalone.mjs +1 -1
  32. package/dist/adapters/ws.cjs +1 -1
  33. package/dist/adapters/ws.d.cts +2 -2
  34. package/dist/adapters/ws.d.mts +2 -2
  35. package/dist/adapters/ws.mjs +1 -1
  36. package/dist/http.cjs +1 -1
  37. package/dist/http.d.cts +1 -1
  38. package/dist/http.d.mts +1 -1
  39. package/dist/http.mjs +1 -1
  40. package/dist/{index-Bdq70sid.d.cts → index-CFQnkrGZ.d.cts} +6 -3
  41. package/dist/{index-Bdq70sid.d.cts.map → index-CFQnkrGZ.d.cts.map} +1 -1
  42. package/dist/{index-Bdq70sid.d.mts → index-CFQnkrGZ.d.mts} +6 -3
  43. package/dist/{index-Bdq70sid.d.mts.map → index-CFQnkrGZ.d.mts.map} +1 -1
  44. package/dist/{index-C8o7kgHD.d.mts → index-DVmu6VtT.d.mts} +2 -2
  45. package/dist/{index-C8o7kgHD.d.mts.map → index-DVmu6VtT.d.mts.map} +1 -1
  46. package/dist/{index-mlF5Hred.d.cts → index-Dn1ucZS5.d.cts} +2 -2
  47. package/dist/{index-mlF5Hred.d.cts.map → index-Dn1ucZS5.d.cts.map} +1 -1
  48. package/dist/index.cjs +1 -1
  49. package/dist/index.d.cts +1 -1
  50. package/dist/index.d.mts +1 -1
  51. package/dist/index.mjs +1 -1
  52. package/dist/{initTRPC-BHFhyRlq.mjs → initTRPC-DPoVGUwX.mjs} +2 -2
  53. package/dist/{initTRPC-BHFhyRlq.mjs.map → initTRPC-DPoVGUwX.mjs.map} +1 -1
  54. package/dist/{initTRPC-Cqhzvadj.cjs → initTRPC-yeYwDikA.cjs} +1 -1
  55. package/dist/{node-http-CgxAZYco.mjs → node-http-Df_b1FfK.mjs} +33 -10
  56. package/dist/{node-http-CgxAZYco.mjs.map → node-http-Df_b1FfK.mjs.map} +1 -1
  57. package/dist/{node-http-zAXiTJ5z.cjs → node-http-vS2eeV-2.cjs} +31 -8
  58. package/dist/observable/index.cjs +2 -2
  59. package/dist/observable/index.d.cts +1 -1
  60. package/dist/observable/index.d.mts +1 -1
  61. package/dist/observable/index.mjs +2 -2
  62. package/dist/{observable-DvS5lN8Q.cjs → observable-1zKJIeLl.cjs} +27 -9
  63. package/dist/{observable-YaZmQKBm.mjs → observable-Cmd1MFy3.mjs} +17 -3
  64. package/dist/{observable-YaZmQKBm.mjs.map → observable-Cmd1MFy3.mjs.map} +1 -1
  65. package/dist/{observable-C__NrSHz.cjs → observable-CtU0hoef.cjs} +16 -2
  66. package/dist/{observable-Crotwz1G.mjs → observable-kpFFzvou.mjs} +28 -10
  67. package/dist/observable-kpFFzvou.mjs.map +1 -0
  68. package/dist/{resolveResponse-KsaMasi_.mjs → resolveResponse-C3K3zKPn.mjs} +2 -2
  69. package/dist/{resolveResponse-KsaMasi_.mjs.map → resolveResponse-C3K3zKPn.mjs.map} +1 -1
  70. package/dist/{resolveResponse-BiNVUUPp.cjs → resolveResponse-CoiQ9diV.cjs} +1 -1
  71. package/dist/rpc.d.cts +1 -1
  72. package/dist/rpc.d.mts +1 -1
  73. package/dist/shared.d.cts +1 -1
  74. package/dist/shared.d.mts +1 -1
  75. package/dist/{unstable-core-do-not-import-Dwco_7Rh.d.mts → unstable-core-do-not-import-CzDUc5m2.d.mts} +2 -2
  76. package/dist/{unstable-core-do-not-import-Dwco_7Rh.d.mts.map → unstable-core-do-not-import-CzDUc5m2.d.mts.map} +1 -1
  77. package/dist/{unstable-core-do-not-import-BSR46h1T.d.cts → unstable-core-do-not-import-Db2TnFh8.d.cts} +2 -2
  78. package/dist/{unstable-core-do-not-import-BSR46h1T.d.cts.map → unstable-core-do-not-import-Db2TnFh8.d.cts.map} +1 -1
  79. package/dist/unstable-core-do-not-import.cjs +2 -2
  80. package/dist/unstable-core-do-not-import.d.cts +1 -1
  81. package/dist/unstable-core-do-not-import.d.mts +1 -1
  82. package/dist/unstable-core-do-not-import.mjs +2 -2
  83. package/dist/{ws-DISNGMFd.mjs → ws-BqEmiHOX.mjs} +348 -195
  84. package/dist/ws-BqEmiHOX.mjs.map +1 -0
  85. package/dist/{ws-DFpyRwue.d.cts → ws-D-DF_k_T.d.cts} +3 -3
  86. package/dist/ws-D-DF_k_T.d.cts.map +1 -0
  87. package/dist/{ws-CO1rjQdN.d.mts → ws-lJRDMspc.d.mts} +3 -3
  88. package/dist/ws-lJRDMspc.d.mts.map +1 -0
  89. package/dist/{ws-BefV3QoE.cjs → ws-zjwsyre9.cjs} +346 -193
  90. package/package.json +9 -11
  91. package/skills/adapter-aws-lambda/SKILL.md +1 -1
  92. package/skills/adapter-express/SKILL.md +1 -1
  93. package/skills/adapter-fastify/SKILL.md +1 -1
  94. package/skills/adapter-fetch/SKILL.md +1 -1
  95. package/skills/adapter-standalone/SKILL.md +1 -1
  96. package/skills/auth/SKILL.md +1 -1
  97. package/skills/caching/SKILL.md +1 -1
  98. package/skills/error-handling/SKILL.md +1 -1
  99. package/skills/middlewares/SKILL.md +1 -1
  100. package/skills/non-json-content-types/SKILL.md +1 -1
  101. package/skills/server-setup/SKILL.md +1 -1
  102. package/skills/server-side-calls/SKILL.md +1 -1
  103. package/skills/service-oriented-architecture/SKILL.md +1 -1
  104. package/skills/subscriptions/SKILL.md +11 -3
  105. package/skills/trpc-router/SKILL.md +1 -1
  106. package/skills/validators/SKILL.md +1 -1
  107. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +37 -8
  108. package/src/adapters/ws.ts +333 -123
  109. package/src/observable/behaviorSubject.ts +20 -2
  110. package/src/observable/observable.ts +26 -11
  111. package/dist/observable-Crotwz1G.mjs.map +0 -1
  112. package/dist/ws-CO1rjQdN.d.mts.map +0 -1
  113. package/dist/ws-DFpyRwue.d.cts.map +0 -1
  114. 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.24.1-canary.9.fb22efc0a",
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
- "gitHead": "fb22efc0a9be45465c063435ddbeb86d4d3239bb"
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
+ }
@@ -9,7 +9,7 @@ sources:
9
9
  metadata:
10
10
  type: core
11
11
  library: trpc
12
- library_version: 11.24.1-canary.9.fb22efc0a
12
+ library_version: 11.25.0
13
13
  ---
14
14
 
15
15
  <!-- Generated from www/v11/docs/server/adapters/aws-lambda.md by www/build/skills.ts. Edit the docs instead. -->
@@ -9,7 +9,7 @@ sources:
9
9
  metadata:
10
10
  type: core
11
11
  library: trpc
12
- library_version: 11.24.1-canary.9.fb22efc0a
12
+ library_version: 11.25.0
13
13
  ---
14
14
 
15
15
  <!-- Generated from www/v11/docs/server/adapters/express.md by www/build/skills.ts. Edit the docs instead. -->
@@ -9,7 +9,7 @@ sources:
9
9
  metadata:
10
10
  type: core
11
11
  library: trpc
12
- library_version: 11.24.1-canary.9.fb22efc0a
12
+ library_version: 11.25.0
13
13
  ---
14
14
 
15
15
  <!-- Generated from www/v11/docs/server/adapters/fastify.md by www/build/skills.ts. Edit the docs instead. -->
@@ -8,7 +8,7 @@ sources:
8
8
  metadata:
9
9
  type: core
10
10
  library: trpc
11
- library_version: 11.24.1-canary.9.fb22efc0a
11
+ library_version: 11.25.0
12
12
  ---
13
13
 
14
14
  <!-- Generated from www/v11/docs/server/adapters/fetch.md by www/build/skills.ts. Edit the docs instead. -->
@@ -9,7 +9,7 @@ sources:
9
9
  metadata:
10
10
  type: core
11
11
  library: trpc
12
- library_version: 11.24.1-canary.9.fb22efc0a
12
+ library_version: 11.25.0
13
13
  ---
14
14
 
15
15
  <!-- Generated from www/v11/docs/server/adapters/standalone.md by www/build/skills.ts. Edit the docs instead. -->
@@ -14,7 +14,7 @@ sources:
14
14
  metadata:
15
15
  type: composition
16
16
  library: trpc
17
- library_version: 11.24.1-canary.9.fb22efc0a
17
+ library_version: 11.25.0
18
18
  ---
19
19
 
20
20
  <!-- Generated from www/v11/docs/server/authorization.md by www/build/skills.ts. Edit the docs instead. -->
@@ -8,7 +8,7 @@ sources:
8
8
  metadata:
9
9
  type: core
10
10
  library: trpc
11
- library_version: 11.24.1-canary.9.fb22efc0a
11
+ library_version: 11.25.0
12
12
  ---
13
13
 
14
14
  <!-- Generated from www/v11/docs/server/caching.md by www/build/skills.ts. Edit the docs instead. -->
@@ -9,7 +9,7 @@ sources:
9
9
  metadata:
10
10
  type: core
11
11
  library: trpc
12
- library_version: 11.24.1-canary.9.fb22efc0a
12
+ library_version: 11.25.0
13
13
  ---
14
14
 
15
15
  <!-- Generated from www/v11/docs/server/error-handling.md by www/build/skills.ts. Edit the docs instead. -->
@@ -8,7 +8,7 @@ sources:
8
8
  metadata:
9
9
  type: core
10
10
  library: trpc
11
- library_version: 11.24.1-canary.9.fb22efc0a
11
+ library_version: 11.25.0
12
12
  ---
13
13
 
14
14
  <!-- Generated from www/v11/docs/server/middlewares.md by www/build/skills.ts. Edit the docs instead. -->
@@ -10,7 +10,7 @@ sources:
10
10
  metadata:
11
11
  type: core
12
12
  library: trpc
13
- library_version: 11.24.1-canary.9.fb22efc0a
13
+ library_version: 11.25.0
14
14
  ---
15
15
 
16
16
  <!-- Generated from www/v11/docs/server/non-json-content-types.md by www/build/skills.ts. Edit the docs instead. -->
@@ -11,7 +11,7 @@ sources:
11
11
  metadata:
12
12
  type: core
13
13
  library: trpc
14
- library_version: 11.24.1-canary.9.fb22efc0a
14
+ library_version: 11.25.0
15
15
  ---
16
16
 
17
17
  <!-- Generated from www/v11/docs/server/overview.md by www/build/skills.ts. Edit the docs instead. -->
@@ -8,7 +8,7 @@ sources:
8
8
  metadata:
9
9
  type: core
10
10
  library: trpc
11
- library_version: 11.24.1-canary.9.fb22efc0a
11
+ library_version: 11.25.0
12
12
  ---
13
13
 
14
14
  <!-- Generated from www/v11/docs/server/server-side-calls.md by www/build/skills.ts. Edit the docs instead. -->
@@ -10,7 +10,7 @@ sources:
10
10
  metadata:
11
11
  type: composition
12
12
  library: trpc
13
- library_version: 11.24.1-canary.9.fb22efc0a
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.24.1-canary.9.fb22efc0a
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
 
@@ -7,7 +7,7 @@ sources:
7
7
  metadata:
8
8
  type: core
9
9
  library: trpc
10
- library_version: 11.24.1-canary.9.fb22efc0a
10
+ library_version: 11.25.0
11
11
  ---
12
12
 
13
13
  <!-- Generated from www/v11/docs/skills.md by www/build/skills.ts. Edit the docs instead. -->
@@ -8,7 +8,7 @@ sources:
8
8
  metadata:
9
9
  type: core
10
10
  library: trpc
11
- library_version: 11.24.1-canary.9.fb22efc0a
11
+ library_version: 11.25.0
12
12
  ---
13
13
 
14
14
  <!-- Generated from www/v11/docs/server/validators.md by www/build/skills.ts. Edit the docs instead. -->
@@ -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 { getErrorShape, run } from '../../unstable-core-do-not-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 shape = getErrorShape({
44
- config: opts.router._def._config,
45
- error,
46
- type: 'unknown',
47
- path: undefined,
48
- input: undefined,
49
- ctx: undefined,
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
  });