Skip to content

Interceptor

Interceptor<Desc> = (next) => InterceptorFn<Desc>

Defined in: types.ts:174

A connectrpc-style interceptor for repository operations.

Interceptors form a middleware chain around every repository method. Each interceptor receives a next function and returns a new function that can run logic before and/or after calling next.

const logger: Interceptor<any> = (next) => async (ctx) => {
const start = performance.now();
try {
const result = await next(ctx);
console.log(`${ctx.operation}: ${performance.now() - start}ms`);
return result;
} catch (err) {
console.error(`${ctx.operation} failed:`, err);
throw err;
}
};
// Narrowing on operation:
const auditor: Interceptor<any> = (next) => async (ctx) => {
if (ctx.operation === "create") {
console.log("Creating resource:", ctx.resource);
}
return next(ctx);
};

Desc extends DescMessage

InterceptorFn<Desc>

InterceptorFn<Desc>