import type { AnyExtractor, Extractor } from "../extract/index.js"; import type { HttpRequest, HttpResponseLike } from "../http/index.js"; import type { HttpService } from "../service/index.js"; /** * Represents a function that handles an HTTP request and returns an HTTP * response. * * The response can either be a promise that resolves to an HTTP-like response * object or a direct HTTP-like response object. */ export type Handler = (req: HttpRequest) => Promise | HttpResponseLike; /** * A handler which receives values extracted from the request. */ export type ExtractHandler = (...args: ExtractorResults) => Promise | HttpResponseLike; /** * A builder for extract handlers. */ export type ExtractHandlerBuilder = { handler: (fn: ExtractHandler) => Handler; }; /** * Creates a builder for creating extract-based request handlers. * * Usage: * ```ts * import { createExtractHandler } from "@taxum/core/routing"; * import { pathParam, json } from "@taxum/core/extract"; * import { z } from "zod"; * * const handler = createExtractHandler( * pathParam(z.uuid()), * json(z.object({ name: z.string() })), * ).handler((id, body) => { * // do something with `id` and `body` * }); * ``` */ export declare const createExtractHandler: (...extractors: Extractors) => ExtractHandlerBuilder; /** * Represents the result type extracted from an `Extractor`. * * This utility type is used to infer the output type `T` that is associated * with a given `Extractor`. */ export type ExtractorResult = E extends Extractor ? T : never; /** * Represents the mapped results of a series of extractors. * * This generic type maps over an array of extractors and produces a resulting * type for each extractor within the array. It ensures that the extracted * results align with the respective extractor types. */ export type ExtractorResults = { [K in keyof T]: ExtractorResult; }; /** * A service that wraps a handler function. */ export declare class HandlerService implements HttpService { private readonly handler; constructor(handler: Handler); invoke(req: HttpRequest): Promise; }