UNPKG

actionhero

Version:

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

51 lines (50 loc) 1.68 kB
import { Initializer, Connection } from "../index"; /** * ```js *var connectionMiddleware = { *name: 'connection middleware', *priority: 1000, *create: (connection) => { * // do stuff *}, *destroy:(connection) => { * // do stuff *} *} * ``` */ export interface ConnectionMiddleware { /**Unique name for the middleware. */ name: string; /**Module load order. Defaults to `api.config.general.defaultMiddlewarePriority`. */ priority?: number; /**Called for each new connection when it is created. Connection is passed to the event handler*/ create?: Function; /**Called for each connection before it is destroyed. Connection is passed to the event handler*/ destroy?: Function; } export interface ConnectionsApi { connections: { [key: string]: Connection; }; middleware: { [key: string]: ConnectionMiddleware; }; globalMiddleware: Array<string>; apply: ConnectionsInitializer["apply"]; applyResponder: ConnectionsInitializer["applyResponder"]; addMiddleware: ConnectionsInitializer["addMiddleware"]; cleanConnection: ConnectionsInitializer["cleanConnection"]; } export declare class ConnectionsInitializer extends Initializer { constructor(); apply: (connectionId: string, method?: string, args?: any[] | Record<string, any>) => Promise<Connection>; applyResponder: (connectionId: string, method: keyof InstanceType<typeof Connection>, args: any) => Promise<{ [key: string]: any; }>; addMiddleware: (data: ConnectionMiddleware) => void; cleanConnection: (connection: Connection) => { [key: string]: any; }; initialize(): Promise<void>; }