@trpc/server 11.0.0-rc.382 → 11.0.0-rc.390

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":"nextAppDirCaller.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/nextAppDirCaller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAIhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAGvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAGzF,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACT,MAAM,yCAAyC,CAAC;AAKjD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAC9C,MAAM,EAAE,QAAQ,CACd;IACE;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,KAAK,CAAA;KAAE,KAAK,MAAM,CAAC;IAClD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;CACzD,GAAG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC,CAClE,GACA,cAAc,CAAC,QAAQ,CAAC,CAwF1B"}
1
+ {"version":3,"file":"nextAppDirCaller.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/nextAppDirCaller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAIhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAGvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AAGzF,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACT,MAAM,yCAAyC,CAAC;AAKjD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAC9C,MAAM,EAAE,QAAQ,CACd;IACE;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,KAAK,CAAA;KAAE,KAAK,MAAM,CAAC;IAClD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;CACzD,GAAG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC,CAClE,GACA,cAAc,CAAC,QAAQ,CAAC,CAyF1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"rethrowNextErrors.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/rethrowNextErrors.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD;;GAEG;AAEH,eAAO,MAAM,iBAAiB,UAAW,SAAS,SAWjD,CAAC"}
1
+ {"version":3,"file":"rethrowNextErrors.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/rethrowNextErrors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAyCpD;;GAEG;AACH,eAAO,MAAM,iBAAiB,UAAW,SAAS,SAqBjD,CAAC"}
@@ -1,21 +1,67 @@
1
1
  'use strict';
2
2
 
3
- var notFound = require('next/dist/client/components/not-found');
4
- var redirect$1 = require('next/dist/client/components/redirect');
5
- var navigation = require('next/navigation');
3
+ var nextNavigation = require('next/navigation.js');
6
4
  var redirect = require('./redirect.js');
7
5
 
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var nextNavigation__namespace = /*#__PURE__*/_interopNamespaceDefault(nextNavigation);
24
+
25
+ /**
26
+ * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.
27
+ * Inlining them here instead...
28
+ * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/redirect.ts#L97-L123
29
+ */ const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT';
30
+ function isRedirectError(error) {
31
+ if (typeof error !== 'object' || error === null || !('digest' in error) || typeof error.digest !== 'string') {
32
+ return false;
33
+ }
34
+ const [errorCode, type, destination, status] = error.digest.split(';', 4);
35
+ const statusCode = Number(status);
36
+ return errorCode === REDIRECT_ERROR_CODE && (type === 'replace' || type === 'push') && typeof destination === 'string' && !isNaN(statusCode);
37
+ }
38
+ /**
39
+ * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.
40
+ * Inlining them here instead...
41
+ * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/not-found.ts#L33-L39
42
+ */ const NOT_FOUND_ERROR_CODE = 'NEXT_NOT_FOUND';
43
+ function isNotFoundError(error) {
44
+ if (typeof error !== 'object' || error === null || !('digest' in error)) {
45
+ return false;
46
+ }
47
+ return error.digest === NOT_FOUND_ERROR_CODE;
48
+ }
8
49
  /**
9
50
  * Rethrow errors that should be handled by Next.js
10
51
  */ const rethrowNextErrors = (error)=>{
11
52
  if (error.code === 'NOT_FOUND') {
12
- navigation.notFound();
53
+ nextNavigation__namespace.notFound();
13
54
  }
14
55
  if (error instanceof redirect.TRPCRedirectError) {
15
- navigation.redirect(...error.args);
56
+ nextNavigation__namespace.redirect(...error.args);
16
57
  }
17
58
  const { cause } = error;
18
- if (redirect$1.isRedirectError(cause) || notFound.isNotFoundError(cause)) {
59
+ // Next.js 15 has `unstable_rethrow`. Use that if it exists.
60
+ if ('unstable_rethrow' in nextNavigation__namespace && typeof nextNavigation__namespace.unstable_rethrow === 'function') {
61
+ nextNavigation__namespace.unstable_rethrow(cause);
62
+ }
63
+ // Before Next.js 15, we have to check and rethrow the error manually.
64
+ if (isRedirectError(cause) || isNotFoundError(cause)) {
19
65
  throw error.cause;
20
66
  }
21
67
  };
@@ -1,18 +1,45 @@
1
- import { isNotFoundError } from 'next/dist/client/components/not-found';
2
- import { isRedirectError } from 'next/dist/client/components/redirect';
3
- import { notFound, redirect } from 'next/navigation';
1
+ import * as nextNavigation from 'next/navigation.js';
4
2
  import { TRPCRedirectError } from './redirect.mjs';
5
3
 
4
+ /**
5
+ * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.
6
+ * Inlining them here instead...
7
+ * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/redirect.ts#L97-L123
8
+ */ const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT';
9
+ function isRedirectError(error) {
10
+ if (typeof error !== 'object' || error === null || !('digest' in error) || typeof error.digest !== 'string') {
11
+ return false;
12
+ }
13
+ const [errorCode, type, destination, status] = error.digest.split(';', 4);
14
+ const statusCode = Number(status);
15
+ return errorCode === REDIRECT_ERROR_CODE && (type === 'replace' || type === 'push') && typeof destination === 'string' && !isNaN(statusCode);
16
+ }
17
+ /**
18
+ * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.
19
+ * Inlining them here instead...
20
+ * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/not-found.ts#L33-L39
21
+ */ const NOT_FOUND_ERROR_CODE = 'NEXT_NOT_FOUND';
22
+ function isNotFoundError(error) {
23
+ if (typeof error !== 'object' || error === null || !('digest' in error)) {
24
+ return false;
25
+ }
26
+ return error.digest === NOT_FOUND_ERROR_CODE;
27
+ }
6
28
  /**
7
29
  * Rethrow errors that should be handled by Next.js
8
30
  */ const rethrowNextErrors = (error)=>{
9
31
  if (error.code === 'NOT_FOUND') {
10
- notFound();
32
+ nextNavigation.notFound();
11
33
  }
12
34
  if (error instanceof TRPCRedirectError) {
13
- redirect(...error.args);
35
+ nextNavigation.redirect(...error.args);
14
36
  }
15
37
  const { cause } = error;
38
+ // Next.js 15 has `unstable_rethrow`. Use that if it exists.
39
+ if ('unstable_rethrow' in nextNavigation && typeof nextNavigation.unstable_rethrow === 'function') {
40
+ nextNavigation.unstable_rethrow(cause);
41
+ }
42
+ // Before Next.js 15, we have to check and rethrow the error manually.
16
43
  if (isRedirectError(cause) || isNotFoundError(cause)) {
17
44
  throw error.cause;
18
45
  }
@@ -1,12 +1,12 @@
1
1
  {
2
- "bundleSize": 102969,
3
- "bundleOrigSize": 151874,
4
- "bundleReduction": 32.2,
2
+ "bundleSize": 105459,
3
+ "bundleOrigSize": 153978,
4
+ "bundleReduction": 31.51,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/unstable-core-do-not-import/stream/stream.ts",
8
- "size": 14457,
9
- "origSize": 15951,
8
+ "size": 14926,
9
+ "origSize": 16301,
10
10
  "renderedExports": [
11
11
  "isPromise",
12
12
  "jsonlStreamProducer",
@@ -17,8 +17,8 @@
17
17
  "/src/unstable-core-do-not-import.ts",
18
18
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
19
19
  ],
20
- "percent": 14.04,
21
- "reduction": 9.37
20
+ "percent": 14.15,
21
+ "reduction": 8.44
22
22
  },
23
23
  {
24
24
  "id": "/src/adapters/ws.ts",
@@ -32,13 +32,13 @@
32
32
  "dependents": [
33
33
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
34
34
  ],
35
- "percent": 10.92,
35
+ "percent": 10.66,
36
36
  "reduction": 0
37
37
  },
38
38
  {
39
39
  "id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
40
- "size": 10457,
41
- "origSize": 10914,
40
+ "size": 10850,
41
+ "origSize": 11195,
42
42
  "renderedExports": [
43
43
  "resolveResponse"
44
44
  ],
@@ -46,8 +46,8 @@
46
46
  "dependents": [
47
47
  "/src/unstable-core-do-not-import.ts"
48
48
  ],
49
- "percent": 10.16,
50
- "reduction": 4.19
49
+ "percent": 10.29,
50
+ "reduction": 3.08
51
51
  },
52
52
  {
53
53
  "id": "/src/unstable-core-do-not-import/procedureBuilder.ts",
@@ -61,7 +61,7 @@
61
61
  "/src/unstable-core-do-not-import.ts",
62
62
  "/src/unstable-core-do-not-import/initTRPC.ts"
63
63
  ],
64
- "percent": 6.14,
64
+ "percent": 6,
65
65
  "reduction": 59.52
66
66
  },
67
67
  {
@@ -80,7 +80,7 @@
80
80
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
81
81
  "/src/unstable-core-do-not-import/initTRPC.ts"
82
82
  ],
83
- "percent": 5.82,
83
+ "percent": 5.68,
84
84
  "reduction": 41.05
85
85
  },
86
86
  {
@@ -95,7 +95,7 @@
95
95
  "/src/unstable-core-do-not-import.ts",
96
96
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
97
97
  ],
98
- "percent": 5.39,
98
+ "percent": 5.26,
99
99
  "reduction": 0
100
100
  },
101
101
  {
@@ -109,13 +109,13 @@
109
109
  "dependents": [
110
110
  "/src/adapters/aws-lambda/index.ts"
111
111
  ],
112
- "percent": 4.71,
112
+ "percent": 4.6,
113
113
  "reduction": 13.62
114
114
  },
115
115
  {
116
116
  "id": "/src/adapters/next-app-dir/nextAppDirCaller.ts",
117
117
  "size": 3135,
118
- "origSize": 4032,
118
+ "origSize": 4033,
119
119
  "renderedExports": [
120
120
  "nextAppDirCaller"
121
121
  ],
@@ -123,8 +123,8 @@
123
123
  "dependents": [
124
124
  "/src/adapters/next-app-dir.ts"
125
125
  ],
126
- "percent": 3.04,
127
- "reduction": 22.25
126
+ "percent": 2.97,
127
+ "reduction": 22.27
128
128
  },
129
129
  {
130
130
  "id": "/src/observable/observable.ts",
@@ -140,7 +140,7 @@
140
140
  "/src/observable/index.ts",
141
141
  "/src/observable/operators.ts"
142
142
  ],
143
- "percent": 3.04,
143
+ "percent": 2.97,
144
144
  "reduction": 0.67
145
145
  },
146
146
  {
@@ -156,7 +156,7 @@
156
156
  "dependents": [
157
157
  "/src/observable/index.ts"
158
158
  ],
159
- "percent": 2.68,
159
+ "percent": 2.61,
160
160
  "reduction": 0
161
161
  },
162
162
  {
@@ -176,7 +176,7 @@
176
176
  "/src/unstable-core-do-not-import/router.ts",
177
177
  "/src/unstable-core-do-not-import/initTRPC.ts"
178
178
  ],
179
- "percent": 2.66,
179
+ "percent": 2.6,
180
180
  "reduction": 45.94
181
181
  },
182
182
  {
@@ -190,7 +190,7 @@
190
190
  "dependents": [
191
191
  "/src/unstable-core-do-not-import.ts"
192
192
  ],
193
- "percent": 2.63,
193
+ "percent": 2.56,
194
194
  "reduction": 40.91
195
195
  },
196
196
  {
@@ -210,7 +210,7 @@
210
210
  "/src/unstable-core-do-not-import/initTRPC.ts",
211
211
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
212
212
  ],
213
- "percent": 2.55,
213
+ "percent": 2.49,
214
214
  "reduction": 55.5
215
215
  },
216
216
  {
@@ -224,7 +224,7 @@
224
224
  "dependents": [
225
225
  "/src/adapters/fetch/index.ts"
226
226
  ],
227
- "percent": 2.19,
227
+ "percent": 2.14,
228
228
  "reduction": 2.17
229
229
  },
230
230
  {
@@ -239,9 +239,23 @@
239
239
  "/src/adapters/node-http/index.ts",
240
240
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts"
241
241
  ],
242
- "percent": 2.11,
242
+ "percent": 2.06,
243
243
  "reduction": 14.12
244
244
  },
245
+ {
246
+ "id": "/src/adapters/next-app-dir/rethrowNextErrors.ts",
247
+ "size": 2050,
248
+ "origSize": 2176,
249
+ "renderedExports": [
250
+ "rethrowNextErrors"
251
+ ],
252
+ "removedExports": [],
253
+ "dependents": [
254
+ "/src/adapters/next-app-dir/nextAppDirCaller.ts"
255
+ ],
256
+ "percent": 1.94,
257
+ "reduction": 5.79
258
+ },
245
259
  {
246
260
  "id": "/src/unstable-core-do-not-import/createProxy.ts",
247
261
  "size": 2000,
@@ -255,7 +269,7 @@
255
269
  "/src/unstable-core-do-not-import.ts",
256
270
  "/src/unstable-core-do-not-import/router.ts"
257
271
  ],
258
- "percent": 1.94,
272
+ "percent": 1.9,
259
273
  "reduction": 0
260
274
  },
261
275
  {
@@ -276,7 +290,7 @@
276
290
  "/src/unstable-core-do-not-import/http/contentType.ts",
277
291
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
278
292
  ],
279
- "percent": 1.68,
293
+ "percent": 1.64,
280
294
  "reduction": 19.47
281
295
  },
282
296
  {
@@ -290,7 +304,7 @@
290
304
  "dependents": [
291
305
  "/src/adapters/node-http/index.ts"
292
306
  ],
293
- "percent": 1.67,
307
+ "percent": 1.63,
294
308
  "reduction": 20.03
295
309
  },
296
310
  {
@@ -302,7 +316,7 @@
302
316
  ],
303
317
  "removedExports": [],
304
318
  "dependents": [],
305
- "percent": 1.53,
319
+ "percent": 1.5,
306
320
  "reduction": 21.04
307
321
  },
308
322
  {
@@ -314,7 +328,7 @@
314
328
  ],
315
329
  "removedExports": [],
316
330
  "dependents": [],
317
- "percent": 1.5,
331
+ "percent": 1.46,
318
332
  "reduction": 26.94
319
333
  },
320
334
  {
@@ -327,7 +341,7 @@
327
341
  ],
328
342
  "removedExports": [],
329
343
  "dependents": [],
330
- "percent": 1.48,
344
+ "percent": 1.45,
331
345
  "reduction": 27.6
332
346
  },
333
347
  {
@@ -341,7 +355,7 @@
341
355
  "dependents": [
342
356
  "/src/adapters/fastify/index.ts"
343
357
  ],
344
- "percent": 1.46,
358
+ "percent": 1.42,
345
359
  "reduction": 34.7
346
360
  },
347
361
  {
@@ -358,7 +372,7 @@
358
372
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
359
373
  "/src/unstable-core-do-not-import/error/getErrorShape.ts"
360
374
  ],
361
- "percent": 1.23,
375
+ "percent": 1.2,
362
376
  "reduction": 23.5
363
377
  },
364
378
  {
@@ -386,7 +400,7 @@
386
400
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
387
401
  "/src/unstable-core-do-not-import/stream/stream.ts"
388
402
  ],
389
- "percent": 1.12,
403
+ "percent": 1.09,
390
404
  "reduction": 27.13
391
405
  },
392
406
  {
@@ -401,7 +415,7 @@
401
415
  "/src/adapters/fastify/index.ts",
402
416
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
403
417
  ],
404
- "percent": 1.1,
418
+ "percent": 1.07,
405
419
  "reduction": 47.59
406
420
  },
407
421
  {
@@ -416,7 +430,7 @@
416
430
  "/src/unstable-core-do-not-import.ts",
417
431
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
418
432
  ],
419
- "percent": 0.96,
433
+ "percent": 0.94,
420
434
  "reduction": 56.22
421
435
  },
422
436
  {
@@ -433,7 +447,7 @@
433
447
  "/src/adapters/next-app-dir/nextAppDirCaller.ts",
434
448
  "/src/adapters/next-app-dir/rethrowNextErrors.ts"
435
449
  ],
436
- "percent": 0.96,
450
+ "percent": 0.94,
437
451
  "reduction": 13.65
438
452
  },
439
453
  {
@@ -447,7 +461,7 @@
447
461
  "dependents": [
448
462
  "/src/adapters/next-app-dir/nextAppDirCaller.ts"
449
463
  ],
450
- "percent": 0.79,
464
+ "percent": 0.78,
451
465
  "reduction": 0.97
452
466
  },
453
467
  {
@@ -459,7 +473,7 @@
459
473
  ],
460
474
  "removedExports": [],
461
475
  "dependents": [],
462
- "percent": 0.74,
476
+ "percent": 0.72,
463
477
  "reduction": 66.9
464
478
  },
465
479
  {
@@ -473,7 +487,7 @@
473
487
  "dependents": [
474
488
  "/src/unstable-core-do-not-import.ts"
475
489
  ],
476
- "percent": 0.65,
490
+ "percent": 0.63,
477
491
  "reduction": 0.6
478
492
  },
479
493
  {
@@ -488,7 +502,7 @@
488
502
  "/src/unstable-core-do-not-import.ts",
489
503
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
490
504
  ],
491
- "percent": 0.61,
505
+ "percent": 0.59,
492
506
  "reduction": 43.49
493
507
  },
494
508
  {
@@ -501,23 +515,9 @@
501
515
  ],
502
516
  "removedExports": [],
503
517
  "dependents": [],
504
- "percent": 0.51,
518
+ "percent": 0.49,
505
519
  "reduction": 67.09
506
520
  },
507
- {
508
- "id": "/src/adapters/next-app-dir/rethrowNextErrors.ts",
509
- "size": 422,
510
- "origSize": 704,
511
- "renderedExports": [
512
- "rethrowNextErrors"
513
- ],
514
- "removedExports": [],
515
- "dependents": [
516
- "/src/adapters/next-app-dir/nextAppDirCaller.ts"
517
- ],
518
- "percent": 0.41,
519
- "reduction": 40.06
520
- },
521
521
  {
522
522
  "id": "/src/unstable-core-do-not-import/rootConfig.ts",
523
523
  "size": 343,
@@ -556,7 +556,7 @@
556
556
  "dependents": [
557
557
  "/src/unstable-core-do-not-import.ts"
558
558
  ],
559
- "percent": 0.27,
559
+ "percent": 0.26,
560
560
  "reduction": 68.45
561
561
  },
562
562
  {
@@ -1 +1 @@
1
- {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAOnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AAUjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAsHD,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAiQnB"}
1
+ {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAOnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AAUjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAsHD,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CA8QnB"}
@@ -92,6 +92,7 @@ async function resolveResponse(opts) {
92
92
  'trpc-accept'
93
93
  ]
94
94
  ]);
95
+ const config = router$1._def._config;
95
96
  const url = new URL(req.url);
96
97
  if (req.method === 'HEAD') {
97
98
  // can be used for lambda warmup
@@ -105,12 +106,12 @@ async function resolveResponse(opts) {
105
106
  let ctx = undefined;
106
107
  let info = undefined;
107
108
  const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
108
- const experimentalIterablesAndDeferreds = router$1._def._config.experimental?.iterablesAndDeferreds ?? false;
109
+ const experimentalIterablesAndDeferreds = config.experimental?.iterablesAndDeferreds ?? false;
109
110
  try {
110
111
  info = contentType.getRequestInfo({
111
112
  req,
112
113
  path: decodeURIComponent(opts.path),
113
- config: router$1._def._config,
114
+ config: config,
114
115
  searchParams: url.searchParams
115
116
  });
116
117
  // we create context early so that error handlers may access context information
@@ -176,7 +177,7 @@ async function resolveResponse(opts) {
176
177
  });
177
178
  return {
178
179
  error: getErrorShape.getErrorShape({
179
- config: opts.router._def._config,
180
+ config,
180
181
  error,
181
182
  type,
182
183
  path: call.path,
@@ -244,6 +245,17 @@ async function resolveResponse(opts) {
244
245
  * }
245
246
  * }
246
247
  */ maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
248
+ formatError (errorOpts) {
249
+ const call = info?.calls[errorOpts.path[0]];
250
+ return getErrorShape.getErrorShape({
251
+ config,
252
+ ctx,
253
+ error: TRPCError.getTRPCErrorFromUnknown(errorOpts.error),
254
+ input: call?.result(),
255
+ path: call?.path,
256
+ type
257
+ });
258
+ },
247
259
  data: promises.map(async (it)=>{
248
260
  const response = await it;
249
261
  if ('result' in response) {
@@ -260,7 +272,7 @@ async function resolveResponse(opts) {
260
272
  }
261
273
  return response;
262
274
  }),
263
- serialize: opts.router._def._config.transformer.output.serialize,
275
+ serialize: config.transformer.output.serialize,
264
276
  onError: (cause)=>{
265
277
  opts.onError?.({
266
278
  error: TRPCError.getTRPCErrorFromUnknown(cause),
@@ -90,6 +90,7 @@ async function resolveResponse(opts) {
90
90
  'trpc-accept'
91
91
  ]
92
92
  ]);
93
+ const config = router._def._config;
93
94
  const url = new URL(req.url);
94
95
  if (req.method === 'HEAD') {
95
96
  // can be used for lambda warmup
@@ -103,12 +104,12 @@ async function resolveResponse(opts) {
103
104
  let ctx = undefined;
104
105
  let info = undefined;
105
106
  const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
106
- const experimentalIterablesAndDeferreds = router._def._config.experimental?.iterablesAndDeferreds ?? false;
107
+ const experimentalIterablesAndDeferreds = config.experimental?.iterablesAndDeferreds ?? false;
107
108
  try {
108
109
  info = getRequestInfo({
109
110
  req,
110
111
  path: decodeURIComponent(opts.path),
111
- config: router._def._config,
112
+ config: config,
112
113
  searchParams: url.searchParams
113
114
  });
114
115
  // we create context early so that error handlers may access context information
@@ -174,7 +175,7 @@ async function resolveResponse(opts) {
174
175
  });
175
176
  return {
176
177
  error: getErrorShape({
177
- config: opts.router._def._config,
178
+ config,
178
179
  error,
179
180
  type,
180
181
  path: call.path,
@@ -242,6 +243,17 @@ async function resolveResponse(opts) {
242
243
  * }
243
244
  * }
244
245
  */ maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
246
+ formatError (errorOpts) {
247
+ const call = info?.calls[errorOpts.path[0]];
248
+ return getErrorShape({
249
+ config,
250
+ ctx,
251
+ error: getTRPCErrorFromUnknown(errorOpts.error),
252
+ input: call?.result(),
253
+ path: call?.path,
254
+ type
255
+ });
256
+ },
245
257
  data: promises.map(async (it)=>{
246
258
  const response = await it;
247
259
  if ('result' in response) {
@@ -258,7 +270,7 @@ async function resolveResponse(opts) {
258
270
  }
259
271
  return response;
260
272
  }),
261
- serialize: opts.router._def._config.transformer.output.serialize,
273
+ serialize: config.transformer.output.serialize,
262
274
  onError: (cause)=>{
263
275
  opts.onError?.({
264
276
  error: getTRPCErrorFromUnknown(cause),
@@ -42,17 +42,15 @@ type PromiseChunk = [
42
42
  chunkIndex: ChunkIndex,
43
43
  status: PROMISE_STATUS_FULFILLED,
44
44
  value: HydratedValue
45
- ] | [
46
- chunkIndex: ChunkIndex,
47
- status: PROMISE_STATUS_REJECTED
48
- ];
45
+ ] | [chunkIndex: ChunkIndex, status: PROMISE_STATUS_REJECTED, error: unknown];
49
46
  type IterableChunk = [chunkIndex: ChunkIndex, status: ASYNC_ITERABLE_STATUS_DONE] | [
50
47
  chunkIndex: ChunkIndex,
51
48
  status: ASYNC_ITERABLE_STATUS_VALUE,
52
49
  value: HydratedValue
53
50
  ] | [
54
51
  chunkIndex: ChunkIndex,
55
- status: ASYNC_ITERABLE_STATUS_ERROR
52
+ status: ASYNC_ITERABLE_STATUS_ERROR,
53
+ error: unknown
56
54
  ];
57
55
  type ChunkData = PromiseChunk | IterableChunk;
58
56
  export declare function isPromise(value: unknown): value is Promise<unknown>;
@@ -66,6 +64,10 @@ export interface ProducerOptions {
66
64
  serialize?: Serialize;
67
65
  data: Record<number, unknown>;
68
66
  onError?: ProducerOnError;
67
+ formatError?: (opts: {
68
+ error: unknown;
69
+ path: (string | number)[];
70
+ }) => unknown;
69
71
  maxDepth?: number;
70
72
  }
71
73
  /**
@@ -87,6 +89,9 @@ export declare function jsonlStreamConsumer<THead>(opts: {
87
89
  from: NodeJSReadableStreamEsque | WebReadableStreamEsque;
88
90
  deserialize?: Deserialize;
89
91
  onError?: ConsumerOnError;
92
+ formatError?: (opts: {
93
+ error: unknown;
94
+ }) => Error;
90
95
  }): Promise<readonly [Awaited<THead>, {
91
96
  readonly controllers: Map<ChunkIndex, ReadableStreamDefaultController<ChunkData | StreamInterruptedError>>;
92
97
  }]>;
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/stream.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,yBAAyB,CAAC;CAC9B,CAAC;AAGF,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,+BAA+B,IAAI,CAAC;AAC1C,KAAK,+BAA+B,GAAG,OAAO,+BAA+B,CAA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C;CACnB;AAkJD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,8BA2BxD;AACD,cAAM,sBAAuB,SAAQ,KAAK;gBAC5B,KAAK,CAAC,EAAE,OAAO;CAK5B;AAMD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,CAAC;AA6FjE;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE;IACrD,IAAI,EAAE,yBAAyB,GAAG,sBAAsB,CAAC;IACzD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC;CACnD;;IAkLA"}
@@ -63,14 +63,18 @@ function createBatchStreamProducer(opts) {
63
63
  PROMISE_STATUS_FULFILLED,
64
64
  hydrate(it, path)
65
65
  ]);
66
- }).catch((err)=>{
66
+ }).catch((error)=>{
67
67
  opts.onError?.({
68
- error: err,
68
+ error,
69
69
  path
70
70
  });
71
71
  enqueue([
72
72
  idx,
73
- PROMISE_STATUS_REJECTED
73
+ PROMISE_STATUS_REJECTED,
74
+ opts.formatError?.({
75
+ error,
76
+ path
77
+ })
74
78
  ]);
75
79
  }).finally(()=>{
76
80
  pending.delete(idx);
@@ -109,7 +113,11 @@ function createBatchStreamProducer(opts) {
109
113
  });
110
114
  controller.enqueue([
111
115
  idx,
112
- ASYNC_ITERABLE_STATUS_ERROR
116
+ ASYNC_ITERABLE_STATUS_ERROR,
117
+ opts.formatError?.({
118
+ error,
119
+ path
120
+ })
113
121
  ]);
114
122
  } finally{
115
123
  pending.delete(idx);
@@ -355,7 +363,9 @@ function createDeferred() {
355
363
  resolve(dehydrate(data));
356
364
  break;
357
365
  case PROMISE_STATUS_REJECTED:
358
- reject(new AsyncError(data));
366
+ reject(opts.formatError?.({
367
+ error: data
368
+ }) ?? new AsyncError(data));
359
369
  break;
360
370
  }
361
371
  }).catch(reject).finally(()=>{
@@ -387,7 +397,9 @@ function createDeferred() {
387
397
  return;
388
398
  case ASYNC_ITERABLE_STATUS_ERROR:
389
399
  controllers.delete(chunkId);
390
- throw new AsyncError(data);
400
+ throw opts.formatError?.({
401
+ error: data
402
+ }) ?? new AsyncError(data);
391
403
  }
392
404
  }
393
405
  }
@@ -61,14 +61,18 @@ function createBatchStreamProducer(opts) {
61
61
  PROMISE_STATUS_FULFILLED,
62
62
  hydrate(it, path)
63
63
  ]);
64
- }).catch((err)=>{
64
+ }).catch((error)=>{
65
65
  opts.onError?.({
66
- error: err,
66
+ error,
67
67
  path
68
68
  });
69
69
  enqueue([
70
70
  idx,
71
- PROMISE_STATUS_REJECTED
71
+ PROMISE_STATUS_REJECTED,
72
+ opts.formatError?.({
73
+ error,
74
+ path
75
+ })
72
76
  ]);
73
77
  }).finally(()=>{
74
78
  pending.delete(idx);
@@ -107,7 +111,11 @@ function createBatchStreamProducer(opts) {
107
111
  });
108
112
  controller.enqueue([
109
113
  idx,
110
- ASYNC_ITERABLE_STATUS_ERROR
114
+ ASYNC_ITERABLE_STATUS_ERROR,
115
+ opts.formatError?.({
116
+ error,
117
+ path
118
+ })
111
119
  ]);
112
120
  } finally{
113
121
  pending.delete(idx);
@@ -353,7 +361,9 @@ function createDeferred() {
353
361
  resolve(dehydrate(data));
354
362
  break;
355
363
  case PROMISE_STATUS_REJECTED:
356
- reject(new AsyncError(data));
364
+ reject(opts.formatError?.({
365
+ error: data
366
+ }) ?? new AsyncError(data));
357
367
  break;
358
368
  }
359
369
  }).catch(reject).finally(()=>{
@@ -385,7 +395,9 @@ function createDeferred() {
385
395
  return;
386
396
  case ASYNC_ITERABLE_STATUS_ERROR:
387
397
  controllers.delete(chunkId);
388
- throw new AsyncError(data);
398
+ throw opts.formatError?.({
399
+ error: data
400
+ }) ?? new AsyncError(data);
389
401
  }
390
402
  }
391
403
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.382+94f198fec",
3
+ "version": "11.0.0-rc.390+d846f1796",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -149,5 +149,5 @@
149
149
  "funding": [
150
150
  "https://trpc.io/sponsor"
151
151
  ],
152
- "gitHead": "94f198fece23e9328f7a30d1badf74de524b0ebb"
152
+ "gitHead": "d846f1796c969778b647dcba43b2bcff1b3a4830"
153
153
  }
@@ -46,6 +46,7 @@ export function nextAppDirCaller<TContext, TMeta>(
46
46
  const createContext = async (): Promise<TContext> => {
47
47
  return config?.createContext?.() ?? ({} as TContext);
48
48
  };
49
+
49
50
  return async (opts) => {
50
51
  const path =
51
52
  config.pathExtractor?.({ meta: opts._def.meta as TMeta }) ?? '';
@@ -1,24 +1,66 @@
1
- import { isNotFoundError } from 'next/dist/client/components/not-found';
2
- import { isRedirectError } from 'next/dist/client/components/redirect';
3
- import {
4
- notFound as __notFound,
5
- redirect as __redirect,
6
- } from 'next/navigation';
1
+ import * as nextNavigation from 'next/navigation.js';
7
2
  import type { TRPCError } from '../../@trpc/server';
8
3
  import { TRPCRedirectError } from './redirect';
9
4
 
10
5
  /**
11
- * Rethrow errors that should be handled by Next.js
6
+ * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.
7
+ * Inlining them here instead...
8
+ * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/redirect.ts#L97-L123
9
+ */
10
+ const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT';
11
+ function isRedirectError(error: unknown) {
12
+ if (
13
+ typeof error !== 'object' ||
14
+ error === null ||
15
+ !('digest' in error) ||
16
+ typeof error.digest !== 'string'
17
+ ) {
18
+ return false;
19
+ }
20
+ const [errorCode, type, destination, status] = error.digest.split(';', 4);
21
+ const statusCode = Number(status);
22
+ return (
23
+ errorCode === REDIRECT_ERROR_CODE &&
24
+ (type === 'replace' || type === 'push') &&
25
+ typeof destination === 'string' &&
26
+ !isNaN(statusCode)
27
+ );
28
+ }
29
+
30
+ /**
31
+ * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.
32
+ * Inlining them here instead...
33
+ * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/not-found.ts#L33-L39
12
34
  */
35
+ const NOT_FOUND_ERROR_CODE = 'NEXT_NOT_FOUND';
36
+ function isNotFoundError(error: unknown) {
37
+ if (typeof error !== 'object' || error === null || !('digest' in error)) {
38
+ return false;
39
+ }
40
+ return error.digest === NOT_FOUND_ERROR_CODE;
41
+ }
13
42
 
43
+ /**
44
+ * Rethrow errors that should be handled by Next.js
45
+ */
14
46
  export const rethrowNextErrors = (error: TRPCError) => {
15
47
  if (error.code === 'NOT_FOUND') {
16
- __notFound();
48
+ nextNavigation.notFound();
17
49
  }
18
50
  if (error instanceof TRPCRedirectError) {
19
- __redirect(...error.args);
51
+ nextNavigation.redirect(...error.args);
20
52
  }
21
53
  const { cause } = error;
54
+
55
+ // Next.js 15 has `unstable_rethrow`. Use that if it exists.
56
+ if (
57
+ 'unstable_rethrow' in nextNavigation &&
58
+ typeof nextNavigation.unstable_rethrow === 'function'
59
+ ) {
60
+ nextNavigation.unstable_rethrow(cause);
61
+ }
62
+
63
+ // Before Next.js 15, we have to check and rethrow the error manually.
22
64
  if (isRedirectError(cause) || isNotFoundError(cause)) {
23
65
  throw error.cause;
24
66
  }
@@ -160,6 +160,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
160
160
  ): Promise<Response> {
161
161
  const { router, req } = opts;
162
162
  const headers = new Headers([['vary', 'trpc-accept']]);
163
+ const config = router._def._config;
163
164
 
164
165
  const url = new URL(req.url);
165
166
 
@@ -181,13 +182,13 @@ export async function resolveResponse<TRouter extends AnyRouter>(
181
182
  const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
182
183
 
183
184
  const experimentalIterablesAndDeferreds =
184
- router._def._config.experimental?.iterablesAndDeferreds ?? false;
185
+ config.experimental?.iterablesAndDeferreds ?? false;
185
186
 
186
187
  try {
187
188
  info = getRequestInfo({
188
189
  req,
189
190
  path: decodeURIComponent(opts.path),
190
- config: router._def._config,
191
+ config: config,
191
192
  searchParams: url.searchParams,
192
193
  });
193
194
 
@@ -268,7 +269,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
268
269
 
269
270
  return {
270
271
  error: getErrorShape({
271
- config: opts.router._def._config,
272
+ config,
272
273
  error,
273
274
  type,
274
275
  path: call.path,
@@ -351,6 +352,18 @@ export async function resolveResponse<TRouter extends AnyRouter>(
351
352
  * }
352
353
  */
353
354
  maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
355
+ formatError(errorOpts) {
356
+ const call = info?.calls[errorOpts.path[0] as any];
357
+
358
+ return getErrorShape({
359
+ config,
360
+ ctx,
361
+ error: getTRPCErrorFromUnknown(errorOpts.error),
362
+ input: call?.result(),
363
+ path: call?.path,
364
+ type,
365
+ });
366
+ },
354
367
  data: promises.map(async (it) => {
355
368
  const response = await it;
356
369
  if ('result' in response) {
@@ -368,7 +381,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
368
381
  }
369
382
  return response;
370
383
  }),
371
- serialize: opts.router._def._config.transformer.output.serialize,
384
+ serialize: config.transformer.output.serialize,
372
385
  onError: (cause) => {
373
386
  opts.onError?.({
374
387
  error: getTRPCErrorFromUnknown(cause),
@@ -79,12 +79,7 @@ type PromiseChunk =
79
79
  status: PROMISE_STATUS_FULFILLED,
80
80
  value: HydratedValue,
81
81
  ]
82
- | [
83
- chunkIndex: ChunkIndex,
84
- status: PROMISE_STATUS_REJECTED,
85
- // do we want to serialize errors?
86
- // , error?: unknown
87
- ];
82
+ | [chunkIndex: ChunkIndex, status: PROMISE_STATUS_REJECTED, error: unknown];
88
83
  type IterableChunk =
89
84
  | [chunkIndex: ChunkIndex, status: ASYNC_ITERABLE_STATUS_DONE]
90
85
  | [
@@ -95,8 +90,7 @@ type IterableChunk =
95
90
  | [
96
91
  chunkIndex: ChunkIndex,
97
92
  status: ASYNC_ITERABLE_STATUS_ERROR,
98
- // do we want to serialize errors?
99
- // , error?: unknown
93
+ error: unknown,
100
94
  ];
101
95
  type ChunkData = PromiseChunk | IterableChunk;
102
96
  type PlaceholderValue = 0 & { __placeholder: true };
@@ -119,6 +113,10 @@ export interface ProducerOptions {
119
113
  serialize?: Serialize;
120
114
  data: Record<number, unknown>;
121
115
  onError?: ProducerOnError;
116
+ formatError?: (opts: {
117
+ error: unknown;
118
+ path: (string | number)[];
119
+ }) => unknown;
122
120
  maxDepth?: number;
123
121
  }
124
122
 
@@ -161,9 +159,13 @@ function createBatchStreamProducer(opts: ProducerOptions) {
161
159
  .then((it) => {
162
160
  enqueue([idx, PROMISE_STATUS_FULFILLED, hydrate(it, path)]);
163
161
  })
164
- .catch((err) => {
165
- opts.onError?.({ error: err, path });
166
- enqueue([idx, PROMISE_STATUS_REJECTED]);
162
+ .catch((error) => {
163
+ opts.onError?.({ error, path });
164
+ enqueue([
165
+ idx,
166
+ PROMISE_STATUS_REJECTED,
167
+ opts.formatError?.({ error, path }),
168
+ ]);
167
169
  })
168
170
  .finally(() => {
169
171
  pending.delete(idx);
@@ -197,7 +199,11 @@ function createBatchStreamProducer(opts: ProducerOptions) {
197
199
  controller.enqueue([idx, ASYNC_ITERABLE_STATUS_DONE]);
198
200
  } catch (error) {
199
201
  opts.onError?.({ error, path });
200
- controller.enqueue([idx, ASYNC_ITERABLE_STATUS_ERROR]);
202
+ controller.enqueue([
203
+ idx,
204
+ ASYNC_ITERABLE_STATUS_ERROR,
205
+ opts.formatError?.({ error, path }),
206
+ ]);
201
207
  } finally {
202
208
  pending.delete(idx);
203
209
  maybeClose();
@@ -403,6 +409,7 @@ export async function jsonlStreamConsumer<THead>(opts: {
403
409
  from: NodeJSReadableStreamEsque | WebReadableStreamEsque;
404
410
  deserialize?: Deserialize;
405
411
  onError?: ConsumerOnError;
412
+ formatError?: (opts: { error: unknown }) => Error;
406
413
  }) {
407
414
  const { deserialize = (v) => v } = opts;
408
415
 
@@ -459,7 +466,9 @@ export async function jsonlStreamConsumer<THead>(opts: {
459
466
  resolve(dehydrate(data));
460
467
  break;
461
468
  case PROMISE_STATUS_REJECTED:
462
- reject(new AsyncError(data));
469
+ reject(
470
+ opts.formatError?.({ error: data }) ?? new AsyncError(data),
471
+ );
463
472
  break;
464
473
  }
465
474
  })
@@ -494,7 +503,9 @@ export async function jsonlStreamConsumer<THead>(opts: {
494
503
  return;
495
504
  case ASYNC_ITERABLE_STATUS_ERROR:
496
505
  controllers.delete(chunkId);
497
- throw new AsyncError(data);
506
+ throw (
507
+ opts.formatError?.({ error: data }) ?? new AsyncError(data)
508
+ );
498
509
  }
499
510
  }
500
511
  },
@@ -541,7 +552,7 @@ export async function jsonlStreamConsumer<THead>(opts: {
541
552
  const head = chunkOrHead as Record<number | string, unknown>;
542
553
 
543
554
  for (const [key, value] of Object.entries(chunkOrHead)) {
544
- const parsed = dehydrate(value);
555
+ const parsed = dehydrate(value as any);
545
556
  head[key] = parsed;
546
557
  }
547
558
  headDeferred.resolve(head as THead);