import * as http from 'http'; import { Readable } from 'node:stream'; export { default as bucket } from 'bucket'; type FileInfo = { size: number; type: string | null; modified: Date; }; type ReadOptions = { signal?: AbortSignal; }; type BucketFile = { readonly path: string; readonly name: string; readonly type?: string; exists(opts?: ReadOptions): Promise; info?(opts?: ReadOptions): Promise; write(content: string | Buffer | ReadableStream, options?: { type?: string; } & ReadOptions): Promise; stream(opts?: ReadOptions): ReadableStream; slice?(start: number, end?: number): BucketFile; bytes(opts?: ReadOptions): Promise; remove?(opts?: ReadOptions): Promise; }; type Bucket = { file(name: string): BucketFile; create?(content: string | Buffer | ReadableStream, options?: { type?: string; } & ReadOptions): Promise; folder?(prefix: string): Bucket; }; type UploadValidate = (ctx: Context) => unknown | Promise; type LimitOptions = { maxFileSize?: number | string; maxTotalSize?: number | string; maxFiles?: number; minSize?: number | string; fileType?: string[]; }; type UploadOptions = LimitOptions & { bucket: string | Bucket; validate?: UploadValidate; }; type UploadedFile = { name: string; path: string; type: string; size: number; }; type CorsSettings = { origin: string | boolean; methods: string; headers: string; credentials?: boolean; }; type CorsOptions = boolean | string | string[] | { origin?: string | string[]; methods?: string | Method[]; headers?: string | string[]; credentials?: boolean; }; type LogLevel = "info"; type Logger = { level?: LogLevel; message: (scope: string, message: string) => void; start: (url: string) => void; request: (ctx: Context, res: Response) => void; }; type TrustProxy = boolean | (string & {}); type SecurityOptions = { trustProxy?: TrustProxy; frameguard?: boolean | string; noSniff?: boolean; referrerPolicy?: boolean | string; hsts?: boolean | string; xssProtection?: boolean; traversalProtection?: boolean; maxBodySize?: number | string | false; csp?: boolean | string; coop?: boolean | string; corp?: boolean | string; permissionsPolicy?: string; }; type SecuritySettings = { trustProxy: TrustProxy; traversalProtection: boolean; maxBodySize: number; headers: Record; hsts: string | null; }; type Time = { (name: string): void; times: [string, number][]; headers: () => string; }; type Fn = (ctx: Context) => ReturnType; type RouteCtx = Omit & { params: [RO["params"]] extends [StandardSchemaV1] ? RO["params"] : Params; } & Pick; type Mids = Fn>>[]; type Exact = RouteOptions & { [K in Exclude]: never; }; declare class Router { protected settings?: Settings; middleware: Middleware[]; handlers: Record; self(): this; handle(method: Method, pathOrFn?: any, ...rest: any[]): this; socket(path: Path, ...middleware: Mids): this; socket(...middleware: Fn[]): this; socket>(options: RO, ...middleware: Fn>>[]): this; socket>(path: Path, options: RO, ...middleware: Mids): this; get(path: Path, ...middleware: Mids): this; get(...middleware: Fn[]): this; get>(options: RO, ...middleware: Fn>>[]): this; get>(path: Path, options: RO, ...middleware: Mids): this; head(path: Path, ...middleware: Mids): this; head(...middleware: Fn[]): this; head>(options: RO, ...middleware: Fn>>[]): this; head>(path: Path, options: RO, ...middleware: Mids): this; post(path: Path, ...middleware: Mids): this; post(...middleware: Fn[]): this; post>(options: RO, ...middleware: Fn>>[]): this; post>(path: Path, options: RO, ...middleware: Mids): this; put(path: Path, ...middleware: Mids): this; put(...middleware: Fn[]): this; put>(options: RO, ...middleware: Fn>>[]): this; put>(path: Path, options: RO, ...middleware: Mids): this; patch(path: Path, ...middleware: Mids): this; patch(...middleware: Fn[]): this; patch>(options: RO, ...middleware: Fn>>[]): this; patch>(path: Path, options: RO, ...middleware: Mids): this; delete(path: Path, ...middleware: Mids): this; delete(...middleware: Fn[]): this; delete>(options: RO, ...middleware: Fn>>[]): this; delete>(path: Path, options: RO, ...middleware: Mids): this; options(path: Path, ...middleware: Mids): this; options(...middleware: Fn[]): this; options>(options: RO, ...middleware: Fn>>[]): this; options>(path: Path, options: RO, ...mid: Mids): this; use(...middleware: Fn[]): this; use(router: Router): this; } declare function router(): Router; type Awaitable = T | Promise; type Strategy = "session" | "cookie" | "token" | "jwt"; type AuthProfile = { provider: string; id: string; email: string; name?: string; avatar?: string; accessToken?: string; refreshToken?: string; raw: Record; }; type AuthMeta = { issuedAt: Date; expiresAt?: Date; strategy?: Strategy; provider?: string; }; type AuthClaims = { sub: string; } & Record; type ProviderOptions = { id?: string; secret?: string; scope?: string | string[]; issuer?: string; } & Record; type RedirectTargets = { login?: string | ((user: any, ctx: Context) => Awaitable); logout?: string; error?: string; }; type RedirectOption = string | ((user: any, ctx: Context) => Awaitable) | RedirectTargets; type AuthConfig = { providers: string | readonly string[] | Record; strategy?: Strategy; expires?: string; redirect?: RedirectOption; onLogin?: (profile: AuthProfile, ctx: Context) => Awaitable; getUser?: (id: string, ctx: Context) => Awaitable; toPublicUser?: (user: any) => Awaitable; onLogout?: (id: string, ctx: Context) => Awaitable; }; type AuthVerify = { issuer: string; audience: string | readonly string[]; cookie?: string; audienceClaim?: string | readonly string[]; getUser?: (id: string, ctx: Context) => Awaitable; }; type AuthInstance = { handler: (request: Request) => Awaitable; path?: string; user?: (ctx: Context) => Awaitable; }; type AuthFunction = (ctx: Context) => Awaitable; type AuthOption = string | AuthFunction | AuthConfig | AuthVerify | AuthInstance; type AuthContext = Pick; type AuthEntry = { name: string; providers?: string[]; user: (ctx: AuthContext) => Promise; routes?: () => Router; }; type AuthSettings = AuthEntry; type StandardIssue = { readonly message: string; readonly path?: readonly (PropertyKey | { readonly key: PropertyKey; })[]; }; interface StandardSchemaV1 { readonly "~standard": { readonly version: 1; readonly vendor: string; readonly validate: (value: unknown) => { value: Output; issues?: undefined; } | { issues: readonly StandardIssue[]; } | Promise<{ value: Output; issues?: undefined; } | { issues: readonly StandardIssue[]; }>; readonly types?: { readonly input: Input; readonly output: Output; }; }; } type SchemaOutput = [S] extends [ StandardSchemaV1 ] ? Output : Fallback; type Variables = Record; type RequestError = Error & { code?: string; status?: number; hint?: string; issues?: readonly StandardIssue[]; }; type ExtendError = string | { message: string; status: number; hint?: string; }; interface ServerErrorConstructor { extend(errors: Record): Record; [key: string]: ((vars?: Variables) => ServerError) | any; } declare class ServerError extends Error { code: string; status: number; hint?: string; constructor(code: string, status: number, message: string | ((vars: Variables) => string), vars?: Variables); static extend(errors: Record): Record; } declare const TypedServerError: typeof ServerError & ServerErrorConstructor; type CookieOptions = string | string[] | Cookie | Cookie[] | null; type SendBody = SerializableValue | JSX.Element | Uint8Array | ReadableStream | Readable | Response | Reply$1 | BucketFile | Promise; interface ResponseData { headers: Headers; status?: number; } declare class Reply$1 { res: ResponseData; constructor(); status(status: number): this; type(type?: string): this; download(name?: string): this; headers(key: string | Record, value?: string | string[]): this; cache(value: CacheOption): this; cookies(key: string | Record, value?: CookieOptions): this; json(body: unknown): Promise; redirect(path: string): Promise; file(path: string | BucketFile): Promise; send(input?: SendBody): Promise; } type Params = Reply$1[K] extends (...args: infer A) => any ? A : never; declare const status: (...args: Params<"status">) => Reply$1; declare const headers: (...args: Params<"headers">) => Reply$1; declare const type: (...args: Params<"type">) => Reply$1; declare const cache: (...args: Params<"cache">) => Reply$1; declare const download: (...args: Params<"download">) => Reply$1; declare const cookies: (...args: Params<"cookies">) => Reply$1; declare const send: (...args: Params<"send">) => Promise; declare const json: (...args: Params<"json">) => Promise; declare const file: (...args: Params<"file">) => Promise; declare const redirect: (...args: Params<"redirect">) => Promise; type Cookie = { value?: string | null; path?: string; expires?: number | string | Date; maxAge?: number; httpOnly?: boolean; secure?: boolean; sameSite?: "Strict" | "Lax" | "None"; }; type ExtractPathParams = Path extends `${string}:${infer Param}(${infer Type})?/${infer Rest}` ? `${Param}:${Type}?` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}(${infer Type})?` ? `${Param}:${Type}?` : Path extends `${string}:${infer Param}(${infer Type})/${infer Rest}` ? `${Param}:${Type}` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}(${infer Type})` ? `${Param}:${Type}` : Path extends `${string}:${infer Param}?/${infer Rest}` ? `${Param}?` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}?` ? `${Param}?` : Path extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}` ? Param : never; type ParamTypeMap = { string: string; number: number; date: Date; }; type InferParamType = T extends keyof ParamTypeMap ? ParamTypeMap[T] : string; type ParamsToObject = { [K in Params as K extends `${infer Key}:${infer _Type}?` ? Key : K extends `${infer Key}:${infer _Type}` ? Key : K extends `${infer Key}?` ? Key : K]: K extends `${infer _Key}:${infer Type}?` ? InferParamType | undefined : K extends `${infer _Key}:${infer Type}` ? InferParamType : K extends `${infer _Key}?` ? string | undefined : string; }; type PathToParams = ParamsToObject>; type Reply = ReturnType; type Method = "get" | "post" | "put" | "patch" | "delete" | "head" | "options" | "socket"; type ContextTypes = { user?: any; params?: any; query?: any; body?: any; }; type Field = K extends keyof C ? SchemaOutput : Fallback; type BodyMode = "parse" | "raw" | "stream"; type CacheOption = string | number | false; type RouteSchema = { tags?: string | string[]; title?: string; description?: string; }; type RouteOptions = { schema?: RouteSchema | false; parser?: BodyMode; body?: StandardSchemaV1; query?: StandardSchemaV1; params?: StandardSchemaV1; response?: StandardSchemaV1; cache?: CacheOption; uploads?: string | Bucket | UploadOptions | false; }; type Route = { path: string; options: Omit & { uploads?: Settings["uploads"]; }; fns: Middleware[]; }; type BasicValue = string | number | boolean | null; type SerializableValue = BasicValue | { [key: string]: SerializableValue; } | Array; type OnError = (error: RequestError, ctx: Context) => Response | Promise; type OnResponse = (response: Response, ctx: Context) => Response | void | Promise; type Options = { port?: number; secrets?: string | string[]; public?: string | Bucket; uploads?: string | Bucket | UploadOptions | false; cors?: CorsOptions; auth?: A; openapi?: boolean | string | { path?: string; title?: string; description?: string; version?: string; }; onError?: OnError; onResponse?: OnResponse; log?: LogLevel | boolean; security?: boolean | SecurityOptions; parser?: BodyMode; cache?: CacheOption; }; type Settings = { port: number; secrets: string[]; public?: Bucket; uploads?: ({ bucket: Bucket; validate?: UploadValidate; } & LimitOptions) | null | false; cors?: CorsSettings; auth?: AuthSettings; openapi?: { path: string; title?: string; description?: string; version?: string; }; onError?: OnError; onResponse?: OnResponse; log: Logger; security: SecuritySettings; parser: BodyMode; cache?: CacheOption; }; type Platform = { provider: string | null; runtime: string | null; production: boolean; }; type BunEnv = Record & { upgrade?: (req: Request, options?: { data?: any; }) => boolean; requestIP?: (req: Request) => { address: string; } | null; }; interface ContextExtension { } type Context = { method: Method; ip: string; signal: AbortSignal; headers: Record; cookies: Record; url: URL & { params: Field>; query: Field>; }; options: Settings; platform: Platform; time?: Time; socket?: WebSocket; sockets?: WebSocket[]; user?: Field>; auth?: AuthMeta; init: number; app: Server; } & ("body" extends keyof C ? { body: Field; } : { body?: SerializableValue | Buffer | ReadableStream; }) & ContextExtension; type InlineReply = Response | Reply | BucketFile | { body: string; headers?: Headers; } | SerializableValue | JSX.Element | Buffer | ReadableStream; type Middleware = (ctx: Context) => InlineReply | Promise | void | Promise; declare global { var env: Record; } declare class ValidationError extends TypedServerError { source: "body" | "query" | "params" | "response"; issues: readonly StandardIssue[]; constructor(source: "body" | "query" | "params" | "response", issues: readonly StandardIssue[]); } declare class Server extends Router { settings: Settings; platform: Platform; sockets: WebSocket[]; websocket: any; port?: number; constructor(options?: Options); self(): this; node(): Promise>; fetch(request: Request, env?: BunEnv): Promise; callback(request: Request, context: unknown): Promise; test(): { get: (path: string, options?: { method?: string; signal?: AbortSignal | null; headers?: HeadersInit; cache?: RequestCache; redirect?: RequestRedirect; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; referrer?: string; referrerPolicy?: ReferrerPolicy; window?: null; }) => Promise; head: (path: string, options?: { method?: string; signal?: AbortSignal | null; headers?: HeadersInit; cache?: RequestCache; redirect?: RequestRedirect; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; referrer?: string; referrerPolicy?: ReferrerPolicy; window?: null; }) => Promise; post: (path: string, body?: string | number | boolean | ArrayBuffer | { [key: string]: SerializableValue; } | SerializableValue[] | ReadableStream | Blob | ArrayBufferView | FormData | URLSearchParams, options?: { method?: string; signal?: AbortSignal | null; headers?: HeadersInit; cache?: RequestCache; redirect?: RequestRedirect; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; referrer?: string; referrerPolicy?: ReferrerPolicy; window?: null; }) => Promise; put: (path: string, body?: string | number | boolean | ArrayBuffer | { [key: string]: SerializableValue; } | SerializableValue[] | ReadableStream | Blob | ArrayBufferView | FormData | URLSearchParams, options?: { method?: string; signal?: AbortSignal | null; headers?: HeadersInit; cache?: RequestCache; redirect?: RequestRedirect; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; referrer?: string; referrerPolicy?: ReferrerPolicy; window?: null; }) => Promise; patch: (path: string, body?: string | number | boolean | ArrayBuffer | { [key: string]: SerializableValue; } | SerializableValue[] | ReadableStream | Blob | ArrayBufferView | FormData | URLSearchParams, options?: { method?: string; signal?: AbortSignal | null; headers?: HeadersInit; cache?: RequestCache; redirect?: RequestRedirect; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; referrer?: string; referrerPolicy?: ReferrerPolicy; window?: null; }) => Promise; delete: (path: string, options?: { method?: string; signal?: AbortSignal | null; headers?: HeadersInit; cache?: RequestCache; redirect?: RequestRedirect; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; referrer?: string; referrerPolicy?: ReferrerPolicy; window?: null; }) => Promise; options: (path: string, options?: { method?: string; signal?: AbortSignal | null; headers?: HeadersInit; cache?: RequestCache; redirect?: RequestRedirect; credentials?: RequestCredentials; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; referrer?: string; referrerPolicy?: ReferrerPolicy; window?: null; }) => Promise; readonly cookies: { [k: string]: string; }; clear: () => void; }; } declare function server(options: Omit & { auth: AuthConfig; }): Server<{ user: U; }>; declare function server(options: Omit & { auth: string; }): Server<{ user: AuthProfile; }>; declare function server(options: Omit & { auth: AuthVerify; }): Server<{ user: U; }>; declare function server(options: Omit & { auth: AuthFunction; }): Server<{ user: NonNullable>; }>; declare function server(options?: Options): Server; export { type AuthClaims, type AuthConfig, type AuthEntry, type AuthFunction, type AuthInstance, type AuthMeta, type AuthOption, type AuthProfile, type AuthSettings, type AuthVerify, type BasicValue, type BodyMode, type Bucket, type BucketFile, type BunEnv, type CacheOption, type Context, type ContextExtension, type ContextTypes, type Cookie, type CorsSettings, type ExtractPathParams, type FileInfo, type InferParamType, type InlineReply, type LogLevel, type Logger, type Method, type Middleware, type Options, type ParamTypeMap, type ParamsToObject, type PathToParams, type Platform, type ProviderOptions, type RedirectOption, type RedirectTargets, type RequestError, type Route, type RouteOptions, type RouteSchema, type SchemaOutput, type SecurityOptions, type SecuritySettings, type SerializableValue, Server, TypedServerError as ServerError, type Settings, type StandardIssue, type StandardSchemaV1, type Strategy, type Time, type UploadOptions, type UploadValidate, type UploadedFile, ValidationError, cache, cookies, server as default, download, file, headers, json, redirect, router, send, status, type };