@trpc/server 11.0.0-rc.677 → 11.0.0-rc.682

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.
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAGL,KAAK,2BAA2B,EACjC,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC3C,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE5D,KAAK,4BAA4B,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACxD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,EAC9B,IAAI,EAAE,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAkCjE"}
1
+ {"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,KAAK,2BAA2B,EAEjC,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC3C,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE5D,KAAK,4BAA4B,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACxD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,EAC9B,IAAI,EAAE,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAkCjE"}
@@ -1,15 +1,20 @@
1
1
  import type * as http from 'http';
2
- export interface IncomingMessageWithBody extends http.IncomingMessage {
2
+ export interface UniversalIncomingMessage extends Omit<http.IncomingMessage, 'socket'> {
3
3
  /**
4
4
  * Many adapters will add a `body` property to the incoming message and pre-parse the body
5
5
  */
6
6
  body?: unknown;
7
+ /**
8
+ * Socket is not always available in all deployments, so we need to make it optional
9
+ * @see https://github.com/trpc/trpc/issues/6341
10
+ */
11
+ socket?: http.IncomingMessage['socket'];
7
12
  }
8
- export declare function createURL(req: http.IncomingMessage): URL;
13
+ export declare function createURL(req: UniversalIncomingMessage): URL;
9
14
  /**
10
15
  * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
11
16
  */
12
- export declare function incomingMessageToRequest(req: http.IncomingMessage, res: http.ServerResponse, opts: {
17
+ export declare function incomingMessageToRequest(req: UniversalIncomingMessage, res: http.ServerResponse, opts: {
13
18
  /**
14
19
  * Max body size in bytes. If the body is larger than this, the request will be aborted
15
20
  */
@@ -1 +1 @@
1
- {"version":3,"file":"incomingMessageToRequest.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/incomingMessageToRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CAAC,eAAe;IACnE;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAiED,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,GAAG,GAAG,CAkBxD;AAwBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,IAAI,EAAE;IACJ;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GACA,OAAO,CAqCT"}
1
+ {"version":3,"file":"incomingMessageToRequest.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/incomingMessageToRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,MAAM,WAAW,wBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC;IAC5C;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;CACzC;AAiED,wBAAgB,SAAS,CAAC,GAAG,EAAE,wBAAwB,GAAG,GAAG,CAkB5D;AAwBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,wBAAwB,EAC7B,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,IAAI,EAAE;IACJ;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GACA,OAAO,CAqCT"}
@@ -8,14 +8,16 @@ require('../../unstable-core-do-not-import/rootConfig.js');
8
8
  function createBody(req, opts) {
9
9
  // Some adapters will pre-parse the body and add it to the request object
10
10
  if ('body' in req) {
11
+ if (req.body === undefined) {
12
+ // If body property exists but is undefined, return undefined
13
+ return undefined;
14
+ }
11
15
  // If the body is already a string, return it directly
12
16
  if (typeof req.body === 'string') {
13
17
  return req.body;
14
- } else if (req.body !== undefined) {
15
- return JSON.stringify(req.body);
16
18
  }
17
- // If body property exists but is undefined, return undefined
18
- return undefined;
19
+ // If body exists but isn't a string, stringify it as JSON
20
+ return JSON.stringify(req.body);
19
21
  }
20
22
  let size = 0;
21
23
  let hasClosed = false;
@@ -88,12 +90,12 @@ function createHeaders(incoming) {
88
90
  const ac = new AbortController();
89
91
  const onAbort = ()=>{
90
92
  res.off('close', onAbort);
91
- req.socket.off('end', onAbort);
93
+ req.socket?.off('end', onAbort);
92
94
  // abort the request
93
95
  ac.abort();
94
96
  };
95
97
  res.once('close', onAbort);
96
- req.socket.once('end', onAbort);
98
+ req.socket?.once('end', onAbort);
97
99
  // Get host from either regular header or HTTP/2 pseudo-header
98
100
  const url = createURL(req);
99
101
  const init = {
@@ -6,14 +6,16 @@ import '../../unstable-core-do-not-import/rootConfig.mjs';
6
6
  function createBody(req, opts) {
7
7
  // Some adapters will pre-parse the body and add it to the request object
8
8
  if ('body' in req) {
9
+ if (req.body === undefined) {
10
+ // If body property exists but is undefined, return undefined
11
+ return undefined;
12
+ }
9
13
  // If the body is already a string, return it directly
10
14
  if (typeof req.body === 'string') {
11
15
  return req.body;
12
- } else if (req.body !== undefined) {
13
- return JSON.stringify(req.body);
14
16
  }
15
- // If body property exists but is undefined, return undefined
16
- return undefined;
17
+ // If body exists but isn't a string, stringify it as JSON
18
+ return JSON.stringify(req.body);
17
19
  }
18
20
  let size = 0;
19
21
  let hasClosed = false;
@@ -86,12 +88,12 @@ function createHeaders(incoming) {
86
88
  const ac = new AbortController();
87
89
  const onAbort = ()=>{
88
90
  res.off('close', onAbort);
89
- req.socket.off('end', onAbort);
91
+ req.socket?.off('end', onAbort);
90
92
  // abort the request
91
93
  ac.abort();
92
94
  };
93
95
  res.once('close', onAbort);
94
- req.socket.once('end', onAbort);
96
+ req.socket?.once('end', onAbort);
95
97
  // Get host from either regular header or HTTP/2 pseudo-header
96
98
  const url = createURL(req);
97
99
  const init = {
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 186969,
3
- "bundleOrigSize": 219149,
4
- "bundleReduction": 14.68,
2
+ "bundleSize": 187210,
3
+ "bundleOrigSize": 219494,
4
+ "bundleReduction": 14.71,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/unstable-core-do-not-import/stream/jsonl.ts",
@@ -17,7 +17,7 @@
17
17
  "/src/unstable-core-do-not-import.ts",
18
18
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
19
19
  ],
20
- "percent": 11.72,
20
+ "percent": 11.71,
21
21
  "reduction": 0
22
22
  },
23
23
  {
@@ -31,7 +31,7 @@
31
31
  "dependents": [
32
32
  "/src/unstable-core-do-not-import.ts"
33
33
  ],
34
- "percent": 11.3,
34
+ "percent": 11.29,
35
35
  "reduction": 0
36
36
  },
37
37
  {
@@ -47,13 +47,13 @@
47
47
  "dependents": [
48
48
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
49
49
  ],
50
- "percent": 10.77,
50
+ "percent": 10.75,
51
51
  "reduction": 0
52
52
  },
53
53
  {
54
54
  "id": "/src/unstable-core-do-not-import/stream/sse.ts",
55
- "size": 12425,
56
- "origSize": 12246,
55
+ "size": 12590,
56
+ "origSize": 12368,
57
57
  "renderedExports": [
58
58
  "sseStreamProducer",
59
59
  "sseStreamConsumer",
@@ -64,7 +64,7 @@
64
64
  "/src/unstable-core-do-not-import.ts",
65
65
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
66
66
  ],
67
- "percent": 6.65,
67
+ "percent": 6.73,
68
68
  "reduction": 0
69
69
  },
70
70
  {
@@ -77,7 +77,7 @@
77
77
  ],
78
78
  "removedExports": [],
79
79
  "dependents": [],
80
- "percent": 6.5,
80
+ "percent": 6.49,
81
81
  "reduction": 11.62
82
82
  },
83
83
  {
@@ -129,7 +129,7 @@
129
129
  "/src/unstable-core-do-not-import/stream/sse.ts",
130
130
  "/src/unstable-core-do-not-import/stream/utils/withPing.ts"
131
131
  ],
132
- "percent": 3.12,
132
+ "percent": 3.11,
133
133
  "reduction": 0
134
134
  },
135
135
  {
@@ -144,7 +144,7 @@
144
144
  "/src/unstable-core-do-not-import.ts",
145
145
  "/src/unstable-core-do-not-import/initTRPC.ts"
146
146
  ],
147
- "percent": 3.1,
147
+ "percent": 3.09,
148
148
  "reduction": 65.01
149
149
  },
150
150
  {
@@ -158,7 +158,7 @@
158
158
  "dependents": [
159
159
  "/src/adapters/aws-lambda/index.ts"
160
160
  ],
161
- "percent": 2.9,
161
+ "percent": 2.89,
162
162
  "reduction": 11.51
163
163
  },
164
164
  {
@@ -178,7 +178,7 @@
178
178
  "/src/observable/operators.ts",
179
179
  "/src/observable/behaviorSubject.ts"
180
180
  ],
181
- "percent": 2.59,
181
+ "percent": 2.58,
182
182
  "reduction": 0
183
183
  },
184
184
  {
@@ -193,9 +193,25 @@
193
193
  "dependents": [
194
194
  "/src/unstable-core-do-not-import/stream/sse.ts"
195
195
  ],
196
- "percent": 2.38,
196
+ "percent": 2.37,
197
197
  "reduction": 0
198
198
  },
199
+ {
200
+ "id": "/src/adapters/node-http/incomingMessageToRequest.ts",
201
+ "size": 3914,
202
+ "origSize": 4578,
203
+ "renderedExports": [
204
+ "createURL",
205
+ "incomingMessageToRequest"
206
+ ],
207
+ "removedExports": [],
208
+ "dependents": [
209
+ "/src/adapters/node-http/index.ts",
210
+ "/src/adapters/node-http/nodeHTTPRequestHandler.ts"
211
+ ],
212
+ "percent": 2.09,
213
+ "reduction": 14.5
214
+ },
199
215
  {
200
216
  "id": "/src/observable/operators.ts",
201
217
  "size": 3910,
@@ -214,22 +230,6 @@
214
230
  "percent": 2.09,
215
231
  "reduction": 1.66
216
232
  },
217
- {
218
- "id": "/src/adapters/node-http/incomingMessageToRequest.ts",
219
- "size": 3838,
220
- "origSize": 4355,
221
- "renderedExports": [
222
- "createURL",
223
- "incomingMessageToRequest"
224
- ],
225
- "removedExports": [],
226
- "dependents": [
227
- "/src/adapters/node-http/index.ts",
228
- "/src/adapters/node-http/nodeHTTPRequestHandler.ts"
229
- ],
230
- "percent": 2.05,
231
- "reduction": 11.87
232
- },
233
233
  {
234
234
  "id": "/src/adapters/next-app-dir/nextAppDirCaller.ts",
235
235
  "size": 3244,
@@ -241,7 +241,7 @@
241
241
  "dependents": [
242
242
  "/src/adapters/next-app-dir.ts"
243
243
  ],
244
- "percent": 1.74,
244
+ "percent": 1.73,
245
245
  "reduction": 22.52
246
246
  },
247
247
  {
@@ -256,7 +256,7 @@
256
256
  "dependents": [
257
257
  "/src/adapters/node-http/index.ts"
258
258
  ],
259
- "percent": 1.47,
259
+ "percent": 1.46,
260
260
  "reduction": 16.3
261
261
  },
262
262
  {
@@ -272,9 +272,9 @@
272
272
  "removedExports": [],
273
273
  "dependents": [
274
274
  "/src/unstable-core-do-not-import.ts",
275
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts",
275
276
  "/src/unstable-core-do-not-import/initTRPC.ts",
276
- "/src/unstable-core-do-not-import/router.ts",
277
- "/src/unstable-core-do-not-import/http/resolveResponse.ts"
277
+ "/src/unstable-core-do-not-import/router.ts"
278
278
  ],
279
279
  "percent": 1.46,
280
280
  "reduction": 45.98
@@ -334,13 +334,13 @@
334
334
  "removedExports": [],
335
335
  "dependents": [
336
336
  "/src/unstable-core-do-not-import.ts",
337
+ "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
338
+ "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
339
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts",
337
340
  "/src/unstable-core-do-not-import/error/TRPCError.ts",
338
341
  "/src/unstable-core-do-not-import/transformer.ts",
339
342
  "/src/unstable-core-do-not-import/middleware.ts",
340
343
  "/src/unstable-core-do-not-import/router.ts",
341
- "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
342
- "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
343
- "/src/unstable-core-do-not-import/http/resolveResponse.ts",
344
344
  "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
345
345
  "/src/unstable-core-do-not-import/http/contentType.ts",
346
346
  "/src/unstable-core-do-not-import/http/isAbortError.ts",
@@ -348,7 +348,7 @@
348
348
  "/src/unstable-core-do-not-import/stream/jsonl.ts",
349
349
  "/src/unstable-core-do-not-import/stream/sse.ts"
350
350
  ],
351
- "percent": 1.32,
351
+ "percent": 1.31,
352
352
  "reduction": 17.51
353
353
  },
354
354
  {
@@ -363,10 +363,10 @@
363
363
  "removedExports": [],
364
364
  "dependents": [
365
365
  "/src/unstable-core-do-not-import.ts",
366
- "/src/unstable-core-do-not-import/middleware.ts",
367
- "/src/unstable-core-do-not-import/router.ts",
368
366
  "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
369
367
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
368
+ "/src/unstable-core-do-not-import/middleware.ts",
369
+ "/src/unstable-core-do-not-import/router.ts",
370
370
  "/src/unstable-core-do-not-import/http/contentType.ts",
371
371
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
372
372
  "/src/unstable-core-do-not-import/stream/sse.ts"
@@ -433,10 +433,10 @@
433
433
  "removedExports": [],
434
434
  "dependents": [
435
435
  "/src/unstable-core-do-not-import.ts",
436
- "/src/unstable-core-do-not-import/error/getErrorShape.ts",
437
- "/src/unstable-core-do-not-import/http/resolveResponse.ts"
436
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts",
437
+ "/src/unstable-core-do-not-import/error/getErrorShape.ts"
438
438
  ],
439
- "percent": 1.12,
439
+ "percent": 1.11,
440
440
  "reduction": 18.54
441
441
  },
442
442
  {
@@ -820,16 +820,6 @@
820
820
  "percent": 0.03,
821
821
  "reduction": 93.9
822
822
  },
823
- {
824
- "id": "/src/index.ts",
825
- "size": 0,
826
- "origSize": 32,
827
- "renderedExports": [],
828
- "removedExports": [],
829
- "dependents": [],
830
- "percent": 0,
831
- "reduction": 100
832
- },
833
823
  {
834
824
  "id": "/src/http.ts",
835
825
  "size": 0,
@@ -843,9 +833,9 @@
843
833
  "reduction": 100
844
834
  },
845
835
  {
846
- "id": "/src/rpc.ts",
836
+ "id": "/src/index.ts",
847
837
  "size": 0,
848
- "origSize": 36,
838
+ "origSize": 32,
849
839
  "renderedExports": [],
850
840
  "removedExports": [],
851
841
  "dependents": [],
@@ -862,6 +852,16 @@
862
852
  "percent": 0,
863
853
  "reduction": 100
864
854
  },
855
+ {
856
+ "id": "/src/rpc.ts",
857
+ "size": 0,
858
+ "origSize": 36,
859
+ "renderedExports": [],
860
+ "removedExports": [],
861
+ "dependents": [],
862
+ "percent": 0,
863
+ "reduction": 100
864
+ },
865
865
  {
866
866
  "id": "/src/unstable-core-do-not-import.ts",
867
867
  "size": 0,
@@ -869,9 +869,9 @@
869
869
  "renderedExports": [],
870
870
  "removedExports": [],
871
871
  "dependents": [
872
- "/src/adapters/next.ts",
873
872
  "/src/adapters/express.ts",
874
873
  "/src/adapters/standalone.ts",
874
+ "/src/adapters/next.ts",
875
875
  "/src/adapters/ws.ts",
876
876
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts",
877
877
  "/src/adapters/next-app-dir/nextAppDirCaller.ts",
@@ -903,9 +903,9 @@
903
903
  "reduction": 100
904
904
  },
905
905
  {
906
- "id": "/src/adapters/fetch/index.ts",
906
+ "id": "/src/adapters/fastify/index.ts",
907
907
  "size": 0,
908
- "origSize": 64,
908
+ "origSize": 78,
909
909
  "renderedExports": [],
910
910
  "removedExports": [],
911
911
  "dependents": [],
@@ -913,9 +913,9 @@
913
913
  "reduction": 100
914
914
  },
915
915
  {
916
- "id": "/src/adapters/fastify/index.ts",
916
+ "id": "/src/adapters/fetch/index.ts",
917
917
  "size": 0,
918
- "origSize": 78,
918
+ "origSize": 64,
919
919
  "renderedExports": [],
920
920
  "removedExports": [],
921
921
  "dependents": [],
@@ -929,9 +929,9 @@
929
929
  "renderedExports": [],
930
930
  "removedExports": [],
931
931
  "dependents": [
932
- "/src/adapters/next.ts",
933
932
  "/src/adapters/express.ts",
934
933
  "/src/adapters/standalone.ts",
934
+ "/src/adapters/next.ts",
935
935
  "/src/adapters/ws.ts",
936
936
  "/src/adapters/fastify/fastifyRequestHandler.ts"
937
937
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/sse.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAWpD,KAAK,SAAS,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AACrC,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAA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EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED,KAAK,oBAAoB,CAAC,OAAO,SAAS,cAAc,IACpD,wBAAwB,CAAC,OAAO,CAAC,GACjC,yBAAyB,CAAC,OAAO,CAAC,GAClC,8BAA8B,CAAC,OAAO,CAAC,GACvC,2BAA2B,CAAC,OAAO,CAAC,GACpC,wBAAwB,CAAC,OAAO,CAAC,GACjC,6BAA6B,CAAC,OAAO,CAAC,CAAC;AAE3C,MAAM,WAAW,wBAAwB,CAAC,OAAO,SAAS,cAAc;IACtE,GAAG,EAAE,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MACF,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,GAChE,SAAS,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,eAAe,CAAC,cAAc,CAAC;CAC7C;AAgBD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,cAAc,EAC9D,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,aAAa,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAiK9C;AAED,eAAO,MAAM,UAAU;;;;;CAKb,CAAC"}
@@ -270,8 +270,12 @@ async function withTimeout(opts) {
270
270
  });
271
271
  });
272
272
  const onAbort = ()=>{
273
- controller.close();
274
- eventSource.close();
273
+ try {
274
+ eventSource.close();
275
+ controller.close();
276
+ } catch {
277
+ // ignore errors in case the controller is already closed
278
+ }
275
279
  };
276
280
  if (signal.aborted) {
277
281
  onAbort();
@@ -268,8 +268,12 @@ async function withTimeout(opts) {
268
268
  });
269
269
  });
270
270
  const onAbort = ()=>{
271
- controller.close();
272
- eventSource.close();
271
+ try {
272
+ eventSource.close();
273
+ controller.close();
274
+ } catch {
275
+ // ignore errors in case the controller is already closed
276
+ }
273
277
  };
274
278
  if (signal.aborted) {
275
279
  onAbort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.677+1032f4880",
3
+ "version": "11.0.0-rc.682+8650a22e8",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -152,5 +152,5 @@
152
152
  "peerDependencies": {
153
153
  "typescript": ">=5.7.2"
154
154
  },
155
- "gitHead": "1032f48805c74e814cad8aba2ba9811e914b7b85"
155
+ "gitHead": "8650a22e8631ae04091209daf09830563d8dcac1"
156
156
  }
@@ -19,8 +19,8 @@ import {
19
19
  // @trpc/server/node-http
20
20
  import {
21
21
  incomingMessageToRequest,
22
- type IncomingMessageWithBody,
23
22
  type NodeHTTPCreateContextOption,
23
+ type UniversalIncomingMessage,
24
24
  } from '../node-http';
25
25
 
26
26
  export type FastifyHandlerOptions<
@@ -54,7 +54,7 @@ export async function fastifyRequestHandler<
54
54
  });
55
55
  };
56
56
 
57
- const incomingMessage = opts.req.raw as IncomingMessageWithBody;
57
+ const incomingMessage: UniversalIncomingMessage = opts.req.raw;
58
58
 
59
59
  // monkey-path body to the IncomingMessage
60
60
  if ('body' in opts.req) {
@@ -1,15 +1,21 @@
1
1
  import type * as http from 'http';
2
2
  import { TRPCError } from '../../@trpc/server';
3
3
 
4
- export interface IncomingMessageWithBody extends http.IncomingMessage {
4
+ export interface UniversalIncomingMessage
5
+ extends Omit<http.IncomingMessage, 'socket'> {
5
6
  /**
6
7
  * Many adapters will add a `body` property to the incoming message and pre-parse the body
7
8
  */
8
9
  body?: unknown;
10
+ /**
11
+ * Socket is not always available in all deployments, so we need to make it optional
12
+ * @see https://github.com/trpc/trpc/issues/6341
13
+ */
14
+ socket?: http.IncomingMessage['socket'];
9
15
  }
10
16
 
11
17
  function createBody(
12
- req: http.IncomingMessage,
18
+ req: UniversalIncomingMessage,
13
19
  opts: {
14
20
  /**
15
21
  * Max body size in bytes. If the body is larger than this, the request will be aborted
@@ -19,16 +25,16 @@ function createBody(
19
25
  ): RequestInit['body'] {
20
26
  // Some adapters will pre-parse the body and add it to the request object
21
27
  if ('body' in req) {
28
+ if (req.body === undefined) {
29
+ // If body property exists but is undefined, return undefined
30
+ return undefined;
31
+ }
22
32
  // If the body is already a string, return it directly
23
33
  if (typeof req.body === 'string') {
24
34
  return req.body;
25
35
  }
26
36
  // If body exists but isn't a string, stringify it as JSON
27
- else if (req.body !== undefined) {
28
- return JSON.stringify(req.body);
29
- }
30
- // If body property exists but is undefined, return undefined
31
- return undefined;
37
+ return JSON.stringify(req.body);
32
38
  }
33
39
  let size = 0;
34
40
  let hasClosed = false;
@@ -71,7 +77,7 @@ function createBody(
71
77
  },
72
78
  });
73
79
  }
74
- export function createURL(req: http.IncomingMessage): URL {
80
+ export function createURL(req: UniversalIncomingMessage): URL {
75
81
  try {
76
82
  const protocol =
77
83
  req.socket && 'encrypted' in req.socket && req.socket.encrypted
@@ -117,7 +123,7 @@ function createHeaders(incoming: http.IncomingHttpHeaders): Headers {
117
123
  * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
118
124
  */
119
125
  export function incomingMessageToRequest(
120
- req: http.IncomingMessage,
126
+ req: UniversalIncomingMessage,
121
127
  res: http.ServerResponse,
122
128
  opts: {
123
129
  /**
@@ -130,14 +136,14 @@ export function incomingMessageToRequest(
130
136
 
131
137
  const onAbort = () => {
132
138
  res.off('close', onAbort);
133
- req.socket.off('end', onAbort);
139
+ req.socket?.off('end', onAbort);
134
140
 
135
141
  // abort the request
136
142
  ac.abort();
137
143
  };
138
144
 
139
145
  res.once('close', onAbort);
140
- req.socket.once('end', onAbort);
146
+ req.socket?.once('end', onAbort);
141
147
 
142
148
  // Get host from either regular header or HTTP/2 pseudo-header
143
149
  const url = createURL(req);
@@ -361,8 +361,12 @@ export function sseStreamConsumer<TConfig extends ConsumerConfig>(
361
361
  });
362
362
 
363
363
  const onAbort = () => {
364
- controller.close();
365
- eventSource.close();
364
+ try {
365
+ eventSource.close();
366
+ controller.close();
367
+ } catch {
368
+ // ignore errors in case the controller is already closed
369
+ }
366
370
  };
367
371
  if (signal.aborted) {
368
372
  onAbort();