alemonjs 2.1.83-alpha.1 → 2.1.83-alpha.2

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 (227) hide show
  1. package/lib/{app → application}/define-children.js +2 -1
  2. package/lib/{app → application/format}/message-api.d.ts +2 -2
  3. package/lib/{app → application/format}/message-api.js +12 -4
  4. package/lib/{app → application/format}/message-format-old.d.ts +1 -1
  5. package/lib/{app → application/format}/message-format.d.ts +1 -2
  6. package/lib/{app → application/format}/message-format.js +0 -2
  7. package/lib/{app/hook-use → application/hooks}/announce.js +4 -3
  8. package/lib/{app/hook-use → application/hooks}/channel.js +4 -3
  9. package/lib/{app/hook-use → application/hooks}/client.d.ts +1 -1
  10. package/lib/{app/hook-use → application/hooks}/client.js +4 -11
  11. package/lib/{app/hook-use → application/hooks}/common.d.ts +7 -7
  12. package/lib/{app/hook-use → application/hooks}/common.js +9 -8
  13. package/lib/{app/hook-use → application/hooks}/event.js +1 -1
  14. package/lib/{app/hook-use → application/hooks}/guild.js +4 -3
  15. package/lib/{app/hook-use → application/hooks}/history.js +4 -3
  16. package/lib/{app/hook-use → application/hooks}/me.js +12 -7
  17. package/lib/{app/hook-use → application/hooks}/media.d.ts +3 -3
  18. package/lib/{app/hook-use → application/hooks}/media.js +4 -3
  19. package/lib/{app/hook-use → application/hooks}/member.js +4 -3
  20. package/lib/{app/hook-use → application/hooks}/mention.js +4 -3
  21. package/lib/{app/hook-use → application/hooks}/message.js +6 -5
  22. package/lib/{app/hook-use → application/hooks}/permission.js +4 -3
  23. package/lib/{app/hook-use → application/hooks}/reaction.js +4 -3
  24. package/lib/{app/hook-use → application/hooks}/request.js +12 -7
  25. package/lib/{app/hook-use → application/hooks}/role.js +4 -3
  26. package/lib/{app/hook-use → application/hooks}/subscribe.js +4 -4
  27. package/lib/{app/hook-use → application/hooks}/user.js +12 -7
  28. package/lib/application/index.d.ts +12 -0
  29. package/lib/application/index.js +32 -0
  30. package/lib/{app → application}/router/dsl.d.ts +1 -1
  31. package/lib/{app → application}/router/dsl.js +11 -7
  32. package/lib/{cbp → application/runtime/cbp}/connects/client.d.ts +1 -1
  33. package/lib/{cbp → application/runtime/cbp}/connects/client.js +11 -20
  34. package/lib/application/runtime/cbp/index.d.ts +3 -0
  35. package/lib/application/runtime/cbp/index.js +3 -0
  36. package/lib/application/runtime/cbp/processor/actions.d.ts +3 -0
  37. package/lib/{cbp → application/runtime/cbp}/processor/actions.js +12 -4
  38. package/lib/application/runtime/cbp/processor/api.d.ts +3 -0
  39. package/lib/{cbp → application/runtime/cbp}/processor/api.js +12 -4
  40. package/lib/application/runtime/cbp/processor/request-registry.d.ts +8 -0
  41. package/lib/application/runtime/cbp/processor/request-registry.js +6 -0
  42. package/lib/application/runtime/client-runtime.d.ts +1 -0
  43. package/lib/application/runtime/client-runtime.js +95 -0
  44. package/lib/{app → application/runtime}/event-error.d.ts +1 -1
  45. package/lib/{app → application/runtime}/event-error.js +1 -1
  46. package/lib/{app → application/runtime}/event-group.d.ts +1 -1
  47. package/lib/{app → application/runtime}/event-middleware.d.ts +1 -1
  48. package/lib/{app → application/runtime}/event-middleware.js +1 -1
  49. package/lib/{app → application/runtime}/event-processor-callHandler.d.ts +1 -1
  50. package/lib/{app → application/runtime}/event-processor-callHandler.js +8 -1
  51. package/lib/{app → application/runtime}/event-processor-cycle.d.ts +1 -1
  52. package/lib/{app → application/runtime}/event-processor-cycleFiles.d.ts +1 -1
  53. package/lib/{app → application/runtime}/event-processor-cycleFiles.js +2 -2
  54. package/lib/{app → application/runtime}/event-processor-cycleRoute.d.ts +1 -1
  55. package/lib/{app → application/runtime}/event-processor-cycleRoute.js +9 -2
  56. package/lib/{app → application/runtime}/event-processor-event.d.ts +1 -1
  57. package/lib/{app → application/runtime}/event-processor-middleware.d.ts +1 -1
  58. package/lib/{app → application/runtime}/event-processor-subscribe.d.ts +1 -1
  59. package/lib/{app → application/runtime}/event-processor-subscribe.js +9 -2
  60. package/lib/{app → application/runtime}/event-processor.d.ts +1 -1
  61. package/lib/{app → application/runtime}/event-processor.js +4 -3
  62. package/lib/{app → application/runtime}/event-response.d.ts +1 -1
  63. package/lib/{app → application/runtime}/event-utils.d.ts +1 -1
  64. package/lib/{app → application/runtime}/event-utils.js +2 -2
  65. package/lib/{app → application/runtime}/hook-event-context.d.ts +2 -2
  66. package/lib/{app → application/runtime}/hook-event-context.js +2 -2
  67. package/lib/application/runtime/http/index.d.ts +4 -0
  68. package/lib/application/runtime/http/index.js +4 -0
  69. package/lib/{server → application/runtime/http}/routers/hello.html.js +1 -1
  70. package/lib/{server → application/runtime/http}/routers/middleware.js +1 -2
  71. package/lib/{server → application/runtime/http}/routers/router.js +11 -4
  72. package/lib/{server → application/runtime/http}/routers/utils.d.ts +1 -1
  73. package/lib/{server → application/runtime/http}/routers/utils.js +6 -6
  74. package/lib/{server/main.js → application/runtime/http-server.js} +2 -6
  75. package/lib/{app → application/runtime}/lifecycle-callbacks.d.ts +1 -1
  76. package/lib/{app → application/runtime}/lifecycle-callbacks.js +2 -7
  77. package/lib/{app/load_modules → application/runtime/load-modules}/load.js +2 -2
  78. package/lib/{app/load_modules → application/runtime/load-modules}/loadChild.js +3 -3
  79. package/lib/{app → application/runtime}/schedule-store.d.ts +1 -1
  80. package/lib/{app → application/runtime}/schedule-store.js +1 -1
  81. package/lib/{app → application/runtime}/store.d.ts +14 -19
  82. package/lib/{app → application/runtime}/store.js +8 -103
  83. package/lib/application/schedule.d.ts +17 -0
  84. package/lib/{app/api → application}/schedule.js +1 -1
  85. package/lib/client.d.ts +1 -1
  86. package/lib/client.js +1 -117
  87. package/lib/common/cbp/constants.d.ts +11 -0
  88. package/lib/common/cbp/constants.js +13 -0
  89. package/lib/{cbp/connects/connect.js → common/cbp/heartbeat.js} +3 -6
  90. package/lib/{cbp → common/cbp}/normalize.d.ts +2 -2
  91. package/lib/{cbp → common/cbp}/normalize.js +1 -5
  92. package/lib/common/cbp/runtime.d.ts +2 -0
  93. package/lib/common/cbp/runtime.js +10 -0
  94. package/lib/{cbp → common/cbp}/typings.d.ts +2 -2
  95. package/lib/{cbp/connects/base.js → common/cbp/ws-connector.js} +7 -9
  96. package/lib/{core → common}/config.d.ts +2 -2
  97. package/lib/{core → common}/config.js +5 -4
  98. package/lib/common/identity.d.ts +11 -0
  99. package/lib/common/identity.js +34 -0
  100. package/lib/common/index.d.ts +15 -0
  101. package/lib/common/index.js +14 -0
  102. package/lib/common/logger.d.ts +6 -0
  103. package/lib/common/logger.js +99 -0
  104. package/lib/common/result.d.ts +7 -0
  105. package/lib/common/result.js +19 -0
  106. package/lib/{core → common}/utils.d.ts +3 -18
  107. package/lib/{core → common}/utils.js +6 -49
  108. package/lib/{core → common}/variable.js +1 -1
  109. package/lib/core/cbp/index.d.ts +1 -0
  110. package/lib/core/cbp/index.js +1 -0
  111. package/lib/core/cbp/processor/config.d.ts +8 -0
  112. package/lib/core/cbp/processor/config.js +29 -0
  113. package/lib/{cbp → core/cbp}/routers/hello.html.js +1 -1
  114. package/lib/{cbp → core/cbp}/server/main.js +10 -4
  115. package/lib/{cbp → core/cbp}/server/testone.d.ts +1 -1
  116. package/lib/{cbp → core/cbp}/server/testone.js +8 -2
  117. package/lib/core/index.d.ts +1 -3
  118. package/lib/core/index.js +1 -3
  119. package/lib/core/process/index.d.ts +3 -0
  120. package/lib/{process → core/process}/index.js +0 -1
  121. package/lib/{process → core/process}/ipc-bridge.js +6 -1
  122. package/lib/{process → core/process}/module.js +13 -4
  123. package/lib/{process → core/process}/platform.js +12 -3
  124. package/lib/core/start.d.ts +2 -0
  125. package/lib/core/start.js +76 -0
  126. package/lib/global.d.ts +4 -3
  127. package/lib/index.d.ts +5 -4
  128. package/lib/index.js +9 -54
  129. package/lib/main.d.ts +1 -2
  130. package/lib/main.js +1 -76
  131. package/lib/{cbp/connects/platform.d.ts → platform/cbp-platform.d.ts} +2 -2
  132. package/lib/{cbp/connects/platform.js → platform/cbp-platform.js} +8 -8
  133. package/lib/{app → platform}/define-platform.js +2 -0
  134. package/lib/platform/event-value.d.ts +7 -0
  135. package/lib/platform/event-value.js +5 -0
  136. package/lib/platform/index.d.ts +5 -0
  137. package/lib/platform/index.js +5 -0
  138. package/lib/types/client/index.d.ts +1 -1
  139. package/lib/types/event/index.d.ts +1 -1
  140. package/lib/types/subscribe/index.d.ts +1 -1
  141. package/package.json +22 -1
  142. package/lib/app/api/schedule.d.ts +0 -17
  143. package/lib/app/index.d.ts +0 -25
  144. package/lib/app/index.js +0 -47
  145. package/lib/cbp/index.d.ts +0 -3
  146. package/lib/cbp/index.js +0 -3
  147. package/lib/cbp/processor/actions.d.ts +0 -3
  148. package/lib/cbp/processor/api.d.ts +0 -3
  149. package/lib/cbp/processor/config.d.ts +0 -33
  150. package/lib/cbp/processor/config.js +0 -56
  151. package/lib/process/index.d.ts +0 -4
  152. /package/lib/{app → application}/define-children.d.ts +0 -0
  153. /package/lib/{app → application}/define-middleware.d.ts +0 -0
  154. /package/lib/{app → application}/define-middleware.js +0 -0
  155. /package/lib/{app → application}/define-response.d.ts +0 -0
  156. /package/lib/{app → application}/define-response.js +0 -0
  157. /package/lib/{app → application}/define-router.d.ts +0 -0
  158. /package/lib/{app → application}/define-router.js +0 -0
  159. /package/lib/{app → application}/expose.d.ts +0 -0
  160. /package/lib/{app → application}/expose.js +0 -0
  161. /package/lib/{app → application/format}/message-format-old.js +0 -0
  162. /package/lib/{app/hook-use → application/hooks}/announce.d.ts +0 -0
  163. /package/lib/{app/hook-use → application/hooks}/channel.d.ts +0 -0
  164. /package/lib/{app/hook-use → application/hooks}/event.d.ts +0 -0
  165. /package/lib/{app/hook-use → application/hooks}/guild.d.ts +0 -0
  166. /package/lib/{app/hook-use → application/hooks}/history.d.ts +0 -0
  167. /package/lib/{app/hook-use → application/hooks}/index.d.ts +0 -0
  168. /package/lib/{app/hook-use → application/hooks}/index.js +0 -0
  169. /package/lib/{app/hook-use → application/hooks}/me.d.ts +0 -0
  170. /package/lib/{app/hook-use → application/hooks}/member.d.ts +0 -0
  171. /package/lib/{app/hook-use → application/hooks}/mention.d.ts +0 -0
  172. /package/lib/{app/hook-use → application/hooks}/message.d.ts +0 -0
  173. /package/lib/{app/hook-use → application/hooks}/permission.d.ts +0 -0
  174. /package/lib/{app/hook-use → application/hooks}/reaction.d.ts +0 -0
  175. /package/lib/{app/hook-use → application/hooks}/request.d.ts +0 -0
  176. /package/lib/{app/hook-use → application/hooks}/role.d.ts +0 -0
  177. /package/lib/{app/hook-use → application/hooks}/route.d.ts +0 -0
  178. /package/lib/{app/hook-use → application/hooks}/route.js +0 -0
  179. /package/lib/{app/hook-use → application/hooks}/subscribe.d.ts +0 -0
  180. /package/lib/{app/hook-use → application/hooks}/user.d.ts +0 -0
  181. /package/lib/{app → application}/router/fallback.d.ts +0 -0
  182. /package/lib/{app → application}/router/fallback.js +0 -0
  183. /package/lib/{app → application}/router/main.d.ts +0 -0
  184. /package/lib/{app → application}/router/main.js +0 -0
  185. /package/lib/{app → application}/router/parser.d.ts +0 -0
  186. /package/lib/{app → application}/router/parser.js +0 -0
  187. /package/lib/{app → application}/router/types.d.ts +0 -0
  188. /package/lib/{app → application}/router/types.js +0 -0
  189. /package/lib/{app → application}/router/validator.d.ts +0 -0
  190. /package/lib/{app → application}/router/validator.js +0 -0
  191. /package/lib/{cbp → application/runtime/cbp}/processor/transport.d.ts +0 -0
  192. /package/lib/{cbp → application/runtime/cbp}/processor/transport.js +0 -0
  193. /package/lib/{app → application/runtime}/event-group.js +0 -0
  194. /package/lib/{app → application/runtime}/event-processor-cycle.js +0 -0
  195. /package/lib/{app → application/runtime}/event-processor-event.js +0 -0
  196. /package/lib/{app → application/runtime}/event-processor-middleware.js +0 -0
  197. /package/lib/{app → application/runtime}/event-response.js +0 -0
  198. /package/lib/{cbp → application/runtime/http}/routers/hello.html.d.ts +0 -0
  199. /package/lib/{server → application/runtime/http}/routers/middleware.d.ts +0 -0
  200. /package/lib/{cbp → application/runtime/http}/routers/router.d.ts +0 -0
  201. /package/lib/{server/main.d.ts → application/runtime/http-server.d.ts} +0 -0
  202. /package/lib/{app/load_modules → application/runtime/load-modules}/index.d.ts +0 -0
  203. /package/lib/{app/load_modules → application/runtime/load-modules}/index.js +0 -0
  204. /package/lib/{app/load_modules → application/runtime/load-modules}/load.d.ts +0 -0
  205. /package/lib/{app/load_modules → application/runtime/load-modules}/loadChild.d.ts +0 -0
  206. /package/lib/{app/config.d.ts → application/runtime/subscribe-status.d.ts} +0 -0
  207. /package/lib/{app/config.js → application/runtime/subscribe-status.js} +0 -0
  208. /package/lib/{app → common}/SinglyLinkedList.d.ts +0 -0
  209. /package/lib/{app → common}/SinglyLinkedList.js +0 -0
  210. /package/lib/{cbp/connects/connect.d.ts → common/cbp/heartbeat.d.ts} +0 -0
  211. /package/lib/{cbp → common/cbp}/typings.js +0 -0
  212. /package/lib/{cbp/connects/base.d.ts → common/cbp/ws-connector.d.ts} +0 -0
  213. /package/lib/{process → common}/direct-channel.d.ts +0 -0
  214. /package/lib/{process → common}/direct-channel.js +0 -0
  215. /package/lib/{core → common}/react.d.ts +0 -0
  216. /package/lib/{core → common}/react.js +0 -0
  217. /package/lib/{core → common}/variable.d.ts +0 -0
  218. /package/lib/{server → core/cbp}/routers/hello.html.d.ts +0 -0
  219. /package/lib/{server → core/cbp}/routers/router.d.ts +0 -0
  220. /package/lib/{cbp → core/cbp}/routers/router.js +0 -0
  221. /package/lib/{cbp → core/cbp}/server/main.d.ts +0 -0
  222. /package/lib/{process → core/process}/ipc-bridge.d.ts +0 -0
  223. /package/lib/{process → core/process}/module.d.ts +0 -0
  224. /package/lib/{process → core/process}/platform.d.ts +0 -0
  225. /package/lib/{app → platform}/define-platform.d.ts +0 -0
  226. /package/lib/{app → platform}/event-format.d.ts +0 -0
  227. /package/lib/{app → platform}/event-format.js +0 -0
@@ -0,0 +1,7 @@
1
+ import { ResultCode } from './variable.js';
2
+ export type Result<T = any> = {
3
+ code: ResultCode;
4
+ message: string | object;
5
+ data: T;
6
+ };
7
+ export declare const createResult: <T>(code: ResultCode, message: string | object, data?: T) => Result<T>;
@@ -0,0 +1,19 @@
1
+ import { logger } from './logger.js';
2
+ import { ResultCode } from './variable.js';
3
+
4
+ const createResult = (code, message, data) => {
5
+ if (code !== ResultCode.Ok) {
6
+ logger.error({
7
+ code,
8
+ message,
9
+ data
10
+ });
11
+ }
12
+ return {
13
+ code,
14
+ message,
15
+ data
16
+ };
17
+ };
18
+
19
+ export { createResult };
@@ -1,21 +1,12 @@
1
1
  import { Dirent } from 'fs';
2
- import { ResultCode } from './variable';
2
+ export { createUserHashKey, fastHash, isMaster, matchIn, useUserHashKey } from './identity.js';
3
+ export type { Result } from './result.js';
4
+ export { createResult } from './result.js';
3
5
  export declare const createHash: (str: string, options?: {
4
6
  length?: number;
5
7
  algorithm?: string;
6
8
  }) => string;
7
- export declare const fastHash: (str: string) => string;
8
9
  export declare const getCachedRegExp: (pattern: string | RegExp) => RegExp;
9
- export declare const createUserHashKey: (event: {
10
- UserId: string;
11
- Platform: string;
12
- }) => string;
13
- export declare const useUserHashKey: (event: {
14
- UserId: string;
15
- Platform: string;
16
- }) => string;
17
- export declare const matchIn: (source: any, key: string) => boolean;
18
- export declare const isMaster: (UserId: string, platform: string) => boolean;
19
10
  export declare const createEventName: (url: string, appKey: string) => string;
20
11
  export declare const stringToNumber: (str: string, size?: number) => number;
21
12
  export declare const getRecursiveDirFiles: (dir: string, condition?: (func: Dirent) => boolean) => {
@@ -25,9 +16,3 @@ export declare const getRecursiveDirFiles: (dir: string, condition?: (func: Dire
25
16
  export declare const showErrorModule: (e: Error) => void;
26
17
  export declare const sanitizeForSerialization: (data: any) => any;
27
18
  export declare const getInputExportPath: (input?: string) => any;
28
- export type Result<T = any> = {
29
- code: ResultCode;
30
- message: string | object;
31
- data: T;
32
- };
33
- export declare const createResult: <T>(code: ResultCode, message: string | object, data?: T) => Result<T>;
@@ -1,9 +1,11 @@
1
1
  import { createHash as createHash$1 } from 'node:crypto';
2
2
  import fs__default, { existsSync, readdirSync } from 'fs';
3
3
  import path__default, { join } from 'path';
4
- import { ResultCode, fileSuffixResponse } from './variable.js';
5
4
  import module$1 from 'module';
6
- import { getConfigValue } from './config.js';
5
+ import { ResultCode, fileSuffixResponse } from './variable.js';
6
+ import { logger } from './logger.js';
7
+ export { createUserHashKey, fastHash, isMaster, matchIn, useUserHashKey } from './identity.js';
8
+ export { createResult } from './result.js';
7
9
 
8
10
  const initRequire = () => { };
9
11
  initRequire.resolve = () => '';
@@ -13,14 +15,6 @@ const createHash = (str, options = {}) => {
13
15
  const hash = createHash$1(algorithm).update(str).digest('hex');
14
16
  return hash.slice(0, length);
15
17
  };
16
- const fastHash = (str) => {
17
- let hash = 0x811c9dc5;
18
- for (let i = 0; i < str.length; i++) {
19
- hash ^= str.charCodeAt(i);
20
- hash = Math.imul(hash, 0x01000193);
21
- }
22
- return (hash >>> 0).toString(36);
23
- };
24
18
  const _regexpCache = new Map();
25
19
  const getCachedRegExp = (pattern) => {
26
20
  if (pattern instanceof RegExp) {
@@ -33,28 +27,6 @@ const getCachedRegExp = (pattern) => {
33
27
  }
34
28
  return cached;
35
29
  };
36
- const createUserHashKey = (event) => {
37
- return fastHash(`${event.Platform}:${event.UserId}`);
38
- };
39
- const useUserHashKey = createUserHashKey;
40
- const matchIn = (source, key) => {
41
- if (Array.isArray(source)) {
42
- return source.includes(key);
43
- }
44
- if (source && typeof source === 'object') {
45
- return Object.prototype.hasOwnProperty.call(source, key) && !!source[key];
46
- }
47
- return false;
48
- };
49
- const isMaster = (UserId, platform) => {
50
- const values = getConfigValue() || {};
51
- const value = values[platform] && typeof values[platform] === 'object' ? values[platform] : {};
52
- const UserKey = createUserHashKey({
53
- Platform: platform,
54
- UserId: UserId
55
- });
56
- return matchIn(values.master_key, UserKey) || matchIn(values.master_id, UserId) || matchIn(value.master_key, UserKey) || matchIn(value.master_id, UserId);
57
- };
58
30
  const createEventName = (url, appKey) => {
59
31
  let uri = url;
60
32
  if (process.platform === 'win32') {
@@ -62,8 +34,7 @@ const createEventName = (url, appKey) => {
62
34
  }
63
35
  const names = uri.split('/').filter(item => item !== '');
64
36
  names.pop();
65
- const name = `${appKey}:${names.join(':')}`;
66
- return name;
37
+ return `${appKey}:${names.join(':')}`;
67
38
  };
68
39
  const stringToNumber = (str, size = 33) => {
69
40
  let hash = 5381;
@@ -140,19 +111,5 @@ const getInputExportPath = (input) => {
140
111
  }
141
112
  }
142
113
  };
143
- const createResult = (code, message, data) => {
144
- if (code !== ResultCode.Ok) {
145
- logger.error({
146
- code,
147
- message,
148
- data: data
149
- });
150
- }
151
- return {
152
- code,
153
- message,
154
- data: data
155
- };
156
- };
157
114
 
158
- export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, matchIn, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey };
115
+ export { createEventName, createHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, sanitizeForSerialization, showErrorModule, stringToNumber };
@@ -61,7 +61,7 @@ class Result {
61
61
  this.#data[this.#currentIndex] = {
62
62
  code: ResultCode.Ok,
63
63
  message: '',
64
- data: data
64
+ data
65
65
  };
66
66
  }
67
67
  this.#data[this.#currentIndex].data = data;
@@ -0,0 +1 @@
1
+ export { cbpServer } from './server/main.js';
@@ -0,0 +1 @@
1
+ export { cbpServer } from './server/main.js';
@@ -0,0 +1,8 @@
1
+ import { WebSocket } from 'ws';
2
+ export declare const childrenClient: Map<string, WebSocket>;
3
+ export declare const platformClient: Map<string, WebSocket>;
4
+ export declare const fullClient: Map<string, WebSocket>;
5
+ export declare const childrenBind: Map<string, string>;
6
+ export declare const clientBindCount: Map<string, number>;
7
+ export declare const bindChannelToClient: (channelId: string, clientId: string) => void;
8
+ export declare const unbindClient: (clientId: string) => void;
@@ -0,0 +1,29 @@
1
+ const childrenClient = new Map();
2
+ const platformClient = new Map();
3
+ const fullClient = new Map();
4
+ const childrenBind = new Map();
5
+ const clientBindCount = new Map();
6
+ const bindChannelToClient = (channelId, clientId) => {
7
+ const oldClientId = childrenBind.get(channelId);
8
+ if (oldClientId && oldClientId !== clientId) {
9
+ const oldCount = clientBindCount.get(oldClientId) ?? 0;
10
+ if (oldCount > 1) {
11
+ clientBindCount.set(oldClientId, oldCount - 1);
12
+ }
13
+ else {
14
+ clientBindCount.delete(oldClientId);
15
+ }
16
+ }
17
+ childrenBind.set(channelId, clientId);
18
+ clientBindCount.set(clientId, (clientBindCount.get(clientId) ?? 0) + 1);
19
+ };
20
+ const unbindClient = (clientId) => {
21
+ for (const [channelId, boundClientId] of childrenBind.entries()) {
22
+ if (boundClientId === clientId) {
23
+ childrenBind.delete(channelId);
24
+ }
25
+ }
26
+ clientBindCount.delete(clientId);
27
+ };
28
+
29
+ export { bindChannelToClient, childrenBind, childrenClient, clientBindCount, fullClient, platformClient, unbindClient };
@@ -1,4 +1,4 @@
1
- import { Component, Head, Title, Style, Body, H1, P, A, Div, Html } from '../../core/react.js';
1
+ import { Component, Head, Title, Style, Body, H1, P, A, Div, Html } from '../../../common/react.js';
2
2
 
3
3
  class App extends Component {
4
4
  render() {
@@ -3,15 +3,21 @@ import { WebSocketServer, WebSocket } from 'ws';
3
3
  import * as flattedJSON from 'flatted';
4
4
  import koaCors from '@koa/cors';
5
5
  import router from '../routers/router.js';
6
- import { ResultCode } from '../../core/variable.js';
7
6
  import 'fs';
8
7
  import 'path';
9
8
  import 'yaml';
10
- import '../../core/utils.js';
11
- import { USER_AGENT_HEADER, USER_AGENT_HEADER_VALUE_MAP, DEVICE_ID_HEADER, FULL_RECEIVE_HEADER, platformClient, childrenClient, fullClient, childrenBind, clientBindCount, unbindClient, bindChannelToClient } from '../processor/config.js';
9
+ import '../../../common/logger.js';
10
+ import { ResultCode } from '../../../common/variable.js';
11
+ import '../../../common/utils.js';
12
+ import 'net';
13
+ import 'v8';
14
+ import 'os';
15
+ import { USER_AGENT_HEADER, USER_AGENT_HEADER_VALUE_MAP, DEVICE_ID_HEADER, FULL_RECEIVE_HEADER } from '../../../common/cbp/constants.js';
16
+ import '../../../common/cbp/runtime.js';
17
+ import { normalizeInboundMessage, getNormalizedDeviceId, getNormalizedEventRouteId } from '../../../common/cbp/normalize.js';
18
+ import { platformClient, childrenClient, fullClient, childrenBind, clientBindCount, unbindClient, bindChannelToClient } from '../processor/config.js';
12
19
  import { createTestOneController } from './testone.js';
13
20
  import { getClientChild } from '../../process/ipc-bridge.js';
14
- import { normalizeInboundMessage, getNormalizedDeviceId, getNormalizedEventRouteId } from '../normalize.js';
15
21
 
16
22
  const routeNormalizedMessage = (message, input) => {
17
23
  const normalized = normalizeInboundMessage(input);
@@ -1,6 +1,6 @@
1
1
  import { IncomingMessage } from 'http';
2
2
  import { WebSocket } from 'ws';
3
- import type { ParsedMessage } from '../typings';
3
+ import type { ParsedMessage } from '../../../common/cbp/typings.js';
4
4
  export declare const createTestOneController: (ws: WebSocket, _request: IncomingMessage) => {
5
5
  onMessage: (parsedMessage: ParsedMessage) => void;
6
6
  close: () => void;
@@ -3,9 +3,15 @@ import { join, dirname } from 'path';
3
3
  import { existsSync, mkdirSync, watch, readFileSync, writeFile } from 'fs';
4
4
  import _ from 'lodash';
5
5
  import { readFile } from 'fs/promises';
6
- import { ResultCode } from '../../core/variable.js';
7
6
  import 'yaml';
8
- import '../../core/utils.js';
7
+ import '../../../common/logger.js';
8
+ import { ResultCode } from '../../../common/variable.js';
9
+ import '../../../common/utils.js';
10
+ import 'net';
11
+ import 'v8';
12
+ import 'os';
13
+ import '../../../common/cbp/runtime.js';
14
+ import 'ws';
9
15
 
10
16
  const createTestOneController = (ws, _request) => {
11
17
  const testonePath = join(process.cwd(), 'testone');
@@ -1,3 +1 @@
1
- export { ResultCode } from './variable.js';
2
- export * from './config.js';
3
- export * from './utils.js';
1
+ export { start } from './start.js';
package/lib/core/index.js CHANGED
@@ -1,3 +1 @@
1
- export { ResultCode } from './variable.js';
2
- export { getConfig, getConfigValue, onWatchConfigValue } from './config.js';
3
- export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, matchIn, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey } from './utils.js';
1
+ export { start } from './start.js';
@@ -0,0 +1,3 @@
1
+ export * from './module.js';
2
+ export * from './platform.js';
3
+ export * from './ipc-bridge.js';
@@ -1,4 +1,3 @@
1
1
  export { startModuleAdapter } from './module.js';
2
2
  export { startPlatformAdapterWithFallback } from './platform.js';
3
3
  export { forwardFromClient, forwardFromPlatform, getClientChild, getPlatformChild, setClientChild, setPlatformChild } from './ipc-bridge.js';
4
- export { createDirectClient, createDirectServer, generateSocketPath } from './direct-channel.js';
@@ -4,7 +4,12 @@ import * as flattedJSON from 'flatted';
4
4
  import 'fs';
5
5
  import 'path';
6
6
  import 'yaml';
7
- import { sanitizeForSerialization } from '../core/utils.js';
7
+ import '../../common/logger.js';
8
+ import { sanitizeForSerialization } from '../../common/utils.js';
9
+ import 'net';
10
+ import 'v8';
11
+ import 'os';
12
+ import '../../common/cbp/runtime.js';
8
13
 
9
14
  let platformChild = null;
10
15
  let clientChild = null;
@@ -1,7 +1,16 @@
1
1
  import childProcess from 'child_process';
2
- import { ResultCode } from '../core/variable.js';
3
- import { getConfigValue } from '../core/config.js';
4
- import '../core/utils.js';
2
+ import { getConfigValue } from '../../common/config.js';
3
+ import { ResultCode } from '../../common/variable.js';
4
+ import '../../common/logger.js';
5
+ import '../../common/utils.js';
6
+ import 'net';
7
+ import 'v8';
8
+ import 'os';
9
+ import 'path';
10
+ import 'fs';
11
+ import 'flatted';
12
+ import '../../common/cbp/runtime.js';
13
+ import 'ws';
5
14
  import module$1 from 'module';
6
15
  import { setClientChild, forwardFromClient } from './ipc-bridge.js';
7
16
 
@@ -17,7 +26,7 @@ function startModuleAdapter() {
17
26
  FORK_TIMEOUT: pro?.fork_timeout ?? 6000
18
27
  };
19
28
  try {
20
- modulePath = require$1.resolve('../client.js');
29
+ modulePath = require$1.resolve('../../client.js');
21
30
  }
22
31
  catch (error) {
23
32
  logger?.warn?.({
@@ -1,7 +1,16 @@
1
1
  import childProcess from 'child_process';
2
- import { ResultCode } from '../core/variable.js';
3
- import { getConfigValue } from '../core/config.js';
4
- import '../core/utils.js';
2
+ import { getConfigValue } from '../../common/config.js';
3
+ import { ResultCode } from '../../common/variable.js';
4
+ import '../../common/logger.js';
5
+ import '../../common/utils.js';
6
+ import 'net';
7
+ import 'v8';
8
+ import 'os';
9
+ import 'path';
10
+ import 'fs';
11
+ import 'flatted';
12
+ import '../../common/cbp/runtime.js';
13
+ import 'ws';
5
14
  import module$1 from 'module';
6
15
  import { setPlatformChild, forwardFromPlatform } from './ipc-bridge.js';
7
16
 
@@ -0,0 +1,2 @@
1
+ import type { StartOptions } from '../types';
2
+ export declare const start: (options?: StartOptions | string) => void;
@@ -0,0 +1,76 @@
1
+ import { getConfig } from '../common/config.js';
2
+ import { cbpServer } from './cbp/server/main.js';
3
+ import { filePrefixCommon, defaultPlatformCommonPrefix } from '../common/variable.js';
4
+ import { startPlatformAdapterWithFallback } from './process/platform.js';
5
+ import { startModuleAdapter } from './process/module.js';
6
+ import { generateSocketPath } from '../common/direct-channel.js';
7
+
8
+ const createOptionsByKey = (options, key, defaultValue) => {
9
+ const cfg = getConfig();
10
+ const curValue = options?.[key] ?? cfg.argv?.[key];
11
+ const value = curValue ?? cfg.value?.[key] ?? defaultValue;
12
+ return value;
13
+ };
14
+ const startPlatform = (options) => {
15
+ const platform = createOptionsByKey(options, 'platform', '');
16
+ const login = createOptionsByKey(options, 'login', '');
17
+ if (!platform && !login) {
18
+ global.__sandbox = true;
19
+ return;
20
+ }
21
+ void startPlatformAdapterWithFallback();
22
+ };
23
+ const startClient = (options) => {
24
+ process.env.input = createOptionsByKey(options, 'input', '');
25
+ process.env.output = createOptionsByKey(options, 'output', '');
26
+ process.env.is_full_receive = String(createOptionsByKey(options, 'is_full_receive', true));
27
+ process.env.port = String(createOptionsByKey(options, 'port', '') || '');
28
+ process.env.url = createOptionsByKey(options, 'url', '');
29
+ startModuleAdapter();
30
+ };
31
+ const start = (options = {}) => {
32
+ if (typeof options === 'string') {
33
+ options = { input: options };
34
+ }
35
+ global.__options = options;
36
+ const port = createOptionsByKey(options, 'port', '');
37
+ const serverPort = createOptionsByKey(options, 'serverPort', '');
38
+ const platform = createOptionsByKey(options, 'platform', '');
39
+ const login = createOptionsByKey(options, 'login', '');
40
+ if (platform) {
41
+ const reg = filePrefixCommon;
42
+ if (reg.test(platform)) {
43
+ process.env.platform = platform;
44
+ process.env.login = platform.replace(reg, '');
45
+ }
46
+ else {
47
+ process.env.platform = platform;
48
+ process.env.login = platform;
49
+ }
50
+ }
51
+ else if (login) {
52
+ process.env.platform = `${defaultPlatformCommonPrefix}${login}`;
53
+ process.env.login = login;
54
+ }
55
+ process.env.port = port ? String(port) : '';
56
+ process.env.serverPort = serverPort;
57
+ if (port) {
58
+ cbpServer(port, () => {
59
+ const httpURL = `http://127.0.0.1:${port}`;
60
+ const wsURL = `ws://127.0.0.1:${port}`;
61
+ logger.info(`[CBP-Server] ${httpURL}`);
62
+ logger.info(`[CBP-Server] ${wsURL}]`);
63
+ startClient(options);
64
+ startPlatform(options);
65
+ });
66
+ }
67
+ else {
68
+ const sockPath = generateSocketPath();
69
+ process.env.__ALEMON_DIRECT_SOCK = sockPath;
70
+ logger.info('[Direct-IPC] 平台↔客户端直连');
71
+ startClient(options);
72
+ startPlatform(options);
73
+ }
74
+ };
75
+
76
+ export { start };
package/lib/global.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { DefineChildrenFunc, OnResponseReversalFunc, OnMiddlewareReversalFunc, OnSelectsFunc, OnDataFormatFunc, OnResponseReversalFuncBack, OnGroupFunc, OnMiddlewareReversalFuncBack, DefineResponseFunc, defineMiddlewareFunc, StoreChildrenApp, StateSubscribeMap, SubscribeKeysMap, LoggerUtils, ResponseState, StartOptions } from './types';
2
- import WebSocket, { Server } from 'ws';
3
- import { IncomingMessage } from 'http';
2
+ import { type Server } from 'ws';
3
+ import type WebSocket from 'ws';
4
+ import type { IncomingMessage } from 'http';
4
5
  import type KoaRouter from 'koa-router';
5
- import type { RuntimeAppRecord } from './app/store.js';
6
+ import type { RuntimeAppRecord } from './application/runtime/store.js';
6
7
  declare global {
7
8
  var __config: any;
8
9
  var __options: StartOptions;
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './types/index.js';
2
2
  export * from './global.js';
3
- export * from './core/index.js';
4
- export * from './cbp/index.js';
5
- export * from './app/index.js';
6
- export * from './main.js';
3
+ export { start } from './main.js';
4
+ export * as common from './common/index.js';
5
+ export * as core from './core/index.js';
6
+ export * as platform from './platform/index.js';
7
+ export * as application from './application/index.js';
package/lib/index.js CHANGED
@@ -1,55 +1,10 @@
1
1
  export { ActionsEventEnum } from './types/event/actions.js';
2
- export { ResultCode } from './core/variable.js';
3
- export { getConfig, getConfigValue, onWatchConfigValue } from './core/config.js';
4
- export { createEventName, createHash, createResult, createUserHashKey, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, isMaster, matchIn, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
5
- export { cbpClient } from './cbp/connects/client.js';
6
- export { cbpPlatform } from './cbp/connects/platform.js';
7
- export { cbpServer } from './cbp/server/main.js';
8
- export { ChildrenApp, Core, Logger, Middleware, MiddlewareRouter, MiddlewareTree, ProcessorEventAutoClearMap, ProcessorEventUserAutoClearMap, Response, ResponseMiddleware, ResponseRouter, ResponseTree, State, StateSubscribe, SubscribeList, bumpStoreVersion, clearRuntimeAppKoaRouters, core, disposeAllRuntimeApps, disposeRuntimeApp, getChildrenApp, getRuntimeApp, getRuntimeAppKoaRouters, getSubscribeList, hasRuntimeAppCapability, listChildrenApps, listRuntimeAppKoaRouters, listRuntimeApps, logger, registerRuntimeApp, setRuntimeAppKoaRouters, toRuntimeAppSnapshot, updateRuntimeAppCapabilities, updateRuntimeAppStatus } from './app/store.js';
9
- export { Expose, clearAllExpose, disposeExpose, registerExpose } from './app/expose.js';
10
- export { loadModels, run } from './app/load_modules/load.js';
11
- export { loadChildren, loadChildrenFile } from './app/load_modules/loadChild.js';
12
- export { defineChildren } from './app/define-children.js';
13
- export { definePlatform } from './app/define-platform.js';
14
- export { defineResponse } from './app/define-response.js';
15
- export { defineMiddleware } from './app/define-middleware.js';
16
- export { defineRouter, lazy, runHandler } from './app/define-router.js';
17
- export { FormatEvent, wrapEvent } from './app/event-format.js';
18
- export { onGroup } from './app/event-group.js';
19
- export { OnMiddleware, onMiddleware } from './app/event-middleware.js';
20
- export { OnProcessor, onProcessor } from './app/event-processor.js';
21
- export { OnResponse, onResponse } from './app/event-response.js';
22
- export { expendCycle } from './app/event-processor-cycle.js';
23
- export { expendEvent } from './app/event-processor-event.js';
24
- export { expendMiddleware } from './app/event-processor-middleware.js';
25
- export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './app/event-processor-subscribe.js';
26
- export { useAnnounce } from './app/hook-use/announce.js';
27
- export { useChannel } from './app/hook-use/channel.js';
28
- export { useClient } from './app/hook-use/client.js';
29
- export { useGuild } from './app/hook-use/guild.js';
30
- export { useHistory } from './app/hook-use/history.js';
31
- export { useMedia } from './app/hook-use/media.js';
32
- export { useMe } from './app/hook-use/me.js';
33
- export { useMember } from './app/hook-use/member.js';
34
- export { useMention } from './app/hook-use/mention.js';
35
- export { useMessage, useSend, useSends } from './app/hook-use/message.js';
36
- export { usePermission } from './app/hook-use/permission.js';
37
- export { useReaction } from './app/hook-use/reaction.js';
38
- export { useRequest } from './app/hook-use/request.js';
39
- export { useRole } from './app/hook-use/role.js';
40
- export { useRoute } from './app/hook-use/route.js';
41
- export { useUser } from './app/hook-use/user.js';
42
- export { useObserver, useSubscribe } from './app/hook-use/subscribe.js';
43
- export { createEvent, useEvent } from './app/hook-use/event.js';
44
- export { clearInterval, clearTimeout, listSchedule, pauseSchedule, resumeSchedule, setCron, setInterval, setTimeout } from './app/api/schedule.js';
45
- export { finishCurrentTrace, getCurrentAppName, getCurrentEvent, getCurrentNext, getCurrentPhase, markEventSendAttempt, markEventSendFailure, markEventSendSuccess, recordEventSendResults, withEventContext, withProcessorTrace } from './app/hook-event-context.js';
46
- export { registerAppDir, scheduleCancel, scheduleCancelAll, scheduleCancelByApp, scheduleCron, scheduleInterval, scheduleList, schedulePause, scheduleResume, scheduleTimeout, unregisterAppDir } from './app/schedule-store.js';
47
- export { createEventValue, createSelects, onSelects, onState, unChildren, unState, useState } from './app/event-utils.js';
48
- export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
49
- export { Format, FormatButtonGroup, FormatMarkDown, FormatSelect } from './app/message-format.js';
50
- export { Router } from './app/router/dsl.js';
51
- export { checkFallbackHint } from './app/router/fallback.js';
52
- export { normalizeRoutePath, parseMessageText } from './app/router/parser.js';
53
- export { validateRouteArgs } from './app/router/validator.js';
54
- export { start } from './main.js';
55
- export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './app/message-format-old.js';
2
+ export { start } from './core/start.js';
3
+ import * as index$1 from './common/index.js';
4
+ export { index$1 as common };
5
+ import * as index$2 from './core/index.js';
6
+ export { index$2 as core };
7
+ import * as index$3 from './platform/index.js';
8
+ export { index$3 as platform };
9
+ import * as index from './application/index.js';
10
+ export { index as application };
package/lib/main.d.ts CHANGED
@@ -1,2 +1 @@
1
- import type { StartOptions } from './types';
2
- export declare const start: (options?: StartOptions | string) => void;
1
+ export { start } from './core/start.js';
package/lib/main.js CHANGED
@@ -1,76 +1 @@
1
- import { getConfig } from './core/config.js';
2
- import { cbpServer } from './cbp/server/main.js';
3
- import { filePrefixCommon, defaultPlatformCommonPrefix } from './core/variable.js';
4
- import { startPlatformAdapterWithFallback } from './process/platform.js';
5
- import { startModuleAdapter } from './process/module.js';
6
- import { generateSocketPath } from './process/direct-channel.js';
7
-
8
- const createOptionsByKey = (options, key, defaultValue) => {
9
- const cfg = getConfig();
10
- const curValue = options?.[key] ?? cfg.argv?.[key];
11
- const value = curValue ?? cfg.value?.[key] ?? defaultValue;
12
- return value;
13
- };
14
- const startPlatform = (options) => {
15
- const platform = createOptionsByKey(options, 'platform', '');
16
- const login = createOptionsByKey(options, 'login', '');
17
- if (!platform && !login) {
18
- global.__sandbox = true;
19
- return;
20
- }
21
- void startPlatformAdapterWithFallback();
22
- };
23
- const startClient = (options) => {
24
- process.env.input = createOptionsByKey(options, 'input', '');
25
- process.env.output = createOptionsByKey(options, 'output', '');
26
- process.env.is_full_receive = String(createOptionsByKey(options, 'is_full_receive', true));
27
- process.env.port = String(createOptionsByKey(options, 'port', '') || '');
28
- process.env.url = createOptionsByKey(options, 'url', '');
29
- startModuleAdapter();
30
- };
31
- const start = (options = {}) => {
32
- if (typeof options === 'string') {
33
- options = { input: options };
34
- }
35
- global.__options = options;
36
- const port = createOptionsByKey(options, 'port', '');
37
- const serverPort = createOptionsByKey(options, 'serverPort', '');
38
- const platform = createOptionsByKey(options, 'platform', '');
39
- const login = createOptionsByKey(options, 'login', '');
40
- if (platform) {
41
- const reg = filePrefixCommon;
42
- if (reg.test(platform)) {
43
- process.env.platform = platform;
44
- process.env.login = platform.replace(reg, '');
45
- }
46
- else {
47
- process.env.platform = platform;
48
- process.env.login = platform;
49
- }
50
- }
51
- else if (login) {
52
- process.env.platform = `${defaultPlatformCommonPrefix}${login}`;
53
- process.env.login = login;
54
- }
55
- process.env.port = port ? String(port) : '';
56
- process.env.serverPort = serverPort;
57
- if (port) {
58
- cbpServer(port, () => {
59
- const httpURL = `http://127.0.0.1:${port}`;
60
- const wsURL = `ws://127.0.0.1:${port}`;
61
- logger.info(`[CBP-Server] ${httpURL}`);
62
- logger.info(`[CBP-Server] ${wsURL}]`);
63
- startClient(options);
64
- startPlatform(options);
65
- });
66
- }
67
- else {
68
- const sockPath = generateSocketPath();
69
- process.env.__ALEMON_DIRECT_SOCK = sockPath;
70
- logger.info('[Direct-IPC] 平台↔客户端直连');
71
- startClient(options);
72
- startPlatform(options);
73
- }
74
- };
75
-
76
- export { start };
1
+ export { start } from './core/start.js';
@@ -1,5 +1,5 @@
1
- import type { EventsEnum } from '../../types';
2
- import type { ActionReplyFunc, ApiReplyFunc } from '../typings';
1
+ import type { ActionReplyFunc, ApiReplyFunc } from '../common/cbp/typings.js';
2
+ import type { EventsEnum } from '../types/index.js';
3
3
  export declare const cbpPlatform: (url?: string, options?: {
4
4
  open: () => void;
5
5
  }) => {