alemonjs 2.1.53 → 2.1.55

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 (98) hide show
  1. package/lib/app/define-router.d.ts +1 -0
  2. package/lib/app/define-router.js +6 -1
  3. package/lib/app/event-format.js +1 -1
  4. package/lib/app/event-processor-cycleFiles.js +2 -6
  5. package/lib/app/expose.d.ts +16 -0
  6. package/lib/app/expose.js +190 -0
  7. package/lib/app/index.d.ts +1 -0
  8. package/lib/app/index.js +2 -1
  9. package/lib/app/load_modules/loadChild.js +4 -0
  10. package/lib/app/store.d.ts +9 -9
  11. package/lib/app/store.js +2 -0
  12. package/lib/index.js +2 -1
  13. package/lib/types/event/index.d.ts +2 -0
  14. package/lib/types/expose/index.d.ts +41 -0
  15. package/lib/types/expose/index.js +1 -0
  16. package/lib/types/index.d.ts +1 -0
  17. package/package.json +1 -1
  18. package/lib/app/define/define-children.d.ts +0 -8
  19. package/lib/app/define/define-children.js +0 -25
  20. package/lib/app/define/define-middleware.d.ts +0 -2
  21. package/lib/app/define/define-middleware.js +0 -8
  22. package/lib/app/define/define-platform.d.ts +0 -13
  23. package/lib/app/define/define-platform.js +0 -40
  24. package/lib/app/define/define-response.d.ts +0 -2
  25. package/lib/app/define/define-response.js +0 -8
  26. package/lib/app/define/define-router.d.ts +0 -17
  27. package/lib/app/define/define-router.js +0 -34
  28. package/lib/app/event/event-group.d.ts +0 -9
  29. package/lib/app/event/event-group.js +0 -29
  30. package/lib/app/event/event-middleware.d.ts +0 -23
  31. package/lib/app/event/event-middleware.js +0 -44
  32. package/lib/app/event/event-response.d.ts +0 -16
  33. package/lib/app/event/event-response.js +0 -23
  34. package/lib/app/event/event-selects.d.ts +0 -13
  35. package/lib/app/event/event-selects.js +0 -15
  36. package/lib/app/event-processor/event-processor-callHandler.d.ts +0 -1
  37. package/lib/app/event-processor/event-processor-callHandler.js +0 -43
  38. package/lib/app/event-processor/event-processor-cycle.d.ts +0 -14
  39. package/lib/app/event-processor/event-processor-cycle.js +0 -97
  40. package/lib/app/event-processor/event-processor-cycleFiles.d.ts +0 -11
  41. package/lib/app/event-processor/event-processor-cycleFiles.js +0 -147
  42. package/lib/app/event-processor/event-processor-cycleRoute.d.ts +0 -10
  43. package/lib/app/event-processor/event-processor-cycleRoute.js +0 -133
  44. package/lib/app/event-processor/event-processor-event.d.ts +0 -24
  45. package/lib/app/event-processor/event-processor-event.js +0 -41
  46. package/lib/app/event-processor/event-processor-middleware.d.ts +0 -14
  47. package/lib/app/event-processor/event-processor-middleware.js +0 -31
  48. package/lib/app/event-processor/event-processor-subscribe.d.ts +0 -35
  49. package/lib/app/event-processor/event-processor-subscribe.js +0 -115
  50. package/lib/app/event-processor/event-processor.d.ts +0 -17
  51. package/lib/app/event-processor/event-processor.js +0 -207
  52. package/lib/app/hook-use/hook-use-api.d.ts +0 -6
  53. package/lib/app/hook-use/hook-use-api.js +0 -22
  54. package/lib/app/hook-use/hook-use-channel.d.ts +0 -8
  55. package/lib/app/hook-use/hook-use-channel.js +0 -33
  56. package/lib/app/hook-use/hook-use-client.d.ts +0 -7
  57. package/lib/app/hook-use/hook-use-client.js +0 -27
  58. package/lib/app/hook-use/hook-use-me.d.ts +0 -8
  59. package/lib/app/hook-use/hook-use-me.js +0 -45
  60. package/lib/app/hook-use/hook-use-menber.d.ts +0 -8
  61. package/lib/app/hook-use/hook-use-menber.js +0 -59
  62. package/lib/app/hook-use/hook-use-mention.d.ts +0 -23
  63. package/lib/app/hook-use/hook-use-mention.js +0 -105
  64. package/lib/app/hook-use/hook-use-message.d.ts +0 -29
  65. package/lib/app/hook-use/hook-use-message.js +0 -88
  66. package/lib/app/hook-use/hook-use-state.d.ts +0 -30
  67. package/lib/app/hook-use/hook-use-state.js +0 -101
  68. package/lib/app/hook-use/hook-use-subscribe.d.ts +0 -46
  69. package/lib/app/hook-use/hook-use-subscribe.js +0 -143
  70. package/lib/app/hook-use-api.d.ts +0 -268
  71. package/lib/app/hook-use-api.js +0 -1213
  72. package/lib/app/hook-use-state.d.ts +0 -3
  73. package/lib/app/hook-use-state.js +0 -68
  74. package/lib/app/hook-use-subscribe.d.ts +0 -73
  75. package/lib/app/hook-use-subscribe.js +0 -112
  76. package/lib/app/message/message-api.d.ts +0 -69
  77. package/lib/app/message/message-api.js +0 -105
  78. package/lib/app/message/message-format-old.d.ts +0 -143
  79. package/lib/app/message/message-format-old.js +0 -359
  80. package/lib/app/message/message-format.d.ts +0 -215
  81. package/lib/app/message/message-format.js +0 -382
  82. package/lib/app/message-controller.d.ts +0 -25
  83. package/lib/app/message-controller.js +0 -66
  84. package/lib/app/message-format.old.d.ts +0 -50
  85. package/lib/app/message-format.old.js +0 -217
  86. package/lib/cbp/processor/handle.d.ts +0 -3
  87. package/lib/cbp/processor/handle.js +0 -32
  88. package/lib/jsx/index.d.ts +0 -105
  89. package/lib/jsx/index.js +0 -211
  90. package/lib/jsx/jsx-dev-runtime.d.ts +0 -2
  91. package/lib/jsx/jsx-dev-runtime.js +0 -1
  92. package/lib/jsx/jsx-runtime.d.ts +0 -18
  93. package/lib/jsx/jsx-runtime.js +0 -24
  94. package/lib/process/client.js +0 -109
  95. package/lib/store/SinglyLinkedList.d.ts +0 -22
  96. package/lib/store/SinglyLinkedList.js +0 -97
  97. package/lib/store/store.d.ts +0 -127
  98. package/lib/store/store.js +0 -443
@@ -1,109 +0,0 @@
1
- import '../types/event/actions.js';
2
- import { getConfigValue } from '../core/config.js';
3
- import { defaultPort } from '../core/variable.js';
4
- import { cbpClient } from '../cbp/connects/client.js';
5
- import 'flatted';
6
- import 'ws';
7
- import '../cbp/processor/config.js';
8
- import 'net';
9
- import 'v8';
10
- import 'os';
11
- import 'path';
12
- import 'fs';
13
- import 'koa';
14
- import '@koa/cors';
15
- import '../cbp/routers/router.js';
16
- import { logger } from '../store/store.js';
17
- import { loadModels } from '../app/load_modules/load.js';
18
- import '../app/load_modules/loadChild.js';
19
- import '../app/define/define-children.js';
20
- import '../app/define/define-response.js';
21
- import '../app/define/define-middleware.js';
22
- import '../app/event-processor/event-processor.js';
23
- import '../core/utils.js';
24
- import '../app/message/message-format-old.js';
25
- import '../app/event/event-group.js';
26
- import '../app/event/event-middleware.js';
27
- import '../app/event/event-response.js';
28
- import '../app/event/event-selects.js';
29
- import '../app/message/message-api.js';
30
- import './platform.js';
31
- import './module.js';
32
-
33
- // 标记当前为客户端进程,防止 definePlatform 被 import 时的副作用
34
- global.__client_loaded = true;
35
- // 连接 CBP 服务器
36
- const main = () => {
37
- const login = process.env.login ?? '';
38
- const platform = process.env.platform ?? '';
39
- const url = process.env.url ?? '';
40
- const port = process.env.port ?? defaultPort;
41
- const isFullReceive = process.env.is_full_receive === 'true' || process.env.is_full_receive === '1';
42
- // 当 login 和 platform 都没有指定时,且指定了 url,则连接到指定的 url
43
- if (!login && !platform && url) {
44
- logger.info(`[Connecting to CBP server at ${url}]`);
45
- cbpClient(url);
46
- }
47
- else {
48
- const httpURL = `http://127.0.0.1:${port}`;
49
- cbpClient(httpURL, { isFullReceive });
50
- }
51
- loadModels();
52
- };
53
- const mainProcess = () => {
54
- // unhandledRejection 捕获未处理的 Promise 拒绝,记录后继续运行,不退出进程
55
- process.on('unhandledRejection', (reason) => {
56
- logger.error('[unhandledRejection] 未捕获的 Promise 拒绝:', reason);
57
- });
58
- // uncaughtException 捕获未捕获的异常,记录后继续运行,不退出进程
59
- process.on('uncaughtException', (error) => {
60
- logger.error('[uncaughtException] 未捕获的异常:', error);
61
- });
62
- // ==================== 信号处理 ====================
63
- ['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
64
- process?.on?.(sig, () => {
65
- logger.info?.(`[alemonjs][${sig}] 收到信号,正在关闭...`);
66
- setImmediate(() => process.exit(0));
67
- });
68
- });
69
- // 监听进程退出事件,记录退出码
70
- process?.on?.('exit', code => {
71
- logger.info?.(`[alemonjs][exit] 进程退出,code=${code}`);
72
- });
73
- // 监听来自主进程的消息,处理启动和停止命令
74
- process.on('message', msg => {
75
- try {
76
- const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
77
- if (data?.type === 'start') {
78
- main();
79
- const values = getConfigValue() || {};
80
- // plugins 优先,回退到旧的 apps_plugins
81
- const startOptions = values.plugins || values.apps_plugins || {};
82
- // start 插件。在apps进程启动中使用
83
- for (const key in startOptions) {
84
- const moduleOptions = startOptions[key];
85
- // 检查 enable 字段,显式设为 false 时跳过
86
- if (typeof moduleOptions === 'object' && moduleOptions?.enable === false) {
87
- continue;
88
- }
89
- void import(key).then(mod => {
90
- if (mod?.default) {
91
- mod.default(moduleOptions);
92
- }
93
- });
94
- }
95
- }
96
- else if (data?.type === 'stop') {
97
- process.exit(0);
98
- }
99
- }
100
- catch {
101
- //
102
- }
103
- });
104
- // 主动发送 ready 消息(serialization: 'advanced' 直接发送对象,无需 JSON.stringify)
105
- if (process.send) {
106
- process.send({ type: 'ready' });
107
- }
108
- };
109
- mainProcess();
@@ -1,22 +0,0 @@
1
- /**
2
- * 单向链表实现
3
- */
4
- declare class ListNode<T> {
5
- data: T;
6
- next: ListNode<T> | null;
7
- constructor(data: T);
8
- }
9
- export declare class SinglyLinkedList<T> {
10
- private head;
11
- private tail;
12
- private size;
13
- private current;
14
- constructor(initialValues?: T[]);
15
- append(data: T): void;
16
- popNext(): ListNode<T> | null;
17
- removeCurrent(): void;
18
- getSize(): number;
19
- resetCursor(): void;
20
- forEach(callback: (node: ListNode<T>) => boolean | undefined): void;
21
- }
22
- export {};
@@ -1,97 +0,0 @@
1
- /**
2
- * 单向链表实现
3
- */
4
- class ListNode {
5
- data; // 节点数据
6
- next; // 指向下一个节点的指针
7
- constructor(data) {
8
- this.data = data;
9
- this.next = null;
10
- }
11
- }
12
- class SinglyLinkedList {
13
- head; // 链表的头节点
14
- tail; // 链表的尾节点,用于 O(1) append
15
- size; // 链表的大小
16
- current; // 当前节点指针
17
- constructor(initialValues) {
18
- this.head = null;
19
- this.tail = null;
20
- this.size = 0;
21
- this.current = null; // 初始化当前节点为 null
22
- if (initialValues) {
23
- initialValues.forEach(value => this.append(value)); // 初始化链表
24
- }
25
- }
26
- // 在链表末尾添加新节点 - O(1)
27
- append(data) {
28
- const newNode = new ListNode(data);
29
- if (!this.head) {
30
- this.head = newNode;
31
- this.tail = newNode;
32
- }
33
- else {
34
- this.tail.next = newNode;
35
- this.tail = newNode;
36
- }
37
- this.size++;
38
- }
39
- // 获取下一个节点并移动指针
40
- popNext() {
41
- if (!this.current) {
42
- this.current = this.head; // 如果当前节点为 null,从头节点开始
43
- }
44
- else {
45
- this.current = this.current.next; // 移动到下一个节点
46
- }
47
- return this.current; // 返回当前节点
48
- }
49
- // 删除当前节点
50
- removeCurrent() {
51
- if (!this.head || !this.current) {
52
- return;
53
- }
54
- if (this.current === this.head) {
55
- this.head = this.head.next; // 移除头节点
56
- if (!this.head) {
57
- this.tail = null; // 链表变空,重置 tail
58
- }
59
- this.current = null; // 重置当前节点
60
- this.size--;
61
- return;
62
- }
63
- let previous = this.head;
64
- while (previous && previous.next !== this.current) {
65
- previous = previous.next;
66
- }
67
- if (previous && this.current) {
68
- previous.next = this.current.next; // 跳过当前节点
69
- // 如果删除的是尾节点,更新 tail
70
- if (this.current === this.tail) {
71
- this.tail = previous;
72
- }
73
- this.current = previous; // 设置为前驱节点,使 popNext() 从正确位置继续
74
- this.size--;
75
- }
76
- }
77
- // 获取链表的大小
78
- getSize() {
79
- return this.size;
80
- }
81
- // 重置游标到起点,使 popNext() 下次从 head 开始
82
- resetCursor() {
83
- this.current = null;
84
- }
85
- // 遍历链表(不改变 current 游标)—— 回调返回 true 时提前终止
86
- forEach(callback) {
87
- let node = this.head;
88
- while (node) {
89
- if (callback(node) === true) {
90
- break;
91
- }
92
- node = node.next;
93
- }
94
- }
95
- }
96
-
97
- export { SinglyLinkedList };
@@ -1,127 +0,0 @@
1
- /**
2
- * 全部挂在全局变量上,
3
- * 要求一个nodejs中,
4
- * 出现不同位置的模块也读取同一个数据
5
- * @description 存储器
6
- */
7
- import { SinglyLinkedList } from './SinglyLinkedList';
8
- import { childrenCallbackRes, ChildrenCycle, EventCycleEnum, EventKeys, StoreMiddlewareItem, StoreResponseItem, SubscribeValue } from '../types';
9
- export declare class Logger {
10
- #private;
11
- /**
12
- * 创建一个 logger,如果未存在全局变量则赋值
13
- * @returns
14
- */
15
- constructor();
16
- get value(): any;
17
- }
18
- export declare class Core {
19
- constructor();
20
- get value(): {
21
- storeState: import("..").ResponseState;
22
- storeStateSubscribe: import("..").StateSubscribeMap;
23
- storeSubscribeList: import("..").SubscribeKeysMap;
24
- storeChildrenApp: {
25
- [key: string]: import("..").StoreChildrenApp;
26
- };
27
- };
28
- }
29
- export declare const bumpStoreVersion: () => void;
30
- export declare class Response {
31
- #private;
32
- get value(): StoreResponseItem[];
33
- }
34
- export declare class ResponseMiddleware {
35
- find(name: string, stateKey: string): StoreResponseItem[];
36
- }
37
- export declare class ResponseRouter {
38
- #private;
39
- get value(): any[];
40
- }
41
- export declare class MiddlewareRouter {
42
- #private;
43
- get value(): any[];
44
- }
45
- export declare class Middleware {
46
- #private;
47
- get value(): StoreMiddlewareItem[];
48
- }
49
- export declare class SubscribeList<T extends EventKeys> {
50
- #private;
51
- constructor(choice: EventCycleEnum, select: T);
52
- get value(): SinglyLinkedList<SubscribeValue>;
53
- }
54
- /**
55
- * 纯函数版 SubscribeList 访问 — 避免每次创建类实例的 GC 开销
56
- */
57
- export declare const getSubscribeList: <T extends EventKeys>(choice: EventCycleEnum, select: T) => SinglyLinkedList<SubscribeValue>;
58
- export declare class StateSubscribe {
59
- #private;
60
- constructor(name: string);
61
- on(callback: (value: boolean) => void): void;
62
- un(callback: (value: boolean) => void): void;
63
- get value(): ((value: boolean) => void)[];
64
- }
65
- /**
66
- * @deprecated 废弃。指令管理可直接配置禁用正则
67
- */
68
- export declare class State {
69
- #private;
70
- /**
71
- *
72
- * @param name
73
- * @param defaultValue 默认,允许匹配
74
- */
75
- constructor(name: string, defaultValue?: boolean);
76
- get value(): boolean;
77
- set value(value: boolean);
78
- }
79
- export declare class ChildrenApp {
80
- #private;
81
- constructor(name?: string);
82
- register(config: childrenCallbackRes): void;
83
- /**
84
- * 推送响应体
85
- * @param data
86
- */
87
- pushResponse(data: StoreResponseItem[]): void;
88
- /**
89
- * 推送响应下的中间件
90
- */
91
- pushResponseMiddleware(data: {
92
- [key: string]: StoreResponseItem;
93
- }): void;
94
- /**
95
- * 推送中间件
96
- * @param data
97
- */
98
- pushMiddleware(data: StoreMiddlewareItem[]): void;
99
- /**
100
- * 推送周期
101
- * @param data
102
- */
103
- pushCycle(data: ChildrenCycle): void;
104
- /**
105
- * 挂载
106
- */
107
- on(): void;
108
- /**
109
- * 卸载
110
- */
111
- un(): void;
112
- /**
113
- * 获取
114
- */
115
- get value(): import("..").StoreChildrenApp;
116
- }
117
- export declare const ProcessorEventAutoClearMap: Map<any, any>;
118
- export declare const ProcessorEventUserAutoClearMap: Map<any, any>;
119
- export declare const logger: any;
120
- export declare const core: {
121
- storeState: import("..").ResponseState;
122
- storeStateSubscribe: import("..").StateSubscribeMap;
123
- storeSubscribeList: import("..").SubscribeKeysMap;
124
- storeChildrenApp: {
125
- [key: string]: import("..").StoreChildrenApp;
126
- };
127
- };