@onebots/core 0.5.0 → 1.0.4
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.
- package/README.md +3 -3
- package/lib/__tests__/config-validator.test.d.ts +4 -0
- package/lib/__tests__/config-validator.test.js +152 -0
- package/lib/__tests__/di-container.test.d.ts +4 -0
- package/lib/__tests__/di-container.test.js +114 -0
- package/lib/__tests__/errors.test.d.ts +4 -0
- package/lib/__tests__/errors.test.js +111 -0
- package/lib/__tests__/integration.test.d.ts +5 -0
- package/lib/__tests__/integration.test.js +112 -0
- package/lib/__tests__/lifecycle.test.d.ts +4 -0
- package/lib/__tests__/lifecycle.test.js +163 -0
- package/lib/account.d.ts +4 -1
- package/lib/account.js +6 -3
- package/lib/adapter.d.ts +67 -1
- package/lib/adapter.js +31 -4
- package/lib/base-app.d.ts +30 -3
- package/lib/base-app.js +295 -142
- package/lib/circuit-breaker.d.ts +94 -0
- package/lib/circuit-breaker.js +206 -0
- package/lib/config-validator.d.ts +51 -0
- package/lib/config-validator.js +184 -0
- package/lib/connection-pool.d.ts +68 -0
- package/lib/connection-pool.js +202 -0
- package/lib/db.d.ts +2 -1
- package/lib/db.js +11 -2
- package/lib/di-container.d.ts +60 -0
- package/lib/di-container.js +103 -0
- package/lib/errors.d.ts +157 -0
- package/lib/errors.js +257 -0
- package/lib/index.d.ts +13 -4
- package/lib/index.js +17 -3
- package/lib/lifecycle.d.ts +75 -0
- package/lib/lifecycle.js +175 -0
- package/lib/logger.d.ts +76 -0
- package/lib/logger.js +156 -0
- package/lib/metrics.d.ts +80 -0
- package/lib/metrics.js +201 -0
- package/lib/middleware/index.d.ts +8 -0
- package/lib/middleware/index.js +8 -0
- package/lib/middleware/metrics-collector.d.ts +9 -0
- package/lib/middleware/metrics-collector.js +64 -0
- package/lib/middleware/rate-limit.d.ts +32 -0
- package/lib/middleware/rate-limit.js +149 -0
- package/lib/middleware/security-audit.d.ts +33 -0
- package/lib/middleware/security-audit.js +223 -0
- package/lib/middleware/token-manager.d.ts +73 -0
- package/lib/middleware/token-manager.js +186 -0
- package/lib/middleware/token-validator.d.ts +42 -0
- package/lib/middleware/token-validator.js +198 -0
- package/lib/protocol.d.ts +2 -3
- package/lib/protocol.js +4 -0
- package/lib/rate-limiter.d.ts +88 -0
- package/lib/rate-limiter.js +196 -0
- package/lib/registry.d.ts +27 -0
- package/lib/registry.js +40 -5
- package/lib/retry.d.ts +87 -0
- package/lib/retry.js +205 -0
- package/lib/router.d.ts +43 -6
- package/lib/router.js +139 -12
- package/lib/timestamp.d.ts +42 -0
- package/lib/timestamp.js +72 -0
- package/lib/types.d.ts +1 -0
- package/lib/types.js +2 -1
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +11 -19
- package/package.json +24 -9
package/lib/utils.js
CHANGED
|
@@ -64,25 +64,14 @@ export function transformObj(obj, callback) {
|
|
|
64
64
|
}
|
|
65
65
|
// 深拷贝
|
|
66
66
|
export function deepClone(obj) {
|
|
67
|
-
|
|
68
|
-
return obj;
|
|
69
|
-
|
|
67
|
+
try {
|
|
68
|
+
return structuredClone(obj);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// structuredClone does not support all types (e.g. functions, DOM nodes).
|
|
72
|
+
// Return the original reference as a best-effort fallback.
|
|
70
73
|
return obj;
|
|
71
|
-
//判断拷贝的obj是对象还是数组
|
|
72
|
-
if (Array.isArray(obj))
|
|
73
|
-
return obj.map(item => deepClone(item));
|
|
74
|
-
const objClone = {};
|
|
75
|
-
for (const key in obj) {
|
|
76
|
-
if (obj.hasOwnProperty(key)) {
|
|
77
|
-
if (obj[key] && typeof obj[key] === "object") {
|
|
78
|
-
objClone[key] = deepClone(obj[key]);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
objClone[key] = obj[key];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
74
|
}
|
|
85
|
-
return objClone;
|
|
86
75
|
}
|
|
87
76
|
export function pick(source, keys, forced) {
|
|
88
77
|
if (!keys)
|
|
@@ -107,11 +96,14 @@ export function omit(source, keys) {
|
|
|
107
96
|
* 将驼峰命名替换为下划线分割命名
|
|
108
97
|
* @param name
|
|
109
98
|
* @returns
|
|
110
|
-
* @todo 是否应该改名 ToUnderLine()?
|
|
111
99
|
*/
|
|
112
|
-
export function
|
|
100
|
+
export function toUnderLine(name) {
|
|
113
101
|
return name.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
114
102
|
}
|
|
103
|
+
/** @deprecated Use {@link toUnderLine} instead. */
|
|
104
|
+
export function toLine(name) {
|
|
105
|
+
return toUnderLine(name);
|
|
106
|
+
}
|
|
115
107
|
export function Mixin(base, ...classes) {
|
|
116
108
|
classes.forEach(ctr => {
|
|
117
109
|
Object.getOwnPropertyNames(ctr.prototype).forEach(name => {
|
package/package.json
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onebots/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "IMHelper 核心抽象层,提供适配器、协议、账号等基础接口和类型",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=22"
|
|
10
10
|
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"import": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./types": {
|
|
17
|
+
"types": "./lib/types.d.ts",
|
|
18
|
+
"import": "./lib/types.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
11
21
|
"keywords": [
|
|
12
22
|
"onebot",
|
|
13
23
|
"qq",
|
|
@@ -19,10 +29,10 @@
|
|
|
19
29
|
"author": "凉菜",
|
|
20
30
|
"license": "MIT",
|
|
21
31
|
"devDependencies": {
|
|
22
|
-
"@types/koa": "^
|
|
32
|
+
"@types/koa": "^3.0.1",
|
|
33
|
+
"@types/koa__router": "^12.0.5",
|
|
23
34
|
"@types/koa-basic-auth": "^2.0.6",
|
|
24
|
-
"@types/koa-
|
|
25
|
-
"@types/koa__router": "^8.0.11",
|
|
35
|
+
"@types/koa-static": "^4.0.4",
|
|
26
36
|
"@types/node": "^22.7.3",
|
|
27
37
|
"@types/ws": "^8.5.3",
|
|
28
38
|
"tsc-alias": "latest",
|
|
@@ -36,18 +46,23 @@
|
|
|
36
46
|
"/lib/**/*.d.ts"
|
|
37
47
|
],
|
|
38
48
|
"dependencies": {
|
|
39
|
-
"@koa/router": "^
|
|
49
|
+
"@koa/router": "^15.1.0",
|
|
40
50
|
"js-yaml": "^4.1.0",
|
|
41
|
-
"koa": "^
|
|
51
|
+
"koa": "^3.1.1",
|
|
42
52
|
"koa-basic-auth": "^4.0.0",
|
|
43
|
-
"koa-
|
|
53
|
+
"koa-body": "^7.0.0",
|
|
54
|
+
"koa-static": "^5.0.0",
|
|
44
55
|
"log4js": "^6.5.2",
|
|
45
56
|
"reflect-metadata": "^0.1.13",
|
|
46
57
|
"ws": "^8.16.0"
|
|
47
58
|
},
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "git+https://github.com/lc-cn/onebots.git"
|
|
62
|
+
},
|
|
48
63
|
"scripts": {
|
|
49
64
|
"start": "node .",
|
|
50
|
-
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
|
|
65
|
+
"build": "rm -f *.tsbuildinfo && tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
|
|
51
66
|
"clean": "rm -rf lib *.tsbuildinfo"
|
|
52
67
|
}
|
|
53
68
|
}
|