alemonjs 2.1.0-alpha.40 → 2.1.0-alpha.41

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 (78) hide show
  1. package/lib/adapter.js +112 -0
  2. package/lib/app/define-chidren.d.ts +1 -2
  3. package/lib/app/define-chidren.js +1 -1
  4. package/lib/app/event-group.d.ts +1 -2
  5. package/lib/app/event-middleware.d.ts +1 -2
  6. package/lib/app/event-middleware.js +1 -1
  7. package/lib/app/event-processor-cycle.d.ts +1 -2
  8. package/lib/app/event-processor-cycle.js +12 -6
  9. package/lib/app/event-processor-event.d.ts +2 -3
  10. package/lib/app/event-processor-middleware.d.ts +2 -3
  11. package/lib/app/event-processor-subscribe.d.ts +2 -3
  12. package/lib/app/event-processor.d.ts +1 -2
  13. package/lib/app/event-response.d.ts +1 -2
  14. package/lib/app/hook-use-api.d.ts +3 -4
  15. package/lib/app/hook-use-api.js +1 -1
  16. package/lib/app/hook-use-state.js +1 -1
  17. package/lib/app/hook-use-subscribe.d.ts +3 -4
  18. package/lib/app/hook-use-subscribe.js +1 -1
  19. package/lib/app/load.js +5 -6
  20. package/lib/app/message-api.d.ts +2 -2
  21. package/lib/app/message-api.js +1 -1
  22. package/lib/app/message-format.d.ts +7 -8
  23. package/lib/app/store.d.ts +6 -6
  24. package/lib/cbp/actions.js +1 -1
  25. package/lib/cbp/api.js +1 -1
  26. package/lib/cbp/client.js +1 -1
  27. package/lib/cbp/connect.js +1 -1
  28. package/lib/cbp/platform.d.ts +1 -2
  29. package/lib/cbp/platform.js +3 -3
  30. package/lib/cbp/server.js +1 -1
  31. package/lib/cbp/testone.js +1 -1
  32. package/lib/cbp/typings.d.ts +2 -3
  33. package/lib/core/config.d.ts +1 -2
  34. package/lib/core/config.js +1 -2
  35. package/lib/core/utils.d.ts +1 -1
  36. package/lib/core/utils.js +2 -3
  37. package/lib/core/variable.d.ts +16 -0
  38. package/lib/core/variable.js +19 -6
  39. package/lib/global.d.ts +5 -5
  40. package/lib/index.d.ts +29 -29
  41. package/lib/index.js +3 -3
  42. package/lib/main.js +14 -28
  43. package/lib/types/actions.d.ts +93 -0
  44. package/lib/types/apis.d.ts +18 -0
  45. package/lib/types/client/index.d.ts +66 -0
  46. package/lib/types/cycle/index.d.ts +42 -0
  47. package/lib/types/event/actions.d.ts +37 -0
  48. package/lib/types/event/actions.js +72 -0
  49. package/lib/types/event/base/expansion.d.ts +5 -0
  50. package/lib/types/event/base/guild.d.ts +18 -0
  51. package/lib/types/event/base/message.d.ts +28 -0
  52. package/lib/types/event/base/platform.d.ts +16 -0
  53. package/lib/types/event/base/user.d.ts +34 -0
  54. package/lib/types/event/channal/index.d.ts +13 -0
  55. package/lib/types/event/guild/index.d.ts +13 -0
  56. package/lib/types/event/index.d.ts +94 -0
  57. package/lib/types/event/interaction/index.d.ts +14 -0
  58. package/lib/types/event/map.d.ts +36 -0
  59. package/lib/types/event/member/index.d.ts +14 -0
  60. package/lib/types/event/message/message.d.ts +23 -0
  61. package/lib/types/event/message/private.message.d.ts +16 -0
  62. package/lib/types/event/request/index.d.ts +13 -0
  63. package/lib/types/logger/index.d.ts +49 -0
  64. package/lib/types/message/ark.d.ts +46 -0
  65. package/lib/types/message/button.d.ts +32 -0
  66. package/lib/types/message/image.d.ts +23 -0
  67. package/lib/types/message/index.d.ts +16 -0
  68. package/lib/types/message/link.d.ts +12 -0
  69. package/lib/types/message/markdown.d.ts +91 -0
  70. package/lib/types/message/mention.d.ts +16 -0
  71. package/lib/types/message/text.d.ts +12 -0
  72. package/lib/types/package/index.d.ts +12 -0
  73. package/lib/types/state/index.d.ts +5 -0
  74. package/lib/types/store/res.d.ts +75 -0
  75. package/lib/types/subscribe/index.d.ts +30 -0
  76. package/lib/utils.d.ts +0 -1
  77. package/lib/utils.js +3 -8
  78. package/package.json +1 -1
package/lib/adapter.js ADDED
@@ -0,0 +1,112 @@
1
+ import { fork } from 'child_process';
2
+ import { createRequire } from 'module';
3
+
4
+ const require = createRequire(import.meta.url);
5
+ /**
6
+ * 启动平台平台连接,优先使用子进程(fork),如不支持或平台连接未响应,则自动降级为 import 动态加载。
7
+ * 自动兼容新老版本平台连接。
8
+ * @param modulePath 平台连接模块绝对路径(require.resolve 得到的)
9
+ * @param env 环境变量对象
10
+ * @param logger 日志对象(需实现 info/warn/error)
11
+ */
12
+ function startAdapterWithFallback() {
13
+ let modulePath = '';
14
+ try {
15
+ modulePath = require.resolve(process.env.platform);
16
+ }
17
+ catch {
18
+ void import(process.env.platform).then(res => res?.default());
19
+ logger?.warn?.('平台连接包未支持 require,降级为 import 加载, 请升级对应的平台连接包以提高进程稳定性');
20
+ return;
21
+ }
22
+ let imported = false; // 标记 import 是否已成功,避免重复
23
+ const startByFork = () => {
24
+ if (imported) {
25
+ return; // 如果已经 import 成功,不再 fork
26
+ }
27
+ let restarted = false;
28
+ let ready = false;
29
+ let child;
30
+ const restart = () => {
31
+ if (restarted || imported) {
32
+ return;
33
+ }
34
+ restarted = true;
35
+ if (child) {
36
+ child.removeAllListeners();
37
+ try {
38
+ child.kill();
39
+ }
40
+ catch { }
41
+ }
42
+ setTimeout(() => {
43
+ startByFork();
44
+ }, 3000);
45
+ };
46
+ try {
47
+ child = fork(modulePath);
48
+ // 超时
49
+ const checkTimeout = async () => {
50
+ if (!ready && !imported) {
51
+ logger?.warn?.('平台连接未及时响应(未发送 ready 消息),降级为 import 加载, 请升级对应的平台连接包以提高进程稳定性');
52
+ try {
53
+ child?.kill();
54
+ }
55
+ catch { }
56
+ await startByImport();
57
+ }
58
+ };
59
+ const timer = setTimeout(() => void checkTimeout(), 2000);
60
+ child.on('exit', (code, signal) => {
61
+ clearTimeout(timer);
62
+ if (!imported) {
63
+ logger?.warn?.(`平台连接子进程已退出,code=${code}, signal=${signal},3秒后自动重启`);
64
+ restart();
65
+ }
66
+ });
67
+ child.on('message', msg => {
68
+ try {
69
+ const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
70
+ if (data?.type === 'ready') {
71
+ ready = true;
72
+ clearTimeout(timer);
73
+ logger?.debug?.('平台连接已就绪(子进程 fork 模式)');
74
+ }
75
+ }
76
+ catch (err) {
77
+ logger?.error?.('平台连接进程通信数据格式错误', err);
78
+ }
79
+ });
80
+ }
81
+ catch (err) {
82
+ logger?.warn?.('fork 启动平台连接失败,将尝试 import 加载', err);
83
+ void startByImport();
84
+ }
85
+ };
86
+ const startByImport = async () => {
87
+ if (imported) {
88
+ return;
89
+ }
90
+ imported = true;
91
+ try {
92
+ let importPath = modulePath;
93
+ if (!importPath.startsWith('file://')) {
94
+ importPath = 'file://' + importPath;
95
+ }
96
+ const mod = await import(importPath);
97
+ if (typeof mod.default === 'function') {
98
+ await mod.default();
99
+ logger?.debug?.('通过 import 启动平台连接完成');
100
+ }
101
+ else {
102
+ logger?.warn?.('通过 import 启动平台连接,但未找到默认导出函数');
103
+ }
104
+ }
105
+ catch (err) {
106
+ logger?.error?.('import 启动平台连接失败', err);
107
+ }
108
+ };
109
+ startByFork();
110
+ }
111
+
112
+ export { startAdapterWithFallback };
@@ -1,5 +1,4 @@
1
- import { DefineChildrenFunc } from '../typing/event/index.js';
2
- import '../global.js';
1
+ import { DefineChildrenFunc } from '../types/event/index.js';
3
2
 
4
3
  /**
5
4
  * 定义子事件
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
 
3
3
  /**
4
4
  * 定义子事件
@@ -1,5 +1,4 @@
1
- import { OnGroupFunc } from '../typing/event/index.js';
2
- import '../global.js';
1
+ import { OnGroupFunc } from '../types/event/index.js';
3
2
 
4
3
  /**
5
4
  * 定义一组标准执行导出
@@ -1,5 +1,4 @@
1
- import { OnMiddlewareReversalFunc, OnMiddlewareReversalFuncBack } from '../typing/event/index.js';
2
- import '../global.js';
1
+ import { OnMiddlewareReversalFunc, OnMiddlewareReversalFuncBack } from '../types/event/index.js';
3
2
 
4
3
  /**
5
4
  * @fileoverview 中间件
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
 
3
3
  /**
4
4
  * 中间件
@@ -1,5 +1,4 @@
1
- import { EventKeys, Events } from '../typing/event/map.js';
2
- import '../global.js';
1
+ import { EventKeys, Events } from '../types/event/map.js';
3
2
 
4
3
  /**
5
4
  * @fileoverview 消息处理快
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
  import { expendEvent } from './event-processor-event.js';
3
3
  import { expendMiddleware } from './event-processor-middleware.js';
4
4
  import { expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './event-processor-subscribe.js';
@@ -29,18 +29,24 @@ const showLog = (event, select) => {
29
29
  });
30
30
  }
31
31
  else {
32
- let baseLog = `[${ResultCode.Ok}][Name: ${select}]`;
32
+ let baseLog = `[Name: ${select}]`;
33
+ if (typeof event['GuildId'] === 'string' && event['GuildId'] !== '') {
34
+ baseLog += `[GuildId:${event['GuildId']}]`;
35
+ }
33
36
  if (typeof event['ChannelId'] === 'string' && event['ChannelId'] !== '') {
34
- baseLog += `[ChannelId: ${event['ChannelId']}]`;
37
+ baseLog += `[ChannelId:${event['ChannelId']}]`;
38
+ }
39
+ if (typeof event['UserKey'] === 'string' && event['UserKey'] !== '') {
40
+ baseLog += `[UserKey:${event['UserKey']}]`;
35
41
  }
36
42
  if (typeof event['UserId'] === 'string' && event['UserId'] !== '') {
37
- baseLog += `[UserId: ${event['UserId']}]`;
43
+ baseLog += `[UserId:${event['UserId']}]`;
38
44
  }
39
45
  if (typeof event['MessageId'] === 'string' && event['MessageId'] !== '') {
40
- baseLog += `[MessageId: ${event['MessageId']}]`;
46
+ baseLog += `[MessageId:${event['MessageId']}]`;
41
47
  }
42
48
  if (typeof event['MessageText'] === 'string' && event['MessageText'] !== '') {
43
- baseLog += `[MessageText: ${event['MessageText']}]`;
49
+ baseLog += `[MessageText:${event['MessageText']}]`;
44
50
  }
45
51
  logger.info(baseLog);
46
52
  }
@@ -1,6 +1,5 @@
1
- import { Next } from '../typing/cycle/index.js';
2
- import '../global.js';
3
- import { EventKeys, Events } from '../typing/event/map.js';
1
+ import { Next } from '../types/cycle/index.js';
2
+ import { EventKeys, Events } from '../types/event/map.js';
4
3
 
5
4
  /**
6
5
  * 消息体处理机制
@@ -1,6 +1,5 @@
1
- import { Next } from '../typing/cycle/index.js';
2
- import '../global.js';
3
- import { EventKeys, Events } from '../typing/event/map.js';
1
+ import { Next } from '../types/cycle/index.js';
2
+ import { EventKeys, Events } from '../types/event/map.js';
4
3
 
5
4
  /**
6
5
  * 处理中间件
@@ -1,6 +1,5 @@
1
- import { Next, EventCycleEnum } from '../typing/cycle/index.js';
2
- import '../global.js';
3
- import { EventKeys, Events } from '../typing/event/map.js';
1
+ import { Next, EventCycleEnum } from '../types/cycle/index.js';
2
+ import { EventKeys, Events } from '../types/event/map.js';
4
3
 
5
4
  /**
6
5
  * @fileoverview 观察者
@@ -1,5 +1,4 @@
1
- import { EventKeys, Events } from '../typing/event/map.js';
2
- import '../global.js';
1
+ import { EventKeys, Events } from '../types/event/map.js';
3
2
 
4
3
  /**
5
4
  * 消息处理器
@@ -1,5 +1,4 @@
1
- import { OnResponseReversalFunc, OnResponseReversalFuncBack } from '../typing/event/index.js';
2
- import '../global.js';
1
+ import { OnResponseReversalFunc, OnResponseReversalFuncBack } from '../types/event/index.js';
3
2
 
4
3
  /**
5
4
  * 处理响应事件
@@ -1,8 +1,7 @@
1
- import { EventKeys, Events } from '../typing/event/map.js';
2
- import { User } from '../typing/event/base/user.js';
1
+ import { EventKeys, Events } from '../types/event/map.js';
2
+ import { User } from '../types/event/base/user.js';
3
3
  import { Result } from '../core/utils.js';
4
- import '../global.js';
5
- import { DataEnums } from '../typing/message/index.js';
4
+ import { DataEnums } from '../types/message/index.js';
6
5
 
7
6
  type Options = {
8
7
  UserId?: string;
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
  import { ChildrenApp } from './store.js';
3
3
  import { createResult } from '../core/utils.js';
4
4
  import { sendAction } from '../cbp/actions.js';
@@ -1,5 +1,5 @@
1
1
  import { getConfig } from '../core/config.js';
2
- import { ResultCode } from '../core/code.js';
2
+ import { ResultCode } from '../core/variable.js';
3
3
  import { State, StateSubscribe } from './store.js';
4
4
 
5
5
  /**
@@ -1,7 +1,6 @@
1
- import { EventCycleEnum } from '../typing/cycle/index.js';
2
- import { Current } from '../typing/event/index.js';
3
- import { EventKeys, Events } from '../typing/event/map.js';
4
- import '../global.js';
1
+ import { EventCycleEnum } from '../types/cycle/index.js';
2
+ import { Current } from '../types/event/index.js';
3
+ import { EventKeys, Events } from '../types/event/map.js';
5
4
 
6
5
  /**
7
6
  * 订阅事件
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
  import { SubscribeList } from './store.js';
3
3
 
4
4
  /**
package/lib/app/load.js CHANGED
@@ -3,8 +3,7 @@ import { existsSync } from 'fs';
3
3
  import { showErrorModule, getRecursiveDirFiles, createEventName } from '../core/utils.js';
4
4
  import { createRequire } from 'module';
5
5
  import { ChildrenApp } from './store.js';
6
- import { ResultCode } from '../core/code.js';
7
- import { file_suffix_middleware } from '../core/variable.js';
6
+ import { ResultCode, fileSuffixMiddleware } from '../core/variable.js';
8
7
 
9
8
  const require = createRequire(import.meta.url);
10
9
  /**
@@ -98,7 +97,7 @@ const loadChildren = async (mainPath, appName) => {
98
97
  * load middleware files
99
98
  */
100
99
  const mwDir = join(mainDir, 'middleware');
101
- const mwFiles = getRecursiveDirFiles(mwDir, item => file_suffix_middleware.test(item.name));
100
+ const mwFiles = getRecursiveDirFiles(mwDir, item => fileSuffixMiddleware.test(item.name));
102
101
  const mwData = [];
103
102
  for (const file of mwFiles) {
104
103
  // 切掉 mainDir
@@ -120,11 +119,11 @@ const loadChildren = async (mainPath, appName) => {
120
119
  app?.onMounted && (await app.onMounted({ response: resData, middleware: mwData }));
121
120
  }
122
121
  catch (e) {
123
- unMounted(e);
122
+ void unMounted(e);
124
123
  }
125
124
  }
126
125
  catch (e) {
127
- unMounted(e);
126
+ void unMounted(e);
128
127
  }
129
128
  // unMounted 卸载
130
129
  }
@@ -158,7 +157,7 @@ const loadChildrenFile = async (appName) => {
158
157
  });
159
158
  return;
160
159
  }
161
- loadChildren(mainPath, appName);
160
+ void loadChildren(mainPath, appName);
162
161
  }
163
162
  catch (e) {
164
163
  showErrorModule(e);
@@ -1,6 +1,6 @@
1
- import { OnDataFormatFunc } from '../typing/event/index.js';
1
+ import { OnDataFormatFunc } from '../types/event/index.js';
2
2
  import { Result } from '../core/utils.js';
3
- import { DataEnums } from '../typing/message/index.js';
3
+ import { DataEnums } from '../types/message/index.js';
4
4
  import '../global.js';
5
5
 
6
6
  type BaseMap = {
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
  import { sendAction } from '../cbp/actions.js';
3
3
 
4
4
  /**
@@ -1,11 +1,10 @@
1
- import '../global.js';
2
- import { DataButton, ButtonRow, DataButtonGroup, DataButtonTemplate } from '../typing/message/button.js';
3
- import { DataArkListTip, DataArkListContent, DataArkList, DataArkListItem, DataArkCard, DataArkBigCard } from '../typing/message/ark.js';
4
- import { DataMarkDown, DataMarkdownTemplate, DataMarkdownText, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataMarkdownCode } from '../typing/message/markdown.js';
5
- import { DataImage, DataImageURL, DataImageFile } from '../typing/message/image.js';
6
- import { DataText } from '../typing/message/text.js';
7
- import { DataMention } from '../typing/message/mention.js';
8
- import { DataLink } from '../typing/message/link.js';
1
+ import { DataButton, ButtonRow, DataButtonGroup, DataButtonTemplate } from '../types/message/button.js';
2
+ import { DataArkListTip, DataArkListContent, DataArkList, DataArkListItem, DataArkCard, DataArkBigCard } from '../types/message/ark.js';
3
+ import { DataMarkDown, DataMarkdownTemplate, DataMarkdownText, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataMarkdownCode } from '../types/message/markdown.js';
4
+ import { DataImage, DataImageURL, DataImageFile } from '../types/message/image.js';
5
+ import { DataText } from '../types/message/text.js';
6
+ import { DataMention } from '../types/message/mention.js';
7
+ import { DataLink } from '../types/message/link.js';
9
8
 
10
9
  /**
11
10
  * 文本消息
@@ -1,10 +1,10 @@
1
- import { EventCycleEnum, ChildrenCycle } from '../typing/cycle/index.js';
2
- import { ResponseState } from '../typing/state/index.js';
3
- import { SinglyLinkedList } from '../datastructure/SinglyLinkedList.js';
4
- import { EventKeys } from '../typing/event/map.js';
5
- import { StoreChildrenApp, StoreResponseItem, StoreMiddlewareItem } from '../typing/store/res.js';
6
- import { StateSubscribeMap, SubscribeKeysMap, SubscribeValue } from '../typing/subscribe/index.js';
1
+ import { EventCycleEnum, ChildrenCycle } from '../types/cycle/index.js';
2
+ import { EventKeys } from '../types/event/map.js';
3
+ import { StoreChildrenApp, StoreResponseItem, StoreMiddlewareItem } from '../types/store/res.js';
4
+ import { StateSubscribeMap, SubscribeKeysMap, SubscribeValue } from '../types/subscribe/index.js';
7
5
  import '../global.js';
6
+ import { ResponseState } from '../types/state/index.js';
7
+ import { SinglyLinkedList } from '../datastructure/SinglyLinkedList.js';
8
8
 
9
9
  declare class Logger {
10
10
  #private;
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
  import { createResult } from '../core/utils.js';
3
3
  import { generateUniqueId, deviceId, actionResolves, actionTimeouts, timeoutTime } from './config.js';
4
4
  import * as flattedJSON from 'flatted';
package/lib/cbp/api.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
  import { createResult } from '../core/utils.js';
3
3
  import { generateUniqueId, deviceId, apiResolves, apiTimeouts, timeoutTime } from './config.js';
4
4
  import * as flattedJSON from 'flatted';
package/lib/cbp/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { WebSocket } from 'ws';
2
2
  import { onProcessor } from '../app/event-processor.js';
3
- import { ResultCode } from '../core/code.js';
3
+ import { ResultCode } from '../core/variable.js';
4
4
  import { deviceId, FULL_RECEIVE_HEADER, DEVICE_ID_HEADER, USER_AGENT_HEADER, apiResolves, apiTimeouts, actionResolves, actionTimeouts, reconnectInterval } from './config.js';
5
5
  import { createResult } from '../core/utils.js';
6
6
  import * as flattedJSON from 'flatted';
@@ -1,4 +1,4 @@
1
- import { ResultCode } from '../core/code.js';
1
+ import { ResultCode } from '../core/variable.js';
2
2
  import { HEARTBEAT_INTERVAL } from './config.js';
3
3
 
4
4
  // 心跳
@@ -1,5 +1,4 @@
1
- import { EventsEnum } from '../typing/event/map.js';
2
- import '../global.js';
1
+ import { EventsEnum } from '../types/event/map.js';
3
2
  import { ActionReplyFunc, ApiReplyFunc } from './typings.js';
4
3
 
5
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { WebSocket } from 'ws';
2
- import { ResultCode } from '../core/code.js';
2
+ import { ResultCode } from '../core/variable.js';
3
3
  import { deviceId, DEVICE_ID_HEADER, USER_AGENT_HEADER, reconnectInterval } from './config.js';
4
4
  import * as flattedJSON from 'flatted';
5
5
  import { useHeartbeat } from './connect.js';
@@ -116,14 +116,14 @@ const cbpPlatform = (url, options = {
116
116
  });
117
117
  if (data.apiId) {
118
118
  for (const cb of apiReplys) {
119
- cb(data,
119
+ void cb(data,
120
120
  // 传入一个消费函数
121
121
  val => replyApi(data, val));
122
122
  }
123
123
  }
124
124
  else if (data.actionId) {
125
125
  for (const cb of actionReplys) {
126
- cb(data,
126
+ void cb(data,
127
127
  // 传入一个消费函数
128
128
  val => replyAction(data, val));
129
129
  }
package/lib/cbp/server.js CHANGED
@@ -2,7 +2,7 @@ import Koa from 'koa';
2
2
  import { WebSocketServer, WebSocket } from 'ws';
3
3
  import router from './router.js';
4
4
  import koaCors from '@koa/cors';
5
- import { ResultCode } from '../core/code.js';
5
+ import { ResultCode } from '../core/variable.js';
6
6
  import { platformClient, childrenClient, fullClient, childrenBind, USER_AGENT_HEADER, USER_AGENT_HEADER_VALUE_MAP, DEVICE_ID_HEADER, FULL_RECEIVE_HEADER } from './config.js';
7
7
  import { getConfig } from '../core/config.js';
8
8
  import * as flattedJSON from 'flatted';
@@ -5,7 +5,7 @@ import { existsSync, mkdirSync, watch, readFileSync, writeFile } from 'fs';
5
5
  import _ from 'lodash';
6
6
  import { readFile } from 'fs/promises';
7
7
  import { actionResolves, actionTimeouts, apiResolves, apiTimeouts } from './config.js';
8
- import { ResultCode } from '../core/code.js';
8
+ import { ResultCode } from '../core/variable.js';
9
9
  import { createResult } from '../core/utils.js';
10
10
 
11
11
  /**
@@ -1,7 +1,6 @@
1
1
  import { Result } from '../core/utils.js';
2
- import '../global.js';
3
- import { Actions } from '../typing/actions.js';
4
- import { Apis } from '../typing/apis.js';
2
+ import { Actions } from '../types/actions.js';
3
+ import { Apis } from '../types/apis.js';
5
4
 
6
5
  type CBPClientOptions = {
7
6
  open?: () => void;
@@ -1,5 +1,4 @@
1
- import '../global.js';
2
- import { Package } from '../typing/package/index.js';
1
+ import { Package } from '../types/package/index.js';
3
2
 
4
3
  /**
5
4
  * 配置类
@@ -1,8 +1,7 @@
1
- import '../typing/event/actions.js';
2
1
  import { existsSync, readFileSync, watch, mkdirSync, writeFileSync } from 'fs';
3
2
  import { join, dirname } from 'path';
4
3
  import YAML from 'yaml';
5
- import { ResultCode } from './code.js';
4
+ import { ResultCode } from './variable.js';
6
5
 
7
6
  /**
8
7
  * 配置类
@@ -1,5 +1,5 @@
1
1
  import { Dirent } from 'fs';
2
- import { ResultCode } from './code.js';
2
+ import { ResultCode } from './variable.js';
3
3
 
4
4
  /**
5
5
  * 将字符串转为定长字符串
package/lib/core/utils.js CHANGED
@@ -2,8 +2,7 @@ import crypto from 'crypto';
2
2
  import fs, { existsSync, readdirSync } from 'fs';
3
3
  import path, { join } from 'path';
4
4
  import { createRequire } from 'module';
5
- import { ResultCode } from './code.js';
6
- import { file_suffix_response } from './variable.js';
5
+ import { fileSuffixResponse, ResultCode } from './variable.js';
7
6
 
8
7
  const require = createRequire(import.meta.url);
9
8
  /**
@@ -67,7 +66,7 @@ const stringToNumber = (str, size = 33) => {
67
66
  * @param condition
68
67
  * @returns
69
68
  */
70
- const getRecursiveDirFiles = (dir, condition = item => file_suffix_response.test(item.name)) => {
69
+ const getRecursiveDirFiles = (dir, condition = item => fileSuffixResponse.test(item.name)) => {
71
70
  //
72
71
  let results = [];
73
72
  if (!existsSync(dir)) {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 结果反馈码
3
+ * @description
4
+ * - 2000: 成功
5
+ */
6
+ declare const ResultCode: {
7
+ readonly Ok: 2000;
8
+ readonly Fail: 4000;
9
+ readonly FailParams: 4001;
10
+ readonly Warn: 2100;
11
+ readonly FailAuth: 4002;
12
+ readonly FailInternal: 5000;
13
+ };
14
+ type ResultCode = (typeof ResultCode)[keyof typeof ResultCode];
15
+
16
+ export { ResultCode };
@@ -4,15 +4,15 @@ const processor_repeated_clear_time_min = 1000 * 3;
4
4
  const processor_repeated_clear_time_max = 1000 * 10;
5
5
  const processor_repeated_clear_size = 37;
6
6
  // 中间件文件后缀正则
7
- const file_suffix_middleware = /^mw(\.|\..*\.)(js|ts|jsx|tsx)$/;
7
+ const fileSuffixMiddleware = /^mw(\.|\..*\.)(js|ts|jsx|tsx)$/;
8
8
  // 相应文件后缀正则
9
- const file_suffix_response = /^res(\.|\..*\.)(js|ts|jsx|tsx)$/;
9
+ const fileSuffixResponse = /^res(\.|\..*\.)(js|ts|jsx|tsx)$/;
10
10
  // 通用框架前缀正则
11
- const file_prefix_common = /^(@alemonjs\/|alemonjs-)/;
11
+ const filePrefixCommon = /^(@alemonjs\/|alemonjs-)/;
12
12
  // 默认端口
13
- const default_port = 17117;
13
+ const defaultPort = 17117;
14
14
  // 默认平台通用前缀
15
- const default_platform_common_prefix = '@alemonjs/';
15
+ const defaultPlatformCommonPrefix = '@alemonjs/';
16
16
  /**
17
17
  * 结果反馈码
18
18
  */
@@ -29,5 +29,18 @@ const FailAuth = 4002;
29
29
  // 授权错误
30
30
  const FailInternal = 5000; // 内部错误
31
31
  const EventMessageText = ['message.create', 'private.message.create', 'interaction.create', 'private.interaction.create'];
32
+ /**
33
+ * 结果反馈码
34
+ * @description
35
+ * - 2000: 成功
36
+ */
37
+ const ResultCode = {
38
+ Ok,
39
+ Fail,
40
+ FailParams,
41
+ Warn,
42
+ FailAuth,
43
+ FailInternal
44
+ };
32
45
 
33
- export { EventMessageText, Fail, FailAuth, FailInternal, FailParams, Ok, Warn, default_platform_common_prefix, default_port, file_prefix_common, file_suffix_middleware, file_suffix_response, processor_repeated_clear_size, processor_repeated_clear_time_max, processor_repeated_clear_time_min, processor_repeated_event_time, processor_repeated_user_time };
46
+ export { EventMessageText, Fail, FailAuth, FailInternal, FailParams, Ok, ResultCode, Warn, defaultPlatformCommonPrefix, defaultPort, filePrefixCommon, fileSuffixMiddleware, fileSuffixResponse, processor_repeated_clear_size, processor_repeated_clear_time_max, processor_repeated_clear_time_min, processor_repeated_event_time, processor_repeated_user_time };
package/lib/global.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { OnResponseReversalFunc, OnResponseReversalFuncBack, OnMiddlewareReversalFunc, OnMiddlewareReversalFuncBack, DefineChildrenFunc, OnSelectsFunc, OnDataFormatFunc, OnGroupFunc } from './typing/event/index.js';
2
- import { StoreChildrenApp } from './typing/store/res.js';
3
- import { StateSubscribeMap, SubscribeKeysMap } from './typing/subscribe/index.js';
4
- import { LoggerUtils } from './typing/logger/index.js';
5
- import { ResponseState } from './typing/state/index.js';
1
+ import { OnResponseReversalFunc, OnResponseReversalFuncBack, OnMiddlewareReversalFunc, OnMiddlewareReversalFuncBack, DefineChildrenFunc, OnSelectsFunc, OnDataFormatFunc, OnGroupFunc } from './types/event/index.js';
2
+ import { StoreChildrenApp } from './types/store/res.js';
3
+ import { StateSubscribeMap, SubscribeKeysMap } from './types/subscribe/index.js';
4
+ import { LoggerUtils } from './types/logger/index.js';
5
+ import { ResponseState } from './types/state/index.js';
6
6
  import WebSocket, { Server } from 'ws';
7
7
  import { IncomingMessage } from 'http';
8
8