@trpc/server 11.23.0 → 11.23.1-canary.14.507382d73

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 (215) hide show
  1. package/dist/adapters/aws-lambda/index.cjs +12 -2
  2. package/dist/adapters/aws-lambda/index.d.cts +24 -1
  3. package/dist/adapters/aws-lambda/index.d.cts.map +1 -1
  4. package/dist/adapters/aws-lambda/index.d.mts +24 -1
  5. package/dist/adapters/aws-lambda/index.d.mts.map +1 -1
  6. package/dist/adapters/aws-lambda/index.mjs +12 -2
  7. package/dist/adapters/aws-lambda/index.mjs.map +1 -1
  8. package/dist/adapters/express.cjs +8 -3
  9. package/dist/adapters/express.d.cts +12 -2
  10. package/dist/adapters/express.d.cts.map +1 -1
  11. package/dist/adapters/express.d.mts +12 -2
  12. package/dist/adapters/express.d.mts.map +1 -1
  13. package/dist/adapters/express.mjs +8 -3
  14. package/dist/adapters/express.mjs.map +1 -1
  15. package/dist/adapters/fastify/index.cjs +20 -4
  16. package/dist/adapters/fastify/index.d.cts +38 -4
  17. package/dist/adapters/fastify/index.d.cts.map +1 -1
  18. package/dist/adapters/fastify/index.d.mts +38 -4
  19. package/dist/adapters/fastify/index.d.mts.map +1 -1
  20. package/dist/adapters/fastify/index.mjs +20 -4
  21. package/dist/adapters/fastify/index.mjs.map +1 -1
  22. package/dist/adapters/fetch/index.cjs +13 -2
  23. package/dist/adapters/fetch/index.d.cts +26 -1
  24. package/dist/adapters/fetch/index.d.cts.map +1 -1
  25. package/dist/adapters/fetch/index.d.mts +26 -1
  26. package/dist/adapters/fetch/index.d.mts.map +1 -1
  27. package/dist/adapters/fetch/index.mjs +13 -2
  28. package/dist/adapters/fetch/index.mjs.map +1 -1
  29. package/dist/adapters/next-app-dir.cjs +19 -9
  30. package/dist/adapters/next-app-dir.d.cts +21 -11
  31. package/dist/adapters/next-app-dir.d.cts.map +1 -1
  32. package/dist/adapters/next-app-dir.d.mts +21 -11
  33. package/dist/adapters/next-app-dir.d.mts.map +1 -1
  34. package/dist/adapters/next-app-dir.mjs +19 -9
  35. package/dist/adapters/next-app-dir.mjs.map +1 -1
  36. package/dist/adapters/next.cjs +10 -4
  37. package/dist/adapters/next.d.cts +13 -2
  38. package/dist/adapters/next.d.cts.map +1 -1
  39. package/dist/adapters/next.d.mts +13 -2
  40. package/dist/adapters/next.d.mts.map +1 -1
  41. package/dist/adapters/next.mjs +10 -4
  42. package/dist/adapters/next.mjs.map +1 -1
  43. package/dist/adapters/node-http/index.cjs +1 -1
  44. package/dist/adapters/node-http/index.d.cts +1 -1
  45. package/dist/adapters/node-http/index.d.mts +1 -1
  46. package/dist/adapters/node-http/index.mjs +1 -1
  47. package/dist/adapters/standalone.cjs +19 -3
  48. package/dist/adapters/standalone.d.cts +32 -6
  49. package/dist/adapters/standalone.d.cts.map +1 -1
  50. package/dist/adapters/standalone.d.mts +32 -6
  51. package/dist/adapters/standalone.d.mts.map +1 -1
  52. package/dist/adapters/standalone.mjs +19 -3
  53. package/dist/adapters/standalone.mjs.map +1 -1
  54. package/dist/adapters/ws.cjs +1 -1
  55. package/dist/adapters/ws.d.cts +2 -2
  56. package/dist/adapters/ws.d.mts +2 -2
  57. package/dist/adapters/ws.mjs +1 -1
  58. package/dist/{asyncGeneratorDelegate-FcEJT04i.mjs → asyncGeneratorDelegate-Bl41FGB5.mjs} +41 -8
  59. package/dist/asyncGeneratorDelegate-Bl41FGB5.mjs.map +1 -0
  60. package/dist/{asyncGeneratorDelegate-Dj-8tGhf.cjs → asyncGeneratorDelegate-CPV0O1Hn.cjs} +40 -7
  61. package/dist/{codes-HK4UsP07.cjs → codes-Be-DrYMh.cjs} +8 -4
  62. package/dist/{codes-C9N0z0an.mjs → codes-nbrm_zWY.mjs} +9 -5
  63. package/dist/codes-nbrm_zWY.mjs.map +1 -0
  64. package/dist/{contentTypeParsers-B1e2ZNvN.cjs → contentTypeParsers-BTdoZrqN.cjs} +12 -0
  65. package/dist/contentTypeParsers-D1EBkFFY.mjs +26 -0
  66. package/dist/contentTypeParsers-D1EBkFFY.mjs.map +1 -0
  67. package/dist/{getErrorShape-hncV8cPE.cjs → getErrorShape-8t0oLscZ.cjs} +16 -5
  68. package/dist/{getErrorShape-zlj81BiC.mjs → getErrorShape-B6z8u8q0.mjs} +17 -6
  69. package/dist/getErrorShape-B6z8u8q0.mjs.map +1 -0
  70. package/dist/http.cjs +3 -3
  71. package/dist/http.d.cts +1 -1
  72. package/dist/http.d.mts +1 -1
  73. package/dist/http.mjs +3 -3
  74. package/dist/{index-BI3Qi_F-.d.cts → index-BGYvuCEh.d.cts} +68 -8
  75. package/dist/index-BGYvuCEh.d.cts.map +1 -0
  76. package/dist/{index-BI3Qi_F-.d.mts → index-BGYvuCEh.d.mts} +68 -8
  77. package/dist/index-BGYvuCEh.d.mts.map +1 -0
  78. package/dist/{index-Tpw5OCTF.d.cts → index-CTfJHk7_.d.cts} +41 -29
  79. package/dist/index-CTfJHk7_.d.cts.map +1 -0
  80. package/dist/{index-CtkOmZzm.d.mts → index-DD2oXVyh.d.mts} +41 -29
  81. package/dist/index-DD2oXVyh.d.mts.map +1 -0
  82. package/dist/index.cjs +3 -3
  83. package/dist/index.d.cts +3 -3
  84. package/dist/index.d.mts +3 -3
  85. package/dist/index.mjs +3 -3
  86. package/dist/{initTRPC-RMeQIy9H.mjs → initTRPC-JhlmAV6P.mjs} +31 -22
  87. package/dist/initTRPC-JhlmAV6P.mjs.map +1 -0
  88. package/dist/{initTRPC-DP-s8c4t.cjs → initTRPC-jn7uHFOx.cjs} +30 -21
  89. package/dist/{node-http-X8RiQEuH.cjs → node-http-CCpTZ1zd.cjs} +13 -6
  90. package/dist/{node-http-ChhZEv1k.mjs → node-http-DTcc6qM4.mjs} +14 -7
  91. package/dist/node-http-DTcc6qM4.mjs.map +1 -0
  92. package/dist/observable/index.cjs +2 -2
  93. package/dist/observable/index.d.cts +1 -1
  94. package/dist/observable/index.d.mts +1 -1
  95. package/dist/observable/index.mjs +2 -2
  96. package/dist/{observable-C-LvH26G.cjs → observable-B8nn0anr.cjs} +27 -4
  97. package/dist/{observable-yEyhfXUI.mjs → observable-CdPmrXKY.mjs} +28 -5
  98. package/dist/observable-CdPmrXKY.mjs.map +1 -0
  99. package/dist/{observable-CkXWrCsV.mjs → observable-F1Nt_3e4.mjs} +16 -4
  100. package/dist/observable-F1Nt_3e4.mjs.map +1 -0
  101. package/dist/{observable-xBsJ11Ns.cjs → observable-N4F1yT7s.cjs} +15 -3
  102. package/dist/{parseTRPCMessage-CJ4DJVBp.mjs → parseTRPCMessage-BO1-cCsX.mjs} +7 -3
  103. package/dist/parseTRPCMessage-BO1-cCsX.mjs.map +1 -0
  104. package/dist/{parseTRPCMessage-CPEfSSFx.cjs → parseTRPCMessage-BsPr5reh.cjs} +6 -2
  105. package/dist/{resolveResponse-DksrxZ2k.mjs → resolveResponse-B2MQmLSr.mjs} +17 -5
  106. package/dist/resolveResponse-B2MQmLSr.mjs.map +1 -0
  107. package/dist/{resolveResponse-CoGjFxK0.cjs → resolveResponse-BQcrvKyB.cjs} +16 -4
  108. package/dist/rpc.cjs +2 -2
  109. package/dist/rpc.d.cts +1 -1
  110. package/dist/rpc.d.mts +1 -1
  111. package/dist/rpc.mjs +2 -2
  112. package/dist/shared.cjs +1 -1
  113. package/dist/shared.d.cts +1 -1
  114. package/dist/shared.d.mts +1 -1
  115. package/dist/shared.mjs +1 -1
  116. package/dist/{unstable-core-do-not-import-B8epiErP.d.cts → unstable-core-do-not-import-DYnAWlN7.d.cts} +517 -161
  117. package/dist/unstable-core-do-not-import-DYnAWlN7.d.cts.map +1 -0
  118. package/dist/{unstable-core-do-not-import-Dbo98mkh.d.mts → unstable-core-do-not-import-hC2_7K-s.d.mts} +517 -161
  119. package/dist/unstable-core-do-not-import-hC2_7K-s.d.mts.map +1 -0
  120. package/dist/unstable-core-do-not-import.cjs +7 -7
  121. package/dist/unstable-core-do-not-import.d.cts +1 -1
  122. package/dist/unstable-core-do-not-import.d.mts +1 -1
  123. package/dist/unstable-core-do-not-import.mjs +7 -7
  124. package/dist/{ws-BYfo-HED.mjs → ws-B9v4J-4P.mjs} +30 -11
  125. package/dist/ws-B9v4J-4P.mjs.map +1 -0
  126. package/dist/ws-DVHbmgfC.d.mts +95 -0
  127. package/dist/ws-DVHbmgfC.d.mts.map +1 -0
  128. package/dist/ws-JzZs-0Zd.d.cts +95 -0
  129. package/dist/ws-JzZs-0Zd.d.cts.map +1 -0
  130. package/dist/{ws-7qWW7Uec.cjs → ws-_SClUVOu.cjs} +29 -10
  131. package/package.json +2 -2
  132. package/skills/adapter-aws-lambda/SKILL.md +1 -1
  133. package/skills/adapter-express/SKILL.md +1 -1
  134. package/skills/adapter-fastify/SKILL.md +1 -1
  135. package/skills/adapter-fetch/SKILL.md +1 -1
  136. package/skills/adapter-standalone/SKILL.md +1 -1
  137. package/skills/auth/SKILL.md +1 -1
  138. package/skills/caching/SKILL.md +2 -2
  139. package/skills/error-handling/SKILL.md +1 -1
  140. package/skills/middlewares/SKILL.md +1 -1
  141. package/skills/non-json-content-types/SKILL.md +13 -4
  142. package/skills/server-setup/SKILL.md +1 -1
  143. package/skills/server-side-calls/SKILL.md +1 -1
  144. package/skills/service-oriented-architecture/SKILL.md +1 -1
  145. package/skills/subscriptions/SKILL.md +1 -1
  146. package/skills/trpc-router/SKILL.md +1 -1
  147. package/skills/validators/SKILL.md +1 -1
  148. package/src/@trpc/server/index.ts +2 -2
  149. package/src/adapters/aws-lambda/index.ts +23 -0
  150. package/src/adapters/express.ts +10 -0
  151. package/src/adapters/fastify/fastifyRequestHandler.ts +5 -0
  152. package/src/adapters/fastify/fastifyTRPCPlugin.ts +30 -1
  153. package/src/adapters/fetch/fetchRequestHandler.ts +11 -0
  154. package/src/adapters/fetch/types.ts +14 -0
  155. package/src/adapters/next-app-dir/nextAppDirCaller.ts +8 -4
  156. package/src/adapters/next-app-dir/notFound.ts +3 -1
  157. package/src/adapters/next-app-dir/redirect.ts +6 -4
  158. package/src/adapters/next-app-dir/rethrowNextErrors.ts +5 -1
  159. package/src/adapters/next.ts +13 -1
  160. package/src/adapters/node-http/incomingMessageToRequest.ts +6 -1
  161. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +3 -1
  162. package/src/adapters/node-http/types.ts +30 -25
  163. package/src/adapters/standalone.ts +30 -4
  164. package/src/adapters/ws.ts +42 -8
  165. package/src/adapters/wsEncoder.ts +5 -6
  166. package/src/observable/behaviorSubject.ts +6 -2
  167. package/src/observable/observable.ts +31 -5
  168. package/src/observable/operators.ts +12 -0
  169. package/src/observable/types.ts +18 -0
  170. package/src/unstable-core-do-not-import/clientish/inference.ts +22 -1
  171. package/src/unstable-core-do-not-import/clientish/inferrable.ts +5 -2
  172. package/src/unstable-core-do-not-import/createProxy.ts +4 -4
  173. package/src/unstable-core-do-not-import/error/TRPCError.ts +19 -0
  174. package/src/unstable-core-do-not-import/error/formatter.ts +15 -2
  175. package/src/unstable-core-do-not-import/error/getErrorShape.ts +2 -0
  176. package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +15 -2
  177. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +9 -0
  178. package/src/unstable-core-do-not-import/http/parseConnectionParams.ts +8 -0
  179. package/src/unstable-core-do-not-import/http/resolveResponse.ts +4 -0
  180. package/src/unstable-core-do-not-import/http/types.ts +55 -27
  181. package/src/unstable-core-do-not-import/initTRPC.ts +51 -27
  182. package/src/unstable-core-do-not-import/middleware.ts +25 -5
  183. package/src/unstable-core-do-not-import/procedure.ts +28 -2
  184. package/src/unstable-core-do-not-import/procedureBuilder.ts +56 -35
  185. package/src/unstable-core-do-not-import/rootConfig.ts +28 -19
  186. package/src/unstable-core-do-not-import/router.ts +71 -11
  187. package/src/unstable-core-do-not-import/rpc/codes.ts +13 -5
  188. package/src/unstable-core-do-not-import/rpc/envelopes.ts +45 -9
  189. package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +5 -1
  190. package/src/unstable-core-do-not-import/stream/tracked.ts +17 -5
  191. package/src/unstable-core-do-not-import/transformer.ts +12 -1
  192. package/src/unstable-core-do-not-import/types.ts +2 -0
  193. package/src/unstable-core-do-not-import/utils.ts +4 -1
  194. package/dist/asyncGeneratorDelegate-FcEJT04i.mjs.map +0 -1
  195. package/dist/codes-C9N0z0an.mjs.map +0 -1
  196. package/dist/contentTypeParsers-Bb-9hUEf.mjs +0 -14
  197. package/dist/contentTypeParsers-Bb-9hUEf.mjs.map +0 -1
  198. package/dist/getErrorShape-zlj81BiC.mjs.map +0 -1
  199. package/dist/index-BI3Qi_F-.d.cts.map +0 -1
  200. package/dist/index-BI3Qi_F-.d.mts.map +0 -1
  201. package/dist/index-CtkOmZzm.d.mts.map +0 -1
  202. package/dist/index-Tpw5OCTF.d.cts.map +0 -1
  203. package/dist/initTRPC-RMeQIy9H.mjs.map +0 -1
  204. package/dist/node-http-ChhZEv1k.mjs.map +0 -1
  205. package/dist/observable-CkXWrCsV.mjs.map +0 -1
  206. package/dist/observable-yEyhfXUI.mjs.map +0 -1
  207. package/dist/parseTRPCMessage-CJ4DJVBp.mjs.map +0 -1
  208. package/dist/resolveResponse-DksrxZ2k.mjs.map +0 -1
  209. package/dist/unstable-core-do-not-import-B8epiErP.d.cts.map +0 -1
  210. package/dist/unstable-core-do-not-import-Dbo98mkh.d.mts.map +0 -1
  211. package/dist/ws-BYfo-HED.mjs.map +0 -1
  212. package/dist/ws-DD1ukLuC.d.cts +0 -61
  213. package/dist/ws-DD1ukLuC.d.cts.map +0 -1
  214. package/dist/ws-DT37N43e.d.mts +0 -61
  215. package/dist/ws-DT37N43e.d.mts.map +0 -1
@@ -9,7 +9,7 @@ sources:
9
9
  metadata:
10
10
  type: core
11
11
  library: trpc
12
- library_version: 11.23.0
12
+ library_version: 11.23.1-canary.14.507382d73
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.23.0
11
+ library_version: 11.23.1-canary.14.507382d73
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.23.0
12
+ library_version: 11.23.1-canary.14.507382d73
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.23.0
17
+ library_version: 11.23.1-canary.14.507382d73
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.23.0
11
+ library_version: 11.23.1-canary.14.507382d73
12
12
  ---
13
13
 
14
14
  <!-- Generated from www/v11/docs/server/caching.md by www/build/skills.ts. Edit the docs instead. -->
@@ -108,7 +108,7 @@ server.listen(3000);
108
108
  `responseMeta` runs once per HTTP response, so with batching it decides the headers for every procedure in the batch: only cache if all of them are public. It also gets the request's `ctx`, e.g. to skip caching for signed-in users. For streamed responses, like those of [`httpBatchStreamLink`](https://trpc.io/docs/client/links/httpBatchStreamLink), the headers are sent before any procedure has finished, so `responseMeta` runs with `eagerGeneration: true` and an empty `errors` array.
109
109
 
110
110
  > [!TIP]
111
- > If you are using the deprecated Next.js Pages Router integration (`@trpc/next`), see the [Next.js SSR caching guide](https://trpc.io/docs/client/nextjs/pages-router/ssr#response-caching-with-ssr) for Next.js-specific caching examples using `createTRPCNext` and the Next.js adapter.
111
+ > If you are using Next.js, see the [Next.js SSR caching guide](https://trpc.io/docs/client/nextjs/pages-router/ssr#response-caching-with-ssr) for Next.js-specific caching examples using `createTRPCNext` and the Next.js adapter.
112
112
 
113
113
  ## Related skills
114
114
 
@@ -9,7 +9,7 @@ sources:
9
9
  metadata:
10
10
  type: core
11
11
  library: trpc
12
- library_version: 11.23.0
12
+ library_version: 11.23.1-canary.14.507382d73
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.23.0
11
+ library_version: 11.23.1-canary.14.507382d73
12
12
  ---
13
13
 
14
14
  <!-- Generated from www/v11/docs/server/middlewares.md by www/build/skills.ts. Edit the docs instead. -->
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: non-json-content-types
3
- description: Handle FormData, file uploads, Blob, Uint8Array, and ReadableStream inputs in tRPC mutations. Use octetInputParser from @trpc/server/http for binary data. Route non-JSON requests with splitLink and isNonJsonSerializable() from @trpc/client, since batching links send them as `{}`. FormData and binary inputs only work with mutations (POST) and skip the transformer. Keep Express or Next.js body parsers off tRPC routes.
3
+ description: Handle FormData, file uploads, Blob, Uint8Array, and ReadableStream inputs in tRPC mutations. Use octetInputParser from @trpc/server/http for binary data. Route non-JSON requests with splitLink and isNonJsonSerializable() from @trpc/client, since batching links send them as `{}`. FormData and binary inputs are sent as POST, so they only work with mutations unless httpLink sets methodOverride to 'POST', and they skip the transformer. Keep Express or Next.js body parsers off tRPC routes.
4
4
  requires:
5
5
  - server-setup
6
6
  - links
@@ -10,7 +10,7 @@ sources:
10
10
  metadata:
11
11
  type: core
12
12
  library: trpc
13
- library_version: 11.23.0
13
+ library_version: 11.23.1-canary.14.507382d73
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. -->
@@ -206,8 +206,17 @@ await client.upload.mutate(file);
206
206
 
207
207
  ## Common mistakes
208
208
 
209
- - **Using a query.** FormData and binary inputs are sent as the body of a `POST` request, so they only work with mutations: `httpLink` throws `FormData is only supported for mutations` for a query.
210
- - **Sending them through a batching link.** `httpBatchLink`, `httpBatchStreamLink` and `wsLink` serialize inputs as JSON, which turns a `FormData` or `File` into `{}`, so input validation fails. Route them to `httpLink` with a [`splitLink`](https://trpc.io/docs/server/non-json-content-types#client-setup).
209
+ - **Using a query.** FormData and binary inputs are sent as the body of a `POST` request, so they only work with mutations: for a query, `httpLink` throws `FormData is only supported for mutations` or `Octet type input is only supported for mutations`. The exception is an `httpLink` with `methodOverride: 'POST'`, which sends every call as a `POST` and so also sends FormData and binary inputs for queries; the server must [allow the method override](https://trpc.io/docs/rpc#overriding-the-default-http-method).
210
+ - **Sending them through a batching link.** `httpBatchLink`, `httpBatchStreamLink` and `wsLink` (with its default encoder) serialize inputs as JSON, which turns a `FormData` or `File` into `{}`, so input validation fails. Route them to `httpLink` with a [`splitLink`](https://trpc.io/docs/server/non-json-content-types#client-setup). Only `httpLink` sends non-JSON inputs:
211
+
212
+ | Link | `application/json` | `FormData` | `File` / `Blob` / `Uint8Array` |
213
+ | --------------------------------------------------------------- | :----------------: | :---------: | :----------------------------: |
214
+ | [`httpLink`](https://trpc.io/docs/client/links/httpLink) | ✅ | ✅ (`POST`) | ✅ (`POST`) |
215
+ | [`httpBatchLink`](https://trpc.io/docs/client/links/httpBatchLink) | ✅ | ❌ | ❌ |
216
+ | [`httpBatchStreamLink`](https://trpc.io/docs/client/links/httpBatchStreamLink) | ✅ | ❌ | ❌ |
217
+ | [`wsLink`](https://trpc.io/docs/server/websockets) | ✅ | ❌ | ❌ |
218
+
219
+ With a binary `experimental_encoder` such as MessagePack, `wsLink` can carry `Uint8Array` values, as in the [WebSocket encoder example](https://github.com/trpc/trpc/tree/main/examples/next-websockets-encoder).
211
220
  - **Transforming the request.** tRPC passes FormData and binary inputs to your procedure as they are, without your `transformer`. If you use one, give the non-JSON `httpLink` a transformer that leaves the request alone, as [shown above](https://trpc.io/docs/server/non-json-content-types#client-setup).
212
221
  - **Letting your server parse the body first.** See [Server Setup](https://trpc.io/docs/server/non-json-content-types#server-setup).
213
222
 
@@ -11,7 +11,7 @@ sources:
11
11
  metadata:
12
12
  type: core
13
13
  library: trpc
14
- library_version: 11.23.0
14
+ library_version: 11.23.1-canary.14.507382d73
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.23.0
11
+ library_version: 11.23.1-canary.14.507382d73
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.23.0
13
+ library_version: 11.23.1-canary.14.507382d73
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. -->
@@ -12,7 +12,7 @@ sources:
12
12
  metadata:
13
13
  type: core
14
14
  library: trpc
15
- library_version: 11.23.0
15
+ library_version: 11.23.1-canary.14.507382d73
16
16
  ---
17
17
 
18
18
  <!-- Generated from www/v11/docs/server/subscriptions.md by www/build/skills.ts. Edit the docs instead. -->
@@ -7,7 +7,7 @@ sources:
7
7
  metadata:
8
8
  type: core
9
9
  library: trpc
10
- library_version: 11.23.0
10
+ library_version: 11.23.1-canary.14.507382d73
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.23.0
11
+ library_version: 11.23.1-canary.14.507382d73
12
12
  ---
13
13
 
14
14
  <!-- Generated from www/v11/docs/server/validators.md by www/build/skills.ts. Edit the docs instead. -->
@@ -145,8 +145,8 @@ export {
145
145
  } from '../../unstable-core-do-not-import';
146
146
 
147
147
  /**
148
- * @deprecated
149
- * Use `Awaited<ReturnType<typeof myFunction>>` instead
148
+ * The type a function's promise resolves to.
149
+ * @deprecated Use `Awaited<ReturnType<typeof myFunction>>` instead.
150
150
  */
151
151
  export type inferAsyncReturnType<TFunction extends (...args: any[]) => any> =
152
152
  Awaited<ReturnType<TFunction>>;
@@ -24,12 +24,24 @@ import { resolveResponse } from '../../@trpc/server/http';
24
24
  import type { inferAPIGWReturn, LambdaEvent } from './getPlanner';
25
25
  import { getPlanner } from './getPlanner';
26
26
 
27
+ /**
28
+ * What `createContext` gets in the AWS Lambda adapter: the event, the
29
+ * Lambda context and the request's `info`.
30
+ * @see https://trpc.io/docs/server/adapters/aws-lambda#2-create-a-trpc-router
31
+ */
27
32
  export type CreateAWSLambdaContextOptions<TEvent extends LambdaEvent> = {
33
+ /** The API Gateway or function URL event. */
28
34
  event: TEvent;
35
+ /** The Lambda invocation's context. */
29
36
  context: APIGWContext;
30
37
  info: TRPCRequestInfo;
31
38
  };
32
39
 
40
+ /**
41
+ * The options of `awsLambdaRequestHandler` and
42
+ * `awsLambdaStreamingRequestHandler`.
43
+ * @see https://trpc.io/docs/server/adapters/aws-lambda
44
+ */
33
45
  export type AWSLambdaOptions<
34
46
  TRouter extends AnyRouter,
35
47
  TEvent extends LambdaEvent,
@@ -39,6 +51,7 @@ export type AWSLambdaOptions<
39
51
  AWSLambdaCreateContextFn<TRouter, TEvent>
40
52
  >;
41
53
 
54
+ /** The `createContext` function the AWS Lambda adapter takes. */
42
55
  export type AWSLambdaCreateContextFn<
43
56
  TRouter extends AnyRouter,
44
57
  TEvent extends LambdaEvent,
@@ -50,6 +63,11 @@ export type AWSLambdaCreateContextFn<
50
63
  | inferRouterContext<TRouter>
51
64
  | Promise<inferRouterContext<TRouter>>;
52
65
 
66
+ /**
67
+ * Creates a Lambda handler for a router, for API Gateway (REST and HTTP
68
+ * APIs) and Lambda function URLs.
69
+ * @see https://trpc.io/docs/server/adapters/aws-lambda#3-use-the-amazon-api-gateway-adapter
70
+ */
53
71
  export function awsLambdaRequestHandler<
54
72
  TRouter extends AnyRouter,
55
73
  TEvent extends LambdaEvent,
@@ -83,6 +101,11 @@ export function awsLambdaRequestHandler<
83
101
  };
84
102
  }
85
103
 
104
+ /**
105
+ * Creates a Lambda handler that streams its response, for use with
106
+ * `awslambda.streamifyResponse()`.
107
+ * @see https://trpc.io/docs/server/adapters/aws-lambda#aws-lambda-response-streaming-adapter
108
+ */
86
109
  export function awsLambdaStreamingRequestHandler<
87
110
  TRouter extends AnyRouter,
88
111
  TEvent extends LambdaEvent,
@@ -17,11 +17,21 @@ import type {
17
17
  } from './node-http';
18
18
  import { internal_exceptionHandler, nodeHTTPRequestHandler } from './node-http';
19
19
 
20
+ /**
21
+ * What `createContext` gets in the Express adapter: `req`, `res` and the
22
+ * request's `info`.
23
+ * @see https://trpc.io/docs/server/adapters/express#2-create-a-trpc-router
24
+ */
20
25
  export type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<
21
26
  express.Request,
22
27
  express.Response
23
28
  >;
24
29
 
30
+ /**
31
+ * Creates an Express middleware that serves a router. Mount it on a path,
32
+ * such as `/trpc`.
33
+ * @see https://trpc.io/docs/server/adapters/express#3-use-the-express-adapter
34
+ */
25
35
  export function createExpressMiddleware<TRouter extends AnyRouter>(
26
36
  opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>,
27
37
  ): express.Handler {
@@ -23,6 +23,7 @@ import {
23
23
  type NodeHTTPCreateContextOption,
24
24
  } from '../node-http';
25
25
 
26
+ /** The options of the Fastify adapter's request handler. */
26
27
  export type FastifyHandlerOptions<
27
28
  TRouter extends AnyRouter,
28
29
  TRequest extends FastifyRequest,
@@ -40,6 +41,10 @@ type FastifyRequestHandlerOptions<
40
41
  path: string;
41
42
  };
42
43
 
44
+ /**
45
+ * Handles one Fastify request for a router. `fastifyTRPCPlugin` uses it;
46
+ * call it yourself to mount tRPC on your own route.
47
+ */
43
48
  export async function fastifyRequestHandler<
44
49
  TRouter extends AnyRouter,
45
50
  TRequest extends FastifyRequest,
@@ -18,11 +18,22 @@ import { getWSConnectionHandler, type WSSHandlerOptions } from '../ws';
18
18
  import type { FastifyHandlerOptions } from './fastifyRequestHandler';
19
19
  import { fastifyRequestHandler } from './fastifyRequestHandler';
20
20
 
21
+ /**
22
+ * The options of `fastifyTRPCPlugin`.
23
+ * @see https://trpc.io/docs/server/adapters/fastify#fastify-plugin-options
24
+ */
21
25
  export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
26
+ /** The path the router is served at, such as `/trpc`. */
22
27
  prefix?: string;
28
+ /**
29
+ * Whether to serve WebSockets too. Needs `@fastify/websocket` to be
30
+ * registered first.
31
+ * @see https://trpc.io/docs/server/adapters/fastify#enable-websockets
32
+ */
23
33
  useWSS?: boolean;
24
34
  /**
25
- * `keepAlive`, `dangerouslyDisablePong` and `experimental_encoder` are only used when `useWSS` is enabled
35
+ * The router and handler options. `keepAlive`, `dangerouslyDisablePong`
36
+ * and `experimental_encoder` only apply with `useWSS`.
26
37
  */
27
38
  trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply> &
28
39
  Pick<
@@ -31,11 +42,29 @@ export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
31
42
  >;
32
43
  }
33
44
 
45
+ /**
46
+ * What `createContext` gets in the Fastify adapter: `req`, `res` and the
47
+ * request's `info`. With `useWSS`, WebSocket connections get the raw
48
+ * `IncomingMessage` as `req` and the `WebSocket` as `res` instead.
49
+ * @see https://trpc.io/docs/server/adapters/fastify#create-the-context
50
+ */
34
51
  export type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<
35
52
  FastifyRequest,
36
53
  FastifyReply
37
54
  >;
38
55
 
56
+ /**
57
+ * A Fastify plugin that serves a router over HTTP, and over WebSockets
58
+ * with `useWSS`.
59
+ * @example
60
+ * ```ts
61
+ * server.register(fastifyTRPCPlugin, {
62
+ * prefix: '/trpc',
63
+ * trpcOptions: { router: appRouter, createContext },
64
+ * });
65
+ * ```
66
+ * @see https://trpc.io/docs/server/adapters/fastify#create-fastify-server
67
+ */
39
68
  export function fastifyTRPCPlugin<TRouter extends AnyRouter>(
40
69
  fastify: FastifyInstance,
41
70
  opts: FastifyTRPCPluginOptions<TRouter>,
@@ -21,6 +21,17 @@ const trimSlashes = (path: string): string => {
21
21
  return path;
22
22
  };
23
23
 
24
+ /**
25
+ * Handles a Fetch API `Request` for a router and returns its `Response`.
26
+ * Works in edge runtimes, Deno, Bun, Cloudflare Workers and Next.js route
27
+ * handlers.
28
+ * @example
29
+ * ```ts
30
+ * const handler = (req: Request) =>
31
+ * fetchRequestHandler({ endpoint: '/trpc', req, router: appRouter });
32
+ * ```
33
+ * @see https://trpc.io/docs/server/adapters/fetch
34
+ */
24
35
  export async function fetchRequestHandler<TRouter extends AnyRouter>(
25
36
  opts: FetchHandlerRequestOptions<TRouter>,
26
37
  ): Promise<Response> {
@@ -19,29 +19,42 @@ import type {
19
19
  TRPCRequestInfo,
20
20
  } from '../../@trpc/server/http';
21
21
 
22
+ /**
23
+ * What `createContext` gets in the Fetch adapter.
24
+ * @see https://trpc.io/docs/server/adapters/fetch#create-the-context
25
+ */
22
26
  export type FetchCreateContextFnOptions = {
23
27
  req: Request;
28
+ /** The response's headers, which you can add to, such as to set cookies. */
24
29
  resHeaders: Headers;
25
30
  info: TRPCRequestInfo;
26
31
  };
27
32
 
33
+ /** The `createContext` function the Fetch adapter takes. */
28
34
  export type FetchCreateContextFn<TRouter extends AnyRouter> = (
29
35
  opts: FetchCreateContextFnOptions,
30
36
  ) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
31
37
 
38
+ /** The Fetch adapter's `createContext` option. */
32
39
  export type FetchCreateContextOption<TRouter extends AnyRouter> =
33
40
  CreateContextCallback<
34
41
  inferRouterContext<TRouter>,
35
42
  FetchCreateContextFn<TRouter>
36
43
  >;
37
44
 
45
+ /** The options of the Fetch adapter. */
38
46
  export type FetchHandlerOptions<TRouter extends AnyRouter> =
39
47
  FetchCreateContextOption<TRouter> &
40
48
  HTTPBaseHandlerOptions<TRouter, Request> & {
41
49
  req: Request;
50
+ /** The path the router is served at, such as `/trpc`. */
42
51
  endpoint: string;
43
52
  };
44
53
 
54
+ /**
55
+ * The options of `fetchRequestHandler`.
56
+ * @see https://trpc.io/docs/server/adapters/fetch
57
+ */
45
58
  export type FetchHandlerRequestOptions<TRouter extends AnyRouter> =
46
59
  HTTPBaseHandlerOptions<TRouter, Request> &
47
60
  CreateContextCallback<
@@ -49,5 +62,6 @@ export type FetchHandlerRequestOptions<TRouter extends AnyRouter> =
49
62
  FetchCreateContextFn<TRouter>
50
63
  > & {
51
64
  req: Request;
65
+ /** The path the router is served at, such as `/trpc`. */
52
66
  endpoint: string;
53
67
  };
@@ -18,22 +18,26 @@ import { TRPCRedirectError } from './redirect';
18
18
  import { rethrowNextErrors } from './rethrowNextErrors';
19
19
 
20
20
  /**
21
- * Create a caller that works with Next.js React Server Components & Server Actions
21
+ * Makes procedures callable as Next.js server actions and from React
22
+ * Server Components. Pass it to `.experimental_caller()`.
23
+ * @see https://trpc.io/docs/client/nextjs/server-actions#1-define-a-base-procedure-with-experimental_caller
22
24
  */
23
25
  export function nextAppDirCaller<TContext, TMeta>(
24
26
  config: Simplify<
25
27
  {
26
28
  /**
27
- * Extract the path from the procedure metadata
29
+ * Names the procedure from its metadata, for logs and errors, since
30
+ * server actions have no router path.
31
+ * @see https://trpc.io/docs/client/nextjs/server-actions#adding-observability-with-metadata
28
32
  */
29
33
  pathExtractor?: (opts: { meta: TMeta }) => string;
30
34
  /**
31
- * Transform form data to a `Record` before passing it to the procedure
35
+ * Turns `FormData` input into an object before validation.
32
36
  * @default true
33
37
  */
34
38
  normalizeFormData?: boolean;
35
39
  /**
36
- * Called when an error occurs in the handler
40
+ * Called when a procedure throws.
37
41
  */
38
42
  onError?: (opts: ErrorHandlerOptions<TContext>) => void;
39
43
  } & CreateContextCallback<TContext, () => MaybePromise<TContext>>
@@ -2,7 +2,9 @@ import type { notFound as __notFound } from 'next/navigation.js';
2
2
  import { TRPCError } from '../../@trpc/server';
3
3
 
4
4
  /**
5
- * Like `next/navigation`'s `notFound()` but throws a `TRPCError` that later will be handled by Next.js
5
+ * Like `notFound()` from `next/navigation`, but throws a `NOT_FOUND`
6
+ * `TRPCError`, which `nextAppDirCaller` turns into Next.js's not-found
7
+ * page.
6
8
  * @public
7
9
  */
8
10
  export const notFound: typeof __notFound = () => {
@@ -2,6 +2,8 @@ import type { RedirectType } from 'next/navigation.js';
2
2
  import { TRPCError } from '../../@trpc/server';
3
3
 
4
4
  /**
5
+ * The error `redirect()` returns, which `nextAppDirCaller` turns into a
6
+ * Next.js redirect.
5
7
  * @internal
6
8
  */
7
9
  export class TRPCRedirectError extends TRPCError {
@@ -18,11 +20,11 @@ export class TRPCRedirectError extends TRPCError {
18
20
  }
19
21
 
20
22
  /**
21
- * Like `next/navigation`'s `redirect()` but throws a `TRPCError` that later will be handled by Next.js
22
- * This provides better typesafety than the `next/navigation`'s `redirect()` since the action continues
23
- * to execute on the frontend even if Next's `redirect()` has a return type of `never`.
23
+ * Like `redirect()` from `next/navigation`, for procedures called through
24
+ * `nextAppDirCaller`. Return it from a resolver; the caller then
25
+ * redirects. Its type is `undefined`, which matches what the client gets,
26
+ * unlike Next.js's `never`.
24
27
  * @public
25
- * @remark You should only use this if you're also using `nextAppDirCaller`.
26
28
  */
27
29
  export const redirect = (url: URL | string, redirectType?: RedirectType) => {
28
30
  // We rethrow this internally so the returntype on the client is undefined.
@@ -41,7 +41,11 @@ function isNotFoundError(error: unknown) {
41
41
  }
42
42
 
43
43
  /**
44
- * Rethrow errors that should be handled by Next.js
44
+ * Turns a caught `TRPCError` into the Next.js control-flow error it stands
45
+ * for: a `NOT_FOUND` code calls `notFound()`, a `TRPCRedirectError` calls
46
+ * `redirect()`, and a `notFound()` or `redirect()` error in `cause` is
47
+ * rethrown. It only takes a `TRPCError`; rethrow Next.js's own errors, such
48
+ * as those `nextAppDirCaller` throws, yourself.
45
49
  */
46
50
  export const rethrowNextErrors = (error: TRPCError) => {
47
51
  if (error.code === 'NOT_FOUND') {
@@ -20,16 +20,28 @@ import type {
20
20
  } from './node-http';
21
21
  import { internal_exceptionHandler, nodeHTTPRequestHandler } from './node-http';
22
22
 
23
+ /**
24
+ * What `createContext` gets in the Next.js API route adapter: `req`, `res`
25
+ * and the request's `info`.
26
+ * @see https://trpc.io/docs/server/adapters/nextjs
27
+ */
23
28
  export type CreateNextContextOptions = NodeHTTPCreateContextFnOptions<
24
29
  NextApiRequest,
25
30
  NextApiResponse
26
31
  >;
27
32
 
28
33
  /**
29
- * Preventing "TypeScript where it's tough not to get "The inferred type of 'xxxx' cannot be named without a reference to [...]"
34
+ * Re-exported so declaration emit can name these types without importing
35
+ * `next` ("The inferred type of 'x' cannot be named").
30
36
  */
31
37
  export type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
32
38
 
39
+ /**
40
+ * Creates a Next.js API route handler for a router, for the Pages Router.
41
+ * The file must be named `[trpc].ts`. For the App Router, use
42
+ * `fetchRequestHandler`.
43
+ * @see https://trpc.io/docs/server/adapters/nextjs#nextjs-example
44
+ */
33
45
  export function createNextApiHandler<TRouter extends AnyRouter>(
34
46
  opts: NodeHTTPHandlerOptions<TRouter, NextApiRequest, NextApiResponse>,
35
47
  ): NextApiHandler {
@@ -91,6 +91,10 @@ function createBody(
91
91
  },
92
92
  });
93
93
  }
94
+ /**
95
+ * The full URL of a Node.js request, from its `Host` header and socket.
96
+ * Throws a `BAD_REQUEST` error if it isn't a valid URL.
97
+ */
94
98
  export function createURL(req: NodeHTTPRequest): URL {
95
99
  try {
96
100
  const protocol =
@@ -137,7 +141,8 @@ function createHeaders(incoming: http.IncomingHttpHeaders): Headers {
137
141
  }
138
142
 
139
143
  /**
140
- * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
144
+ * Turns a Node.js `IncomingMessage` into a Fetch API `Request`. The
145
+ * request's signal aborts when the client disconnects.
141
146
  */
142
147
  export function incomingMessageToRequest(
143
148
  req: NodeHTTPRequest,
@@ -28,6 +28,7 @@ import type {
28
28
  import { writeResponse } from './writeResponse';
29
29
 
30
30
  /**
31
+ * Answers with an error response when handling a request throws.
31
32
  * @internal
32
33
  */
33
34
  export function internal_exceptionHandler<
@@ -67,7 +68,8 @@ export function internal_exceptionHandler<
67
68
  }
68
69
 
69
70
  /**
70
- * @remark the promise never rejects
71
+ * Handles a Node.js request for a router. The adapters for Express,
72
+ * Next.js and the standalone server use it. The promise never rejects.
71
73
  */
72
74
  export async function nodeHTTPRequestHandler<
73
75
  TRouter extends AnyRouter,