global.d.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { IncomingMessage, ServerResponse } from "http";
  2. import request from "request";
  3. import Session from "../system/module/mvc/lib/session";
  4. /**
  5. * Global variable
  6. **/
  7. declare global{
  8. //系统对象
  9. let SYSTEM:any;
  10. //全局FS对象
  11. let FILE:any;
  12. //全局Request
  13. let REQUEST:request;
  14. //全局Moment
  15. let Moment:Moment;
  16. //Logger
  17. declare namespace LOGGER {
  18. function log(msg:string):void;
  19. function info(msg:string):void;
  20. function debug(msg:string):void;
  21. function warn(msg:string):void;
  22. function error(msg:string):void;
  23. }
  24. //数据库配置项接口
  25. declare interface DBOption{
  26. host:string,
  27. port:number,
  28. user?:string,
  29. password?:string,
  30. database?:string,
  31. prefix?:string
  32. }
  33. declare function DBCallback(err:Error,data:any):void;
  34. declare function H(helperName:string):any;
  35. declare function M(moduleName:string):any;
  36. // declare namespace DBManager {
  37. // function create(DatabaseType:string,option:DBOption,GlobalName?:string,callback?:(err:Error|null,conn?:any)=>void);
  38. // /**
  39. // * @param dbname 数据库名称,目前支持: redis | mysql | mongodb | memcache
  40. // */
  41. // function getOption(dbname:string):DBOption;
  42. // }
  43. // let ROOTPATH:string;
  44. // let SYSTEM:object;
  45. declare interface RequestData{
  46. req:IncomingMessage|undefined,
  47. res:ServerResponse|undefined,
  48. path:string|null,
  49. method:string,
  50. COOKIE:any,
  51. GET:any,
  52. POST:any,
  53. UPLOAD:any,
  54. SESSION:any
  55. }
  56. declare class CONTROLLER{
  57. REFERER:string;
  58. COOKIE:any;
  59. GET:any;
  60. POST:any;
  61. UPLOAD:any;
  62. SESSION:Session;
  63. DATA:AnyKeyString;
  64. end(data:any,status?:number,mime?:string):void;
  65. endRedirect(location:string,permanently:boolean);
  66. endJSON(somthing:any);
  67. endAPI(errorCode:number,somthing:any);
  68. endView(viewname:string,data:any,option?:any);
  69. setCookie(key:string,value:any,expire?:number|'forever',path?:string);
  70. renewCookie(key:string,expire:number|'forever',path?:string);
  71. }
  72. declare class MysqlUtil{
  73. /**
  74. * K-V数据转为Sql语句结构
  75. **/
  76. public static objToKVString(obj:any,joinStr?:string,keyPrefix?:string);
  77. /**
  78. * 自动处理数据模型与数据,返回处理后符合模型的数据对象,包含数据安全性处理
  79. * @param module 数据模型
  80. * @param data 待处理数据
  81. * @param filter 自动过滤非模型字段数据(可选,默认不过滤)
  82. * @prarm reverse 反向处理,由写入处理变为取出处理,并自动根据模型字段类型进行可视化处理(可选,默认写入状态)
  83. **/
  84. public static analyzeFields(module:any,data:any,filter?:boolean,reverse?:boolean)
  85. public static escape(value:any);
  86. public static createPageLimit(page?:number,perPage?:number,orderField?:string);
  87. public static createOrderBy(order_filed?:string,order_desc?:boolean);
  88. }
  89. declare interface MysqlResult{err:any|null,data:any|Array|null|undefined}
  90. declare interface AnyKeyString{[key:string]:any}
  91. }
  92. export = {}