UNPKG

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