@trpc/server 11.0.0-next.325 → 11.0.0-next.327

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.
@@ -40,7 +40,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
40
40
  });
41
41
  fastify.get(prefix ?? '/', {
42
42
  websocket: true
43
- }, ({ socket }, req)=>onConnection(socket, req.raw));
43
+ }, (socket, req)=>onConnection(socket, req.raw));
44
44
  }
45
45
  done();
46
46
  }
@@ -38,7 +38,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
38
38
  });
39
39
  fastify.get(prefix ?? '/', {
40
40
  websocket: true
41
- }, ({ socket }, req)=>onConnection(socket, req.raw));
41
+ }, (socket, req)=>onConnection(socket, req.raw));
42
42
  }
43
43
  done();
44
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"nextAppDirCaller.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/nextAppDirCaller.ts"],"names":[],"mappings":"AAGA,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;AAIjD,KAAK,eAAe,CAAC,QAAQ,IAAI,MAAM,SAAS,QAAQ,GACpD;IACE,aAAa,CAAC,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC;CAC9C,GACD;IACE,aAAa,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC;CAC7C,CAAC;AAEN;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EACvC,MAAM,EAAE,QAAQ,CACd;IACE;;;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,eAAe,CAAC,QAAQ,CAAC,CAC9B,GACA,cAAc,CAAC,QAAQ,CAAC,CA8E1B"}
1
+ {"version":3,"file":"nextAppDirCaller.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/nextAppDirCaller.ts"],"names":[],"mappings":"AAGA,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,KAAK,eAAe,CAAC,QAAQ,IAAI,MAAM,SAAS,QAAQ,GACpD;IACE,aAAa,CAAC,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC;CAC9C,GACD;IACE,aAAa,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC;CAC7C,CAAC;AAEN;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EACvC,MAAM,EAAE,QAAQ,CACd;IACE;;;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,eAAe,CAAC,QAAQ,CAAC,CAC9B,GACA,cAAc,CAAC,QAAQ,CAAC,CAsF1B"}
@@ -4,6 +4,7 @@ require('../../unstable-core-do-not-import/utils.js');
4
4
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
5
5
  require('../../unstable-core-do-not-import/rootConfig.js');
6
6
  var formDataToObject = require('./formDataToObject.js');
7
+ var redirect = require('./redirect.js');
7
8
  var rethrowNextErrors = require('./rethrowNextErrors.js');
8
9
 
9
10
  /**
@@ -52,6 +53,9 @@ var rethrowNextErrors = require('./rethrowNextErrors.js');
52
53
  getRawInput: async ()=>input,
53
54
  path: '',
54
55
  input
56
+ }).then((data)=>{
57
+ if (data instanceof redirect.TRPCRedirectError) throw data;
58
+ return data;
55
59
  }).catch(handleError);
56
60
  }
57
61
  case 'query':
@@ -63,6 +67,9 @@ var rethrowNextErrors = require('./rethrowNextErrors.js');
63
67
  getRawInput: async ()=>input1,
64
68
  path: '',
65
69
  input: input1
70
+ }).then((data)=>{
71
+ if (data instanceof redirect.TRPCRedirectError) throw data;
72
+ return data;
66
73
  }).catch(handleError);
67
74
  }
68
75
  default:
@@ -2,6 +2,7 @@ import '../../unstable-core-do-not-import/utils.mjs';
2
2
  import { TRPCError, getTRPCErrorFromUnknown } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
3
3
  import '../../unstable-core-do-not-import/rootConfig.mjs';
4
4
  import { formDataToObject } from './formDataToObject.mjs';
5
+ import { TRPCRedirectError } from './redirect.mjs';
5
6
  import { rethrowNextErrors } from './rethrowNextErrors.mjs';
6
7
 
7
8
  /**
@@ -50,6 +51,9 @@ import { rethrowNextErrors } from './rethrowNextErrors.mjs';
50
51
  getRawInput: async ()=>input,
51
52
  path: '',
52
53
  input
54
+ }).then((data)=>{
55
+ if (data instanceof TRPCRedirectError) throw data;
56
+ return data;
53
57
  }).catch(handleError);
54
58
  }
55
59
  case 'query':
@@ -61,6 +65,9 @@ import { rethrowNextErrors } from './rethrowNextErrors.mjs';
61
65
  getRawInput: async ()=>input1,
62
66
  path: '',
63
67
  input: input1
68
+ }).then((data)=>{
69
+ if (data instanceof TRPCRedirectError) throw data;
70
+ return data;
64
71
  }).catch(handleError);
65
72
  }
66
73
  default:
@@ -1,15 +1,18 @@
1
- import type { redirect as __redirect } from 'next/navigation';
1
+ import type { RedirectType } from 'next/navigation';
2
2
  import { TRPCError } from '../../@trpc/server';
3
3
  /**
4
4
  * @internal
5
5
  */
6
6
  export declare class TRPCRedirectError extends TRPCError {
7
- readonly args: [url: string, type?: import("next/navigation").RedirectType | undefined];
8
- constructor(...args: Parameters<typeof __redirect>);
7
+ readonly args: readonly [string, RedirectType | undefined];
8
+ constructor(url: URL | string, redirectType?: RedirectType);
9
9
  }
10
10
  /**
11
11
  * Like `next/navigation`'s `redirect()` but throws a `TRPCError` that later will be handled by Next.js
12
+ * This provides better typesafety than the `next/navigation`'s `redirect()` since the action continues
13
+ * to execute on the frontend even if Next's `redirect()` has a return type of `never`.
12
14
  * @public
15
+ * @remark You should only use this if you're also using `nextAppDirCaller`.
13
16
  */
14
- export declare const redirect: typeof __redirect;
17
+ export declare const redirect: (url: URL | string, redirectType?: RedirectType) => undefined;
15
18
  //# sourceMappingURL=redirect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/redirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,SAAgB,IAAI,2EAAC;gBACT,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC;CAUnD;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,UAE7B,CAAC"}
1
+ {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/redirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,SAAgB,IAAI,8CAAC;gBACT,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY;CAS3D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,GAAG,MAAM,iBAAiB,YAAY,cAGtE,CAAC"}
@@ -7,21 +7,27 @@ require('../../unstable-core-do-not-import/rootConfig.js');
7
7
  /**
8
8
  * @internal
9
9
  */ class TRPCRedirectError extends TRPCError.TRPCError {
10
- constructor(...args){
11
- const [url] = args;
10
+ constructor(url, redirectType){
12
11
  super({
13
12
  // TODO(?): This should maybe a custom error code
14
13
  code: 'UNPROCESSABLE_CONTENT',
15
14
  message: `Redirect error to "${url}" that will be handled by Next.js`
16
15
  });
17
- this.args = args;
16
+ this.args = [
17
+ url.toString(),
18
+ redirectType
19
+ ];
18
20
  }
19
21
  }
20
22
  /**
21
23
  * Like `next/navigation`'s `redirect()` but throws a `TRPCError` that later will be handled by Next.js
24
+ * This provides better typesafety than the `next/navigation`'s `redirect()` since the action continues
25
+ * to execute on the frontend even if Next's `redirect()` has a return type of `never`.
22
26
  * @public
23
- */ const redirect = (...args)=>{
24
- throw new TRPCRedirectError(...args);
27
+ * @remark You should only use this if you're also using `nextAppDirCaller`.
28
+ */ const redirect = (url, redirectType)=>{
29
+ // We rethrow this internally so the returntype on the client is undefined.
30
+ return new TRPCRedirectError(url, redirectType);
25
31
  };
26
32
 
27
33
  exports.TRPCRedirectError = TRPCRedirectError;
@@ -5,21 +5,27 @@ import '../../unstable-core-do-not-import/rootConfig.mjs';
5
5
  /**
6
6
  * @internal
7
7
  */ class TRPCRedirectError extends TRPCError {
8
- constructor(...args){
9
- const [url] = args;
8
+ constructor(url, redirectType){
10
9
  super({
11
10
  // TODO(?): This should maybe a custom error code
12
11
  code: 'UNPROCESSABLE_CONTENT',
13
12
  message: `Redirect error to "${url}" that will be handled by Next.js`
14
13
  });
15
- this.args = args;
14
+ this.args = [
15
+ url.toString(),
16
+ redirectType
17
+ ];
16
18
  }
17
19
  }
18
20
  /**
19
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`.
20
24
  * @public
21
- */ const redirect = (...args)=>{
22
- throw new TRPCRedirectError(...args);
25
+ * @remark You should only use this if you're also using `nextAppDirCaller`.
26
+ */ const redirect = (url, redirectType)=>{
27
+ // We rethrow this internally so the returntype on the client is undefined.
28
+ return new TRPCRedirectError(url, redirectType);
23
29
  };
24
30
 
25
31
  export { TRPCRedirectError, redirect };
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 97903,
3
- "bundleOrigSize": 157073,
4
- "bundleReduction": 37.67,
2
+ "bundleSize": 98628,
3
+ "bundleOrigSize": 157786,
4
+ "bundleReduction": 37.49,
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": 10.39,
18
+ "percent": 10.31,
19
19
  "reduction": 0
20
20
  },
21
21
  {
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "removedExports": [],
29
29
  "dependents": [],
30
- "percent": 9.68,
30
+ "percent": 9.61,
31
31
  "reduction": 20.86
32
32
  },
33
33
  {
@@ -43,7 +43,7 @@
43
43
  "/src/unstable-core-do-not-import.ts",
44
44
  "/src/unstable-core-do-not-import/initTRPC.ts"
45
45
  ],
46
- "percent": 6.54,
46
+ "percent": 6.49,
47
47
  "reduction": 59.24
48
48
  },
49
49
  {
@@ -62,7 +62,7 @@
62
62
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts",
63
63
  "/src/unstable-core-do-not-import/initTRPC.ts"
64
64
  ],
65
- "percent": 5.96,
65
+ "percent": 5.91,
66
66
  "reduction": 41.71
67
67
  },
68
68
  {
@@ -78,7 +78,7 @@
78
78
  "dependents": [
79
79
  "/src/adapters/node-http/content-type/form-data/index.ts"
80
80
  ],
81
- "percent": 5.08,
81
+ "percent": 5.05,
82
82
  "reduction": 38
83
83
  },
84
84
  {
@@ -92,7 +92,7 @@
92
92
  ],
93
93
  "removedExports": [],
94
94
  "dependents": [],
95
- "percent": 4.51,
95
+ "percent": 4.48,
96
96
  "reduction": 32.71
97
97
  },
98
98
  {
@@ -106,7 +106,7 @@
106
106
  "dependents": [
107
107
  "/src/adapters/node-http/index.ts"
108
108
  ],
109
- "percent": 4.02,
109
+ "percent": 3.99,
110
110
  "reduction": 13.56
111
111
  },
112
112
  {
@@ -120,7 +120,7 @@
120
120
  "dependents": [
121
121
  "/src/adapters/fetch/index.ts"
122
122
  ],
123
- "percent": 3.54,
123
+ "percent": 3.52,
124
124
  "reduction": 9.9
125
125
  },
126
126
  {
@@ -139,7 +139,7 @@
139
139
  "dependents": [
140
140
  "/src/adapters/aws-lambda/index.ts"
141
141
  ],
142
- "percent": 3.38,
142
+ "percent": 3.35,
143
143
  "reduction": 34.98
144
144
  },
145
145
  {
@@ -156,9 +156,23 @@
156
156
  "/src/observable/index.ts",
157
157
  "/src/observable/operators.ts"
158
158
  ],
159
- "percent": 3.2,
159
+ "percent": 3.17,
160
160
  "reduction": 0.67
161
161
  },
162
+ {
163
+ "id": "/src/adapters/next-app-dir/nextAppDirCaller.ts",
164
+ "size": 3050,
165
+ "origSize": 3903,
166
+ "renderedExports": [
167
+ "nextAppDirCaller"
168
+ ],
169
+ "removedExports": [],
170
+ "dependents": [
171
+ "/src/adapters/next-app-dir.ts"
172
+ ],
173
+ "percent": 3.09,
174
+ "reduction": 21.85
175
+ },
162
176
  {
163
177
  "id": "/src/observable/operators.ts",
164
178
  "size": 2756,
@@ -172,7 +186,7 @@
172
186
  "dependents": [
173
187
  "/src/observable/index.ts"
174
188
  ],
175
- "percent": 2.82,
189
+ "percent": 2.79,
176
190
  "reduction": 0
177
191
  },
178
192
  {
@@ -192,23 +206,9 @@
192
206
  "/src/unstable-core-do-not-import/router.ts",
193
207
  "/src/unstable-core-do-not-import/initTRPC.ts"
194
208
  ],
195
- "percent": 2.8,
209
+ "percent": 2.78,
196
210
  "reduction": 45.94
197
211
  },
198
- {
199
- "id": "/src/adapters/next-app-dir/nextAppDirCaller.ts",
200
- "size": 2732,
201
- "origSize": 3597,
202
- "renderedExports": [
203
- "nextAppDirCaller"
204
- ],
205
- "removedExports": [],
206
- "dependents": [
207
- "/src/adapters/next-app-dir.ts"
208
- ],
209
- "percent": 2.79,
210
- "reduction": 24.05
211
- },
212
212
  {
213
213
  "id": "/src/unstable-core-do-not-import/initTRPC.ts",
214
214
  "size": 2665,
@@ -220,7 +220,7 @@
220
220
  "dependents": [
221
221
  "/src/unstable-core-do-not-import.ts"
222
222
  ],
223
- "percent": 2.72,
223
+ "percent": 2.7,
224
224
  "reduction": 41.3
225
225
  },
226
226
  {
@@ -240,7 +240,7 @@
240
240
  "/src/unstable-core-do-not-import/initTRPC.ts",
241
241
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
242
242
  ],
243
- "percent": 2.68,
243
+ "percent": 2.66,
244
244
  "reduction": 55.5
245
245
  },
246
246
  {
@@ -255,7 +255,7 @@
255
255
  "/src/adapters/fastify/index.ts",
256
256
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
257
257
  ],
258
- "percent": 2.53,
258
+ "percent": 2.51,
259
259
  "reduction": 36.53
260
260
  },
261
261
  {
@@ -267,7 +267,7 @@
267
267
  ],
268
268
  "removedExports": [],
269
269
  "dependents": [],
270
- "percent": 2.5,
270
+ "percent": 2.48,
271
271
  "reduction": 32.42
272
272
  },
273
273
  {
@@ -288,7 +288,7 @@
288
288
  "/src/unstable-core-do-not-import/middleware.ts",
289
289
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
290
290
  ],
291
- "percent": 1.77,
291
+ "percent": 1.76,
292
292
  "reduction": 19.47
293
293
  },
294
294
  {
@@ -302,7 +302,7 @@
302
302
  "dependents": [
303
303
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts"
304
304
  ],
305
- "percent": 1.68,
305
+ "percent": 1.66,
306
306
  "reduction": 34.79
307
307
  },
308
308
  {
@@ -314,7 +314,7 @@
314
314
  ],
315
315
  "removedExports": [],
316
316
  "dependents": [],
317
- "percent": 1.64,
317
+ "percent": 1.62,
318
318
  "reduction": 29.12
319
319
  },
320
320
  {
@@ -328,7 +328,7 @@
328
328
  "dependents": [
329
329
  "/src/adapters/node-http/content-type/json/index.ts"
330
330
  ],
331
- "percent": 1.62,
331
+ "percent": 1.61,
332
332
  "reduction": 0.19
333
333
  },
334
334
  {
@@ -340,7 +340,7 @@
340
340
  ],
341
341
  "removedExports": [],
342
342
  "dependents": [],
343
- "percent": 1.61,
343
+ "percent": 1.6,
344
344
  "reduction": 21.04
345
345
  },
346
346
  {
@@ -353,7 +353,7 @@
353
353
  ],
354
354
  "removedExports": [],
355
355
  "dependents": [],
356
- "percent": 1.56,
356
+ "percent": 1.55,
357
357
  "reduction": 27.6
358
358
  },
359
359
  {
@@ -370,13 +370,13 @@
370
370
  "/src/unstable-core-do-not-import/utils.ts",
371
371
  "/src/unstable-core-do-not-import/router.ts"
372
372
  ],
373
- "percent": 1.54,
373
+ "percent": 1.53,
374
374
  "reduction": 5.58
375
375
  },
376
376
  {
377
377
  "id": "/src/adapters/fastify/fastifyTRPCPlugin.ts",
378
- "size": 1486,
379
- "origSize": 2263,
378
+ "size": 1481,
379
+ "origSize": 2259,
380
380
  "renderedExports": [
381
381
  "fastifyTRPCPlugin"
382
382
  ],
@@ -384,8 +384,8 @@
384
384
  "dependents": [
385
385
  "/src/adapters/fastify/index.ts"
386
386
  ],
387
- "percent": 1.52,
388
- "reduction": 34.33
387
+ "percent": 1.5,
388
+ "reduction": 34.44
389
389
  },
390
390
  {
391
391
  "id": "/src/adapters/node-http/content-type/form-data/streamSlice.ts",
@@ -398,7 +398,7 @@
398
398
  "dependents": [
399
399
  "/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts"
400
400
  ],
401
- "percent": 1.42,
401
+ "percent": 1.41,
402
402
  "reduction": 0
403
403
  },
404
404
  {
@@ -414,7 +414,7 @@
414
414
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts",
415
415
  "/src/unstable-core-do-not-import/error/getErrorShape.ts"
416
416
  ],
417
- "percent": 1.29,
417
+ "percent": 1.28,
418
418
  "reduction": 22.76
419
419
  },
420
420
  {
@@ -439,7 +439,7 @@
439
439
  "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
440
440
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
441
441
  ],
442
- "percent": 1.12,
442
+ "percent": 1.11,
443
443
  "reduction": 23.23
444
444
  },
445
445
  {
@@ -457,6 +457,23 @@
457
457
  "percent": 1.01,
458
458
  "reduction": 56.22
459
459
  },
460
+ {
461
+ "id": "/src/adapters/next-app-dir/redirect.ts",
462
+ "size": 987,
463
+ "origSize": 1143,
464
+ "renderedExports": [
465
+ "TRPCRedirectError",
466
+ "redirect"
467
+ ],
468
+ "removedExports": [],
469
+ "dependents": [
470
+ "/src/adapters/next-app-dir.ts",
471
+ "/src/adapters/next-app-dir/nextAppDirCaller.ts",
472
+ "/src/adapters/next-app-dir/rethrowNextErrors.ts"
473
+ ],
474
+ "percent": 1,
475
+ "reduction": 13.65
476
+ },
460
477
  {
461
478
  "id": "/src/adapters/next-app-dir/formDataToObject.ts",
462
479
  "size": 818,
@@ -468,7 +485,7 @@
468
485
  "dependents": [
469
486
  "/src/adapters/next-app-dir/nextAppDirCaller.ts"
470
487
  ],
471
- "percent": 0.84,
488
+ "percent": 0.83,
472
489
  "reduction": 0.97
473
490
  },
474
491
  {
@@ -529,7 +546,7 @@
529
546
  "/src/unstable-core-do-not-import.ts",
530
547
  "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts"
531
548
  ],
532
- "percent": 0.64,
549
+ "percent": 0.63,
533
550
  "reduction": 43.49
534
551
  },
535
552
  {
@@ -545,22 +562,6 @@
545
562
  "percent": 0.59,
546
563
  "reduction": 65.23
547
564
  },
548
- {
549
- "id": "/src/adapters/next-app-dir/redirect.ts",
550
- "size": 575,
551
- "origSize": 732,
552
- "renderedExports": [
553
- "TRPCRedirectError",
554
- "redirect"
555
- ],
556
- "removedExports": [],
557
- "dependents": [
558
- "/src/adapters/next-app-dir.ts",
559
- "/src/adapters/next-app-dir/rethrowNextErrors.ts"
560
- ],
561
- "percent": 0.59,
562
- "reduction": 21.45
563
- },
564
565
  {
565
566
  "id": "/src/adapters/next-app-dir/rethrowNextErrors.ts",
566
567
  "size": 422,
@@ -599,7 +600,7 @@
599
600
  ],
600
601
  "removedExports": [],
601
602
  "dependents": [],
602
- "percent": 0.35,
603
+ "percent": 0.34,
603
604
  "reduction": 71.37
604
605
  },
605
606
  {
@@ -627,7 +628,7 @@
627
628
  "dependents": [
628
629
  "/src/unstable-core-do-not-import.ts"
629
630
  ],
630
- "percent": 0.23,
631
+ "percent": 0.22,
631
632
  "reduction": 94.55
632
633
  },
633
634
  {
@@ -665,8 +666,8 @@
665
666
  ],
666
667
  "removedExports": [],
667
668
  "dependents": [
668
- "/src/adapters/node-http/content-type/form-data/index.ts",
669
- "/src/adapters/node-http/content-type/json/index.ts"
669
+ "/src/adapters/node-http/content-type/json/index.ts",
670
+ "/src/adapters/node-http/content-type/form-data/index.ts"
670
671
  ],
671
672
  "percent": 0.12,
672
673
  "reduction": 86.68
@@ -802,8 +803,8 @@
802
803
  "removedExports": [],
803
804
  "dependents": [
804
805
  "/src/adapters/express.ts",
805
- "/src/adapters/next.ts",
806
- "/src/adapters/standalone.ts"
806
+ "/src/adapters/standalone.ts",
807
+ "/src/adapters/next.ts"
807
808
  ],
808
809
  "percent": 0,
809
810
  "reduction": 100
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-next.325+f1170b720",
3
+ "version": "11.0.0-next.327+1c757e8d3",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -126,7 +126,7 @@
126
126
  "access": "public"
127
127
  },
128
128
  "devDependencies": {
129
- "@fastify/websocket": "^7.1.2",
129
+ "@fastify/websocket": "^10.0.1",
130
130
  "@tanstack/react-query": "^5.25.0",
131
131
  "@types/aws-lambda": "^8.10.97",
132
132
  "@types/express": "^4.17.17",
@@ -140,7 +140,7 @@
140
140
  "devalue": "^4.0.0",
141
141
  "eslint": "^8.56.0",
142
142
  "express": "^4.17.1",
143
- "fastify": "^4.13.0",
143
+ "fastify": "^4.16.0",
144
144
  "fastify-plugin": "^4.5.0",
145
145
  "hash-sum": "^2.0.0",
146
146
  "myzod": "^1.3.1",
@@ -161,5 +161,5 @@
161
161
  "funding": [
162
162
  "https://trpc.io/sponsor"
163
163
  ],
164
- "gitHead": "f1170b720166af7de6180f5adf856f73c30835bc"
164
+ "gitHead": "1c757e8d30578eb3172495c300383867a0307444"
165
165
  }
@@ -60,7 +60,7 @@ export function fastifyTRPCPlugin<TRouter extends AnyRouter>(
60
60
  ...(opts.trpcOptions as unknown as WSSHandlerOptions<TRouter>),
61
61
  });
62
62
 
63
- fastify.get(prefix ?? '/', { websocket: true }, ({ socket }, req) =>
63
+ fastify.get(prefix ?? '/', { websocket: true }, (socket, req) =>
64
64
  onConnection(socket, req.raw),
65
65
  );
66
66
  }
@@ -12,6 +12,7 @@ import type {
12
12
  Simplify,
13
13
  } from '../../unstable-core-do-not-import/types';
14
14
  import { formDataToObject } from './formDataToObject';
15
+ import { TRPCRedirectError } from './redirect';
15
16
  import { rethrowNextErrors } from './rethrowNextErrors';
16
17
 
17
18
  type ContextCallback<TContext> = object extends TContext
@@ -95,6 +96,10 @@ export function nextAppDirCaller<TContext>(
95
96
  path: '',
96
97
  input,
97
98
  })
99
+ .then((data) => {
100
+ if (data instanceof TRPCRedirectError) throw data;
101
+ return data;
102
+ })
98
103
  .catch(handleError);
99
104
  }
100
105
  case 'query': {
@@ -107,6 +112,10 @@ export function nextAppDirCaller<TContext>(
107
112
  path: '',
108
113
  input,
109
114
  })
115
+ .then((data) => {
116
+ if (data instanceof TRPCRedirectError) throw data;
117
+ return data;
118
+ })
110
119
  .catch(handleError);
111
120
  }
112
121
  default: {
@@ -1,4 +1,4 @@
1
- import type { redirect as __redirect } from 'next/navigation';
1
+ import type { RedirectType } from 'next/navigation';
2
2
  import { TRPCError } from '../../@trpc/server';
3
3
 
4
4
  /**
@@ -6,22 +6,25 @@ import { TRPCError } from '../../@trpc/server';
6
6
  */
7
7
  export class TRPCRedirectError extends TRPCError {
8
8
  public readonly args;
9
- constructor(...args: Parameters<typeof __redirect>) {
10
- const [url] = args;
9
+ constructor(url: URL | string, redirectType?: RedirectType) {
11
10
  super({
12
11
  // TODO(?): This should maybe a custom error code
13
12
  code: 'UNPROCESSABLE_CONTENT',
14
13
  message: `Redirect error to "${url}" that will be handled by Next.js`,
15
14
  });
16
15
 
17
- this.args = args;
16
+ this.args = [url.toString(), redirectType] as const;
18
17
  }
19
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
24
  * @public
25
+ * @remark You should only use this if you're also using `nextAppDirCaller`.
24
26
  */
25
- export const redirect: typeof __redirect = (...args) => {
26
- throw new TRPCRedirectError(...args);
27
+ export const redirect = (url: URL | string, redirectType?: RedirectType) => {
28
+ // We rethrow this internally so the returntype on the client is undefined.
29
+ return new TRPCRedirectError(url, redirectType) as unknown as undefined;
27
30
  };