UNPKG

lynx-framework

Version:

lynx is a NodeJS framework for Web Development, based on decorators and the async/await support.

121 lines (120 loc) 4.78 kB
/// <reference types="node" /> import { Express } from 'express'; import * as express from 'express'; import * as nunjucks from 'nunjucks'; import 'reflect-metadata'; import * as multer from 'multer'; import Config from './config'; import BaseModule from './base.module'; import ErrorController from './error.controller'; import User from './entities/user.entity'; import { APIResponseWrapper } from './api-response-wrapper'; import { MailClient } from './mail-client'; import { FileOptions } from './file.response'; /** * Utility function to check if we are in the production environment. * @return true if the NODE_ENV is set to "production", false otherwise */ export declare function isProduction(): boolean; /** * Retrieve the preferred language from an express request, using the accepts-languages * header value. * @param req the express request * @return the two letter lower-cased language, or "*" (wildcard), or null */ export declare function getLanguageFromRequest(req: express.Request): string; export declare let app: App; export declare type ResizeFunction = (path: string, options: FileOptions) => Promise<Buffer>; /** * The App class contains the initialization code for a Lynx application. */ export default class App { express: Express; httpServer: any; private readonly _config; private readonly _nunjucksEnvironment; private readonly _upload; private _templateMap; private _modules; private _errorController; apiResponseWrapper: APIResponseWrapper; private _mailClient; private _appSession; private _customResizeFunction; get config(): Config; get templateMap(): any; get nunjucksEnvironment(): nunjucks.Environment; get upload(): multer.Instance; get mailClient(): MailClient; get appSession(): any; /** * If not null, contains a custom function that perform the resizing of an image */ get customResizeFunction(): ResizeFunction | null; /** * Set a new image resizing function, that will be executed automatically when a new file is downloaded. * The cache system will automatically work; this function shall only execute the image resizing. */ set customResizeFunction(resizeFunction: ResizeFunction | null); /** * This property allow the customization of the standard error controller. * You need to create the controller using its standard constructor: * new MyCustomErrorController(app) */ set customErrorController(ctrl: ErrorController); constructor(config: Config, modules?: BaseModule[]); private recursiveGenerateTemplateMap; private generateTemplateMap; private recursiveExecuteMigrations; /** * This method will execute the migrations. * By default, this method will be executed automatically during the app * startup. In some scenario, like hight-scalability, this behaviour could * be unwanted. Thus, it is possibly otherwise to explicitly call this method * in some other way (for example, connecting it to a standard http route). */ executeMigrations(): Promise<void>; private loadTranslations; private loadMiddlewares; private loadControllers; private loadTemplating; startServer(port: number): void; /** * Proxy method to the usual `route` method available from the controller * @param name the name of the route * @param parameters an object containing the parameters of the route * @returns the compiled url */ route(name: string, parameters?: any): string; /** * Request the translation of a string * @param str the string to be translated * @param req the request from which infer the language * @param language optionally, the language can be forced using this variable * @returns the translated string */ translate(str: string, req: express.Request, language?: string): string; /** * Request the translation of a string, formatted with parameters. * Each parameter should be encoded as {0}, {1}, etc... * @param str the string key to be translated * @param req the original request * @param language optionally, the language can be forced using this variable * @param args the arguments to format the string */ translateFormat(str: string, req: express.Request, language: string | undefined, ...args: any): string; private format; /** * Utility method to generate an user token * @param user the user * @returns the token for the user */ generateTokenForUser(user: User): string; } declare global { interface Array<T> { serialize(): Array<any>; removeHiddenField(field: string): void; addHiddenField(field: string): void; } }