/** * Middleware function type * Middleware function gets `callable` method and arguments with which it will be called. * Must return a Promise which will resolve as array [(new) function, callback] * where: * function - original method, or replace for it (f.e. wrapped). * callback - function which will be called with "promisified" result of execution `callable`, * should return received promise, new promise, or new result value */ export declare type Middleware any = (...args: any[]) => any> = (callable: Callable, args: Parameters) => Promise<[ (...args: Parameters) => ReturnType, ((p: Promise>) => Promise>) | void ]>; export declare class Middlewarer { private middlewares; /** * Add middleware to chain */ use(middleware: Middleware): this; /** * Call method with middlewares chain * * @param callable - original method for call * @param ...args - callable arguments */ call Promise>(callable: Fun, ...args: Parameters): Promise>; /** * Wrap function to execute with middlewares in future * @example * function fn(i: number) { ... } * const wrappedFn = middlewarer.wrap(fn) * fn(10) * * @param callable * @param meta metadata for new method */ wrap Promise>(callable: Fun, meta?: { methodName?: string; }): ((...args: Parameters) => ReturnType) | Fun; /** * Wrap all methods in object * * @param object * @param meta metadata for new method */ wrapObjectMethods(object: any, meta: { namespace: string; }): void; static skipMiddleware(something: T): T & { skipMiddleware: true; }; }