@tsed/common
Version:
A TypeScript Framework on top of Express
98 lines (97 loc) • 3.09 kB
TypeScript
import { Type } from "@tsed/core";
import { Container, InjectorService, IProvider } from "@tsed/di";
import { IRoute, Platform, PlatformApplication } from "../../platform";
/**
* @ignore
*/
export interface PlatformType<T = any> extends Type<T> {
providers: IProvider[];
}
/**
* @ignore
*/
export interface PlatformBootstrap {
bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder>;
}
/**
* @platform
*/
export declare abstract class PlatformBuilder {
static currentPlatform: Type<PlatformBuilder> & PlatformBootstrap;
protected startedAt: Date;
protected PLATFORM_NAME: string;
protected _rootModule: any;
protected _injector: InjectorService;
protected locals: Container;
constructor();
get name(): string;
get injector(): InjectorService;
get rootModule(): any;
get app(): PlatformApplication;
get platform(): Platform;
/**
* Return the settings configured by the decorator @@Configuration@@.
*
* ```typescript
* @Configuration({
* rootDir: Path.resolve(__dirname),
* port: 8000,
* httpsPort: 8080,
* mount: {
* "/rest": "${rootDir}/controllers/**\/*.js"
* }
* })
* export class Server {
* $onInit(){
* console.log(this.settings); // {rootDir, port, httpsPort,...}
* }
* }
* ```
*
* @returns {PlatformConfiguration}
*/
get settings(): TsED.Configuration & import("@tsed/di").DIConfiguration;
get logger(): import("@tsed/di").IDILogger;
static build<T extends PlatformBuilder>(platformBuildClass: PlatformType<T>): T;
/**
* Add classes to the components list
* @param classes
*/
addComponents(classes: any | any[]): this;
/**
* Add classes decorated by @@Controller@@ to components container.
*
* ### Example
*
* ```typescript
* @Controller('/ctrl')
* class MyController{
* }
*
* platform.addControllers('/rest', [MyController])
* ```
*
* ::: tip
* If the MyController class isn't decorated, the class will be ignored.
* :::
*
* @param {string} endpoint
* @param {any[]} controllers
*/
addControllers(endpoint: string, controllers: any | string | (any | string)[]): void;
runLifecycle(): Promise<void>;
loadInjector(): Promise<void>;
listen(): Promise<void>;
stop(): Promise<void>;
ready(): Promise<void>;
callHook(key: string, ...args: any[]): Promise<void>;
loadStatics(): Promise<void>;
useProvider(token: Type<any>, settings: Partial<IProvider>): this;
useProviders(providers: IProvider<any>[]): this;
protected bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<this>;
protected listenServers(): Promise<void>;
protected logRoutes(): void;
protected loadRoutes(routes: IRoute[]): Promise<void>;
protected createInjector(module: Type<any>, settings: any): void;
protected createRootModule(module: Type<any>): void;
}