import * as express from 'express'; import { Record } from '@quenk/noni/lib/data/record'; import { Path } from '@quenk/noni/lib/io/file'; import { Mutable } from '@quenk/potoo/lib/actor/framework/resident'; import { Runtime } from '@quenk/potoo/lib/actor/system/vm/runtime'; import { Address } from '@quenk/potoo/lib/actor/address'; import { Filter } from '../api/request'; import { Connection } from '../connection/pool'; import { App } from '../'; import { Middleware } from '../middleware'; import { FilterChain, FullStaticDirConf, RouteConf } from '../conf'; import { ModuleConf } from './conf'; /** * ModuleInfo holds all the internal runtime information about a Module within * the application. * * This interface is separate from the main Module class to allow for use * without the actor specific properties from potoo. */ export interface ModuleInfo { /** * path the module's routes are to be mounted at. */ path: Path; /** * address the module received from the potoo VM. */ address: Address; /** * module instance (active one). */ module: Module; /** * parent of this ModuleInfo. * * If missing indicates the ModuleInfo is the root. */ parent?: ModuleInfo; /** * ancestors (direct) of the ModuleInfo. */ ancestors: ModuleInfo[]; /** * conf object used to create the module. */ conf: ModuleConf; /** * express app for the module. */ express: express.Application; /** * connections available to the module. */ connections: Record; /** * routing configured for the module. */ routing: RoutingInfo; } /** * isMain tests if a ModuleInfo is the main module. */ export declare const isMain: (mod: ModuleInfo) => boolean; /** * RoutingInfo holds all the Module's routing information. */ export interface RoutingInfo { /** * middleware (express) that will be installed and executed for each * request is handled. * * Due to how express works, these are inherited by child modules. */ middleware: { available: Map; enabled: Middleware[]; }; /** * globalFilters are filters that are executed before or after the filters * of the route. * * These are innherited by child modules hence the name. */ globalFilters: { before: Filter[]; after: Filter[]; }; /** * handlers are used when certain error conditions are encountered such * as missing CSRF tokens or 404s. * * The key specifies the condition and the value is a chain of filters to * executed when the condition is met. * * These are inherited by child modules. */ handlers: Record; /** * dirs are the static directories that are served by the module. */ dirs: Record; /** * routes configured for the module. * * These specify which requests are actually valid for handling by the * application. They are not inherited by child modules. */ routes: RouteConf[]; } /** * Module is a contained unit of route and configuration data for a single * mount point in a tendril application. * * In tendril, an application is broken up into one more Modules that * represent the respective areas of concern. Modules are responsible * for configuring and handling their assigned routes (endpoints) in the * application and can spawn or child actors for one off or persistent tasks. */ export declare class Module extends Mutable { app: App; runtime: Runtime; conf: ModuleConf; constructor(app: App, runtime: Runtime, conf: ModuleConf); address: string; /** * routeHandler given a final RouteConf, produces an express request handler * that executes each filter sequentially. */ routeHandler: (route: RouteConf) => (request: express.Request, response: express.Response) => Promise; errorHandler: (err: Error, request: express.Request, response: express.Response, _: express.NextFunction) => Promise; noneHandler: (request: express.Request, response: express.Response) => Promise; handleRequest(request: express.Request, response: express.Response, filters: FilterChain, route?: RouteConf): Promise; run(): Promise; }