Middleware
Middleware with phantom output type.
The Output parameter tracks what this middleware adds to context at compile time. The _output brand is phantom — it exists only in the type system for inference, not at runtime.
Created via the middleware factory. Attached to commands via CommandBuilder.middleware().
- Import:
@kjanat/dreamcli - Export kind: type
- Declared in:
src/core/schema/middleware.ts - Source link:
packages/dreamcli/src/core/schema/middleware.ts:108
Signatures
ts
type Middleware<Output extends Record<string, unknown>> = MiddlewareImpl & { _output: Output; };Examples
ts
interface User { id: string; name: string }
const auth = middleware<{ user: User }>(async ({ next }) => {
const user = await getUser();
if (!user) throw new CLIError('Not authenticated', { code: 'AUTH_REQUIRED' });
return next({ user });
});