import { Action } from "@rarible/action"; import CallableInstance from "callable-instance"; import { MethodWithPrepare } from "../../types/common"; import type { PreparedFillInfo } from "../../types/order/fill/domain"; /** * 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 type Middleware any = (...args: any[]) => any> = (callable: Callable, args: Parameters) => Promise<[ (...args: Parameters) => ReturnType, ((p: Promise>) => Promise>) | void ]>; export declare class WrappedAdvancedFn any = (...args: any[]) => any> extends CallableInstance, ReturnType> { fn: T; args: Parameters; parent?: WrappedAdvancedFn; name?: string; context?: PreparedFillInfo; constructor(fn: T, args: Parameters, o?: { parent?: WrappedAdvancedFn; name?: string; }); private fnCallable; setContext(context: PreparedFillInfo): void; static isWrappedAdvancedFn(instance: any): instance is WrappedAdvancedFn; static getParent(instance: any): WrappedAdvancedFn | undefined; } 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, parent, saveContext, }: { args: Parameters; parent?: WrappedAdvancedFn; saveContext?: boolean; }): 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 | MethodWithPrepare>(callable: Fun, meta?: { methodName?: string; parent?: WrappedAdvancedFn; }): ((...args: Parameters) => ReturnType) | Fun; wrapMethodWithPrepare>(method: T, fnName: string): T; wrapFunction any>(callable: T, fnName: string, { saveContext, parent, }?: { saveContext?: boolean; parent?: WrappedAdvancedFn; }): T; wrapAction>(action: T, fnName: string, { parent }?: { parent?: WrappedAdvancedFn; }): T; /** * Wrap all methods in object * * @param object * @param meta metadata for new method */ wrapObjectMethods(object: any, meta: { namespace: string; }): void; /** * Wrap methods in api controller * * @param object * @param meta metadata for new method */ wrapApiControllerMethods(object: any, meta: { namespace: string; }): void; static skipMiddleware(something: T): T & { skipMiddleware: true; }; }