feat: handlers declare deps via arg decorators, graph-validated at boot

This commit is contained in:
chrnx committed 2026-06-26 01:44:57 -05:00
1 parent 5bb825e293
commit 7114bf685e
4 files changed
+39 -6

No files matched your search

+15 -1
View File
@@ -4,6 +4,7 @@ import { Provider, Step, Route, Get, Module, Transformer } from '../src/metadata
import { JsonTransformer } from '../src/transformers';
import { Unauthorized } from '../src/signals';
import { createApp } from '../src/app';
import { needs, param } from '../src/params';
@Provider({ provides: 'db' })
class Db { provide() { return { db: { find: (t: string) => (t === 'good' ? { id: 'u1' } : null) } }; } }
@@ -21,7 +22,7 @@ class Auth {
class UserCtl {
@Get('/:id')
@Transformer(JsonTransformer)
getUser(ctx: any) { return { id: ctx.params.id, user: ctx.user }; }
getUser(@needs('user') user: any, @param('id') id: string) { return { id, user }; }
}
@Module({ mountpoint: '/api', providers: [Db], steps: [Auth], controllers: [UserCtl] })
@@ -76,3 +77,16 @@ test('optional provider failure warns but does not abort boot', async () => {
server.close();
warn.mockRestore();
});
test('boot fails when a handler needs something nothing provides', () => {
@Route('/things')
class ThingCtl {
@Get('/')
list(@needs('missing') _m: any) { return []; }
}
@Module({ mountpoint: '/t', providers: [], steps: [], controllers: [ThingCtl] })
class ThingModule {}
expect(() => createApp({ modules: [ThingModule] }))
.toThrow(/handler 'list' needs 'missing'/);
});