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

+29 -12
View File
@@ -1,10 +1,20 @@
/** Names of every lifecycle event the framework emits over the {@link Bus}. */
export type LifecycleEvent =
| 'boot:provider:start' | 'boot:provider:ok' | 'boot:provider:fail'
| 'request:step:enter' | 'request:step:leave' | 'request:step:error'
| 'stream:open' | 'stream:close' | 'stream:error'
| 'mesh:connect' | 'mesh:disconnect' | 'mesh:rpc:error'
| 'boot:provider:start'
| 'boot:provider:ok'
| 'boot:provider:fail'
| 'request:step:enter'
| 'request:step:leave'
| 'request:step:error'
| 'stream:open'
| 'stream:close'
| 'stream:error'
| 'mesh:connect'
| 'mesh:disconnect'
| 'mesh:rpc:error'
| 'plugin:mounted';
/** Data carried by a lifecycle event: the subject's name plus optional scope, error and timing. */
export interface EventPayload {
name: string;
scope?: string;
@@ -12,19 +22,26 @@ export interface EventPayload {
durationMs?: number;
}
/** In-process pub/sub for framework lifecycle events; observer failures are swallowed so they never break the pipeline. */
export class Bus {
private readonly listeners = new Map<LifecycleEvent, Set<(p: EventPayload) => void>>();
on(event: LifecycleEvent, fn: (p: EventPayload) => void): () => void {
const set = this.listeners.get(event) ?? new Set();
set.add(fn);
this.listeners.set(event, set);
return () => set.delete(fn);
/** Subscribe `listener` to `event`; returns an unsubscribe function. */
on(event: LifecycleEvent, listener: (p: EventPayload) => void): () => void {
const listenerSet = this.listeners.get(event) ?? new Set();
listenerSet.add(listener);
this.listeners.set(event, listenerSet);
return () => listenerSet.delete(listener);
}
emit(event: LifecycleEvent, p: EventPayload): void {
for (const fn of this.listeners.get(event) ?? []) {
try { fn(p); } catch { /* observers must never break the pipeline */ }
/** Dispatch `payload` to every listener of `event`; a throwing listener is isolated and does not affect the others. */
emit(event: LifecycleEvent, payload: EventPayload): void {
for (const listener of this.listeners.get(event) ?? []) {
try {
listener(payload);
} catch {
/* observers must never break the pipeline */
}
}
}
}