global.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. refer:any,
  50. method:string,
  51. COOKIE:any,
  52. GET:any,
  53. POST:any,
  54. UPLOAD:any,
  55. SESSION:any
  56. }
  57. declare class CONTROLLER{
  58. REFERER:string;
  59. REQPATH:string;
  60. REQMETHOD:string;
  61. REQTIME:number;
  62. COOKIE:any;
  63. GET:any;
  64. POST:any;
  65. UPLOAD:any;
  66. SESSION:Session;
  67. DATA:AnyKeyString;
  68. end(data:any,status?:number,mime?:string):void;
  69. endRedirect(location:string,permanently?:boolean);
  70. endJSON(somthing:any);
  71. endAPI(errorCode:number,somthing:any);
  72. endView(viewname:string,data?:any,option?:any);
  73. setCookie(key:string,value:any,expire?:number|'forever',path?:string);
  74. renewCookie(key:string,expire:number|'forever',path?:string);
  75. }
  76. declare class MysqlUtil{
  77. /**
  78. * K-V数据转为Sql语句结构
  79. **/
  80. public static objToKVString(obj:any,joinStr?:string,keyPrefix?:string);
  81. /**
  82. * 自动处理数据模型与数据,返回处理后符合模型的数据对象,包含数据安全性处理
  83. * @param module 数据模型
  84. * @param data 待处理数据
  85. * @param filter 自动过滤非模型字段数据(可选,默认不过滤)
  86. * @prarm reverse 反向处理,由写入处理变为取出处理,并自动根据模型字段类型进行可视化处理(可选,默认写入状态)
  87. **/
  88. public static analyzeFields(module:any,data:any,filter?:boolean,reverse?:boolean)
  89. public static escape(value:any);
  90. public static createPageLimit(page?:number,perPage?:number,orderField?:string);
  91. public static createOrderBy(order_filed?:string,order_desc?:boolean);
  92. }
  93. declare interface MysqlResult{err:any|null,data:any|Array|null|undefined}
  94. declare interface AnyKeyString{[key:string]:any}
  95. }
  96. export = {}