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>
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { Bus } from './bus';
|
|
|
|
/** A step or provider a plugin contributes to the graph. */
|
|
export interface ScopeNode {
|
|
kind: 'step' | 'provider';
|
|
name: string;
|
|
needs: string[];
|
|
provides: string[];
|
|
run: (ctx: any) => any;
|
|
}
|
|
|
|
/** The narrow surface a plugin uses to register nodes into the host graph. */
|
|
export interface ScopeApi {
|
|
add(node: ScopeNode): void;
|
|
}
|
|
/** The capabilities handed to a plugin: event subscription and node registration only. */
|
|
export interface PluginApi {
|
|
bus: { on: Bus['on'] };
|
|
scope: ScopeApi;
|
|
}
|
|
/** A plugin: a function that wires itself up through the provided PluginApi. */
|
|
export type Plugin = (api: PluginApi) => void;
|
|
|
|
/** Runs a plugin against a restricted API, then emits `plugin:mounted`. */
|
|
export function mountPlugin(plugin: Plugin, bus: Bus, scope: ScopeApi): void {
|
|
// Hand the plugin ONLY on() and add(). No emit, no other scope. Isolation is structural.
|
|
const api: PluginApi = { bus: { on: bus.on.bind(bus) }, scope };
|
|
plugin(api);
|
|
bus.emit('plugin:mounted', { name: plugin.name || 'anonymous' });
|
|
}
|