@trpc/server
Version:
61 lines (60 loc) • 3.11 kB
text/typescript
import { jn as HTTPBaseHandlerOptions, zn as AnyRouter } from "../../unstable-core-do-not-import-hC2_7K-s.mjs";
import { o as NodeHTTPCreateContextFnOptions, s as NodeHTTPCreateContextOption } from "../../index-DD2oXVyh.mjs";
import { i as WSSHandlerOptions } from "../../ws-DVHbmgfC.mjs";
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
//#region src/adapters/fastify/fastifyRequestHandler.d.ts
/** The options of the Fastify adapter's request handler. */
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
req: TRequest;
res: TResponse;
path: string;
};
/**
* Handles one Fastify request for a router. `fastifyTRPCPlugin` uses it;
* call it yourself to mount tRPC on your own route.
*/
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
//#endregion
//#region src/adapters/fastify/fastifyTRPCPlugin.d.ts
/**
* The options of `fastifyTRPCPlugin`.
* @see https://trpc.io/docs/server/adapters/fastify#fastify-plugin-options
*/
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
/** The path the router is served at, such as `/trpc`. */
prefix?: string;
/**
* Whether to serve WebSockets too. Needs `@fastify/websocket` to be
* registered first.
* @see https://trpc.io/docs/server/adapters/fastify#enable-websockets
*/
useWSS?: boolean;
/**
* The router and handler options. `keepAlive`, `dangerouslyDisablePong`
* and `experimental_encoder` only apply with `useWSS`.
*/
trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply> & Pick<WSSHandlerOptions<TRouter>, 'keepAlive' | 'dangerouslyDisablePong' | 'experimental_encoder'>;
}
/**
* What `createContext` gets in the Fastify adapter: `req`, `res` and the
* request's `info`. With `useWSS`, WebSocket connections get the raw
* `IncomingMessage` as `req` and the `WebSocket` as `res` instead.
* @see https://trpc.io/docs/server/adapters/fastify#create-the-context
*/
export type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
/**
* A Fastify plugin that serves a router over HTTP, and over WebSockets
* with `useWSS`.
* @example
* ```ts
* server.register(fastifyTRPCPlugin, {
* prefix: '/trpc',
* trpcOptions: { router: appRouter, createContext },
* });
* ```
* @see https://trpc.io/docs/server/adapters/fastify#create-fastify-server
*/
export declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
//#endregion
//# sourceMappingURL=index.d.mts.map