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
+28
-10
@@ -1,3 +1,4 @@
|
||||
/** Serialized request context sent across the mesh for a scope or route RPC. */
|
||||
export interface RequestEnvelope {
|
||||
method: string;
|
||||
params: Record<string, string>;
|
||||
@@ -6,10 +7,23 @@ export interface RequestEnvelope {
|
||||
headers: Record<string, string | string[] | undefined>;
|
||||
}
|
||||
|
||||
export interface ScopeEntry { token: string; scope: 'app' | 'request' }
|
||||
export interface RouteEntry { method: string; pattern: string }
|
||||
export interface Manifest { scopes: ScopeEntry[]; routes: RouteEntry[] }
|
||||
/** Manifest entry for an exported scope token and its lifetime. */
|
||||
export interface ScopeEntry {
|
||||
token: string;
|
||||
scope: 'app' | 'request';
|
||||
}
|
||||
/** Manifest entry for an exported route. */
|
||||
export interface RouteEntry {
|
||||
method: string;
|
||||
pattern: string;
|
||||
}
|
||||
/** A mesh server's advertised scopes and routes. */
|
||||
export interface Manifest {
|
||||
scopes: ScopeEntry[];
|
||||
routes: RouteEntry[];
|
||||
}
|
||||
|
||||
/** Discriminated union of every message on the mesh wire. */
|
||||
export type Frame =
|
||||
| { type: 'hello'; secret: string }
|
||||
| { type: 'manifest'; scopes: ScopeEntry[]; routes: RouteEntry[] }
|
||||
@@ -19,14 +33,18 @@ export type Frame =
|
||||
|
||||
const TYPES = new Set(['hello', 'manifest', 'rpc-req', 'rpc-res']);
|
||||
|
||||
export function encode(f: Frame): string {
|
||||
return JSON.stringify(f);
|
||||
/** Serialize a frame to a JSON wire string. */
|
||||
export function encode(frame: Frame): string {
|
||||
return JSON.stringify(frame);
|
||||
}
|
||||
|
||||
export function decode(s: string): Frame {
|
||||
const f = JSON.parse(s) as { type?: unknown };
|
||||
if (typeof f.type !== 'string' || !TYPES.has(f.type)) {
|
||||
throw new Error(`unknown frame type: ${String(f.type)}`);
|
||||
/** Parse a wire string into a frame, throwing if the `type` tag is unknown. */
|
||||
export function decode(json: string): Frame {
|
||||
const parsed = JSON.parse(json) as { type?: unknown };
|
||||
|
||||
if (typeof parsed.type !== 'string' || !TYPES.has(parsed.type)) {
|
||||
throw new Error(`unknown frame type: ${String(parsed.type)}`);
|
||||
}
|
||||
return f as Frame;
|
||||
|
||||
return parsed as Frame;
|
||||
}
|
||||
Reference in new issue
Block a user