UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

42 lines (41 loc) 1.44 kB
export declare namespace action { /** * var middleware = { * name: 'userId checker', * global: false, * priority: 1000, * preProcessor: async (data) => { * if(!data.params.userId){ * throw new Error('All actions require a userId') * } * }, * postProcessor: async (data) => { * if(data.thing.stuff == false){ data.toRender = false } * } *} */ interface ActionMiddleware { /**Unique name for the middleware. */ name: string; /**Is this middleware applied to all actions? */ global: boolean; /**Module load order. Defaults to `api.config.general.defaultMiddlewarePriority`. */ priority?: number; /**Called before the action runs. Has access to all params, before sanitization. Can modify the data object for use in actions. */ preProcessor?: Function; /**Called after the action runs. */ postProcessor?: Function; } /** * Add a middleware component available to pre or post-process actions. */ function addMiddleware(data: ActionMiddleware): void; /** * Run an Action in-line, perhaps from within another Action or Task. */ function run<ActionClass>(actionName: string, actionVersion?: string | number, params?: { [key: string]: any; }, connectionProperties?: {}): Promise<{ [key: string]: any; }>; }