feat: 'did you mean' boot hint, flow compile-time type-test, and demos

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-06-28 02:36:37 -05:00
1 parent cc0044ba6a
commit 9d8088d0a9
7 files changed
+88 -3

No files matched your search

+7
View File
@@ -108,6 +108,13 @@ test('boot fails when a handler needs something nothing provides', () => {
.toThrow(/handler 'list' needs 'missing'/);
});
it('boot error for a misspelled @needs suggests the closest token', () => {
@Step({ provides: 'user', needs: [] }) class Auth { run() { return { user: 1 }; } }
@Route('/u') class Ctl { @Get('/x') x(@needs('usr') u: any) { return { u }; } }
@Module({ mountpoint: '/api', steps: [Auth], controllers: [Ctl] }) class M {}
expect(() => createApp({ modules: [M] })).toThrow(/did you mean 'user'\?/);
});
import { Sse, Ws } from '../src/metadata';
import { inbound } from '../src/params';
import { channel } from '../src/channel';
+11 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it, test } from 'vitest';
import { topoSort, GraphNode, subgraphFor } from '../src/graph';
import { topoSort, GraphNode, subgraphFor, nearest } from '../src/graph';
const node = (name: string, needs: string[], provides: string[]): GraphNode =>
({ name, needs, provides, origin: 'test' });
@@ -41,3 +41,13 @@ describe('subgraphFor', () => {
expect(subgraphFor(['user'], ordered).map((n) => n.name)).not.toContain('audit');
});
});
describe('nearest', () => {
it('suggests a close candidate (edit distance <= 2)', () => {
expect(nearest('usr', ['user', 'config', 'db'])).toBe('user');
expect(nearest('confgi', ['user', 'config'])).toBe('config');
});
it('returns undefined when nothing is close', () => {
expect(nearest('zzzzzz', ['user', 'db'])).toBeUndefined();
});
});
+6
View File
@@ -12,5 +12,11 @@ test('type guarantee holds (this file must typecheck)', () => {
// @ts-expect-error — `user` is not in the accumulated context
.handle((ctx) => ctx.user);
// GUARANTEE: a step can only read tokens produced by PRIOR steps.
flow<{ req: { token: string } }>()
.step('user', (ctx) => ({ user: ctx.req.token })) // produces `user`
// @ts-expect-error — `db` was never produced by a prior step (only `user` was)
.step('next', (ctx) => ({ next: ctx.db }));
expect(true).toBe(true);
});