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
@@ -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();
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ const fakeLink = (calls: any[]): Link => ({
|
||||
describe('teacup buildRemote', () => {
|
||||
it('makes a provider node (app) and a step node (request) with RPC runners returning merge objects', async () => {
|
||||
const calls: any[] = [];
|
||||
const { providers, steps } = buildRemote(fakeLink(calls), 'ws://t');
|
||||
const { providers, steps } = buildRemote(fakeLink(calls));
|
||||
expect(providers.map((p) => p.name)).toEqual(['config']);
|
||||
expect(steps.map((s) => s.name)).toEqual(['auth']);
|
||||
expect(await providers[0].run({})).toEqual({ config: { url: 'db://x' } });
|
||||
@@ -22,7 +22,7 @@ describe('teacup buildRemote', () => {
|
||||
|
||||
it('makes a proxy route entry with method+pattern', async () => {
|
||||
const calls: any[] = [];
|
||||
const { routes } = buildRemote(fakeLink(calls), 'ws://t');
|
||||
const { routes } = buildRemote(fakeLink(calls));
|
||||
expect(routes[0]).toMatchObject({ method: 'GET', pattern: '/u/:id' });
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user