/** * @module minions-sdk/middleware * Middleware pipeline for intercepting Minions client operations. * * Middleware functions follow a Koa-style "onion" model: each middleware can * run logic before *and* after the core operation by placing code on either * side of the `await next()` call. Skipping `next()` short-circuits the * pipeline and prevents the core operation from executing. * * @example * ```typescript * const logger: MinionMiddleware = async (ctx, next) => { * console.log(`→ ${ctx.operation}`, ctx.args); * await next(); * console.log(`← ${ctx.operation}`, ctx.result); * }; * ``` */ /** All interceptable operations on the Minions client. */ export type MinionOperation = 'create' | 'update' | 'softDelete' | 'hardDelete' | 'restore' | 'save' | 'load' | 'remove' | 'list' | 'search' | 'listIndex' | 'searchIndex' | 'count'; /** * Context object passed through the middleware pipeline. * * - `operation` — the operation being executed. * - `args` — operation-specific arguments (e.g. `{ typeSlug, input }` for create). * - `result` — populated by the core operation (or a middleware that short-circuits). * - `metadata` — free-form bag for cross-middleware communication. */ export interface MinionContext { /** The operation being intercepted. */ readonly operation: MinionOperation; /** Operation arguments — shape depends on the operation. */ args: Record; /** Result of the operation — populated after the core logic (or by middleware). */ result?: unknown; /** Shared state for cross-middleware communication. */ metadata: Record; } /** Advance to the next middleware (or the core operation). */ export type NextFn = () => Promise; /** * A middleware function that can intercept any Minions client operation. * * Call `await next()` to proceed to the next middleware / core operation. * Omit the `next()` call to short-circuit. */ export type MinionMiddleware = (ctx: MinionContext, next: NextFn) => Promise; /** * Execute a middleware pipeline ending with a core operation. * * Each middleware wraps the next one in an "onion" pattern: * ``` * mw1-before → mw2-before → core → mw2-after → mw1-after * ``` * * @param middlewares - Ordered array of middleware functions. * @param ctx - The context for this operation. * @param core - The core operation to run at the center of the pipeline. */ export declare function runMiddleware(middlewares: readonly MinionMiddleware[], ctx: MinionContext, core: () => Promise): Promise; //# sourceMappingURL=Middleware.d.ts.map