/** * Middleware Chain * * Runs a chain of middleware functions for stream connections. */ import type { StreamMiddleware, StreamMiddlewareContext, StreamMiddlewareResult } from '@plyaz/types/core'; /** * MiddlewareChain - Runs middleware in sequence * * Each middleware can: * - Continue to next middleware (return { continue: true }) * - Stop the chain (return { continue: false, error: ... }) * - Modify context (return { continue: true, context: { ... } }) * * @example * ```typescript * const chain = new MiddlewareChain(); * chain.use(rateLimitMiddleware); * chain.use(authMiddleware); * * const result = await chain.run(context); * if (!result.continue) { * return new Response(result.error?.message, { status: 429 }); * } * ``` */ export declare class MiddlewareChain { private readonly logger; private readonly middlewares; constructor(); /** * Add a middleware to the chain. * * @param middleware - Middleware function to add * @returns this for chaining */ use(middleware: StreamMiddleware): this; /** * Run all middleware in sequence. * * @param initialContext - Initial context to pass to first middleware * @returns Final result after all middleware have run */ run(initialContext: StreamMiddlewareContext): Promise; /** * Get the number of middleware in the chain. */ get length(): number; /** * Clear all middleware from the chain. */ clear(): void; } //# sourceMappingURL=MiddlewareChain.d.ts.map