@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.
Files changed (66) hide show
  1. package/README.md +3 -3
  2. package/lib/__tests__/config-validator.test.d.ts +4 -0
  3. package/lib/__tests__/config-validator.test.js +152 -0
  4. package/lib/__tests__/di-container.test.d.ts +4 -0
  5. package/lib/__tests__/di-container.test.js +114 -0
  6. package/lib/__tests__/errors.test.d.ts +4 -0
  7. package/lib/__tests__/errors.test.js +111 -0
  8. package/lib/__tests__/integration.test.d.ts +5 -0
  9. package/lib/__tests__/integration.test.js +112 -0
  10. package/lib/__tests__/lifecycle.test.d.ts +4 -0
  11. package/lib/__tests__/lifecycle.test.js +163 -0
  12. package/lib/account.d.ts +4 -1
  13. package/lib/account.js +6 -3
  14. package/lib/adapter.d.ts +67 -1
  15. package/lib/adapter.js +31 -4
  16. package/lib/base-app.d.ts +30 -3
  17. package/lib/base-app.js +295 -142
  18. package/lib/circuit-breaker.d.ts +94 -0
  19. package/lib/circuit-breaker.js +206 -0
  20. package/lib/config-validator.d.ts +51 -0
  21. package/lib/config-validator.js +184 -0
  22. package/lib/connection-pool.d.ts +68 -0
  23. package/lib/connection-pool.js +202 -0
  24. package/lib/db.d.ts +2 -1
  25. package/lib/db.js +11 -2
  26. package/lib/di-container.d.ts +60 -0
  27. package/lib/di-container.js +103 -0
  28. package/lib/errors.d.ts +157 -0
  29. package/lib/errors.js +257 -0
  30. package/lib/index.d.ts +13 -4
  31. package/lib/index.js +17 -3
  32. package/lib/lifecycle.d.ts +75 -0
  33. package/lib/lifecycle.js +175 -0
  34. package/lib/logger.d.ts +76 -0
  35. package/lib/logger.js +156 -0
  36. package/lib/metrics.d.ts +80 -0
  37. package/lib/metrics.js +201 -0
  38. package/lib/middleware/index.d.ts +8 -0
  39. package/lib/middleware/index.js +8 -0
  40. package/lib/middleware/metrics-collector.d.ts +9 -0
  41. package/lib/middleware/metrics-collector.js +64 -0
  42. package/lib/middleware/rate-limit.d.ts +32 -0
  43. package/lib/middleware/rate-limit.js +149 -0
  44. package/lib/middleware/security-audit.d.ts +33 -0
  45. package/lib/middleware/security-audit.js +223 -0
  46. package/lib/middleware/token-manager.d.ts +73 -0
  47. package/lib/middleware/token-manager.js +186 -0
  48. package/lib/middleware/token-validator.d.ts +42 -0
  49. package/lib/middleware/token-validator.js +198 -0
  50. package/lib/protocol.d.ts +2 -3
  51. package/lib/protocol.js +4 -0
  52. package/lib/rate-limiter.d.ts +88 -0
  53. package/lib/rate-limiter.js +196 -0
  54. package/lib/registry.d.ts +27 -0
  55. package/lib/registry.js +40 -5
  56. package/lib/retry.d.ts +87 -0
  57. package/lib/retry.js +205 -0
  58. package/lib/router.d.ts +43 -6
  59. package/lib/router.js +139 -12
  60. package/lib/timestamp.d.ts +42 -0
  61. package/lib/timestamp.js +72 -0
  62. package/lib/types.d.ts +1 -0
  63. package/lib/types.js +2 -1
  64. package/lib/utils.d.ts +2 -1
  65. package/lib/utils.js +11 -19
  66. 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
- if (typeof obj !== "object")
68
- return obj;
69
- if (!obj)
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 toLine(name) {
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.5.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": "^2.13.4",
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-bodyparser": "^4.3.7",
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": "^10.1.1",
49
+ "@koa/router": "^15.1.0",
40
50
  "js-yaml": "^4.1.0",
41
- "koa": "^2.13.4",
51
+ "koa": "^3.1.1",
42
52
  "koa-basic-auth": "^4.0.0",
43
- "koa-bodyparser": "^4.3.0",
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
  }