feat: beta-hardening — routing, degradation, mesh gate, uploads, @header

Restructure first: split the two oversized files by cohesion (http.ts 449
→ http/{router,request,stream,ws,server,types}; app.ts 556 → app/{types,
introspect,index}), rename cryptic locals, JSDoc the public API, and
extract helpers so no function exceeds the complexity gate (createApp
187 → <15, listen 113 → 6). Public import paths are unchanged (barrels).

On that structure, five features that close the biggest gaps vs
Express/Fastify/Nest for a comparable beta:

- routing: `:name*` catch-all, specificity precedence (static ▸ param ▸
  catch-all, not registration order), and 405 + Allow when a path exists
  under a different method (was 404)
- visible degradation: optional providers that fail boot are summarized on
  listen() and queryable via app.degraded(), instead of a silent warn
- mesh is alpha — gated behind `experimental: true`; createApp throws if
  `mesh` is configured without it
- multipart moves to the optional `busboy` peer dependency (clear 501 when
  absent), keeping the core at one runtime dependency
- `@header('name')` as a singular alias of `@headers`

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-07 12:00:15 -05:00
1 parent 9d79972f62
commit d6c5cee0ee
42 files changed
+2619 -1170

No files matched your search

+11 -7
View File
@@ -2,29 +2,33 @@ import { isHttpError, Redirect, ValidationError } from './signals';
import type { TransformerFn } from './metadata';
import { flattenPath } from './standard-schema';
/** Default transformer: serialize a handler's return value as a JSON `200` response. */
export const JsonTransformer: TransformerFn = (value) => ({
status: 200,
headers: { 'content-type': 'application/json' },
body: JSON.stringify(value),
});
export function errorToResponse(e: unknown): { status: number; headers: Record<string, string>; body: string } {
if (e instanceof ValidationError) {
/** Map a thrown value to a JSON error response (422 for validation, HttpError status, else 500). */
export function errorToResponse(error: unknown): { status: number; headers: Record<string, string>; body: string } {
if (error instanceof ValidationError) {
return {
status: 422,
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
error: 'Validation failed',
source: e.source,
issues: e.issues.map((i) => ({ path: flattenPath(i), message: i.message })),
source: error.source,
issues: error.issues.map((issue) => ({ path: flattenPath(issue), message: issue.message })),
}),
};
}
if (isHttpError(e)) {
if (isHttpError(error)) {
const headers: Record<string, string> = { 'content-type': 'application/json' };
if (e instanceof Redirect) headers.location = e.location;
return { status: e.status, headers, body: JSON.stringify({ error: e.message }) };
if (error instanceof Redirect) headers.location = error.location;
return { status: error.status, headers, body: JSON.stringify({ error: error.message }) };
}
return {
status: 500,
headers: { 'content-type': 'application/json' },