AIDK API Reference / aidk-kernel / applyMiddleware
Function: applyMiddleware() ​
ts
function applyMiddleware<TArgs, TOutput>(procedure: Procedure<(...args: TArgs) => TOutput>, ...middleware: (
| MiddlewarePipeline
| Middleware<TArgs>)[]): Procedure<(...args: TArgs) => TOutput>;Defined in: packages/kernel/src/procedure.ts:1553
Type-safe helper to apply middleware to a Procedure while preserving types.
This helper ensures that middleware types are correctly matched to the Procedure's argument types, avoiding the need for type assertions.
Type Parameters ​
| Type Parameter |
|---|
TArgs extends any[] |
TOutput |
Parameters ​
| Parameter | Type |
|---|---|
procedure | Procedure<(...args: TArgs) => TOutput> |
...middleware | ( | MiddlewarePipeline | Middleware<TArgs>)[] |
Returns ​
Procedure<(...args: TArgs) => TOutput>
Example ​
typescript
const proc = createProcedure({ name: 'test' }, async (input: string) => input);
const middleware: Middleware<[string]>[] = [...];
const procWithMw = applyMiddleware(proc, middleware);
// procWithMw is still Procedure<[string], string> - types preserved!