@trpc/server 11.28.1 → 11.28.2-canary.4.g7a3f50a24
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.
- package/dist/adapters/next-app-dir.cjs +4 -4
- package/dist/adapters/next-app-dir.d.cts +2 -0
- package/dist/adapters/next-app-dir.d.cts.map +1 -1
- package/dist/adapters/next-app-dir.d.mts +2 -0
- package/dist/adapters/next-app-dir.d.mts.map +1 -1
- package/dist/adapters/next-app-dir.mjs +4 -4
- package/dist/adapters/next-app-dir.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/adapter-aws-lambda/SKILL.md +1 -1
- package/skills/adapter-express/SKILL.md +1 -1
- package/skills/adapter-fastify/SKILL.md +1 -1
- package/skills/adapter-fetch/SKILL.md +1 -1
- package/skills/adapter-standalone/SKILL.md +1 -1
- package/skills/auth/SKILL.md +1 -1
- package/skills/caching/SKILL.md +1 -1
- package/skills/error-handling/SKILL.md +1 -1
- package/skills/middlewares/SKILL.md +1 -1
- package/skills/non-json-content-types/SKILL.md +1 -1
- package/skills/server-setup/SKILL.md +1 -1
- package/skills/server-side-calls/SKILL.md +1 -1
- package/skills/service-oriented-architecture/SKILL.md +1 -1
- package/skills/subscriptions/SKILL.md +1 -1
- package/skills/trpc-router/SKILL.md +1 -1
- package/skills/validators/SKILL.md +1 -1
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +6 -4
|
@@ -90,13 +90,13 @@ function nextAppDirCaller(config) {
|
|
|
90
90
|
cause
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
|
-
const handleError = (cause) => {
|
|
93
|
+
const handleError = (input) => (cause) => {
|
|
94
94
|
var _config$onError;
|
|
95
95
|
const error = require_asyncGeneratorDelegate.getTRPCErrorFromUnknown(cause);
|
|
96
96
|
(_config$onError = config.onError) === null || _config$onError === void 0 || _config$onError.call(config, {
|
|
97
97
|
ctx,
|
|
98
98
|
error,
|
|
99
|
-
input
|
|
99
|
+
input,
|
|
100
100
|
path,
|
|
101
101
|
type: opts._def.type
|
|
102
102
|
});
|
|
@@ -124,7 +124,7 @@ function nextAppDirCaller(config) {
|
|
|
124
124
|
}).then((data) => {
|
|
125
125
|
if (data instanceof TRPCRedirectError) throw data;
|
|
126
126
|
return data;
|
|
127
|
-
}).catch(handleError);
|
|
127
|
+
}).catch(handleError(input));
|
|
128
128
|
}
|
|
129
129
|
case "query": {
|
|
130
130
|
const input = opts.args[0];
|
|
@@ -139,7 +139,7 @@ function nextAppDirCaller(config) {
|
|
|
139
139
|
}).then((data) => {
|
|
140
140
|
if (data instanceof TRPCRedirectError) throw data;
|
|
141
141
|
return data;
|
|
142
|
-
}).catch(handleError);
|
|
142
|
+
}).catch(handleError(input));
|
|
143
143
|
}
|
|
144
144
|
default: throw new require_asyncGeneratorDelegate.TRPCError({
|
|
145
145
|
code: "NOT_IMPLEMENTED",
|
|
@@ -22,6 +22,8 @@ declare function nextAppDirCaller<TContext, TMeta>(config: Simplify<{
|
|
|
22
22
|
normalizeFormData?: boolean;
|
|
23
23
|
/**
|
|
24
24
|
* Called when a procedure throws.
|
|
25
|
+
* `input` is the value the procedure received, so `FormData` is
|
|
26
|
+
* already normalized to an object when `normalizeFormData` is on.
|
|
25
27
|
*/
|
|
26
28
|
onError?: (opts: ErrorHandlerOptions<TContext>) => void;
|
|
27
29
|
} & CreateContextCallback<TContext, () => MaybePromise<TContext>>>): CallerOverride<TContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-app-dir.d.cts","names":["nextRedirect","__notFound"],"sources":["../../src/adapters/next-app-dir/nextAppDirCaller.ts","../../src/adapters/next-app-dir/redirect.ts","../../src/adapters/next-app-dir/notFound.ts","../../src/adapters/next-app-dir/rethrowNextErrors.ts"],"mappings":";;;;;;;;iBAwBgB,iBAAiB,UAAU,OACzC,QAAQ;;;;;;EAOJ,iBAAiB;IAAQ,MAAM;;;;;;EAK/B
|
|
1
|
+
{"version":3,"file":"next-app-dir.d.cts","names":["nextRedirect","__notFound"],"sources":["../../src/adapters/next-app-dir/nextAppDirCaller.ts","../../src/adapters/next-app-dir/redirect.ts","../../src/adapters/next-app-dir/notFound.ts","../../src/adapters/next-app-dir/rethrowNextErrors.ts"],"mappings":";;;;;;;;iBAwBgB,iBAAiB,UAAU,OACzC,QAAQ;;;;;;EAOJ,iBAAiB;IAAQ,MAAM;;;;;;EAK/B;;;;;;EAMA,WAAW,MAAM,oBAAoB;IACnC,sBAAsB,gBAAgB,aAAa,cAExD,eAAe;;;;;KCvCb,eAAe,YAAY,kBAAkBA;;;;;;;;cA2BrC,WAAQ,KAAS,cAAY,eAAiB;;;;;;;cCzB9C,iBAAiBC;;;;;;;;qBCwCjB,oBAAiB,OAAW"}
|
|
@@ -21,6 +21,8 @@ declare function nextAppDirCaller<TContext, TMeta>(config: Simplify<{
|
|
|
21
21
|
normalizeFormData?: boolean;
|
|
22
22
|
/**
|
|
23
23
|
* Called when a procedure throws.
|
|
24
|
+
* `input` is the value the procedure received, so `FormData` is
|
|
25
|
+
* already normalized to an object when `normalizeFormData` is on.
|
|
24
26
|
*/
|
|
25
27
|
onError?: (opts: ErrorHandlerOptions<TContext>) => void;
|
|
26
28
|
} & CreateContextCallback<TContext, () => MaybePromise<TContext>>>): CallerOverride<TContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-app-dir.d.mts","names":["nextRedirect","__notFound"],"sources":["../../src/adapters/next-app-dir/nextAppDirCaller.ts","../../src/adapters/next-app-dir/redirect.ts","../../src/adapters/next-app-dir/notFound.ts","../../src/adapters/next-app-dir/rethrowNextErrors.ts"],"mappings":";;;;;;;iBAwBgB,iBAAiB,UAAU,OACzC,QAAQ;;;;;;EAOJ,iBAAiB;IAAQ,MAAM;;;;;;EAK/B
|
|
1
|
+
{"version":3,"file":"next-app-dir.d.mts","names":["nextRedirect","__notFound"],"sources":["../../src/adapters/next-app-dir/nextAppDirCaller.ts","../../src/adapters/next-app-dir/redirect.ts","../../src/adapters/next-app-dir/notFound.ts","../../src/adapters/next-app-dir/rethrowNextErrors.ts"],"mappings":";;;;;;;iBAwBgB,iBAAiB,UAAU,OACzC,QAAQ;;;;;;EAOJ,iBAAiB;IAAQ,MAAM;;;;;;EAK/B;;;;;;EAMA,WAAW,MAAM,oBAAoB;IACnC,sBAAsB,gBAAgB,aAAa,cAExD,eAAe;;;;;KCvCb,eAAe,YAAY,kBAAkBA;;;;;;;;cA2BrC,WAAQ,KAAS,cAAY,eAAiB;;;;;;;cCzB9C,iBAAiBC;;;;;;;;qBCwCjB,oBAAiB,OAAW"}
|
|
@@ -87,13 +87,13 @@ function nextAppDirCaller(config) {
|
|
|
87
87
|
cause
|
|
88
88
|
});
|
|
89
89
|
});
|
|
90
|
-
const handleError = (cause) => {
|
|
90
|
+
const handleError = (input) => (cause) => {
|
|
91
91
|
var _config$onError;
|
|
92
92
|
const error = getTRPCErrorFromUnknown(cause);
|
|
93
93
|
(_config$onError = config.onError) === null || _config$onError === void 0 || _config$onError.call(config, {
|
|
94
94
|
ctx,
|
|
95
95
|
error,
|
|
96
|
-
input
|
|
96
|
+
input,
|
|
97
97
|
path,
|
|
98
98
|
type: opts._def.type
|
|
99
99
|
});
|
|
@@ -121,7 +121,7 @@ function nextAppDirCaller(config) {
|
|
|
121
121
|
}).then((data) => {
|
|
122
122
|
if (data instanceof TRPCRedirectError) throw data;
|
|
123
123
|
return data;
|
|
124
|
-
}).catch(handleError);
|
|
124
|
+
}).catch(handleError(input));
|
|
125
125
|
}
|
|
126
126
|
case "query": {
|
|
127
127
|
const input = opts.args[0];
|
|
@@ -136,7 +136,7 @@ function nextAppDirCaller(config) {
|
|
|
136
136
|
}).then((data) => {
|
|
137
137
|
if (data instanceof TRPCRedirectError) throw data;
|
|
138
138
|
return data;
|
|
139
|
-
}).catch(handleError);
|
|
139
|
+
}).catch(handleError(input));
|
|
140
140
|
}
|
|
141
141
|
default: throw new TRPCError({
|
|
142
142
|
code: "NOT_IMPLEMENTED",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-app-dir.mjs","names":[],"sources":["../../src/adapters/next-app-dir/redirect.ts","../../src/adapters/next-app-dir/rethrowNextErrors.ts","../../src/adapters/next-app-dir/nextAppDirCaller.ts","../../src/adapters/next-app-dir/notFound.ts"],"sourcesContent":["import type { redirect as nextRedirect } from 'next/navigation.js';\nimport { TRPCError } from '../../@trpc/server';\n\n/**\n * Taken from `redirect()`'s signature: Next 15 exports `RedirectType` as an\n * enum, Next 16 only as a value, typed `'push' | 'replace'`.\n */\ntype RedirectType = NonNullable<Parameters<typeof nextRedirect>[1]>;\n\n/**\n * The error `redirect()` returns, which `nextAppDirCaller` turns into a\n * Next.js redirect.\n * @internal\n */\nexport class TRPCRedirectError extends TRPCError {\n public readonly args;\n constructor(url: URL | string, redirectType?: RedirectType) {\n super({\n // TODO(?): This should maybe a custom error code\n code: 'UNPROCESSABLE_CONTENT',\n message: `Redirect error to \"${url}\" that will be handled by Next.js`,\n });\n\n this.args = [url.toString(), redirectType] as const;\n }\n}\n\n/**\n * Like `redirect()` from `next/navigation`, for procedures called through\n * `nextAppDirCaller`. Return it from a resolver; the caller then\n * redirects. Its type is `undefined`, which matches what the client gets,\n * unlike Next.js's `never`.\n * @public\n */\nexport const redirect = (url: URL | string, redirectType?: RedirectType) => {\n // We rethrow this internally so the returntype on the client is undefined.\n return new TRPCRedirectError(url, redirectType) as unknown as undefined;\n};\n","import * as nextNavigation from 'next/navigation';\nimport type { TRPCError } from '../../@trpc/server';\nimport { TRPCRedirectError } from './redirect';\n\n/**\n * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.\n * Inlining them here instead...\n * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/redirect.ts#L97-L123\n */\nconst REDIRECT_ERROR_CODE = 'NEXT_REDIRECT';\nfunction isRedirectError(error: unknown) {\n if (\n typeof error !== 'object' ||\n error === null ||\n !('digest' in error) ||\n typeof error.digest !== 'string'\n ) {\n return false;\n }\n const [errorCode, type, destination, status] = error.digest.split(';', 4);\n const statusCode = Number(status);\n return (\n errorCode === REDIRECT_ERROR_CODE &&\n (type === 'replace' || type === 'push') &&\n typeof destination === 'string' &&\n !isNaN(statusCode)\n );\n}\n\n/**\n * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.\n * Inlining them here instead...\n * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/not-found.ts#L33-L39\n */\nconst NOT_FOUND_ERROR_CODE = 'NEXT_NOT_FOUND';\nfunction isNotFoundError(error: unknown) {\n if (typeof error !== 'object' || error === null || !('digest' in error)) {\n return false;\n }\n return error.digest === NOT_FOUND_ERROR_CODE;\n}\n\n/**\n * Turns a caught `TRPCError` into the Next.js control-flow error it stands\n * for: a `NOT_FOUND` code calls `notFound()`, a `TRPCRedirectError` calls\n * `redirect()`, and a `notFound()` or `redirect()` error in `cause` is\n * rethrown. It only takes a `TRPCError`; rethrow Next.js's own errors, such\n * as those `nextAppDirCaller` throws, yourself.\n */\nexport const rethrowNextErrors = (error: TRPCError) => {\n if (error.code === 'NOT_FOUND') {\n nextNavigation.notFound();\n }\n if (error instanceof TRPCRedirectError) {\n nextNavigation.redirect(...error.args);\n }\n const { cause } = error;\n\n // Next.js 15 has `unstable_rethrow`. Use that if it exists.\n if (\n 'unstable_rethrow' in nextNavigation &&\n typeof nextNavigation.unstable_rethrow === 'function'\n ) {\n nextNavigation.unstable_rethrow(cause);\n }\n\n // Before Next.js 15, we have to check and rethrow the error manually.\n if (isRedirectError(cause) || isNotFoundError(cause)) {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n throw cause!;\n }\n};\n","import type { CreateContextCallback } from '../../@trpc/server';\nimport { getTRPCErrorFromUnknown, TRPCError } from '../../@trpc/server';\n// oxlint-disable-next-line no-restricted-imports\nimport { formDataToObject } from '../../unstable-core-do-not-import';\n// FIXME: fix lint rule, this is ok\n// oxlint-disable-next-line no-restricted-imports\nimport type { ErrorHandlerOptions } from '../../unstable-core-do-not-import/procedure';\n// FIXME: fix lint rule, this is ok\n// oxlint-disable-next-line no-restricted-imports\nimport type { CallerOverride } from '../../unstable-core-do-not-import/procedureBuilder';\n// FIXME: fix lint rule, this is ok\n// oxlint-disable-next-line no-restricted-imports\nimport type {\n MaybePromise,\n Simplify,\n} from '../../unstable-core-do-not-import/types';\nimport { TRPCRedirectError } from './redirect';\nimport { rethrowNextErrors } from './rethrowNextErrors';\n\n/**\n * Makes procedures callable as Next.js server actions and from React\n * Server Components. Pass it to `.experimental_caller()`.\n * @see https://trpc.io/docs/client/nextjs/server-actions#1-define-a-base-procedure-with-experimental_caller\n */\nexport function nextAppDirCaller<TContext, TMeta>(\n config: Simplify<\n {\n /**\n * Names the procedure from its metadata, for logs and errors, since\n * server actions have no router path.\n * @see https://trpc.io/docs/client/nextjs/server-actions#adding-observability-with-metadata\n */\n pathExtractor?: (opts: { meta: TMeta }) => string;\n /**\n * Turns `FormData` input into an object before validation.\n * @default true\n */\n normalizeFormData?: boolean;\n /**\n * Called when a procedure throws.\n */\n onError?: (opts: ErrorHandlerOptions<TContext>) => void;\n } & CreateContextCallback<TContext, () => MaybePromise<TContext>>\n >,\n): CallerOverride<TContext> {\n const {\n normalizeFormData = true,\n\n // rethrowNextErrors = true\n } = config;\n const createContext = async (): Promise<TContext> => {\n return config?.createContext?.() ?? ({} as TContext);\n };\n\n return async (opts) => {\n const path =\n config.pathExtractor?.({ meta: opts._def.meta as TMeta }) ?? '';\n const ctx: TContext = await createContext().catch((cause) => {\n const error = new TRPCError({\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Failed to create context',\n cause,\n });\n\n throw error;\n });\n\n const handleError = (cause: unknown) => {\n const error = getTRPCErrorFromUnknown(cause);\n\n config.onError?.({\n ctx,\n error,\n input: opts.args[0],\n path,\n type: opts._def.type,\n });\n\n rethrowNextErrors(error);\n\n throw error;\n };\n switch (opts._def.type) {\n case 'mutation': {\n /**\n * When you wrap an action with useFormState, it gets an extra argument as its first argument.\n * The submitted form data is therefore its second argument instead of its first as it would usually be.\n * The new first argument that gets added is the current state of the form.\n * @see https://react.dev/reference/react-dom/hooks/useFormState#my-action-can-no-longer-read-the-submitted-form-data\n */\n let input = opts.args.length === 1 ? opts.args[0] : opts.args[1];\n if (normalizeFormData && input instanceof FormData) {\n input = formDataToObject(input);\n }\n\n return await opts\n .invoke({\n type: opts._def.type,\n ctx,\n getRawInput: async () => input,\n path,\n input,\n signal: undefined,\n batchIndex: 0,\n })\n .then((data) => {\n if (data instanceof TRPCRedirectError) throw data;\n return data;\n })\n .catch(handleError);\n }\n case 'query': {\n const input = opts.args[0];\n return await opts\n .invoke({\n type: opts._def.type,\n ctx,\n getRawInput: async () => input,\n path,\n input,\n signal: undefined,\n batchIndex: 0,\n })\n .then((data) => {\n if (data instanceof TRPCRedirectError) throw data;\n return data;\n })\n .catch(handleError);\n }\n case 'subscription':\n default: {\n throw new TRPCError({\n code: 'NOT_IMPLEMENTED',\n message: `Not implemented for type ${opts._def.type}`,\n });\n }\n }\n };\n}\n","import type { notFound as __notFound } from 'next/navigation.js';\nimport { TRPCError } from '../../@trpc/server';\n\n/**\n * Like `notFound()` from `next/navigation`, but throws a `NOT_FOUND`\n * `TRPCError`, which `nextAppDirCaller` turns into Next.js's not-found\n * page.\n * @public\n */\nexport const notFound: typeof __notFound = () => {\n throw new TRPCError({\n code: 'NOT_FOUND',\n });\n};\n"],"mappings":";;;;;;;;;;AAcA,IAAa,oBAAb,cAAuC,UAAU;CAE/C,YAAY,KAAmB,cAA6B;EAC1D,MAAM;GAEJ,MAAM;GACN,SAAS,sBAAsB,IAAI;EACrC,CAAC;EANa,gBAAA,MAAA,QAAA,KAAA,CAAA;EAQd,KAAK,OAAO,CAAC,IAAI,SAAS,GAAG,YAAY;CAC3C;AACF;;;;;;;;AASA,MAAa,YAAY,KAAmB,iBAAgC;CAE1E,OAAO,IAAI,kBAAkB,KAA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L;CACF;AACF;;;;;;;;ACjIA,MAAa,iBAAoC;CAC/C,MAAM,IAAI,UAAU,EAClB,MAAM,YACR,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"next-app-dir.mjs","names":[],"sources":["../../src/adapters/next-app-dir/redirect.ts","../../src/adapters/next-app-dir/rethrowNextErrors.ts","../../src/adapters/next-app-dir/nextAppDirCaller.ts","../../src/adapters/next-app-dir/notFound.ts"],"sourcesContent":["import type { redirect as nextRedirect } from 'next/navigation.js';\nimport { TRPCError } from '../../@trpc/server';\n\n/**\n * Taken from `redirect()`'s signature: Next 15 exports `RedirectType` as an\n * enum, Next 16 only as a value, typed `'push' | 'replace'`.\n */\ntype RedirectType = NonNullable<Parameters<typeof nextRedirect>[1]>;\n\n/**\n * The error `redirect()` returns, which `nextAppDirCaller` turns into a\n * Next.js redirect.\n * @internal\n */\nexport class TRPCRedirectError extends TRPCError {\n public readonly args;\n constructor(url: URL | string, redirectType?: RedirectType) {\n super({\n // TODO(?): This should maybe a custom error code\n code: 'UNPROCESSABLE_CONTENT',\n message: `Redirect error to \"${url}\" that will be handled by Next.js`,\n });\n\n this.args = [url.toString(), redirectType] as const;\n }\n}\n\n/**\n * Like `redirect()` from `next/navigation`, for procedures called through\n * `nextAppDirCaller`. Return it from a resolver; the caller then\n * redirects. Its type is `undefined`, which matches what the client gets,\n * unlike Next.js's `never`.\n * @public\n */\nexport const redirect = (url: URL | string, redirectType?: RedirectType) => {\n // We rethrow this internally so the returntype on the client is undefined.\n return new TRPCRedirectError(url, redirectType) as unknown as undefined;\n};\n","import * as nextNavigation from 'next/navigation';\nimport type { TRPCError } from '../../@trpc/server';\nimport { TRPCRedirectError } from './redirect';\n\n/**\n * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.\n * Inlining them here instead...\n * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/redirect.ts#L97-L123\n */\nconst REDIRECT_ERROR_CODE = 'NEXT_REDIRECT';\nfunction isRedirectError(error: unknown) {\n if (\n typeof error !== 'object' ||\n error === null ||\n !('digest' in error) ||\n typeof error.digest !== 'string'\n ) {\n return false;\n }\n const [errorCode, type, destination, status] = error.digest.split(';', 4);\n const statusCode = Number(status);\n return (\n errorCode === REDIRECT_ERROR_CODE &&\n (type === 'replace' || type === 'push') &&\n typeof destination === 'string' &&\n !isNaN(statusCode)\n );\n}\n\n/**\n * @remarks The helpers from `next/dist/client/components/*` has been removed in Next.js 15.\n * Inlining them here instead...\n * @see https://github.com/vercel/next.js/blob/5ae286ffd664e5c76841ed64f6e2da85a0835922/packages/next/src/client/components/not-found.ts#L33-L39\n */\nconst NOT_FOUND_ERROR_CODE = 'NEXT_NOT_FOUND';\nfunction isNotFoundError(error: unknown) {\n if (typeof error !== 'object' || error === null || !('digest' in error)) {\n return false;\n }\n return error.digest === NOT_FOUND_ERROR_CODE;\n}\n\n/**\n * Turns a caught `TRPCError` into the Next.js control-flow error it stands\n * for: a `NOT_FOUND` code calls `notFound()`, a `TRPCRedirectError` calls\n * `redirect()`, and a `notFound()` or `redirect()` error in `cause` is\n * rethrown. It only takes a `TRPCError`; rethrow Next.js's own errors, such\n * as those `nextAppDirCaller` throws, yourself.\n */\nexport const rethrowNextErrors = (error: TRPCError) => {\n if (error.code === 'NOT_FOUND') {\n nextNavigation.notFound();\n }\n if (error instanceof TRPCRedirectError) {\n nextNavigation.redirect(...error.args);\n }\n const { cause } = error;\n\n // Next.js 15 has `unstable_rethrow`. Use that if it exists.\n if (\n 'unstable_rethrow' in nextNavigation &&\n typeof nextNavigation.unstable_rethrow === 'function'\n ) {\n nextNavigation.unstable_rethrow(cause);\n }\n\n // Before Next.js 15, we have to check and rethrow the error manually.\n if (isRedirectError(cause) || isNotFoundError(cause)) {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n throw cause!;\n }\n};\n","import type { CreateContextCallback } from '../../@trpc/server';\nimport { getTRPCErrorFromUnknown, TRPCError } from '../../@trpc/server';\n// oxlint-disable-next-line no-restricted-imports\nimport { formDataToObject } from '../../unstable-core-do-not-import';\n// FIXME: fix lint rule, this is ok\n// oxlint-disable-next-line no-restricted-imports\nimport type { ErrorHandlerOptions } from '../../unstable-core-do-not-import/procedure';\n// FIXME: fix lint rule, this is ok\n// oxlint-disable-next-line no-restricted-imports\nimport type { CallerOverride } from '../../unstable-core-do-not-import/procedureBuilder';\n// FIXME: fix lint rule, this is ok\n// oxlint-disable-next-line no-restricted-imports\nimport type {\n MaybePromise,\n Simplify,\n} from '../../unstable-core-do-not-import/types';\nimport { TRPCRedirectError } from './redirect';\nimport { rethrowNextErrors } from './rethrowNextErrors';\n\n/**\n * Makes procedures callable as Next.js server actions and from React\n * Server Components. Pass it to `.experimental_caller()`.\n * @see https://trpc.io/docs/client/nextjs/server-actions#1-define-a-base-procedure-with-experimental_caller\n */\nexport function nextAppDirCaller<TContext, TMeta>(\n config: Simplify<\n {\n /**\n * Names the procedure from its metadata, for logs and errors, since\n * server actions have no router path.\n * @see https://trpc.io/docs/client/nextjs/server-actions#adding-observability-with-metadata\n */\n pathExtractor?: (opts: { meta: TMeta }) => string;\n /**\n * Turns `FormData` input into an object before validation.\n * @default true\n */\n normalizeFormData?: boolean;\n /**\n * Called when a procedure throws.\n * `input` is the value the procedure received, so `FormData` is\n * already normalized to an object when `normalizeFormData` is on.\n */\n onError?: (opts: ErrorHandlerOptions<TContext>) => void;\n } & CreateContextCallback<TContext, () => MaybePromise<TContext>>\n >,\n): CallerOverride<TContext> {\n const {\n normalizeFormData = true,\n\n // rethrowNextErrors = true\n } = config;\n const createContext = async (): Promise<TContext> => {\n return config?.createContext?.() ?? ({} as TContext);\n };\n\n return async (opts) => {\n const path =\n config.pathExtractor?.({ meta: opts._def.meta as TMeta }) ?? '';\n const ctx: TContext = await createContext().catch((cause) => {\n const error = new TRPCError({\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Failed to create context',\n cause,\n });\n\n throw error;\n });\n\n const handleError = (input: unknown) => (cause: unknown) => {\n const error = getTRPCErrorFromUnknown(cause);\n\n config.onError?.({\n ctx,\n error,\n input,\n path,\n type: opts._def.type,\n });\n\n rethrowNextErrors(error);\n\n throw error;\n };\n switch (opts._def.type) {\n case 'mutation': {\n /**\n * When you wrap an action with useFormState, it gets an extra argument as its first argument.\n * The submitted form data is therefore its second argument instead of its first as it would usually be.\n * The new first argument that gets added is the current state of the form.\n * @see https://react.dev/reference/react-dom/hooks/useFormState#my-action-can-no-longer-read-the-submitted-form-data\n */\n let input = opts.args.length === 1 ? opts.args[0] : opts.args[1];\n if (normalizeFormData && input instanceof FormData) {\n input = formDataToObject(input);\n }\n\n return await opts\n .invoke({\n type: opts._def.type,\n ctx,\n getRawInput: async () => input,\n path,\n input,\n signal: undefined,\n batchIndex: 0,\n })\n .then((data) => {\n if (data instanceof TRPCRedirectError) throw data;\n return data;\n })\n .catch(handleError(input));\n }\n case 'query': {\n const input = opts.args[0];\n return await opts\n .invoke({\n type: opts._def.type,\n ctx,\n getRawInput: async () => input,\n path,\n input,\n signal: undefined,\n batchIndex: 0,\n })\n .then((data) => {\n if (data instanceof TRPCRedirectError) throw data;\n return data;\n })\n .catch(handleError(input));\n }\n case 'subscription':\n default: {\n throw new TRPCError({\n code: 'NOT_IMPLEMENTED',\n message: `Not implemented for type ${opts._def.type}`,\n });\n }\n }\n };\n}\n","import type { notFound as __notFound } from 'next/navigation.js';\nimport { TRPCError } from '../../@trpc/server';\n\n/**\n * Like `notFound()` from `next/navigation`, but throws a `NOT_FOUND`\n * `TRPCError`, which `nextAppDirCaller` turns into Next.js's not-found\n * page.\n * @public\n */\nexport const notFound: typeof __notFound = () => {\n throw new TRPCError({\n code: 'NOT_FOUND',\n });\n};\n"],"mappings":";;;;;;;;;;AAcA,IAAa,oBAAb,cAAuC,UAAU;CAE/C,YAAY,KAAmB,cAA6B;EAC1D,MAAM;GAEJ,MAAM;GACN,SAAS,sBAAsB,IAAI;EACrC,CAAC;EANa,gBAAA,MAAA,QAAA,KAA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M;KAC7C,OAAO;IACT,CAAC,CAAC,CACD,MAAM,YAAY,KAAK,CAAC;GAC7B;GAEA,SACE,MAAM,IAAI,UAAU;IAClB,MAAM;IACN,SAAS,4BAA4B,KAAK,KAAK;GACjD,CAAC;EAEL;CACF;AACF;;;;;;;;ACnIA,MAAa,iBAAoC;CAC/C,MAAM,IAAI,UAAU,EAClB,MAAM,YACR,CAAC;AACH"}
|
package/package.json
CHANGED
package/skills/auth/SKILL.md
CHANGED
package/skills/caching/SKILL.md
CHANGED
|
@@ -10,7 +10,7 @@ sources:
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: composition
|
|
12
12
|
library: trpc
|
|
13
|
-
library_version: 11.28.
|
|
13
|
+
library_version: 11.28.2-canary.4.g7a3f50a24
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
<!-- Generated from www/v11/docs/server/service-oriented-architecture.md by www/build/skills.ts. Edit the docs instead. -->
|
|
@@ -38,6 +38,8 @@ export function nextAppDirCaller<TContext, TMeta>(
|
|
|
38
38
|
normalizeFormData?: boolean;
|
|
39
39
|
/**
|
|
40
40
|
* Called when a procedure throws.
|
|
41
|
+
* `input` is the value the procedure received, so `FormData` is
|
|
42
|
+
* already normalized to an object when `normalizeFormData` is on.
|
|
41
43
|
*/
|
|
42
44
|
onError?: (opts: ErrorHandlerOptions<TContext>) => void;
|
|
43
45
|
} & CreateContextCallback<TContext, () => MaybePromise<TContext>>
|
|
@@ -65,13 +67,13 @@ export function nextAppDirCaller<TContext, TMeta>(
|
|
|
65
67
|
throw error;
|
|
66
68
|
});
|
|
67
69
|
|
|
68
|
-
const handleError = (cause: unknown) => {
|
|
70
|
+
const handleError = (input: unknown) => (cause: unknown) => {
|
|
69
71
|
const error = getTRPCErrorFromUnknown(cause);
|
|
70
72
|
|
|
71
73
|
config.onError?.({
|
|
72
74
|
ctx,
|
|
73
75
|
error,
|
|
74
|
-
input
|
|
76
|
+
input,
|
|
75
77
|
path,
|
|
76
78
|
type: opts._def.type,
|
|
77
79
|
});
|
|
@@ -107,7 +109,7 @@ export function nextAppDirCaller<TContext, TMeta>(
|
|
|
107
109
|
if (data instanceof TRPCRedirectError) throw data;
|
|
108
110
|
return data;
|
|
109
111
|
})
|
|
110
|
-
.catch(handleError);
|
|
112
|
+
.catch(handleError(input));
|
|
111
113
|
}
|
|
112
114
|
case 'query': {
|
|
113
115
|
const input = opts.args[0];
|
|
@@ -125,7 +127,7 @@ export function nextAppDirCaller<TContext, TMeta>(
|
|
|
125
127
|
if (data instanceof TRPCRedirectError) throw data;
|
|
126
128
|
return data;
|
|
127
129
|
})
|
|
128
|
-
.catch(handleError);
|
|
130
|
+
.catch(handleError(input));
|
|
129
131
|
}
|
|
130
132
|
case 'subscription':
|
|
131
133
|
default: {
|