export type HttpEntry = {
    listener: Function;
    port: number | string;
    name?: string;
    before?: string;
    after?: string;
    urlPath?: string;
    host?: string;
};
/**
 * Topological sort of middleware entries respecting `before`/`after` constraints.
 * Uses the original registration index as a tiebreaker so config order is preserved
 * when there are no constraints between two entries.
 *
 * `before: 'X'` → this entry must run before the FIRST entry named X.
 * `after: 'X'`  → this entry must run after the LAST entry named X.
 *
 * @param onCycle - called when a cycle is detected; entries are returned unsorted.
 */
export declare function topoSort(entries: HttpEntry[], onCycle?: () => void): HttpEntry[];
/**
 * Builds a linear middleware chain from a sorted array of entries.
 * The first entry in `sorted` is the outermost (called first).
 * `fallback` is invoked when all entries call next() without handling the request.
 */
export declare function buildLinearChain(sorted: HttpEntry[], fallback: Function): Function;
/**
 * Resolves transitive `after` dependencies for a set of entries.
 * If entry A says `after: 'auth'` and auth is in `nameToEntry` but not in `entries`,
 * auth is pulled into the result so that the ordering constraint can be satisfied.
 * `before` constraints do NOT pull in entries — they only affect ordering.
 */
export declare function resolveDeps(entries: HttpEntry[], nameToEntry: Map<string, HttpEntry>): HttpEntry[];
/**
 * Normalizes a urlPath by stripping a single trailing slash (except for the root '/').
 * '/api' and '/api/' are treated equivalently for routing/matching.
 */
export declare function normalizeUrlPath(urlPath: string | undefined): string | undefined;
/**
 * Returns true when `request` satisfies the route's host and urlPath constraints.
 * urlPath matching is prefix-based and segment-boundary-aware:
 *   '/api' matches '/api' and '/api/foo' but NOT '/api2'.
 * Trailing slashes on `route.urlPath` are ignored.
 */
export declare function matchesRoute(request: any, route: {
    host?: string;
    urlPath?: string;
}): boolean;
/**
 * Returns a proxy of `request` with `pathname` and `url` rewritten so that
 * `prefix` is stripped from the path. e.g. prefix='/foo', pathname='/foo/bar' → '/bar'.
 * Trailing slashes on `prefix` are ignored. The strip is computed lazily on each
 * access so that downstream mutations to `request.pathname` remain reflected.
 * The original request object is not mutated.
 */
export declare function stripPrefix(request: any, prefix: string): any;
/**
 * Builds a dispatching chain when sub-routes (urlPath/host) are present.
 *
 * Each sub-route gets its own complete chain. If a sub-route entry declares
 * `after: 'X'`, entry X is pulled in from any route's registry so that the
 * constraint can be satisfied without requiring X to be explicitly registered
 * in the sub-route. This is how auth on the default route propagates into
 * sub-route chains that depend on it.
 *
 * Dispatch priority: host+path > host-only > path-only; longer paths win ties.
 *
 * `requestArgIndex` tells the dispatcher which positional argument carries the request
 * object used for host/path matching. HTTP and upgrade chains pass it at index 0;
 * WebSocket chains pass `(ws, request, chainCompletion)` so request is at index 1.
 * The matched (and prefix-stripped) request is substituted back into the same
 * position before forwarding to the inner chain.
 */
export declare function buildRoutedChain(portEntries: HttpEntry[], fallback: Function, onCycle?: () => void, requestArgIndex?: number): Function;
/**
 * Builds the complete middleware chain for a given port from the full responders list.
 * Uses a flat linear chain when no sub-routes are present (fast path),
 * or a route-dispatching chain when any entry has urlPath or host.
 */
export declare function makeCallbackChain(responders: HttpEntry[], portNum: number | string, fallback: Function, onCycle?: () => void, requestArgIndex?: number): Function;
