UNPKG

@trpc/server

Version:

The tRPC server library

57 lines (56 loc) • 2.58 kB
import { Ai as Simplify, Ti as MaybePromise, _t as CallerOverride, oi as TRPCError, rt as ErrorHandlerOptions, ur as CreateContextCallback } from "../unstable-core-do-not-import-d-SHdPM9.mjs"; import { notFound as notFound$1, redirect as redirect$1 } from "next/navigation.js"; /** * Makes procedures callable as Next.js server actions and from React * Server Components. Pass it to `.experimental_caller()`. * @see https://trpc.io/docs/client/nextjs/server-actions#1-define-a-base-procedure-with-experimental_caller */ declare function nextAppDirCaller<TContext, TMeta>(config: Simplify<{ /** * Names the procedure from its metadata, for logs and errors, since * server actions have no router path. * @see https://trpc.io/docs/client/nextjs/server-actions#adding-observability-with-metadata */ pathExtractor?: (opts: { meta: TMeta; }) => string; /** * Turns `FormData` input into an object before validation. * @default true */ normalizeFormData?: boolean; /** * Called when a procedure throws. */ onError?: (opts: ErrorHandlerOptions<TContext>) => void; } & CreateContextCallback<TContext, () => MaybePromise<TContext>>>): CallerOverride<TContext>; /** * Taken from `redirect()`'s signature: Next 15 exports `RedirectType` as an * enum, Next 16 only as a value, typed `'push' | 'replace'`. */ type RedirectType = NonNullable<Parameters<typeof redirect$1>[1]>; /** * Like `redirect()` from `next/navigation`, for procedures called through * `nextAppDirCaller`. Return it from a resolver; the caller then * redirects. Its type is `undefined`, which matches what the client gets, * unlike Next.js's `never`. * @public */ declare const redirect: (url: URL | string, redirectType?: RedirectType) => undefined; /** * Like `notFound()` from `next/navigation`, but throws a `NOT_FOUND` * `TRPCError`, which `nextAppDirCaller` turns into Next.js's not-found * page. * @public */ declare const notFound: typeof notFound$1; /** * Turns a caught `TRPCError` into the Next.js control-flow error it stands * for: a `NOT_FOUND` code calls `notFound()`, a `TRPCRedirectError` calls * `redirect()`, and a `notFound()` or `redirect()` error in `cause` is * rethrown. It only takes a `TRPCError`; rethrow Next.js's own errors, such * as those `nextAppDirCaller` throws, yourself. */ export declare const rethrowNextErrors: (error: TRPCError) => void; export { nextAppDirCaller as experimental_nextAppDirCaller, notFound as experimental_notFound, redirect as experimental_redirect }; //# sourceMappingURL=next-app-dir.d.mts.map