import { ExtensionKey, type HttpRequest } from "../http/index.js"; import type { HttpLayer } from "../layer/index.js"; import type { HttpService } from "../service/index.js"; export declare const REQUEST_ID: ExtensionKey; export type MakeRequestId = (req: HttpRequest) => string | null; /** * A layer that manages request IDs for incoming requests. * * This function ensures that each request is associated with a unique * identifier, which can be either provided in the request headers or * dynamically generated. * * @example * ```ts * import { SetRequestIdLayer } from "@taxum/core/middleware/request-id"; * import { m, Router } from "@taxum/core/routing"; * * const router = new Router() * .route("/", m.get(() => "Hello World)) * .layer(SetRequestIdLayer.default()); * ``` */ export declare class SetRequestIdLayer implements HttpLayer { private readonly headerName; private readonly makeRequestId; /** * Creates a new {@link SetRequestIdLayer}. * * @param headerName - the name of the header to be used. * @param makeRequestId - a function to generate a request ID. */ constructor(headerName?: string, makeRequestId?: MakeRequestId); /** * Creates a new middleware with the header name defaulting to `X-Request-Id` * with UUID request IDs. */ static default(): SetRequestIdLayer; layer(inner: HttpService): HttpService; } /** * A layer that propagates a request ID header from the incoming request to the * outgoing response. * * The purpose of this layer is to ensure consistency of the request ID header * across the request-response cycle. If the response does not already include * the request ID header, it will include the one from the incoming request. * Additionally, the request ID is stored in the response extensions for further * processing. * * @example * ```ts * import { PropagateRequestId } from "@taxum/core/middleware/request-id"; * import { m, Router } from "@taxum/core/routing"; * * const router = new Router() * .route("/", m.get(() => "Hello World)) * .layer(PropagateRequestIdLayer.default()); * ``` */ export declare class PropagateRequestIdLayer implements HttpLayer { private readonly headerName; /** * Creates a new {@link PropagateRequestIdLayer}. * * @param headerName - the name of the header to be used. */ constructor(headerName?: string); /** * Creates a new middleware with the header name defaulting to `X-Request-Id`. */ static default(): PropagateRequestIdLayer; layer(inner: HttpService): HttpService; }