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

+9 -5
View File
@@ -25,12 +25,12 @@ class TeacupModule {}
describe('mesh skeleton integration', () => {
it('teacup resolves remote app-scope + request-scope into a local handler', async () => {
const teapot = createApp({ modules: [TeapotModule], mesh: { secret: SECRET } });
const teapot = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: SECRET } });
const tServer = await teapot.listen(0);
const tPort = (tServer.address() as any).port;
const url = `ws://127.0.0.1:${tPort}/__mesh__/control`;
const teacup = createApp({ modules: [TeacupModule], mesh: { teapots: [{ url, secret: SECRET }] } });
const teacup = createApp({ modules: [TeacupModule], experimental: true, mesh: { teapots: [{ url, secret: SECRET }] } });
const cServer = await teacup.listen(0);
const cPort = (cServer.address() as any).port;
@@ -40,8 +40,12 @@ describe('mesh skeleton integration', () => {
tServer.close(); cServer.close();
});
it('mesh is gated behind experimental: true', () => {
expect(() => createApp({ modules: [TeapotModule], mesh: { secret: SECRET } })).toThrow(/alpha feature/);
});
it('teapot still serves its own local route (regression)', async () => {
const app = createApp({ modules: [TeapotModule], mesh: { secret: SECRET } });
const app = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: SECRET } });
const s = await app.listen(0); const p = (s.address() as any).port;
const res = await fetch(`http://127.0.0.1:${p}/api/remote/ping`);
expect(await res.json()).toEqual({ pong: true });
@@ -49,9 +53,9 @@ describe('mesh skeleton integration', () => {
});
it('rejects a bad secret (teacup boot fails)', async () => {
const teapot = createApp({ modules: [TeapotModule], mesh: { secret: SECRET } });
const teapot = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: SECRET } });
const tServer = await teapot.listen(0); const tPort = (tServer.address() as any).port;
const teacup = createApp({ modules: [TeacupModule], mesh: { teapots: [{ url: `ws://127.0.0.1:${tPort}/__mesh__/control`, secret: 'WRONG' }], timeoutMs: 800 } });
const teacup = createApp({ modules: [TeacupModule], experimental: true, mesh: { teapots: [{ url: `ws://127.0.0.1:${tPort}/__mesh__/control`, secret: 'WRONG' }], timeoutMs: 800 } });
await expect(teacup.listen(0)).rejects.toThrow();
tServer.close();
});