import { Context,Application} from 'egg'; import { RequestOptions,HttpClientResponse} from 'urllib/lib'; import * as url from 'url'; import * as mysql from 'mysql'; export type DBConfig = { key:string, name:string, host:string, port:string, user:string, password:string, db:string, } & ({ type:'mysql', } | { type:'ads', limit:number, group?:string, }); export type HttpHost = { key:string, host:string, } export type EnvConfig = { backendRootPath:string, userCode:string, appUserConfig:any, } type LoggerFunction = (msg:string,...args:any[])=>void; export interface FuncRunArgs { readonly app:Application; readonly userCode:string; /** * 获取数据库实例 * @param dbKey 配置的数据库key */ getDb(dbKey:string,isIplusDataSource?:boolean):Promise; /**调用http接口请求 * @param hostKey 配置的域名key * @param path 请求路径 * @param options 请求的选项 */ curlByKey(hostKey:string):Promise>; curlByKey(hostKey:string,path:string):Promise>; curlByKey(hostKey:string,options:RequestOptions):Promise>; curlByKey(hostKey:string,path:string,options:RequestOptions):Promise>; curl(url:string|url.URL,options?:RequestOptions):Promise>; /**获取用户的轻应用配置信息 * @param key 配置的key */ getAppConfigValue(key:string):any; logger:{ debug:LoggerFunction, info:LoggerFunction, warn:LoggerFunction, error:LoggerFunction, }, //render(tplFile:string,context:any):void; } export type Func = (ctx:Context, args:FuncRunArgs)=>any; export type MysqlConnectionP = Omit & { connect(): Promise; connect(options: any): Promise; changeUser(options: mysql.ConnectionOptions): Promise; changeUser(): Promise; beginTransaction(options: mysql.QueryOptions ): Promise; beginTransaction(): Promise; commit(options?: mysql.QueryOptions): Promise; commit(): Promise; rollback(options: mysql.QueryOptions): Promise; rollback(): Promise; query(query:mysql.Query):mysql.Query; query(options:string|mysql.QueryOptions):Promise; query(options:string|mysql.QueryOptions,value:any):Promise; ping(options: mysql.QueryOptions): Promise; ping(): Promise; statistics(options: mysql.QueryOptions): Promise; statistics(): Promise; /** * Close the connection. Any queued data (eg queries) will be sent first. If * there are any fatal errors, the connection will be immediately closed. * @param callback Handler for any fatal error */ end(): Promise; end(options: any): Promise; }