@trpc/server 11.0.0-next.324 → 11.0.0-next.326

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/adapters/next-app-dir/index.d.ts +1 -0
  2. package/adapters/next-app-dir/index.js +1 -0
  3. package/dist/adapters/aws-lambda/index.js +1 -0
  4. package/dist/adapters/aws-lambda/index.mjs +1 -0
  5. package/dist/adapters/aws-lambda/utils.js +1 -0
  6. package/dist/adapters/aws-lambda/utils.mjs +1 -0
  7. package/dist/adapters/fastify/fastifyRequestHandler.js +1 -0
  8. package/dist/adapters/fastify/fastifyRequestHandler.mjs +1 -0
  9. package/dist/adapters/fetch/fetchRequestHandler.js +1 -0
  10. package/dist/adapters/fetch/fetchRequestHandler.mjs +1 -0
  11. package/dist/adapters/next-app-dir/formDataToObject.d.ts +2 -0
  12. package/dist/adapters/next-app-dir/formDataToObject.d.ts.map +1 -0
  13. package/dist/adapters/next-app-dir/formDataToObject.js +34 -0
  14. package/dist/adapters/next-app-dir/formDataToObject.mjs +32 -0
  15. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +24 -0
  16. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -0
  17. package/dist/adapters/next-app-dir/nextAppDirCaller.js +86 -0
  18. package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +84 -0
  19. package/dist/adapters/next-app-dir/notFound.d.ts +7 -0
  20. package/dist/adapters/next-app-dir/notFound.d.ts.map +1 -0
  21. package/dist/adapters/next-app-dir/notFound.js +16 -0
  22. package/dist/adapters/next-app-dir/notFound.mjs +14 -0
  23. package/dist/adapters/next-app-dir/redirect.d.ts +18 -0
  24. package/dist/adapters/next-app-dir/redirect.d.ts.map +1 -0
  25. package/dist/adapters/next-app-dir/redirect.js +34 -0
  26. package/dist/adapters/next-app-dir/redirect.mjs +31 -0
  27. package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts +6 -0
  28. package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts.map +1 -0
  29. package/dist/adapters/next-app-dir/rethrowNextErrors.js +23 -0
  30. package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +21 -0
  31. package/dist/adapters/next-app-dir.d.ts +4 -0
  32. package/dist/adapters/next-app-dir.d.ts.map +1 -0
  33. package/dist/adapters/next-app-dir.js +11 -0
  34. package/dist/adapters/next-app-dir.mjs +3 -0
  35. package/dist/adapters/next.js +1 -0
  36. package/dist/adapters/next.mjs +1 -0
  37. package/dist/adapters/node-http/content-type/json/getPostBody.js +1 -0
  38. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +1 -0
  39. package/dist/adapters/node-http/content-type/json/index.js +1 -0
  40. package/dist/adapters/node-http/content-type/json/index.mjs +1 -0
  41. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +1 -0
  42. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +1 -0
  43. package/dist/adapters/standalone.js +1 -0
  44. package/dist/adapters/standalone.mjs +1 -0
  45. package/dist/adapters/ws.js +1 -0
  46. package/dist/adapters/ws.mjs +1 -0
  47. package/dist/bundle-analysis.json +158 -73
  48. package/dist/http.js +1 -0
  49. package/dist/http.mjs +1 -0
  50. package/dist/index.js +1 -0
  51. package/dist/index.mjs +1 -0
  52. package/dist/rpc.js +1 -0
  53. package/dist/rpc.mjs +1 -0
  54. package/dist/shared.js +1 -0
  55. package/dist/shared.mjs +1 -0
  56. package/dist/unstable-core-do-not-import/clientish/inference.d.ts +3 -3
  57. package/dist/unstable-core-do-not-import/clientish/inference.d.ts.map +1 -1
  58. package/dist/unstable-core-do-not-import/error/getErrorShape.js +1 -0
  59. package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +1 -0
  60. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +1 -0
  61. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +1 -0
  62. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
  63. package/dist/unstable-core-do-not-import/initTRPC.js +2 -4
  64. package/dist/unstable-core-do-not-import/initTRPC.mjs +2 -4
  65. package/dist/unstable-core-do-not-import/procedure.d.ts +8 -7
  66. package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -1
  67. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +9 -21
  68. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
  69. package/dist/unstable-core-do-not-import/procedureBuilder.js +5 -6
  70. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +6 -7
  71. package/dist/unstable-core-do-not-import/router.d.ts +3 -3
  72. package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
  73. package/dist/unstable-core-do-not-import/utils.d.ts +5 -0
  74. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  75. package/dist/unstable-core-do-not-import/utils.js +9 -0
  76. package/dist/unstable-core-do-not-import/utils.mjs +9 -1
  77. package/dist/unstable-core-do-not-import.js +1 -0
  78. package/dist/unstable-core-do-not-import.mjs +1 -1
  79. package/package.json +8 -3
  80. package/src/adapters/next-app-dir/formDataToObject.ts +36 -0
  81. package/src/adapters/next-app-dir/nextAppDirCaller.ts +129 -0
  82. package/src/adapters/next-app-dir/notFound.ts +12 -0
  83. package/src/adapters/next-app-dir/redirect.ts +30 -0
  84. package/src/adapters/next-app-dir/rethrowNextErrors.ts +25 -0
  85. package/src/adapters/next-app-dir.ts +3 -0
  86. package/src/unstable-core-do-not-import/clientish/inference.ts +9 -5
  87. package/src/unstable-core-do-not-import/initTRPC.ts +2 -6
  88. package/src/unstable-core-do-not-import/procedure.ts +10 -17
  89. package/src/unstable-core-do-not-import/procedureBuilder.ts +34 -49
  90. package/src/unstable-core-do-not-import/router.ts +4 -3
  91. package/src/unstable-core-do-not-import/utils.ts +12 -0
@@ -0,0 +1 @@
1
+ export * from '../../dist/adapters/next-app-dir';
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/adapters/next-app-dir');
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ require('../../unstable-core-do-not-import/utils.js');
3
4
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
4
5
  var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
5
6
  require('../../unstable-core-do-not-import/rootConfig.js');
@@ -1,3 +1,4 @@
1
+ import '../../unstable-core-do-not-import/utils.mjs';
1
2
  import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
2
3
  import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
3
4
  import '../../unstable-core-do-not-import/rootConfig.mjs';
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ require('../../unstable-core-do-not-import/utils.js');
3
4
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
4
5
  require('../../unstable-core-do-not-import/rootConfig.js');
5
6
 
@@ -1,3 +1,4 @@
1
+ import '../../unstable-core-do-not-import/utils.mjs';
1
2
  import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
2
3
  import '../../unstable-core-do-not-import/rootConfig.mjs';
3
4
 
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var node_stream = require('node:stream');
4
+ require('../../unstable-core-do-not-import/utils.js');
4
5
  var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
5
6
  var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
6
7
  require('../../unstable-core-do-not-import/rootConfig.js');
@@ -1,4 +1,5 @@
1
1
  import { Readable } from 'node:stream';
2
+ import '../../unstable-core-do-not-import/utils.mjs';
2
3
  import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
3
4
  import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
4
5
  import '../../unstable-core-do-not-import/rootConfig.mjs';
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ require('../../unstable-core-do-not-import/utils.js');
3
4
  var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
4
5
  var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
5
6
  var toURL = require('../../unstable-core-do-not-import/http/toURL.js');
@@ -1,3 +1,4 @@
1
+ import '../../unstable-core-do-not-import/utils.mjs';
1
2
  import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
2
3
  import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
3
4
  import { toURL } from '../../unstable-core-do-not-import/http/toURL.mjs';
@@ -0,0 +1,2 @@
1
+ export declare function formDataToObject(formData: FormData): Record<string, unknown>;
2
+ //# sourceMappingURL=formDataToObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formDataToObject.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/formDataToObject.ts"],"names":[],"mappings":"AA2BA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,2BAQlD"}
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
4
+ if (typeof path === 'string') {
5
+ path = path.split(/[\.\[\]]/).filter(Boolean);
6
+ }
7
+ if (path.length > 1) {
8
+ const p = path.shift();
9
+ const isArrayIndex = /^\d+$/.test(path[0]);
10
+ obj[p] = obj[p] || (isArrayIndex ? [] : {});
11
+ set(obj[p], path, value);
12
+ return;
13
+ }
14
+ const p1 = path[0];
15
+ if (obj[p1] === undefined) {
16
+ obj[p1] = value;
17
+ } else if (Array.isArray(obj[p1])) {
18
+ obj[p1].push(value);
19
+ } else {
20
+ obj[p1] = [
21
+ obj[p1],
22
+ value
23
+ ];
24
+ }
25
+ }
26
+ function formDataToObject(formData) {
27
+ const obj = {};
28
+ for (const [key, value] of formData.entries()){
29
+ set(obj, key, value);
30
+ }
31
+ return obj;
32
+ }
33
+
34
+ exports.formDataToObject = formDataToObject;
@@ -0,0 +1,32 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */ function set(obj, path, value) {
2
+ if (typeof path === 'string') {
3
+ path = path.split(/[\.\[\]]/).filter(Boolean);
4
+ }
5
+ if (path.length > 1) {
6
+ const p = path.shift();
7
+ const isArrayIndex = /^\d+$/.test(path[0]);
8
+ obj[p] = obj[p] || (isArrayIndex ? [] : {});
9
+ set(obj[p], path, value);
10
+ return;
11
+ }
12
+ const p1 = path[0];
13
+ if (obj[p1] === undefined) {
14
+ obj[p1] = value;
15
+ } else if (Array.isArray(obj[p1])) {
16
+ obj[p1].push(value);
17
+ } else {
18
+ obj[p1] = [
19
+ obj[p1],
20
+ value
21
+ ];
22
+ }
23
+ }
24
+ function formDataToObject(formData) {
25
+ const obj = {};
26
+ for (const [key, value] of formData.entries()){
27
+ set(obj, key, value);
28
+ }
29
+ return obj;
30
+ }
31
+
32
+ export { formDataToObject };
@@ -0,0 +1,24 @@
1
+ import type { ErrorHandlerOptions } from '../../unstable-core-do-not-import/procedure';
2
+ import type { CallerOverride } from '../../unstable-core-do-not-import/procedureBuilder';
3
+ import type { MaybePromise, Simplify } from '../../unstable-core-do-not-import/types';
4
+ type ContextCallback<TContext> = object extends TContext ? {
5
+ createContext?: () => MaybePromise<TContext>;
6
+ } : {
7
+ createContext: () => MaybePromise<TContext>;
8
+ };
9
+ /**
10
+ * Create a caller that works with Next.js React Server Components & Server Actions
11
+ */
12
+ export declare function nextAppDirCaller<TContext>(config: Simplify<{
13
+ /**
14
+ * Transform form data to a `Record` before passing it to the procedure
15
+ * @default true
16
+ */
17
+ normalizeFormData?: boolean;
18
+ /**
19
+ * Called when an error occurs in the handler
20
+ */
21
+ onError?: (opts: ErrorHandlerOptions<TContext>) => void;
22
+ } & ContextCallback<TContext>>): CallerOverride<TContext>;
23
+ export {};
24
+ //# sourceMappingURL=nextAppDirCaller.d.ts.map
@@ -0,0 +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;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"}
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+
3
+ require('../../unstable-core-do-not-import/utils.js');
4
+ var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
5
+ require('../../unstable-core-do-not-import/rootConfig.js');
6
+ var formDataToObject = require('./formDataToObject.js');
7
+ var redirect = require('./redirect.js');
8
+ var rethrowNextErrors = require('./rethrowNextErrors.js');
9
+
10
+ /**
11
+ * Create a caller that works with Next.js React Server Components & Server Actions
12
+ */ function nextAppDirCaller(config) {
13
+ const { normalizeFormData =true } = config;
14
+ const createContext = async ()=>{
15
+ return config?.createContext?.() ?? {};
16
+ };
17
+ return async (opts)=>{
18
+ const ctx = await createContext().catch((cause)=>{
19
+ const error = new TRPCError.TRPCError({
20
+ code: 'INTERNAL_SERVER_ERROR',
21
+ message: 'Failed to create context',
22
+ cause
23
+ });
24
+ throw error;
25
+ });
26
+ const handleError = (cause)=>{
27
+ const error = TRPCError.getTRPCErrorFromUnknown(cause);
28
+ config.onError?.({
29
+ ctx,
30
+ error,
31
+ input: opts.args[0],
32
+ path: '',
33
+ type: opts._def.type
34
+ });
35
+ rethrowNextErrors.rethrowNextErrors(error);
36
+ throw error;
37
+ };
38
+ switch(opts._def.type){
39
+ case 'mutation':
40
+ {
41
+ /**
42
+ * When you wrap an action with useFormState, it gets an extra argument as its first argument.
43
+ * The submitted form data is therefore its second argument instead of its first as it would usually be.
44
+ * The new first argument that gets added is the current state of the form.
45
+ * @see https://react.dev/reference/react-dom/hooks/useFormState#my-action-can-no-longer-read-the-submitted-form-data
46
+ */ let input = opts.args.length === 1 ? opts.args[0] : opts.args[1];
47
+ if (normalizeFormData && input instanceof FormData) {
48
+ input = formDataToObject.formDataToObject(input);
49
+ }
50
+ return await opts.invoke({
51
+ type: opts._def.type,
52
+ ctx,
53
+ getRawInput: async ()=>input,
54
+ path: '',
55
+ input
56
+ }).then((data)=>{
57
+ if (data instanceof redirect.TRPCRedirectError) throw data;
58
+ return data;
59
+ }).catch(handleError);
60
+ }
61
+ case 'query':
62
+ {
63
+ const input1 = opts.args[0];
64
+ return await opts.invoke({
65
+ type: opts._def.type,
66
+ ctx,
67
+ getRawInput: async ()=>input1,
68
+ path: '',
69
+ input: input1
70
+ }).then((data)=>{
71
+ if (data instanceof redirect.TRPCRedirectError) throw data;
72
+ return data;
73
+ }).catch(handleError);
74
+ }
75
+ default:
76
+ {
77
+ throw new TRPCError.TRPCError({
78
+ code: 'NOT_IMPLEMENTED',
79
+ message: `Not implemented for type ${opts._def.type}`
80
+ });
81
+ }
82
+ }
83
+ };
84
+ }
85
+
86
+ exports.nextAppDirCaller = nextAppDirCaller;
@@ -0,0 +1,84 @@
1
+ import '../../unstable-core-do-not-import/utils.mjs';
2
+ import { TRPCError, getTRPCErrorFromUnknown } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
3
+ import '../../unstable-core-do-not-import/rootConfig.mjs';
4
+ import { formDataToObject } from './formDataToObject.mjs';
5
+ import { TRPCRedirectError } from './redirect.mjs';
6
+ import { rethrowNextErrors } from './rethrowNextErrors.mjs';
7
+
8
+ /**
9
+ * Create a caller that works with Next.js React Server Components & Server Actions
10
+ */ function nextAppDirCaller(config) {
11
+ const { normalizeFormData =true } = config;
12
+ const createContext = async ()=>{
13
+ return config?.createContext?.() ?? {};
14
+ };
15
+ return async (opts)=>{
16
+ const ctx = await createContext().catch((cause)=>{
17
+ const error = new TRPCError({
18
+ code: 'INTERNAL_SERVER_ERROR',
19
+ message: 'Failed to create context',
20
+ cause
21
+ });
22
+ throw error;
23
+ });
24
+ const handleError = (cause)=>{
25
+ const error = getTRPCErrorFromUnknown(cause);
26
+ config.onError?.({
27
+ ctx,
28
+ error,
29
+ input: opts.args[0],
30
+ path: '',
31
+ type: opts._def.type
32
+ });
33
+ rethrowNextErrors(error);
34
+ throw error;
35
+ };
36
+ switch(opts._def.type){
37
+ case 'mutation':
38
+ {
39
+ /**
40
+ * When you wrap an action with useFormState, it gets an extra argument as its first argument.
41
+ * The submitted form data is therefore its second argument instead of its first as it would usually be.
42
+ * The new first argument that gets added is the current state of the form.
43
+ * @see https://react.dev/reference/react-dom/hooks/useFormState#my-action-can-no-longer-read-the-submitted-form-data
44
+ */ let input = opts.args.length === 1 ? opts.args[0] : opts.args[1];
45
+ if (normalizeFormData && input instanceof FormData) {
46
+ input = formDataToObject(input);
47
+ }
48
+ return await opts.invoke({
49
+ type: opts._def.type,
50
+ ctx,
51
+ getRawInput: async ()=>input,
52
+ path: '',
53
+ input
54
+ }).then((data)=>{
55
+ if (data instanceof TRPCRedirectError) throw data;
56
+ return data;
57
+ }).catch(handleError);
58
+ }
59
+ case 'query':
60
+ {
61
+ const input1 = opts.args[0];
62
+ return await opts.invoke({
63
+ type: opts._def.type,
64
+ ctx,
65
+ getRawInput: async ()=>input1,
66
+ path: '',
67
+ input: input1
68
+ }).then((data)=>{
69
+ if (data instanceof TRPCRedirectError) throw data;
70
+ return data;
71
+ }).catch(handleError);
72
+ }
73
+ default:
74
+ {
75
+ throw new TRPCError({
76
+ code: 'NOT_IMPLEMENTED',
77
+ message: `Not implemented for type ${opts._def.type}`
78
+ });
79
+ }
80
+ }
81
+ };
82
+ }
83
+
84
+ export { nextAppDirCaller };
@@ -0,0 +1,7 @@
1
+ import type { notFound as __notFound } from 'next/navigation';
2
+ /**
3
+ * Like `next/navigation`'s `notFound()` but throws a `TRPCError` that later will be handled by Next.js
4
+ * @public
5
+ */
6
+ export declare const notFound: typeof __notFound;
7
+ //# sourceMappingURL=notFound.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notFound.d.ts","sourceRoot":"","sources":["../../../src/adapters/next-app-dir/notFound.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG9D;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,UAI7B,CAAC"}
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ require('../../unstable-core-do-not-import/utils.js');
4
+ var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
5
+ require('../../unstable-core-do-not-import/rootConfig.js');
6
+
7
+ /**
8
+ * Like `next/navigation`'s `notFound()` but throws a `TRPCError` that later will be handled by Next.js
9
+ * @public
10
+ */ const notFound = ()=>{
11
+ throw new TRPCError.TRPCError({
12
+ code: 'NOT_FOUND'
13
+ });
14
+ };
15
+
16
+ exports.notFound = notFound;
@@ -0,0 +1,14 @@
1
+ import '../../unstable-core-do-not-import/utils.mjs';
2
+ import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
3
+ import '../../unstable-core-do-not-import/rootConfig.mjs';
4
+
5
+ /**
6
+ * Like `next/navigation`'s `notFound()` but throws a `TRPCError` that later will be handled by Next.js
7
+ * @public
8
+ */ const notFound = ()=>{
9
+ throw new TRPCError({
10
+ code: 'NOT_FOUND'
11
+ });
12
+ };
13
+
14
+ export { notFound };
@@ -0,0 +1,18 @@
1
+ import type { RedirectType } from 'next/navigation';
2
+ import { TRPCError } from '../../@trpc/server';
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare class TRPCRedirectError extends TRPCError {
7
+ readonly args: readonly [string, RedirectType | undefined];
8
+ constructor(url: URL | string, redirectType?: RedirectType);
9
+ }
10
+ /**
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`.
14
+ * @public
15
+ * @remark You should only use this if you're also using `nextAppDirCaller`.
16
+ */
17
+ export declare const redirect: (url: URL | string, redirectType?: RedirectType) => undefined;
18
+ //# sourceMappingURL=redirect.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ require('../../unstable-core-do-not-import/utils.js');
4
+ var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
5
+ require('../../unstable-core-do-not-import/rootConfig.js');
6
+
7
+ /**
8
+ * @internal
9
+ */ class TRPCRedirectError extends TRPCError.TRPCError {
10
+ constructor(url, redirectType){
11
+ super({
12
+ // TODO(?): This should maybe a custom error code
13
+ code: 'UNPROCESSABLE_CONTENT',
14
+ message: `Redirect error to "${url}" that will be handled by Next.js`
15
+ });
16
+ this.args = [
17
+ url.toString(),
18
+ redirectType
19
+ ];
20
+ }
21
+ }
22
+ /**
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`.
26
+ * @public
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);
31
+ };
32
+
33
+ exports.TRPCRedirectError = TRPCRedirectError;
34
+ exports.redirect = redirect;
@@ -0,0 +1,31 @@
1
+ import '../../unstable-core-do-not-import/utils.mjs';
2
+ import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
3
+ import '../../unstable-core-do-not-import/rootConfig.mjs';
4
+
5
+ /**
6
+ * @internal
7
+ */ class TRPCRedirectError extends TRPCError {
8
+ constructor(url, redirectType){
9
+ super({
10
+ // TODO(?): This should maybe a custom error code
11
+ code: 'UNPROCESSABLE_CONTENT',
12
+ message: `Redirect error to "${url}" that will be handled by Next.js`
13
+ });
14
+ this.args = [
15
+ url.toString(),
16
+ redirectType
17
+ ];
18
+ }
19
+ }
20
+ /**
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`.
24
+ * @public
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);
29
+ };
30
+
31
+ export { TRPCRedirectError, redirect };
@@ -0,0 +1,6 @@
1
+ import type { TRPCError } from '../../@trpc/server';
2
+ /**
3
+ * Rethrow errors that should be handled by Next.js
4
+ */
5
+ export declare const rethrowNextErrors: (error: TRPCError) => void;
6
+ //# sourceMappingURL=rethrowNextErrors.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,23 @@
1
+ 'use strict';
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');
6
+ var redirect = require('./redirect.js');
7
+
8
+ /**
9
+ * Rethrow errors that should be handled by Next.js
10
+ */ const rethrowNextErrors = (error)=>{
11
+ if (error.code === 'NOT_FOUND') {
12
+ navigation.notFound();
13
+ }
14
+ if (error instanceof redirect.TRPCRedirectError) {
15
+ navigation.redirect(...error.args);
16
+ }
17
+ const { cause } = error;
18
+ if (redirect$1.isRedirectError(cause) || notFound.isNotFoundError(cause)) {
19
+ throw error.cause;
20
+ }
21
+ };
22
+
23
+ exports.rethrowNextErrors = rethrowNextErrors;
@@ -0,0 +1,21 @@
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';
4
+ import { TRPCRedirectError } from './redirect.mjs';
5
+
6
+ /**
7
+ * Rethrow errors that should be handled by Next.js
8
+ */ const rethrowNextErrors = (error)=>{
9
+ if (error.code === 'NOT_FOUND') {
10
+ notFound();
11
+ }
12
+ if (error instanceof TRPCRedirectError) {
13
+ redirect(...error.args);
14
+ }
15
+ const { cause } = error;
16
+ if (isRedirectError(cause) || isNotFoundError(cause)) {
17
+ throw error.cause;
18
+ }
19
+ };
20
+
21
+ export { rethrowNextErrors };
@@ -0,0 +1,4 @@
1
+ export { nextAppDirCaller as experimental_nextAppDirCaller } from './next-app-dir/nextAppDirCaller';
2
+ export { redirect as experimental_redirect } from './next-app-dir/redirect';
3
+ export { notFound as experimental_notFound } from './next-app-dir/notFound';
4
+ //# sourceMappingURL=next-app-dir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-app-dir.d.ts","sourceRoot":"","sources":["../../src/adapters/next-app-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,IAAI,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AACpG,OAAO,EAAE,QAAQ,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,QAAQ,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var nextAppDirCaller = require('./next-app-dir/nextAppDirCaller.js');
4
+ var redirect = require('./next-app-dir/redirect.js');
5
+ var notFound = require('./next-app-dir/notFound.js');
6
+
7
+
8
+
9
+ exports.experimental_nextAppDirCaller = nextAppDirCaller.nextAppDirCaller;
10
+ exports.experimental_redirect = redirect.redirect;
11
+ exports.experimental_notFound = notFound.notFound;
@@ -0,0 +1,3 @@
1
+ export { nextAppDirCaller as experimental_nextAppDirCaller } from './next-app-dir/nextAppDirCaller.mjs';
2
+ export { redirect as experimental_redirect } from './next-app-dir/redirect.mjs';
3
+ export { notFound as experimental_notFound } from './next-app-dir/notFound.mjs';
@@ -2,6 +2,7 @@
2
2
 
3
3
  var getErrorShape = require('../unstable-core-do-not-import/error/getErrorShape.js');
4
4
  var TRPCError = require('../unstable-core-do-not-import/error/TRPCError.js');
5
+ require('../unstable-core-do-not-import/utils.js');
5
6
  require('../unstable-core-do-not-import/rootConfig.js');
6
7
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
7
8
 
@@ -1,5 +1,6 @@
1
1
  import { getErrorShape } from '../unstable-core-do-not-import/error/getErrorShape.mjs';
2
2
  import { TRPCError } from '../unstable-core-do-not-import/error/TRPCError.mjs';
3
+ import '../unstable-core-do-not-import/utils.mjs';
3
4
  import '../unstable-core-do-not-import/rootConfig.mjs';
4
5
  import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
5
6
 
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ require('../../../../unstable-core-do-not-import/utils.js');
3
4
  var TRPCError = require('../../../../unstable-core-do-not-import/error/TRPCError.js');
4
5
  require('../../../../unstable-core-do-not-import/rootConfig.js');
5
6
 
@@ -1,3 +1,4 @@
1
+ import '../../../../unstable-core-do-not-import/utils.mjs';
1
2
  import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
2
3
  import '../../../../unstable-core-do-not-import/rootConfig.mjs';
3
4
 
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ require('../../../../unstable-core-do-not-import/utils.js');
3
4
  var contentType$1 = require('../../../../unstable-core-do-not-import/http/contentType.js');
4
5
  require('../../../../unstable-core-do-not-import/rootConfig.js');
5
6
  var contentType = require('../../internals/contentType.js');
@@ -1,3 +1,4 @@
1
+ import '../../../../unstable-core-do-not-import/utils.mjs';
1
2
  import { getJsonContentTypeInputs } from '../../../../unstable-core-do-not-import/http/contentType.mjs';
2
3
  import '../../../../unstable-core-do-not-import/rootConfig.mjs';
3
4
  import { createNodeHTTPContentTypeHandler } from '../../internals/contentType.mjs';
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ require('../../unstable-core-do-not-import/utils.js');
3
4
  var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
4
5
  var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
5
6
  require('../../unstable-core-do-not-import/rootConfig.js');
@@ -1,3 +1,4 @@
1
+ import '../../unstable-core-do-not-import/utils.mjs';
1
2
  import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
2
3
  import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
3
4
  import '../../unstable-core-do-not-import/rootConfig.mjs';
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var http = require('node:http');
4
+ require('../unstable-core-do-not-import/utils.js');
4
5
  var toURL = require('../unstable-core-do-not-import/http/toURL.js');
5
6
  require('../unstable-core-do-not-import/rootConfig.js');
6
7
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');