Problem
buildMiddlewareChain() wraps every middleware layer and every next() call in an async function. A completely synchronous middleware chain therefore creates and awaits a promise at each layer, including Stacks' normal maintenance pass-through path.
Proposed change
Compose middleware with plain functions. Return synchronous Response values directly, and attach a continuation only when a downstream layer returns a promise. Preserve null-to-200 fallback behavior, synchronous throws, rejected promises, middleware ordering, short circuits, and repeated next() behavior.
Acceptance criteria
- Keep synchronous middleware chains synchronous.
- Preserve asynchronous middleware and error behavior.
- Add deterministic coverage for sync chaining, async chaining, short circuits, and thrown errors.
- Improve representative middleware and downstream Stacks request benchmarks on exact Bun 1.4.2.
- Pass the complete suite, typechecks, lint, and package build.
- Keep stable package publication pending explicit release approval.