import type { ExecutionContext, MiddlewareHandler } from "../types.js"; import type { MiddlewarePipelineOptions } from "./types.js"; import type { RuntimeAdapter } from "../../../platform/adapters/base.js"; /** Implement middleware pipeline. */ export declare class MiddlewarePipeline { private middlewares; private teardownCallbacks; private registry; constructor(_options?: MiddlewarePipelineOptions); use(middleware: MiddlewareHandler): this; useFor(pattern: RegExp, ...handlers: MiddlewareHandler[]): this; onTeardown(cb: () => void | Promise): this; compose(): MiddlewareHandler; execute(req: Request, env?: Record, executionCtx?: ExecutionContext, adapter?: RuntimeAdapter): Promise; /** * Run the middleware pipeline with a final request handler. * Unlike {@link execute}, which returns a 404 when no middleware responds, * `handle` invokes the given handler as the terminal step so middleware * can add headers, validate auth, etc. before the handler runs. * * ```ts * const pipeline = new MiddlewarePipeline().use(cors({ origin: "*" })); * export function GET(req: Request) { * return pipeline.handle(req, () => * Response.json({ ok: true }) * ); * } * ``` */ handle(req: Request, handler: (req: Request) => Response | Promise): Promise; /** * Run every registered teardown callback once, in registration order, * without discarding them, so a module-scoped route pipeline fires them * again on the next request. Called by {@link execute} and {@link handle}: * after response bodies close, are canceled, or error; immediately for * bodyless, locked, or already-read responses and handler/middleware * exceptions. Callback errors are logged and swallowed so cleanup failures * never surface to the client. Locked or already-read response bodies cannot * be wrapped by the Fetch API, so immediate cleanup is the unavoidable * fallback for those invalid response states. */ private runTeardownCallbacks; private withResponseTeardown; private copyResponseMetadata; private wrapBodyWithTeardown; /** * Drain and discard all registered teardown callbacks. Unlike the * per-request cleanup run by {@link execute} / {@link handle}, this clears * the callbacks so they never run again. Use it for one-shot lifecycle * cleanup, e.g. draining a long-lived pipeline on server shutdown. */ teardown(): Promise; getMiddleware(): Array<{ name?: string; order?: number; }>; } //# sourceMappingURL=pipeline.d.ts.map