ts-api-core
Version:
Nodejs api framework core
99 lines (98 loc) • 4.07 kB
TypeScript
import { IBaseConfig } from './base.config';
import { ConfigScope, ScopeEnum } from '../mvc/ioc.decorator';
import { ServerConfig, WebServer } from '../server/web.server';
import { ClassType, TargetType } from './type';
import { RequestContext } from '../context/request.context';
/** TS-API-Core 应用 */
export declare class App {
private static readonly serversMap;
private static readonly _context;
/** 配置信息 */
static config?: IBaseConfig;
/**
* 服务名称
*/
static serviceName: string;
/** 根据端口号获取服务信息 */
static getWebServer(port: number): WebServer | undefined;
/** 全局上下文对象 */
static get context(): RequestContext;
/**
* 是否在控制台显示 Http 请求调试信息,默认 `true`
*/
static deubgHttpRequest: boolean;
/**
* 是否在控制台打印数据库查询调试信息,默认 `false` (数组元素为数据包类型名,如 `["ComQueryPacket"]` )
*/
static deubgDBConnection: boolean | string[];
/** 初始化配置信息 */
private static initConfig;
private static initServer;
private static registerSystemInterface;
/**
* 初始化应用
* @param serviceName 服务名称
* @param options 初始化选项
*/
static initialize(serviceName: string, options?: {
/** 系统配置信息 */
config?: IBaseConfig | Record<string, any>;
/** WEB服务配置 */
server?: ServerConfig | ServerConfig[];
/** 需要注册的实体类 */
entitys?: (TargetType<any> | ClassType<any>)[];
/** 是否在控制台打印 http 调试信息, 默认 `true` */
deubgHttpRequest?: boolean;
/** 是否在控制台打印数据库查询调试信息,默认 `false` (数组元素为数据包类型名,如 `["ComQueryPacket", "OkPacket"]` ) */
deubgDBConnection?: boolean | string[];
}): void;
/**
* 注册对象定义
* @param identifier 标识名称, 不区分大小写
* @param scope 作用域, 默认 `ScopeEnum.Request`
* @param module 实现类
*/
static bind(module: ClassType<any>, identifier?: string, scope?: ScopeEnum): void;
/**
* 单例模式注册
* @param identifier 标识名称, 不区分大小写
* @param module 实现类
*/
static singleton(module: ClassType<any>, identifier?: string): void;
/**
* 注入已有对象
* @param identifier 标识名称, 不区分大小写
* @param obj 对象
*/
static registerObject(identifier: string, obj: any): void;
/**
* 绑定动态 Wrapper 函数定义
* @param identifier 标识名称, 不区分大小写
* @param provider 实现函数
* @description `
* export function xxx(context: RequestContext): any {
* return () => { return data; }
* }`
*/
static injectWrapper(provider: (context: RequestContext, ...args: any | undefined) => any, identifier: string): void;
/**
* 获取对象实例
* @param identifier 标识符
* @param context 上下文对象
* @param ...args 参数列表
*/
static resolve<T>(identifier: string | ClassType<T>, context?: RequestContext, ...args: any | undefined): T | undefined;
/**
* 获取配置信息
* @param path 配置信息的名称完整路径,默认使用字段名称,不区分大小写
* @param scope 配置信息来源, 默认 `ConfigScope.config`。如果是数组,则以先后顺序作为优先级获取
* @param defaultValue 默认值
* @param context 上下文对象
*/
static getConfig<T>(path: string, scope?: ConfigScope | ConfigScope[], context?: RequestContext, defaultValue?: T): T | undefined;
/**
* 注入属性
* @param instance 对象实例
*/
static resolveInject(context: RequestContext | undefined, instance: any, target?: TargetType<any>): void;
}