wok-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/cache/cache.js +94 -0
  4. package/dist/cache/config.js +19 -0
  5. package/dist/cache/index.js +27 -0
  6. package/dist/cache/purge-task.js +56 -0
  7. package/dist/cache/stat.js +47 -0
  8. package/dist/config/convert.js +36 -0
  9. package/dist/config/exception.js +14 -0
  10. package/dist/config/index.js +67 -0
  11. package/dist/http-client/index.js +132 -0
  12. package/dist/i18n/ar.js +17 -0
  13. package/dist/i18n/de.js +17 -0
  14. package/dist/i18n/en-us.js +17 -0
  15. package/dist/i18n/es.js +17 -0
  16. package/dist/i18n/fr.js +17 -0
  17. package/dist/i18n/i18n.js +231 -0
  18. package/dist/i18n/index.js +52 -0
  19. package/dist/i18n/ja.js +17 -0
  20. package/dist/i18n/ko.js +17 -0
  21. package/dist/i18n/msg.js +2 -0
  22. package/dist/i18n/pt.js +17 -0
  23. package/dist/i18n/ru.js +17 -0
  24. package/dist/i18n/tag.js +18 -0
  25. package/dist/i18n/zh-HK.js +17 -0
  26. package/dist/i18n/zh-TW.js +17 -0
  27. package/dist/i18n/zh-cn.js +17 -0
  28. package/dist/index.js +13 -0
  29. package/dist/log/config.js +28 -0
  30. package/dist/log/date.js +21 -0
  31. package/dist/log/file.js +79 -0
  32. package/dist/log/index.js +109 -0
  33. package/dist/log/level.js +39 -0
  34. package/dist/log/store.js +16 -0
  35. package/dist/mongodb/collection.js +2 -0
  36. package/dist/mongodb/config.js +34 -0
  37. package/dist/mongodb/doc.js +2 -0
  38. package/dist/mongodb/exception.js +14 -0
  39. package/dist/mongodb/index.js +58 -0
  40. package/dist/mongodb/manager/base.js +563 -0
  41. package/dist/mongodb/manager/index.js +63 -0
  42. package/dist/mongodb/manager/tx-strict.js +84 -0
  43. package/dist/mongodb/manager/tx.js +30 -0
  44. package/dist/mongodb/migration.js +52 -0
  45. package/dist/mvc/access-log.js +31 -0
  46. package/dist/mvc/config.js +20 -0
  47. package/dist/mvc/exchange.js +113 -0
  48. package/dist/mvc/handler/index.js +6 -0
  49. package/dist/mvc/handler/json.js +33 -0
  50. package/dist/mvc/handler/restful.js +35 -0
  51. package/dist/mvc/handler/upload.js +33 -0
  52. package/dist/mvc/index.js +316 -0
  53. package/dist/mvc/interceptor.js +2 -0
  54. package/dist/mvc/query.js +43 -0
  55. package/dist/mvc/render/file.js +177 -0
  56. package/dist/mvc/render/html/html.js +90 -0
  57. package/dist/mvc/render/html/index.js +18 -0
  58. package/dist/mvc/render/html/style.js +2 -0
  59. package/dist/mvc/render/index.js +7 -0
  60. package/dist/mvc/render/json.js +26 -0
  61. package/dist/mvc/render/text.js +16 -0
  62. package/dist/mvc/router.js +2 -0
  63. package/dist/mysql/config.js +49 -0
  64. package/dist/mysql/exception.js +14 -0
  65. package/dist/mysql/index.js +85 -0
  66. package/dist/mysql/manager/base.js +233 -0
  67. package/dist/mysql/manager/index.js +107 -0
  68. package/dist/mysql/manager/ops/count.js +20 -0
  69. package/dist/mysql/manager/ops/criteria.js +326 -0
  70. package/dist/mysql/manager/ops/delete.js +65 -0
  71. package/dist/mysql/manager/ops/exist.js +26 -0
  72. package/dist/mysql/manager/ops/find.js +111 -0
  73. package/dist/mysql/manager/ops/index.js +14 -0
  74. package/dist/mysql/manager/ops/insert.js +101 -0
  75. package/dist/mysql/manager/ops/modify.js +10 -0
  76. package/dist/mysql/manager/ops/paginate.js +23 -0
  77. package/dist/mysql/manager/ops/query.js +9 -0
  78. package/dist/mysql/manager/ops/update.js +201 -0
  79. package/dist/mysql/manager/tx-strict.js +98 -0
  80. package/dist/mysql/manager/tx.js +30 -0
  81. package/dist/mysql/manager/utils.js +56 -0
  82. package/dist/mysql/migration.js +136 -0
  83. package/dist/mysql/table-info.js +8 -0
  84. package/dist/task/daily.js +58 -0
  85. package/dist/task/fixed-delay.js +33 -0
  86. package/dist/task/fixed-rate.js +37 -0
  87. package/dist/task/index.js +9 -0
  88. package/dist/task/task.js +39 -0
  89. package/dist/validation/exception.js +44 -0
  90. package/dist/validation/index.js +29 -0
  91. package/dist/validation/validator/array.js +38 -0
  92. package/dist/validation/validator/enum.js +28 -0
  93. package/dist/validation/validator/index.js +14 -0
  94. package/dist/validation/validator/length.js +40 -0
  95. package/dist/validation/validator/max-length.js +35 -0
  96. package/dist/validation/validator/max.js +29 -0
  97. package/dist/validation/validator/min-length.js +33 -0
  98. package/dist/validation/validator/min.js +29 -0
  99. package/dist/validation/validator/not-blank.js +33 -0
  100. package/dist/validation/validator/not-null.js +21 -0
  101. package/dist/validation/validator/plain-obj.js +32 -0
  102. package/dist/validation/validator/regexp.js +30 -0
  103. package/documentation/en/index.md +1 -0
  104. package/documentation/zh-cn/cache.md +59 -0
  105. package/documentation/zh-cn/config.md +68 -0
  106. package/documentation/zh-cn/http-client.md +33 -0
  107. package/documentation/zh-cn/i18n.md +154 -0
  108. package/documentation/zh-cn/index.md +25 -0
  109. package/documentation/zh-cn/log.md +40 -0
  110. package/documentation/zh-cn/mongodb.md +262 -0
  111. package/documentation/zh-cn/mvc.md +430 -0
  112. package/documentation/zh-cn/mysql.md +389 -0
  113. package/documentation/zh-cn/task.md +50 -0
  114. package/documentation/zh-cn/test.md +57 -0
  115. package/documentation/zh-cn/validate.md +125 -0
  116. package/package.json +46 -0
  117. package/types/cache/cache.d.ts +52 -0
  118. package/types/cache/config.d.ts +32 -0
  119. package/types/cache/index.d.ts +2 -0
  120. package/types/cache/purge-task.d.ts +11 -0
  121. package/types/cache/stat.d.ts +26 -0
  122. package/types/config/convert.d.ts +6 -0
  123. package/types/config/exception.d.ts +7 -0
  124. package/types/config/index.d.ts +15 -0
  125. package/types/http-client/index.d.ts +71 -0
  126. package/types/i18n/ar.d.ts +2 -0
  127. package/types/i18n/de.d.ts +2 -0
  128. package/types/i18n/en-us.d.ts +2 -0
  129. package/types/i18n/es.d.ts +2 -0
  130. package/types/i18n/fr.d.ts +2 -0
  131. package/types/i18n/i18n.d.ts +102 -0
  132. package/types/i18n/index.d.ts +9 -0
  133. package/types/i18n/ja.d.ts +2 -0
  134. package/types/i18n/ko.d.ts +2 -0
  135. package/types/i18n/msg.d.ts +50 -0
  136. package/types/i18n/pt.d.ts +2 -0
  137. package/types/i18n/ru.d.ts +2 -0
  138. package/types/i18n/tag.d.ts +11 -0
  139. package/types/i18n/zh-HK.d.ts +2 -0
  140. package/types/i18n/zh-TW.d.ts +2 -0
  141. package/types/i18n/zh-cn.d.ts +2 -0
  142. package/types/index.d.ts +10 -0
  143. package/types/log/config.d.ts +27 -0
  144. package/types/log/date.d.ts +2 -0
  145. package/types/log/file.d.ts +5 -0
  146. package/types/log/index.d.ts +34 -0
  147. package/types/log/level.d.ts +15 -0
  148. package/types/log/store.d.ts +12 -0
  149. package/types/mongodb/collection.d.ts +25 -0
  150. package/types/mongodb/config.d.ts +45 -0
  151. package/types/mongodb/doc.d.ts +11 -0
  152. package/types/mongodb/exception.d.ts +7 -0
  153. package/types/mongodb/index.d.ts +29 -0
  154. package/types/mongodb/manager/base.d.ts +188 -0
  155. package/types/mongodb/manager/index.d.ts +38 -0
  156. package/types/mongodb/manager/tx-strict.d.ts +41 -0
  157. package/types/mongodb/manager/tx.d.ts +21 -0
  158. package/types/mongodb/migration.d.ts +12 -0
  159. package/types/mvc/access-log.d.ts +7 -0
  160. package/types/mvc/config.d.ts +30 -0
  161. package/types/mvc/exchange.d.ts +72 -0
  162. package/types/mvc/handler/index.d.ts +3 -0
  163. package/types/mvc/handler/json.d.ts +23 -0
  164. package/types/mvc/handler/restful.d.ts +11 -0
  165. package/types/mvc/handler/upload.d.ts +40 -0
  166. package/types/mvc/index.d.ts +49 -0
  167. package/types/mvc/interceptor.d.ts +11 -0
  168. package/types/mvc/query.d.ts +13 -0
  169. package/types/mvc/render/file.d.ts +10 -0
  170. package/types/mvc/render/html/html.d.ts +98 -0
  171. package/types/mvc/render/html/index.d.ts +11 -0
  172. package/types/mvc/render/html/style.d.ts +1201 -0
  173. package/types/mvc/render/index.d.ts +4 -0
  174. package/types/mvc/render/json.d.ts +17 -0
  175. package/types/mvc/render/text.d.ts +10 -0
  176. package/types/mvc/router.d.ts +11 -0
  177. package/types/mysql/config.d.ts +86 -0
  178. package/types/mysql/exception.d.ts +7 -0
  179. package/types/mysql/index.d.ts +16 -0
  180. package/types/mysql/manager/base.d.ts +158 -0
  181. package/types/mysql/manager/index.d.ts +36 -0
  182. package/types/mysql/manager/ops/count.d.ts +13 -0
  183. package/types/mysql/manager/ops/criteria.d.ts +120 -0
  184. package/types/mysql/manager/ops/delete.d.ts +46 -0
  185. package/types/mysql/manager/ops/exist.d.ts +6 -0
  186. package/types/mysql/manager/ops/find.d.ts +66 -0
  187. package/types/mysql/manager/ops/index.d.ts +10 -0
  188. package/types/mysql/manager/ops/insert.d.ts +18 -0
  189. package/types/mysql/manager/ops/modify.d.ts +3 -0
  190. package/types/mysql/manager/ops/paginate.d.ts +36 -0
  191. package/types/mysql/manager/ops/query.d.ts +3 -0
  192. package/types/mysql/manager/ops/update.d.ts +70 -0
  193. package/types/mysql/manager/tx-strict.d.ts +34 -0
  194. package/types/mysql/manager/tx.d.ts +15 -0
  195. package/types/mysql/manager/utils.d.ts +17 -0
  196. package/types/mysql/migration.d.ts +8 -0
  197. package/types/mysql/table-info.d.ts +36 -0
  198. package/types/task/daily.d.ts +15 -0
  199. package/types/task/fixed-delay.d.ts +8 -0
  200. package/types/task/fixed-rate.d.ts +8 -0
  201. package/types/task/index.d.ts +4 -0
  202. package/types/task/task.d.ts +33 -0
  203. package/types/validation/exception.d.ts +43 -0
  204. package/types/validation/index.d.ts +32 -0
  205. package/types/validation/validator/array.d.ts +5 -0
  206. package/types/validation/validator/enum.d.ts +8 -0
  207. package/types/validation/validator/index.d.ts +11 -0
  208. package/types/validation/validator/length.d.ts +10 -0
  209. package/types/validation/validator/max-length.d.ts +8 -0
  210. package/types/validation/validator/max.d.ts +7 -0
  211. package/types/validation/validator/min-length.d.ts +6 -0
  212. package/types/validation/validator/min.d.ts +7 -0
  213. package/types/validation/validator/not-blank.d.ts +7 -0
  214. package/types/validation/validator/not-null.d.ts +6 -0
  215. package/types/validation/validator/plain-obj.d.ts +7 -0
  216. package/types/validation/validator/regexp.d.ts +8 -0
@@ -0,0 +1,52 @@
1
+ import { CacheStat } from './stat';
2
+ /**
3
+ * 缓存内容
4
+ */
5
+ export interface CacheContent {
6
+ /**
7
+ * 保存的值
8
+ */
9
+ val: any;
10
+ /**
11
+ * 过期时间
12
+ */
13
+ expireAt: number;
14
+ }
15
+ export declare class Cache {
16
+ private readonly valueMap;
17
+ private readonly stat;
18
+ /**
19
+ * promise 表,作用是处理异步并发问题,如果有相同的 key 同时请求,保证异步的 provider 只执行一次
20
+ */
21
+ private promiseMap;
22
+ constructor(valueMap: Map<string, CacheContent>, stat: CacheStat);
23
+ /**
24
+ * 放入缓存
25
+ * @param key
26
+ * @param val
27
+ * @param expiresInSeconds
28
+ */
29
+ put(key: string, val: any, expiresInSeconds?: number): void;
30
+ /**
31
+ * 获取缓存值
32
+ * @param key
33
+ * @returns
34
+ */
35
+ get<T>(key: string): T | undefined;
36
+ /**
37
+ * 清除所有缓存
38
+ */
39
+ clear(): void;
40
+ /**
41
+ * 删除.
42
+ * @param key
43
+ */
44
+ remove(key: string): void;
45
+ /**
46
+ * 在缓存值不存在时计算缓存的值,然后放入并返回.
47
+ * @param key
48
+ * @param provider
49
+ * @param expiresInSeconds
50
+ */
51
+ computeIfAbsent<T>(key: string, provider: () => Promise<T> | T, expiresInSeconds?: number): Promise<T>;
52
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 缓存的配置
3
+ */
4
+ interface CacheConfig {
5
+ /**
6
+ * 默认的存活时长,取值:1-3600,默认 60。存活时间应该尽可能的短,尤其是当缓存的内容比较大时,
7
+ * 否则缓存的内容长时间占用内存,会对 gc 造成影响。
8
+ */
9
+ defaultExpireInSeconds: number;
10
+ /**
11
+ * 是否启用统计任务,启用后每隔指定的时间打印一次缓存统计信息,用于了解缓存的情况.
12
+ */
13
+ statTaskEnabled: boolean;
14
+ /**
15
+ * 统计任务执行的周期,单位秒,取值 60-3600。统计周期也即是时间窗口,
16
+ * 每个周期都是独立的,只统计这个周期内的缓存使用情况。
17
+ */
18
+ statInterval: number;
19
+ /**
20
+ * 最大元素数量,为了控制缓存占用的内存空间,可以将 maxElements 设置的低一些。
21
+ */
22
+ maxElements: number;
23
+ /**
24
+ * 数据清理任务执行周期,单位秒.取值 1-3600,清理任务完成两件事:删除过期数据和驱逐多余记录。
25
+ * 如果项目规模小,缓存的内容非常少,可以将间隔设置长一些,降低频率.
26
+ * 如果缓存的内容很多,频率需要高一些,及时将无效数据清理掉。
27
+ * 否则缓存会长时间占用很高的内存无法被回收,回收器完成检查却需要很长时间,影响gc效率.
28
+ */
29
+ cleaningInterval: number;
30
+ }
31
+ export declare const config: CacheConfig;
32
+ export {};
@@ -0,0 +1,2 @@
1
+ import { Cache } from './cache';
2
+ export declare function getCache(): Cache;
@@ -0,0 +1,11 @@
1
+ import { Task } from '../task';
2
+ import { CacheContent } from './cache';
3
+ /**
4
+ * 缓存清理任务
5
+ */
6
+ export declare class PurgeTask implements Task {
7
+ private readonly valueMap;
8
+ readonly name = "cache purge";
9
+ constructor(valueMap: Map<string, CacheContent>);
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 缓存统计.
3
+ */
4
+ export declare class CacheStat {
5
+ private readonly valueMap;
6
+ /**
7
+ * 开始统计时间
8
+ */
9
+ private start;
10
+ private totalGet;
11
+ private totalHit;
12
+ constructor(valueMap: Map<string, any>);
13
+ /**
14
+ * 添加 get 次数
15
+ * @param hit 是否命中
16
+ */
17
+ addGet(hit: boolean): void;
18
+ /**
19
+ * 清空统计信息,重新开始统计.
20
+ */
21
+ clear(): void;
22
+ /**
23
+ * 输出日志
24
+ */
25
+ log(): void;
26
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 转换值.
3
+ * @param val
4
+ * @param defaultVal
5
+ */
6
+ export declare function convert(val: string, defaultVal: any): string | number | boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 配置异常.
3
+ */
4
+ export declare class ConfigException extends Error {
5
+ readonly message: string;
6
+ constructor(message: string);
7
+ }
@@ -0,0 +1,15 @@
1
+ import { ValidationOpts } from '../validation';
2
+ /**
3
+ * 获取配置
4
+ * @param envPrefix
5
+ */
6
+ export declare function getConfig<T>(envPrefix: string): T | undefined;
7
+ /**
8
+ * 注册配置信息.
9
+ * @param defaultConfig 默认值, 模块会根据默认值来映射环境变量,默认值所有的属性都不能是 undefined,否则无法映射.
10
+ * @param envPrefix 环境变量前缀.
11
+ * @param validation 校验规则,如果有值,初始化的时候会对配置进行校验
12
+ * @returns 映射了环境变量后的配置
13
+ */
14
+ export declare function registerConfig<T extends {}>(defaultConfig: T, envPrefix: string, validation?: ValidationOpts<T>): T;
15
+ export * from './exception';
@@ -0,0 +1,71 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { IncomingHttpHeaders } from 'http';
4
+ /**
5
+ * 请求选项.
6
+ */
7
+ export interface HttpRequestOpts {
8
+ /**
9
+ * 链接地址.
10
+ */
11
+ url: string;
12
+ /**
13
+ * 查询参数,附加在链接地址上
14
+ */
15
+ query?: Record<string, string[] | string>;
16
+ /**
17
+ * 正文,可以是序列化好的字符串或二进制内容.
18
+ */
19
+ body?: string | Buffer;
20
+ /**
21
+ * 消息头
22
+ */
23
+ headers?: IncomingHttpHeaders;
24
+ /**
25
+ * 请求方法
26
+ */
27
+ method: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
28
+ /**
29
+ * 超时时间,单位毫秒,默认 5000
30
+ */
31
+ timeout?: number;
32
+ /**
33
+ * 是否跟随重定向
34
+ */
35
+ followRedirect?: boolean;
36
+ }
37
+ /**
38
+ * 响应信息.
39
+ */
40
+ export interface HttpResponseInfo {
41
+ /**
42
+ * 状态码
43
+ */
44
+ status: number;
45
+ /**
46
+ * 消息头.
47
+ */
48
+ headers: IncomingHttpHeaders;
49
+ /**
50
+ * 响应正文
51
+ */
52
+ body: Buffer;
53
+ }
54
+ /**
55
+ * 发送 http 请求.
56
+ * @param opts
57
+ * @returns
58
+ */
59
+ export declare function doRequest(opts: HttpRequestOpts): Promise<HttpResponseInfo>;
60
+ /**
61
+ * 发送 json 格式的 post 请求,body 是未序列化的普通对象,表示要发送的请求数据.
62
+ * @param opts
63
+ */
64
+ export declare function postJson<T>(opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout'> & {
65
+ body: any;
66
+ }): Promise<T>;
67
+ /**
68
+ * get 请求获取 json 格式数据.
69
+ * @param opts
70
+ */
71
+ export declare function getJson<T>(opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout'>): Promise<T>;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const ar: I18nMsgs;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const de: I18nMsgs;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const enUS: I18nMsgs;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const es: I18nMsgs;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const fr: I18nMsgs;
@@ -0,0 +1,102 @@
1
+ /// <reference types="node" />
2
+ import { IncomingHttpHeaders } from 'http';
3
+ /**
4
+ * 绑定语言的 i18n 类型,不可切换语言.
5
+ */
6
+ export declare class BoundI18n<T> {
7
+ private readonly lang;
8
+ private readonly msgs;
9
+ constructor(lang: string, msgs: T);
10
+ /**
11
+ * 获取当前语言
12
+ */
13
+ getLang(): string;
14
+ /**
15
+ * 构建国际化消息.
16
+ * @param key 消息模板的 key
17
+ * @param args 参数,如果 key 对应的消息模板有占位符号({})可以使用参数来填充
18
+ */
19
+ buildMsg(key: keyof T, ...args: string[]): string;
20
+ }
21
+ /**
22
+ * 国际化,提供不同语言消息构建的功能,默认英文.
23
+ */
24
+ export declare class I18n<T> {
25
+ readonly enMsgs: T;
26
+ /**
27
+ * 当前语言
28
+ */
29
+ private lang;
30
+ /**
31
+ * 消息模板表,与当前语言是对应的
32
+ */
33
+ private msgs;
34
+ /**
35
+ * 消息表,key 是语言,value 是一个 key 为地区,value 为 消息模板的 map,两层 map 为的是能够快速匹配.
36
+ * 地区为空的情况下,缺省值为 - 。语言和地区的 key 全转成小写存储。
37
+ */
38
+ private msgsMap;
39
+ /**
40
+ * 构造 i18n 对象,必须指定英文的消息模板作为默认。
41
+ * @param enMsgs 英文的消息模板
42
+ */
43
+ constructor(enMsgs: T);
44
+ protected findMsgsByLang(langTag: string): T | undefined;
45
+ /**
46
+ * 设置一种语言对应的消息模板,支持异步,可以做动态加载
47
+ * @param langTag
48
+ * @param msgs
49
+ */
50
+ setMsgs(langTag: string, msgs: T): void;
51
+ /**
52
+ * 给定一个语言标签列表,获得可以被支持的标签列表
53
+ * @param tags
54
+ */
55
+ getSupportedLanguageTags(...tags: string[]): string[];
56
+ /**
57
+ * 设置当前语言,如果指定的语言不被支持,则修改无效
58
+ * @param lang 语言本标签,如 en-US
59
+ * @returns 是否成功,如果语言不支持则返回 false,不会改变现有语言
60
+ */
61
+ setLang(lang: string): boolean;
62
+ /**
63
+ * 获取当前语言
64
+ */
65
+ getLang(): string;
66
+ /**
67
+ * 构建国际化消息.
68
+ * @param key 消息模板的 key
69
+ * @param args 参数,如果 key 对应的消息模板有占位符号({})可以使用参数来填充
70
+ */
71
+ buildMsg(key: keyof T, ...args: string[]): string;
72
+ /**
73
+ * 绑定一种语言,生成新的 i18n 对象,该对象仅能使用某一种语言.
74
+ * @param langTag 语言标签,无值则表示绑定当前语言
75
+ * @returns 返回一个语言受限的 i18n 对象.
76
+ */
77
+ bindLang(langTag?: string): BoundI18n<T>;
78
+ /**
79
+ * 根据请求进行语言切换,解析消息头 'accept-language' ,如果 'accept-language' 中没有包含能够支持的语言则使用默认的英文.
80
+ * @param headers 消息头
81
+ */
82
+ switchByRequest(headers: IncomingHttpHeaders): void;
83
+ private parseAcceptLanguage;
84
+ /**
85
+ * 根据请求进行语言绑定,解析消息头 'accept-language',绑定受支持的第一个语言,如果没有可以被支持的语言,则使用默认的英文.
86
+ * @param headers 消息头
87
+ */
88
+ bindByRequest(headers: IncomingHttpHeaders): BoundI18n<T>;
89
+ }
90
+ /**
91
+ * 可扩展的 i18n ,增加扩展新 i18n 对象的功能,记录扩展的新对象,同步 setLang 操作
92
+ */
93
+ export declare class ExtensibleI18n<T extends object> extends I18n<T> {
94
+ private extendedI18ns;
95
+ setLang(lang: string): boolean;
96
+ /**
97
+ * 扩展国际化内容,生成一个新的 i18n 对象,与当前的 i18n 对象语言保持一致,可在新对象中设置扩展部分的语言。
98
+ * <K> 新的消息模板类型
99
+ * @param enMsgs
100
+ */
101
+ extend<K extends object>(enMsgs: K): I18n<K>;
102
+ }
@@ -0,0 +1,9 @@
1
+ import { ExtensibleI18n } from './i18n';
2
+ import { I18nMsgs } from './msg';
3
+ /**
4
+ * 获取 i18n 对象
5
+ * @returns
6
+ */
7
+ export declare function getI18n(): ExtensibleI18n<I18nMsgs>;
8
+ export * from './i18n';
9
+ export * from './msg';
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const ja: I18nMsgs;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const ko: I18nMsgs;
@@ -0,0 +1,50 @@
1
+ export interface I18nMsgs {
2
+ /**
3
+ * 校验错误,不是数组
4
+ */
5
+ 'validate-err-array': string;
6
+ /**
7
+ * 校验错误:不是数字
8
+ */
9
+ 'validate-err-numer': string;
10
+ /**
11
+ * 校验错误:不得大于
12
+ */
13
+ 'validate-err-max': string;
14
+ /**
15
+ * 校验错误:不得小于
16
+ */
17
+ 'validate-err-min': string;
18
+ /**
19
+ * 枚举校验错误,值不在范围内
20
+ */
21
+ 'validate-err-enum': string;
22
+ /**
23
+ * 校验错误:不能为空
24
+ */
25
+ 'validate-err-empty': string;
26
+ /**
27
+ * 校验错误:不是字符串
28
+ */
29
+ 'validate-err-string': string;
30
+ /**
31
+ * 校验错误:格式不正确
32
+ */
33
+ 'validate-err-incorrect-format': string;
34
+ /**
35
+ * 校验错误,没有 length 属性
36
+ */
37
+ 'validate-err-no-length': string;
38
+ /**
39
+ * 校验错误,length 不是数字
40
+ */
41
+ 'validate-err-length-not-number': string;
42
+ /**
43
+ * 校验错误:最小长度
44
+ */
45
+ 'validate-err-min-length': string;
46
+ /**
47
+ * 校验错误:最大长度
48
+ */
49
+ 'validate-err-max-length': string;
50
+ }
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const pt: I18nMsgs;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const ru: I18nMsgs;
@@ -0,0 +1,11 @@
1
+ export interface LangTag {
2
+ lang: string;
3
+ region?: string;
4
+ }
5
+ /**
6
+ * 解析语言标签,语言标签格式非常多,这里仅支持语言加地区的形式,如 zh-CN。
7
+ * 更多信息可以查看 https://www.rfc-editor.org/rfc/bcp/bcp47.txt 。
8
+ * @param tag
9
+ * @returns 语言和地区信息,为了方便匹配,全转小写
10
+ */
11
+ export declare function parseLangTag(tag: string): LangTag;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from "./msg";
2
+ export declare const zhHK: I18nMsgs;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const zhTW: I18nMsgs;
@@ -0,0 +1,2 @@
1
+ import { I18nMsgs } from './msg';
2
+ export declare const zhCN: I18nMsgs;
@@ -0,0 +1,10 @@
1
+ export * from './log';
2
+ export * from './i18n';
3
+ export * from './validation';
4
+ export * from './config';
5
+ export * from './cache';
6
+ export * from './task';
7
+ export * from './mvc';
8
+ export * from './mysql';
9
+ export * from './http-client';
10
+ export * from './mongodb';
@@ -0,0 +1,27 @@
1
+ import { LogLevel } from './level';
2
+ /**
3
+ * 日志配置的定义
4
+ */
5
+ export interface LogConfig {
6
+ /**
7
+ * 是否输出到文件,如果为 true ,则会在根目录下生成 logs 目录存放日志文件.
8
+ */
9
+ file: boolean;
10
+ /**
11
+ * 文件目录
12
+ */
13
+ fileDir: string;
14
+ /**
15
+ * 文件最大保存天数.需要开启文件才有效.
16
+ */
17
+ fileMaxDays: number;
18
+ /**
19
+ * 要输出的日志级别.
20
+ */
21
+ level: LogLevel;
22
+ }
23
+ /**
24
+ * 默认配置信息.
25
+ */
26
+ declare const config: LogConfig;
27
+ export { config };
@@ -0,0 +1,2 @@
1
+ export declare function currentDateTimeStr(): string;
2
+ export declare function formatDateTime(date: Date): string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 文件存储.
3
+ * @param log
4
+ */
5
+ export declare function fileStore(log: string): void;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 获取日志对象.
3
+ * @returns
4
+ */
5
+ export declare function getLogger(): Readonly<{
6
+ /**
7
+ * debug 日志
8
+ */
9
+ debug(message: string): void;
10
+ isDebugEnabled(): boolean;
11
+ /**
12
+ * info 日志
13
+ * @param message
14
+ */
15
+ info(message: string): void;
16
+ isInfoEnabled(): boolean;
17
+ /**
18
+ * 警告日志
19
+ * @param message
20
+ * @param error
21
+ */
22
+ warn(message: string, error?: any): void;
23
+ isWarnEnabled(): boolean;
24
+ /**
25
+ * 错误日志
26
+ * @param message
27
+ * @param error
28
+ */
29
+ error(message: string, error?: any): void;
30
+ isErrorEnabled(): boolean;
31
+ }>;
32
+ export * from './config';
33
+ export * from './level';
34
+ export { setLogStore } from './store';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 日志级别.
3
+ */
4
+ export declare enum LogLevel {
5
+ DEBUG = "DEBUG",
6
+ INFO = "INFO",
7
+ WARN = "WARN",
8
+ ERROR = "ERROR"
9
+ }
10
+ export declare const LogLevelVals: Record<LogLevel, number>;
11
+ /**
12
+ * 解析日志级别
13
+ * @param level
14
+ */
15
+ export declare function parseLogLevel(level: string): LogLevel;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 日志存储函数
3
+ */
4
+ export interface LogStore {
5
+ (log: string): void;
6
+ }
7
+ /**
8
+ * 设置日志存储.
9
+ * @param store
10
+ */
11
+ export declare function setLogStore(store: LogStore): void;
12
+ export declare function getLogStore(): LogStore | undefined;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * mogodb 集合信息
3
+ *
4
+ * <T> 数据类型,不能包含有 _id 字段,主键字段名称固定,不可以设置
5
+ */
6
+ export interface MongoCollection<T> {
7
+ /**
8
+ * 集合名称.
9
+ */
10
+ collectionName: string;
11
+ /**
12
+ * 创建时间字段信息,设置后在创建时会自动更新该字段
13
+ */
14
+ createdDate?: {
15
+ field: keyof T;
16
+ type: 'number' | 'date';
17
+ };
18
+ /**
19
+ * 更新时间字段信息,设置后在更新记录时会自动维护该字段
20
+ */
21
+ updatedDate?: {
22
+ field: keyof T;
23
+ type: 'number' | 'date';
24
+ };
25
+ }
@@ -0,0 +1,45 @@
1
+ import { ValidationOpts } from '../validation';
2
+ /**
3
+ * MongoDB 配置.
4
+ */
5
+ export interface MongoDBConfig {
6
+ /**
7
+ * 连接地址.
8
+ * 示例:mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&writeConcern=majority
9
+ */
10
+ uri: string;
11
+ /** The maximum number of connections in the connection pool. */
12
+ maxPoolSize: number;
13
+ /** The minimum number of connections in the connection pool. */
14
+ minPoolSize: number;
15
+ /** The maximum number of connections that may be in the process of being established concurrently by the connection pool. */
16
+ maxConnecting: number;
17
+ /** The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. */
18
+ maxIdleTimeMS: number;
19
+ /** The maximum time in milliseconds that a thread can wait for a connection to become available. */
20
+ waitQueueTimeoutMS: number;
21
+ /**
22
+ * 开启慢查询警告,默认开启
23
+ */
24
+ slowQueryWarn: boolean;
25
+ /**
26
+ * 慢查询毫秒数,默认 200
27
+ */
28
+ slowQueryMs: number;
29
+ /**
30
+ *事务超时时间,单位毫秒,默认 5000,设置为0的值表示不限制
31
+ */
32
+ transactionTimeout: number;
33
+ /**
34
+ * 事务严格模式
35
+ */
36
+ transactionStrict: boolean;
37
+ }
38
+ /**
39
+ * 默认配置.
40
+ */
41
+ export declare const defaultConfig: MongoDBConfig;
42
+ /**
43
+ * 配置校验
44
+ */
45
+ export declare const configValidation: ValidationOpts<MongoDBConfig>;
@@ -0,0 +1,11 @@
1
+ import { ObjectId } from 'mongodb';
2
+ /**
3
+ * 文档 id
4
+ */
5
+ export type MongoDocId = string | ObjectId;
6
+ /**
7
+ * 带 id 的文档。<T> 是自定义的集合类型,不包含主键字段。
8
+ */
9
+ export type MongoDocWithId<T> = T & {
10
+ _id: MongoDocId;
11
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * MongoDB 异常.
3
+ */
4
+ export declare class MongoDBException extends Error {
5
+ readonly message: string;
6
+ constructor(message: string);
7
+ }