1 | import {BaseEntity, Connection, SelectQueryBuilder} from '@bxjs/typeorm'
|
2 | import {Container, interfaces} from 'inversify'
|
3 |
|
4 | declare global {
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function xreset()
|
17 |
|
18 | function xconfig(path: string, defaultValue?: any)
|
19 |
|
20 | function xthrow(code?: string | Error, param?: any, reject_param?: any): void
|
21 |
|
22 | function xassert(expr: any, code?: string, param?: any): any
|
23 |
|
24 | // // 验证规则文档 https://github.com/node-modules/parameter
|
25 | // function xcheck(param: { [propName: string]: any }, rules: { [propName: string]: any })
|
26 |
|
27 | // 对于异常内容的格式化参数解析处理成为四元组code/msg/param/stack
|
28 | function xerror(err: Error, param?: any)
|
29 |
|
30 | // 用于获取错误栈的root cause根本原因(第一个被拦截的错误发生位置)
|
31 | function xroot(err: Error)
|
32 |
|
33 | // 获取异常调用栈用于辅助错误提示定位
|
34 | function xstack(err: Error, compact?: boolean)
|
35 |
|
36 | function xlog(...args)
|
37 |
|
38 | // TODO
|
39 | // function xdebug(...args)
|
40 |
|
41 | // 钉钉IM群机器人报警通知
|
42 | function xwarn(...args)
|
43 |
|
44 | // async/await的非阻塞异步延迟方法,用于调试阻塞程序的执行进行单步调试的效果。延时单位毫秒。缺省参数为无限延时
|
45 | function xsleep(ms?: number)
|
46 |
|
47 | // 默认超时3000毫秒
|
48 | function xget(url: string, param?: { [propName: string]: any },
|
49 | headers?: { [propName: string]: any }, timeout?: number)
|
50 |
|
51 | // 默认超时3000毫秒
|
52 | function xpost(url: string, param?: { [propName: string]: any },
|
53 | headers?: { [propName: string]: any }, timeout?: number): any
|
54 |
|
55 |
|
56 | function xredirect(url: string, param?: {})
|
57 |
|
58 | // 如果只有key参数表示读取属性(缺省值为undefined),如果key为空表示读取所有的请求cookies属性,否则表示响应设置cookies
|
59 | function xcookie(key?: string, value?: string, option?: {
|
60 |
|
61 | domain?: string,
|
62 | path?: string,
|
63 | httpOnly?: boolean,
|
64 | sameSite?: boolean | 'lax' | 'strict',
|
65 | secure?: boolean,
|
66 | encode?: string,
|
67 | expires?: Date,
|
68 | maxAge?: number,
|
69 | }): any
|
70 |
|
71 | // 判断user-agent请求是否为移动端
|
72 | function xismobile(): boolean
|
73 |
|
74 | function xassign(target, source, ...args): any
|
75 |
|
76 | function xconnect(callback: (connect: Connection) => Promise<any>, config?: string): Promise<any>
|
77 |
|
78 | // 创建ORM实体对象的时候,支持前端参数的自动批量赋值逻辑实现。
|
79 | function xnew<T extends BaseEntity>(TYPE: new () => T, param?: any, ...args): T
|
80 |
|
81 | // 查询构造器易用性封装
|
82 | function xquery<T>(connect: Connection, TYPE: new () => T, alias?: string): SelectQueryBuilder<T>
|
83 |
|
84 |
|
85 | // 分页查询获取总数以及原始记录数据
|
86 | function xcount<T>(sql: SelectQueryBuilder<T>, page: number, size: number): Promise<[any[] | null, number]>
|
87 |
|
88 | class xsession {
|
89 | // 读取当前会话标识
|
90 | static readonly id
|
91 |
|
92 | static get(key: string, defaultValue?: any): Promise<any>
|
93 |
|
94 | static set(key: string, value: any): Promise<any>
|
95 |
|
96 | static delete(key: string): Promise<any>
|
97 |
|
98 | // 用户登出的时候需要调用此接口删除服务端缓存的会话状态信息
|
99 | static destroy(): Promise<any>
|
100 | }
|
101 |
|
102 | class xuser {
|
103 | // 读取当前登录用户标识
|
104 | static readonly id
|
105 |
|
106 | // 读取用户登录缓存在session之中的常用用户基本信息参数
|
107 | static readonly param
|
108 |
|
109 | static get(key: string, defaultValue?: any): Promise<any>
|
110 |
|
111 | static set(key: string, value: any): Promise<any>
|
112 |
|
113 | static delete(key: string): Promise<any>
|
114 |
|
115 | // 当用户恢复储出厂设置的时候调用此接口清空当前用户的持久化缓存信息
|
116 | static destroy(): Promise<any>
|
117 | }
|
118 |
|
119 | class xcache {
|
120 | static get(key: string, defaultValue?: any): Promise<any>
|
121 |
|
122 | static set(key: string, value: any): Promise<any>
|
123 |
|
124 | static delete(key: string): Promise<any>
|
125 |
|
126 | static destroy(): Promise<any>
|
127 | }
|
128 |
|
129 |
|
130 | /**
|
131 | * 路由修饰符,用于定义entries相关入口文件的相关额外属性,方便自动化工具以及框架识别完成各种辅助操作。
|
132 | * name 路由名称
|
133 | * desc 路由描述
|
134 | * path 缺省文件相对路径路由格式的覆盖重写
|
135 | * auth 该路由是否需要登录认证(缺省为true需要登录认证)
|
136 | */
|
137 | function xroute(param: { name?: string, desc?: string, path?: string, auth?: boolean }): Function
|
138 |
|
139 | // 模拟数据模板定义使用教程 http://mockjs.com/0.1/#%E6%95%B0%E6%8D%AE%E5%8D%A0%E4%BD%8D%E7%AC%A6%E5%AE%9A%E4%B9%89%20DPD
|
140 | function xmock<T>(rules: T): any
|
141 |
|
142 | function xrandom(name: string, data: any[])
|
143 |
|
144 | // laravel风格JSON对象验证器封装,详细文档见 https://github.com/skaterdav85/validatorjs
|
145 | function xcheck<T>(param: T, rules: T, messages?: Object)
|
146 |
|
147 | //【IoC容器管理】单实例全局插件容器
|
148 | const xcontainer: Container
|
149 |
|
150 | //【IoC容器管理】应用层的插件实现类绑定到BXJS统一注册的标准插件的映射关系在全局容器实例中注册
|
151 | function xbind<T>(TYPE: new () => T): interfaces.BindingInWhenOnSyntax<T>
|
152 |
|
153 | //【IoC容器管理】框架或应用依赖标准规范接口插件的类实例获取方法
|
154 | function xgot<T>(TYPE: new () => T): T
|
155 |
|
156 | class YAuth {
|
157 | // 插件标识
|
158 | readonly id
|
159 |
|
160 | // 登录逻辑实现
|
161 | login(user_id: string, user_param?: Object): Promise<void>
|
162 |
|
163 | // 登出逻辑实现
|
164 | logout(): Promise<void>
|
165 |
|
166 | // 判断是否处于登录状态
|
167 | getLoginStatus(): Promise<boolean>
|
168 | }
|
169 |
|
170 | // 同步系统命令调用执行
|
171 | function xcmd(...args: string[]): Promise<any>
|
172 |
|
173 | // 对于数组嵌套回调函数的nodejs异步处理方法的统一封装
|
174 | // https://blog.csdn.net/sam976/article/details/52330424
|
175 | // 异步方法中map、forEach和for循环中带来的异步执行问题
|
176 | // https://blog.csdn.net/fangjian1204/article/details/50585073
|
177 | // node.js在遇到“循环+异步”时的注意事项
|
178 | function xmap<T>(values: T[], callack: (v: T) => Promise<any>): Promise<any[]>
|
179 |
|
180 | // Refer to document: https://help.aliyun.com/document_detail/62670.html
|
181 | // 获取ACM配置信息接口的统一封装
|
182 | function xacm(group: string, id: string): Promise<void>
|
183 |
|
184 | // base64编码
|
185 | function xbase64encode(value: string)
|
186 |
|
187 | // base64解码
|
188 | function xbase64decode(value: string)
|
189 |
|
190 | // 根据当前配置的时区正确获取当前时间值避免线上FC容器默认是格林尼治时间而非北京时间问题
|
191 | function xnow(format?)
|
192 | } |
\ | No newline at end of file |