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

+56 -20
View File
@@ -1,45 +1,81 @@
export interface GraphNodeView { name: string; kind: 'provider' | 'step'; origin: string; needs: string[]; provides: string[] }
export interface GraphRouteView { pattern: string; method: string; transport: string; chain: string[] }
export interface GraphView { nodes: GraphNodeView[]; routes: GraphRouteView[] }
/** Renderable view of a graph node (provider or step). */
export interface GraphNodeView {
name: string;
kind: 'provider' | 'step';
origin: string;
needs: string[];
provides: string[];
}
/** Renderable view of a route and the chain of nodes feeding its handler. */
export interface GraphRouteView {
pattern: string;
method: string;
transport: string;
chain: string[];
}
/** Full graph payload consumed by the diagram renderers. */
export interface GraphView {
nodes: GraphNodeView[];
routes: GraphRouteView[];
}
const nid = (s: string) => 'n_' + s.replace(/[^a-zA-Z0-9]/g, '_');
const rid = (s: string) => 'r_' + s.replace(/[^a-zA-Z0-9]/g, '_');
/** Sanitizes a node name into a Mermaid/DOT-safe node id. */
const nid = (name: string) => 'n_' + name.replace(/[^a-zA-Z0-9]/g, '_');
/** Sanitizes a route pattern into a Mermaid/DOT-safe node id. */
const rid = (pattern: string) => 'r_' + pattern.replace(/[^a-zA-Z0-9]/g, '_');
/** Renders the graph view as Mermaid `flowchart` source. */
export function toMermaid(view: GraphView): string {
const known = new Set(view.nodes.map((n) => n.name));
const known = new Set(view.nodes.map((node) => node.name));
const out: string[] = ['flowchart LR'];
for (const n of view.nodes) {
out.push(n.kind === 'provider' ? ` ${nid(n.name)}(["${n.name}"])` : ` ${nid(n.name)}["${n.name}"]`);
for (const node of view.nodes) {
out.push(
node.kind === 'provider' ? ` ${nid(node.name)}(["${node.name}"])` : ` ${nid(node.name)}["${node.name}"]`,
);
}
for (const n of view.nodes) for (const need of n.needs) if (known.has(need)) out.push(` ${nid(need)} --> ${nid(n.name)}`);
for (const r of view.routes) {
out.push(` ${rid(r.pattern)}{{"${r.method} ${r.pattern}"}}`);
for (const c of r.chain) if (known.has(c)) out.push(` ${nid(c)} --> ${rid(r.pattern)}`);
for (const node of view.nodes)
for (const need of node.needs) if (known.has(need)) out.push(` ${nid(need)} --> ${nid(node.name)}`);
for (const route of view.routes) {
out.push(` ${rid(route.pattern)}{{"${route.method} ${route.pattern}"}}`);
for (const link of route.chain) if (known.has(link)) out.push(` ${nid(link)} --> ${rid(route.pattern)}`);
}
return out.join('\n');
}
/** Renders the graph view as Graphviz DOT source. */
export function toDOT(view: GraphView): string {
const known = new Set(view.nodes.map((n) => n.name));
const known = new Set(view.nodes.map((node) => node.name));
const out: string[] = ['digraph green_tea {', ' rankdir=LR;'];
for (const n of view.nodes) {
out.push(` "${n.name}" [shape=${n.kind === 'provider' ? 'ellipse' : 'box'}];`);
for (const node of view.nodes) {
out.push(` "${node.name}" [shape=${node.kind === 'provider' ? 'ellipse' : 'box'}];`);
}
for (const n of view.nodes) for (const need of n.needs) if (known.has(need)) out.push(` "${need}" -> "${n.name}";`);
for (const r of view.routes) {
const label = `${r.method} ${r.pattern}`;
for (const node of view.nodes)
for (const need of node.needs) if (known.has(need)) out.push(` "${need}" -> "${node.name}";`);
for (const route of view.routes) {
const label = `${route.method} ${route.pattern}`;
out.push(` "${label}" [shape=hexagon];`);
for (const c of r.chain) if (known.has(c)) out.push(` "${c}" -> "${label}";`);
for (const link of route.chain) if (known.has(link)) out.push(` "${link}" -> "${label}";`);
}
out.push('}');
return out.join('\n');
}
/** Wraps Mermaid source in a self-contained HTML page that renders it in the browser. */
export function graphHtml(mermaid: string): string {
return [
'<!doctype html><html><head><meta charset="utf-8"><title>green-tea graph</title>',
'<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script></head>',
'<body><pre class="mermaid">', mermaid, '</pre>',
'<body><pre class="mermaid">',
mermaid,
'</pre>',
'<script>mermaid.initialize({ startOnLoad: true });</script></body></html>',
].join('\n');
}