Skip to content

tRPC v12 isn’t on npm yet. The @trpc12/* packages on this site can’t be installed until it’s released. Use v11 today

tRPC

Bun

Bun.serve takes handler.fetch; WebSockets run on Effect's Bun server.

module "bun"Bun.function serve<undefined, never>(options: Bun.Serve.Options<undefined, never>): Bun.Server<undefined>serve({ Serve.HostnamePortServeOptions<WebSocketData>.port?: string | number | undefinedport: 3000, fetch: (request: Request) => Promise<Response>fetch: const handler: FetchHandler<undefined>handler.FetchHandler<undefined>.fetch: (request: Request) => Promise<Response>fetch });

Bun's server WebSockets aren't web-standard WebSockets, so for WebSockets run serve(handler) on BunHttpServer.layer from @effect/platform-bun:

import { import BunHttpServerBunHttpServer, import BunRuntimeBunRuntime } from '@effect/platform-bun';
import { import LayerLayer } from 'effect';
import { function serve(handler: FetchLike | (FetchLike & WebSocketHandlerLike), opts?: HttpOptions): Layer.Layer<never, never, HttpServer>serve } from '@trpc12/trpc/http';

function serve(handler: FetchLike | (FetchLike & WebSocketHandlerLike), opts?: HttpOptions): Layer.Layer<never, never, HttpServer>serve(const handler: FetchHandler<undefined>handler).Pipeable.pipe<Layer.Layer<never, never, HttpServer>, Layer.Layer<never, ServeError, never>, Effect<never, ServeError, never>, void>(this: Layer.Layer<never, never, HttpServer>, ab: (_: Layer.Layer<never, never, HttpServer>) => Layer.Layer<never, ServeError, never>, bc: (_: Layer.Layer<never, ServeError, never>) => Effect<never, ServeError, never>, cd: (_: Effect<never, ServeError, never>) => void): void (+21 overloads)pipe(
  import LayerLayer.const provide: <never, ServeError, HttpServer | HttpPlatform | Generator | BunServices>(that: Layer.Layer<HttpServer | HttpPlatform | Generator | BunServices, ServeError, never>) => <RIn2, E2, ROut2>(self: Layer.Layer<ROut2, E2, RIn2>) => Layer.Layer<ROut2, ServeError | E2, Exclude<RIn2, HttpServer | HttpPlatform | Generator | BunServices>> (+3 overloads)provide(import BunHttpServerBunHttpServer.
const layer: <string>(options: BunHttpServer.ServeOptions<string> & {
    readonly disablePreemptiveShutdown?: boolean | undefined;
    readonly gracefulShutdownTimeout?: Input | undefined;
    readonly websocket?: BunHttpServer.WebSocketOptions | undefined;
}) => Layer.Layer<HttpServer | HttpPlatform | Generator | BunServices, ServeError>
layer
({ Serve.HostnamePortServeOptions<WebSocketData>.port?: string | number | undefinedport: 3000 })),
import LayerLayer.const launch: <RIn, E, ROut>(self: Layer.Layer<ROut, E, RIn>) => Effect<never, E, RIn>launch, import BunRuntimeBunRuntime.
const runMain: {
    (options?: {
        readonly disableErrorReporting?: boolean | undefined;
        readonly teardown?: Teardown | undefined;
    }): <E, A>(effect: Effect<A, E>) => void;
    <E, A>(effect: Effect<A, E>, options?: {
        readonly disableErrorReporting?: boolean | undefined;
        readonly teardown?: Teardown | undefined;
    }): void;
}
runMain
,
);

CI runs a suite on Bun this way (pnpm test:bun): batched queries, files, SSE with resume, wsLink, and aborting on disconnect.