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:
42 files changed
+2619
-1170
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import type { GraphNode } from '../graph';
|
||||
import type { GraphView } from '../graph-viz';
|
||||
import type { InspectLine, Explain, ExplainNode, RoutePlan } from './types';
|
||||
|
||||
/** Lists the provider/step/handler chain for a route, in execution order. */
|
||||
export function inspectRoute(routePlans: RoutePlan[], routePath: string, booted: boolean): InspectLine[] {
|
||||
if (!booted) throw new Error('inspect() unavailable before listen() for mesh apps');
|
||||
const plan = routePlans.find((candidate) => candidate.pattern === routePath);
|
||||
if (!plan) throw new Error(`no route: ${routePath}`);
|
||||
return [
|
||||
...plan.providers.map((provider) => ({
|
||||
name: provider.name,
|
||||
kind: 'provider' as const,
|
||||
origin: provider.origin,
|
||||
})),
|
||||
...plan.steps.map((step) => ({ name: step.name, kind: 'step' as const, origin: step.origin })),
|
||||
{ name: plan.handlerName, kind: 'handler' as const, origin: plan.origin },
|
||||
];
|
||||
}
|
||||
|
||||
/** Builds the full dependency-graph view: every provider/step node plus each route's chain. */
|
||||
export function buildGraphView(
|
||||
providerNodes: GraphNode[],
|
||||
stepNodes: GraphNode[],
|
||||
routePlans: RoutePlan[],
|
||||
booted: boolean,
|
||||
): GraphView {
|
||||
if (!booted) throw new Error('graph() unavailable before listen() for mesh apps');
|
||||
return {
|
||||
nodes: [
|
||||
...providerNodes.map((node) => ({
|
||||
name: node.name,
|
||||
kind: 'provider' as const,
|
||||
origin: node.origin,
|
||||
needs: node.needs,
|
||||
provides: node.provides,
|
||||
})),
|
||||
...stepNodes.map((node) => ({
|
||||
name: node.name,
|
||||
kind: 'step' as const,
|
||||
origin: node.origin,
|
||||
needs: node.needs,
|
||||
provides: node.provides,
|
||||
})),
|
||||
],
|
||||
routes: routePlans.map((plan) => ({
|
||||
pattern: plan.pattern,
|
||||
method: plan.method,
|
||||
transport: plan.transport,
|
||||
chain: [...plan.providers.map((node) => node.name), ...plan.steps.map((node) => node.name), plan.handlerName],
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/** Explains a single route: its match criteria and the ordered chain with each node's needs/provides. */
|
||||
export function explainRoute(routePlans: RoutePlan[], routePath: string, booted: boolean): Explain {
|
||||
if (!booted) throw new Error('explain() unavailable before listen() for mesh apps');
|
||||
const plan = routePlans.find((candidate) => candidate.pattern === routePath);
|
||||
if (!plan) throw new Error(`no route: ${routePath}`);
|
||||
const toExplainNode = (node: GraphNode, kind: 'provider' | 'step'): ExplainNode => ({
|
||||
name: node.name,
|
||||
kind,
|
||||
origin: node.origin,
|
||||
needs: node.needs,
|
||||
provides: node.provides,
|
||||
});
|
||||
return {
|
||||
pattern: plan.pattern,
|
||||
method: plan.method,
|
||||
transport: plan.transport,
|
||||
chain: [
|
||||
...plan.providers.map((node) => toExplainNode(node, 'provider')),
|
||||
...plan.steps.map((node) => toExplainNode(node, 'step')),
|
||||
{ name: plan.handlerName, kind: 'handler', origin: plan.origin, needs: plan.needs, provides: [] },
|
||||
],
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user