@trpc/server 11.0.0-rc.364 → 11.0.0-rc.369

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":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI7E,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAUjB,wBAAsB,sBAAsB,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBA8ClE"}
1
+ {"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI7E,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,wBAAsB,sBAAsB,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBA4ClE"}
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var node_stream = require('node:stream');
3
4
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
4
5
  var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
5
6
  require('../../unstable-core-do-not-import/rootConfig.js');
@@ -14,11 +15,6 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
14
15
  * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
15
16
  * ```
16
17
  */ // @trpc/server
17
- function assertAsyncIterable(value) {
18
- if (!(Symbol.asyncIterator in value)) {
19
- throw new Error('Expected AsyncIterable - are you using Node >= 18.0.0?');
20
- }
21
- }
22
18
  async function nodeHTTPRequestHandler(opts) {
23
19
  const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
24
20
  return handleViaMiddleware(opts.req, opts.res, async (err)=>{
@@ -52,12 +48,10 @@ async function nodeHTTPRequestHandler(opts) {
52
48
  opts.res.setHeader(key, value);
53
49
  }
54
50
  if (response.body) {
55
- assertAsyncIterable(response.body);
56
- for await (const chunk of response.body){
57
- opts.res.write(chunk);
58
- }
51
+ node_stream.Readable.fromWeb(response.body).pipe(opts.res);
52
+ } else {
53
+ opts.res.end();
59
54
  }
60
- opts.res.end();
61
55
  });
62
56
  }
63
57
 
@@ -1,3 +1,4 @@
1
+ import { Readable } from 'node:stream';
1
2
  import { getTRPCErrorFromUnknown } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
2
3
  import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
3
4
  import '../../unstable-core-do-not-import/rootConfig.mjs';
@@ -12,11 +13,6 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
12
13
  * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
13
14
  * ```
14
15
  */ // @trpc/server
15
- function assertAsyncIterable(value) {
16
- if (!(Symbol.asyncIterator in value)) {
17
- throw new Error('Expected AsyncIterable - are you using Node >= 18.0.0?');
18
- }
19
- }
20
16
  async function nodeHTTPRequestHandler(opts) {
21
17
  const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
22
18
  return handleViaMiddleware(opts.req, opts.res, async (err)=>{
@@ -50,12 +46,10 @@ async function nodeHTTPRequestHandler(opts) {
50
46
  opts.res.setHeader(key, value);
51
47
  }
52
48
  if (response.body) {
53
- assertAsyncIterable(response.body);
54
- for await (const chunk of response.body){
55
- opts.res.write(chunk);
56
- }
49
+ Readable.fromWeb(response.body).pipe(opts.res);
50
+ } else {
51
+ opts.res.end();
57
52
  }
58
- opts.res.end();
59
53
  });
60
54
  }
61
55
 
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 86140,
3
- "bundleOrigSize": 132897,
4
- "bundleReduction": 35.18,
2
+ "bundleSize": 85905,
3
+ "bundleOrigSize": 132659,
4
+ "bundleReduction": 35.24,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/adapters/ws.ts",
@@ -15,7 +15,7 @@
15
15
  "dependents": [
16
16
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
17
17
  ],
18
- "percent": 11.81,
18
+ "percent": 11.84,
19
19
  "reduction": 0
20
20
  },
21
21
  {
@@ -29,7 +29,7 @@
29
29
  "dependents": [
30
30
  "/src/unstable-core-do-not-import.ts"
31
31
  ],
32
- "percent": 11.02,
32
+ "percent": 11.05,
33
33
  "reduction": 4.97
34
34
  },
35
35
  {
@@ -44,7 +44,7 @@
44
44
  "/src/unstable-core-do-not-import.ts",
45
45
  "/src/unstable-core-do-not-import/initTRPC.ts"
46
46
  ],
47
- "percent": 7.34,
47
+ "percent": 7.36,
48
48
  "reduction": 59.52
49
49
  },
50
50
  {
@@ -63,7 +63,7 @@
63
63
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
64
64
  "/src/unstable-core-do-not-import/initTRPC.ts"
65
65
  ],
66
- "percent": 6.95,
66
+ "percent": 6.97,
67
67
  "reduction": 41.05
68
68
  },
69
69
  {
@@ -78,7 +78,7 @@
78
78
  "/src/unstable-core-do-not-import.ts",
79
79
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
80
80
  ],
81
- "percent": 6.44,
81
+ "percent": 6.46,
82
82
  "reduction": 0
83
83
  },
84
84
  {
@@ -92,7 +92,7 @@
92
92
  "dependents": [
93
93
  "/src/adapters/aws-lambda/index.ts"
94
94
  ],
95
- "percent": 5.63,
95
+ "percent": 5.65,
96
96
  "reduction": 13.62
97
97
  },
98
98
  {
@@ -109,7 +109,7 @@
109
109
  "/src/observable/index.ts",
110
110
  "/src/observable/operators.ts"
111
111
  ],
112
- "percent": 3.63,
112
+ "percent": 3.64,
113
113
  "reduction": 0.67
114
114
  },
115
115
  {
@@ -123,7 +123,7 @@
123
123
  "dependents": [
124
124
  "/src/adapters/next-app-dir.ts"
125
125
  ],
126
- "percent": 3.54,
126
+ "percent": 3.55,
127
127
  "reduction": 20.12
128
128
  },
129
129
  {
@@ -139,7 +139,7 @@
139
139
  "dependents": [
140
140
  "/src/observable/index.ts"
141
141
  ],
142
- "percent": 3.2,
142
+ "percent": 3.21,
143
143
  "reduction": 0
144
144
  },
145
145
  {
@@ -173,7 +173,7 @@
173
173
  "dependents": [
174
174
  "/src/unstable-core-do-not-import.ts"
175
175
  ],
176
- "percent": 3.08,
176
+ "percent": 3.09,
177
177
  "reduction": 41.46
178
178
  },
179
179
  {
@@ -193,7 +193,7 @@
193
193
  "/src/unstable-core-do-not-import/initTRPC.ts",
194
194
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
195
195
  ],
196
- "percent": 3.05,
196
+ "percent": 3.06,
197
197
  "reduction": 55.5
198
198
  },
199
199
  {
@@ -223,23 +223,9 @@
223
223
  "/src/unstable-core-do-not-import.ts",
224
224
  "/src/unstable-core-do-not-import/router.ts"
225
225
  ],
226
- "percent": 2.32,
226
+ "percent": 2.33,
227
227
  "reduction": 0
228
228
  },
229
- {
230
- "id": "/src/adapters/node-http/nodeHTTPRequestHandler.ts",
231
- "size": 1956,
232
- "origSize": 2390,
233
- "renderedExports": [
234
- "nodeHTTPRequestHandler"
235
- ],
236
- "removedExports": [],
237
- "dependents": [
238
- "/src/adapters/node-http/index.ts"
239
- ],
240
- "percent": 2.27,
241
- "reduction": 18.16
242
- },
243
229
  {
244
230
  "id": "/src/adapters/node-http/incomingMessageToRequest.ts",
245
231
  "size": 1954,
@@ -273,9 +259,23 @@
273
259
  "/src/unstable-core-do-not-import/http/contentType.ts",
274
260
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
275
261
  ],
276
- "percent": 2.01,
262
+ "percent": 2.02,
277
263
  "reduction": 19.47
278
264
  },
265
+ {
266
+ "id": "/src/adapters/node-http/nodeHTTPRequestHandler.ts",
267
+ "size": 1721,
268
+ "origSize": 2152,
269
+ "renderedExports": [
270
+ "nodeHTTPRequestHandler"
271
+ ],
272
+ "removedExports": [],
273
+ "dependents": [
274
+ "/src/adapters/node-http/index.ts"
275
+ ],
276
+ "percent": 2,
277
+ "reduction": 20.03
278
+ },
279
279
  {
280
280
  "id": "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
281
281
  "size": 1580,
@@ -285,7 +285,7 @@
285
285
  ],
286
286
  "removedExports": [],
287
287
  "dependents": [],
288
- "percent": 1.83,
288
+ "percent": 1.84,
289
289
  "reduction": 21.04
290
290
  },
291
291
  {
@@ -297,7 +297,7 @@
297
297
  ],
298
298
  "removedExports": [],
299
299
  "dependents": [],
300
- "percent": 1.79,
300
+ "percent": 1.8,
301
301
  "reduction": 26.94
302
302
  },
303
303
  {
@@ -324,7 +324,7 @@
324
324
  "dependents": [
325
325
  "/src/adapters/fastify/index.ts"
326
326
  ],
327
- "percent": 1.74,
327
+ "percent": 1.75,
328
328
  "reduction": 34.7
329
329
  },
330
330
  {
@@ -356,7 +356,7 @@
356
356
  "/src/adapters/fastify/index.ts",
357
357
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
358
358
  ],
359
- "percent": 1.31,
359
+ "percent": 1.32,
360
360
  "reduction": 47.59
361
361
  },
362
362
  {
@@ -454,7 +454,7 @@
454
454
  "/src/unstable-core-do-not-import.ts",
455
455
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
456
456
  ],
457
- "percent": 0.77,
457
+ "percent": 0.78,
458
458
  "reduction": 0.6
459
459
  },
460
460
  {
@@ -482,7 +482,7 @@
482
482
  ],
483
483
  "removedExports": [],
484
484
  "dependents": [],
485
- "percent": 0.6,
485
+ "percent": 0.61,
486
486
  "reduction": 67.09
487
487
  },
488
488
  {
@@ -634,9 +634,9 @@
634
634
  "reduction": 100
635
635
  },
636
636
  {
637
- "id": "/src/rpc.ts",
637
+ "id": "/src/shared.ts",
638
638
  "size": 0,
639
- "origSize": 36,
639
+ "origSize": 653,
640
640
  "renderedExports": [],
641
641
  "removedExports": [],
642
642
  "dependents": [],
@@ -644,9 +644,9 @@
644
644
  "reduction": 100
645
645
  },
646
646
  {
647
- "id": "/src/unstable-core-do-not-import.ts",
647
+ "id": "/src/rpc.ts",
648
648
  "size": 0,
649
- "origSize": 1908,
649
+ "origSize": 36,
650
650
  "renderedExports": [],
651
651
  "removedExports": [],
652
652
  "dependents": [],
@@ -654,9 +654,9 @@
654
654
  "reduction": 100
655
655
  },
656
656
  {
657
- "id": "/src/shared.ts",
657
+ "id": "/src/unstable-core-do-not-import.ts",
658
658
  "size": 0,
659
- "origSize": 653,
659
+ "origSize": 1908,
660
660
  "renderedExports": [],
661
661
  "removedExports": [],
662
662
  "dependents": [],
@@ -713,8 +713,8 @@
713
713
  "removedExports": [],
714
714
  "dependents": [
715
715
  "/src/adapters/express.ts",
716
- "/src/adapters/next.ts",
717
716
  "/src/adapters/standalone.ts",
717
+ "/src/adapters/next.ts",
718
718
  "/src/adapters/fastify/fastifyRequestHandler.ts"
719
719
  ],
720
720
  "percent": 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.364+d95fb467b",
3
+ "version": "11.0.0-rc.369+0fb9a1d0a",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -122,7 +122,7 @@
122
122
  "@types/express": "^4.17.17",
123
123
  "@types/hash-sum": "^1.0.0",
124
124
  "@types/node": "^20.10.0",
125
- "@types/react": "^18.3.0",
125
+ "@types/react": "^18.3.1",
126
126
  "@types/react-dom": "^18.3.0",
127
127
  "@types/ws": "^8.2.0",
128
128
  "devalue": "^5.0.0",
@@ -133,8 +133,8 @@
133
133
  "hash-sum": "^2.0.0",
134
134
  "myzod": "^1.3.1",
135
135
  "next": "^14.1.4",
136
- "react": "^18.3.0",
137
- "react-dom": "^18.3.0",
136
+ "react": "^18.3.1",
137
+ "react-dom": "^18.3.1",
138
138
  "rollup": "^4.9.5",
139
139
  "superjson": "^1.12.4",
140
140
  "superstruct": "^1.0.0",
@@ -149,5 +149,5 @@
149
149
  "funding": [
150
150
  "https://trpc.io/sponsor"
151
151
  ],
152
- "gitHead": "d95fb467b966558ade5d1e2065faa33c9821ab6c"
152
+ "gitHead": "0fb9a1d0a5ed26aa155b6d01d5deebe22cbf19cf"
153
153
  }
@@ -10,6 +10,7 @@
10
10
 
11
11
  // @trpc/server
12
12
 
13
+ import { Readable } from 'node:stream';
13
14
  import { getTRPCErrorFromUnknown, type AnyRouter } from '../../@trpc/server';
14
15
  import type { ResolveHTTPRequestOptionsContextFn } from '../../@trpc/server/http';
15
16
  import { resolveResponse } from '../../@trpc/server/http';
@@ -20,14 +21,6 @@ import type {
20
21
  NodeHTTPResponse,
21
22
  } from './types';
22
23
 
23
- function assertAsyncIterable<TValue>(
24
- value: any,
25
- ): asserts value is AsyncIterable<TValue> {
26
- if (!(Symbol.asyncIterator in value)) {
27
- throw new Error('Expected AsyncIterable - are you using Node >= 18.0.0?');
28
- }
29
- }
30
-
31
24
  export async function nodeHTTPRequestHandler<
32
25
  TRouter extends AnyRouter,
33
26
  TRequest extends NodeHTTPRequest,
@@ -71,11 +64,9 @@ export async function nodeHTTPRequestHandler<
71
64
  opts.res.setHeader(key, value);
72
65
  }
73
66
  if (response.body) {
74
- assertAsyncIterable(response.body);
75
- for await (const chunk of response.body) {
76
- opts.res.write(chunk);
77
- }
67
+ Readable.fromWeb(response.body as any).pipe(opts.res);
68
+ } else {
69
+ opts.res.end();
78
70
  }
79
- opts.res.end();
80
71
  });
81
72
  }