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.
- package/lib/app/define-router.d.ts +1 -0
- package/lib/app/define-router.js +6 -1
- package/lib/app/event-format.js +1 -1
- package/lib/app/event-processor-cycleFiles.js +2 -6
- package/lib/app/expose.d.ts +16 -0
- package/lib/app/expose.js +190 -0
- package/lib/app/index.d.ts +1 -0
- package/lib/app/index.js +2 -1
- package/lib/app/load_modules/loadChild.js +4 -0
- package/lib/app/store.d.ts +9 -9
- package/lib/app/store.js +2 -0
- package/lib/index.js +2 -1
- package/lib/types/event/index.d.ts +2 -0
- package/lib/types/expose/index.d.ts +41 -0
- package/lib/types/expose/index.js +1 -0
- package/lib/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/lib/app/define/define-children.d.ts +0 -8
- package/lib/app/define/define-children.js +0 -25
- package/lib/app/define/define-middleware.d.ts +0 -2
- package/lib/app/define/define-middleware.js +0 -8
- package/lib/app/define/define-platform.d.ts +0 -13
- package/lib/app/define/define-platform.js +0 -40
- package/lib/app/define/define-response.d.ts +0 -2
- package/lib/app/define/define-response.js +0 -8
- package/lib/app/define/define-router.d.ts +0 -17
- package/lib/app/define/define-router.js +0 -34
- package/lib/app/event/event-group.d.ts +0 -9
- package/lib/app/event/event-group.js +0 -29
- package/lib/app/event/event-middleware.d.ts +0 -23
- package/lib/app/event/event-middleware.js +0 -44
- package/lib/app/event/event-response.d.ts +0 -16
- package/lib/app/event/event-response.js +0 -23
- package/lib/app/event/event-selects.d.ts +0 -13
- package/lib/app/event/event-selects.js +0 -15
- package/lib/app/event-processor/event-processor-callHandler.d.ts +0 -1
- package/lib/app/event-processor/event-processor-callHandler.js +0 -43
- package/lib/app/event-processor/event-processor-cycle.d.ts +0 -14
- package/lib/app/event-processor/event-processor-cycle.js +0 -97
- package/lib/app/event-processor/event-processor-cycleFiles.d.ts +0 -11
- package/lib/app/event-processor/event-processor-cycleFiles.js +0 -147
- package/lib/app/event-processor/event-processor-cycleRoute.d.ts +0 -10
- package/lib/app/event-processor/event-processor-cycleRoute.js +0 -133
- package/lib/app/event-processor/event-processor-event.d.ts +0 -24
- package/lib/app/event-processor/event-processor-event.js +0 -41
- package/lib/app/event-processor/event-processor-middleware.d.ts +0 -14
- package/lib/app/event-processor/event-processor-middleware.js +0 -31
- package/lib/app/event-processor/event-processor-subscribe.d.ts +0 -35
- package/lib/app/event-processor/event-processor-subscribe.js +0 -115
- package/lib/app/event-processor/event-processor.d.ts +0 -17
- package/lib/app/event-processor/event-processor.js +0 -207
- package/lib/app/hook-use/hook-use-api.d.ts +0 -6
- package/lib/app/hook-use/hook-use-api.js +0 -22
- package/lib/app/hook-use/hook-use-channel.d.ts +0 -8
- package/lib/app/hook-use/hook-use-channel.js +0 -33
- package/lib/app/hook-use/hook-use-client.d.ts +0 -7
- package/lib/app/hook-use/hook-use-client.js +0 -27
- package/lib/app/hook-use/hook-use-me.d.ts +0 -8
- package/lib/app/hook-use/hook-use-me.js +0 -45
- package/lib/app/hook-use/hook-use-menber.d.ts +0 -8
- package/lib/app/hook-use/hook-use-menber.js +0 -59
- package/lib/app/hook-use/hook-use-mention.d.ts +0 -23
- package/lib/app/hook-use/hook-use-mention.js +0 -105
- package/lib/app/hook-use/hook-use-message.d.ts +0 -29
- package/lib/app/hook-use/hook-use-message.js +0 -88
- package/lib/app/hook-use/hook-use-state.d.ts +0 -30
- package/lib/app/hook-use/hook-use-state.js +0 -101
- package/lib/app/hook-use/hook-use-subscribe.d.ts +0 -46
- package/lib/app/hook-use/hook-use-subscribe.js +0 -143
- package/lib/app/hook-use-api.d.ts +0 -268
- package/lib/app/hook-use-api.js +0 -1213
- package/lib/app/hook-use-state.d.ts +0 -3
- package/lib/app/hook-use-state.js +0 -68
- package/lib/app/hook-use-subscribe.d.ts +0 -73
- package/lib/app/hook-use-subscribe.js +0 -112
- package/lib/app/message/message-api.d.ts +0 -69
- package/lib/app/message/message-api.js +0 -105
- package/lib/app/message/message-format-old.d.ts +0 -143
- package/lib/app/message/message-format-old.js +0 -359
- package/lib/app/message/message-format.d.ts +0 -215
- package/lib/app/message/message-format.js +0 -382
- package/lib/app/message-controller.d.ts +0 -25
- package/lib/app/message-controller.js +0 -66
- package/lib/app/message-format.old.d.ts +0 -50
- package/lib/app/message-format.old.js +0 -217
- package/lib/cbp/processor/handle.d.ts +0 -3
- package/lib/cbp/processor/handle.js +0 -32
- package/lib/jsx/index.d.ts +0 -105
- package/lib/jsx/index.js +0 -211
- package/lib/jsx/jsx-dev-runtime.d.ts +0 -2
- package/lib/jsx/jsx-dev-runtime.js +0 -1
- package/lib/jsx/jsx-runtime.d.ts +0 -18
- package/lib/jsx/jsx-runtime.js +0 -24
- package/lib/process/client.js +0 -109
- package/lib/store/SinglyLinkedList.d.ts +0 -22
- package/lib/store/SinglyLinkedList.js +0 -97
- package/lib/store/store.d.ts +0 -127
- package/lib/store/store.js +0 -443
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview 中间件
|
|
3
|
-
* @module middleware
|
|
4
|
-
* @author ningmengchongshui
|
|
5
|
-
*/
|
|
6
|
-
import { OnMiddlewareReversalFunc, OnMiddlewareReversalFuncBack } from '../../types';
|
|
7
|
-
/**
|
|
8
|
-
* 中间件
|
|
9
|
-
* @param select 事件选择
|
|
10
|
-
* @param callback 回调函数,处理事件和 API
|
|
11
|
-
* @throws {Error} - 如果 select 无效,抛出错误。
|
|
12
|
-
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare const onMiddleware: OnMiddlewareReversalFunc;
|
|
16
|
-
/**
|
|
17
|
-
* 废弃,请使用 onMiddleware
|
|
18
|
-
* @deprecated
|
|
19
|
-
* @param select
|
|
20
|
-
* @param callback
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
export declare const OnMiddleware: OnMiddlewareReversalFuncBack;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ResultCode } from '../../core/variable.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 中间件
|
|
5
|
-
* @param select 事件选择
|
|
6
|
-
* @param callback 回调函数,处理事件和 API
|
|
7
|
-
* @throws {Error} - 如果 select 无效,抛出错误。
|
|
8
|
-
* @throws {Error} - 如果 callback 无效,抛出错误。
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
const onMiddleware = (select, callback) => {
|
|
12
|
-
// 参数检查
|
|
13
|
-
if (typeof callback !== 'function') {
|
|
14
|
-
logger.error({
|
|
15
|
-
code: ResultCode.FailParams,
|
|
16
|
-
message: 'Invalid callback: callback must be a function',
|
|
17
|
-
data: null
|
|
18
|
-
});
|
|
19
|
-
throw new Error('Invalid callback: callback must be a function');
|
|
20
|
-
}
|
|
21
|
-
if (typeof select === 'string' || typeof select === 'object') {
|
|
22
|
-
return { current: callback, select };
|
|
23
|
-
}
|
|
24
|
-
logger.error({
|
|
25
|
-
code: ResultCode.FailParams,
|
|
26
|
-
message: 'Invalid select: select must be a string or object',
|
|
27
|
-
data: null
|
|
28
|
-
});
|
|
29
|
-
throw new Error('Invalid select: select must be a string or object');
|
|
30
|
-
};
|
|
31
|
-
global.onMiddleware = onMiddleware;
|
|
32
|
-
/**
|
|
33
|
-
* 废弃,请使用 onMiddleware
|
|
34
|
-
* @deprecated
|
|
35
|
-
* @param select
|
|
36
|
-
* @param callback
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
const OnMiddleware = (callback, select) => {
|
|
40
|
-
return onMiddleware(select, callback);
|
|
41
|
-
};
|
|
42
|
-
global.OnMiddleware = OnMiddleware;
|
|
43
|
-
|
|
44
|
-
export { OnMiddleware, onMiddleware };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { OnResponseReversalFunc, OnResponseReversalFuncBack } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* 处理响应事件
|
|
4
|
-
* @param select 事件选择
|
|
5
|
-
* @param callback 回调函数,处理事件和 API
|
|
6
|
-
* @returns 回调函数的执行结果
|
|
7
|
-
*/
|
|
8
|
-
export declare const onResponse: OnResponseReversalFunc;
|
|
9
|
-
/**
|
|
10
|
-
* 废弃,请使用 onResponse
|
|
11
|
-
* @deprecated
|
|
12
|
-
* @param callback
|
|
13
|
-
* @param select
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export declare const OnResponse: OnResponseReversalFuncBack;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 处理响应事件
|
|
3
|
-
* @param select 事件选择
|
|
4
|
-
* @param callback 回调函数,处理事件和 API
|
|
5
|
-
* @returns 回调函数的执行结果
|
|
6
|
-
*/
|
|
7
|
-
const onResponse = (select, callback) => {
|
|
8
|
-
return { current: callback, select };
|
|
9
|
-
};
|
|
10
|
-
global.onResponse = onResponse;
|
|
11
|
-
/**
|
|
12
|
-
* 废弃,请使用 onResponse
|
|
13
|
-
* @deprecated
|
|
14
|
-
* @param callback
|
|
15
|
-
* @param select
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
const OnResponse = (callback, select) => {
|
|
19
|
-
return onResponse(select, callback);
|
|
20
|
-
};
|
|
21
|
-
global.OnResponse = OnResponse;
|
|
22
|
-
|
|
23
|
-
export { OnResponse, onResponse };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { EventKeys } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* 创建选择器
|
|
4
|
-
* @param values
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export declare const onSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated 废弃,请使用onSelects
|
|
10
|
-
* @param values
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export declare const createSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 创建选择器
|
|
3
|
-
* @param values
|
|
4
|
-
* @returns
|
|
5
|
-
*/
|
|
6
|
-
const onSelects = (values) => values;
|
|
7
|
-
global.onSelects = onSelects;
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated 废弃,请使用onSelects
|
|
10
|
-
* @param values
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
const createSelects = onSelects;
|
|
14
|
-
|
|
15
|
-
export { createSelects, onSelects };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createCallHandler: (valueEvent: any) => (currents: any, nextEvent: any) => void;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { showErrorModule } from '../../core/utils.js';
|
|
2
|
-
|
|
3
|
-
const createCallHandler = valueEvent => {
|
|
4
|
-
// 开始处理 handler
|
|
5
|
-
const callHandler = (currents, nextEvent) => {
|
|
6
|
-
let index = 0;
|
|
7
|
-
let isClose = false;
|
|
8
|
-
let isNext = false;
|
|
9
|
-
const start = async () => {
|
|
10
|
-
if (index >= currents.length) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (isNext) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (isClose) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
// 统一使用 await,无需区分同步/异步函数
|
|
21
|
-
const res = await currents[index](valueEvent, (...cns) => {
|
|
22
|
-
isNext = true;
|
|
23
|
-
nextEvent(...cns);
|
|
24
|
-
});
|
|
25
|
-
// return true → 局部中间件放行,继续执行 children handler
|
|
26
|
-
// return void/false → 处理完毕或拦截,停止当前链
|
|
27
|
-
if (res !== true) {
|
|
28
|
-
isClose = true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
showErrorModule(err);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
++index;
|
|
36
|
-
void start();
|
|
37
|
-
};
|
|
38
|
-
void start();
|
|
39
|
-
};
|
|
40
|
-
return callHandler;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export { createCallHandler };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview 消息处理快
|
|
3
|
-
* 登录模块向核心模块发送数据
|
|
4
|
-
* 核心模块调用模块索引
|
|
5
|
-
* @module processor
|
|
6
|
-
* @author ningmengchongshui
|
|
7
|
-
*/
|
|
8
|
-
import { Events, EventKeys } from '../../types';
|
|
9
|
-
/**
|
|
10
|
-
* 消息体处理机制
|
|
11
|
-
* @param event
|
|
12
|
-
* @param key
|
|
13
|
-
*/
|
|
14
|
-
export declare const expendCycle: <T extends EventKeys>(valueEvent: Events[T], select: T, config?: any) => void;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { ResultCode } from '../../core/variable.js';
|
|
2
|
-
import { expendEvent } from './event-processor-event.js';
|
|
3
|
-
import { expendMiddleware } from './event-processor-middleware.js';
|
|
4
|
-
import { expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './event-processor-subscribe.js';
|
|
5
|
-
import { getConfigValue } from '../../core/config.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 打印日志
|
|
9
|
-
* @param event
|
|
10
|
-
* @param select
|
|
11
|
-
*/
|
|
12
|
-
const showLog = (event, select) => {
|
|
13
|
-
if (process.env.NODE_ENV === 'development') {
|
|
14
|
-
const log = {
|
|
15
|
-
Name: select
|
|
16
|
-
};
|
|
17
|
-
for (const key in event) {
|
|
18
|
-
if (Object.prototype.hasOwnProperty.call(event, key)) {
|
|
19
|
-
const value = event[key];
|
|
20
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
21
|
-
log[key] = value;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
logger.debug({
|
|
26
|
-
code: ResultCode.Ok,
|
|
27
|
-
message: 'new event',
|
|
28
|
-
data: log
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
// 批量收集非空字段后一次 join — 避免多次 typeof 检查 + 字符串 += 拼接
|
|
33
|
-
const parts = [`[Name:${select}]`];
|
|
34
|
-
const fields = ['GuildId', 'ChannelId', 'UserKey', 'UserId', 'MessageId', 'MessageText'];
|
|
35
|
-
for (const f of fields) {
|
|
36
|
-
const v = event[f];
|
|
37
|
-
if (typeof v === 'string' && v !== '') {
|
|
38
|
-
parts.push(`[${f}:${v}]`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
logger.info(parts.join(''));
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* 消息体处理机制
|
|
46
|
-
* @param event
|
|
47
|
-
* @param key
|
|
48
|
-
*/
|
|
49
|
-
const expendCycle = (valueEvent, select, config) => {
|
|
50
|
-
const nextEnd = () => { };
|
|
51
|
-
// unmount
|
|
52
|
-
const nextUnMount = (cn, ...cns) => {
|
|
53
|
-
if (cn) {
|
|
54
|
-
nextEnd(...cns);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
void expendSubscribeUnmount(valueEvent, select, nextEnd);
|
|
58
|
-
};
|
|
59
|
-
// event
|
|
60
|
-
const nextEvent = (cn, ...cns) => {
|
|
61
|
-
if (cn) {
|
|
62
|
-
nextUnMount(...cns);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
void expendEvent(valueEvent, select, nextUnMount);
|
|
66
|
-
};
|
|
67
|
-
// mount
|
|
68
|
-
const nextMount = (cn, ...cns) => {
|
|
69
|
-
if (cn) {
|
|
70
|
-
nextEvent(...cns);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
void expendSubscribeMount(valueEvent, select, nextEvent);
|
|
74
|
-
};
|
|
75
|
-
// middleware
|
|
76
|
-
const nextCreate = (cn, ...cns) => {
|
|
77
|
-
if (cn) {
|
|
78
|
-
nextMount(...cns);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
void expendMiddleware(valueEvent, select, nextMount);
|
|
82
|
-
};
|
|
83
|
-
const value = config ?? getConfigValue() ?? {};
|
|
84
|
-
if (Array.isArray(value?.logs?.channel_id)) {
|
|
85
|
-
const channelIds = value?.logs?.channel_id;
|
|
86
|
-
if (channelIds && channelIds.length > 0 && channelIds.includes(valueEvent['ChannelId'])) {
|
|
87
|
-
showLog(valueEvent, select);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
showLog(valueEvent, select);
|
|
92
|
-
}
|
|
93
|
-
// create
|
|
94
|
-
void expendSubscribeCreate(valueEvent, select, nextCreate);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export { expendCycle };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Next, Events, EventKeys, StoreResponseItem } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* 清除模块缓存(用于热更新等场景)
|
|
4
|
-
*/
|
|
5
|
-
export declare const clearModuleCache: (path?: string) => void;
|
|
6
|
-
/**
|
|
7
|
-
* 创建 next 处理函数
|
|
8
|
-
* @param event
|
|
9
|
-
* @param select
|
|
10
|
-
*/
|
|
11
|
-
export declare const createNextStep: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next, files: StoreResponseItem[], callHandler: (currents: any, nextEvent: any) => void) => Next;
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { useState } from '../hook-use/hook-use-state.js';
|
|
2
|
-
import { getCachedRegExp, showErrorModule } from '../../core/utils.js';
|
|
3
|
-
import { EventMessageText } from '../../core/variable.js';
|
|
4
|
-
import { ResponseMiddleware } from '../../store/store.js';
|
|
5
|
-
|
|
6
|
-
// 模块级单例 — ResponseMiddleware 无状态,无需每文件 new
|
|
7
|
-
const responseMiddlewareSingleton = new ResponseMiddleware();
|
|
8
|
-
// 模块缓存,避免每次事件处理都重新 import
|
|
9
|
-
const moduleCache = new Map();
|
|
10
|
-
/**
|
|
11
|
-
* 清除模块缓存(用于热更新等场景)
|
|
12
|
-
*/
|
|
13
|
-
const clearModuleCache = (path) => {
|
|
14
|
-
if (path) {
|
|
15
|
-
moduleCache.delete(path);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
moduleCache.clear();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const loadModule = async (filePath) => {
|
|
22
|
-
if (moduleCache.has(filePath)) {
|
|
23
|
-
return moduleCache.get(filePath);
|
|
24
|
-
}
|
|
25
|
-
const mod = await import(`file://${filePath}`);
|
|
26
|
-
moduleCache.set(filePath, mod);
|
|
27
|
-
return mod;
|
|
28
|
-
};
|
|
29
|
-
const callHandlerFile = async (valueEvent, select, file, nextStep, callback) => {
|
|
30
|
-
try {
|
|
31
|
-
const app = await loadModule(file.path);
|
|
32
|
-
// bad case
|
|
33
|
-
if (!app?.default?.current || !app?.default?.select) {
|
|
34
|
-
// 继续
|
|
35
|
-
nextStep();
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
// 检查状态
|
|
39
|
-
if (file?.stateKey) {
|
|
40
|
-
const [state] = useState(file?.stateKey);
|
|
41
|
-
if (state === false) {
|
|
42
|
-
// 继续
|
|
43
|
-
nextStep();
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (EventMessageText.includes(select)) {
|
|
48
|
-
if (app?.regular) {
|
|
49
|
-
if (!getCachedRegExp(app.regular).test(valueEvent['MessageText'])) {
|
|
50
|
-
// 继续
|
|
51
|
-
nextStep();
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const selects = Array.isArray(app.default.select) ? app.default.select : [app.default.select];
|
|
57
|
-
if (!selects.includes(select)) {
|
|
58
|
-
// 继续
|
|
59
|
-
nextStep();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
callback(app);
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
showErrorModule(err);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* 创建 next 处理函数
|
|
70
|
-
* @param event
|
|
71
|
-
* @param select
|
|
72
|
-
*/
|
|
73
|
-
const createNextStep = (valueEvent, select, next, files, callHandler) => {
|
|
74
|
-
let valueI = 0;
|
|
75
|
-
// 记录被close的中间件。优化下调用性能
|
|
76
|
-
const recordCloseMw = new Set();
|
|
77
|
-
/**
|
|
78
|
-
* 下一步
|
|
79
|
-
* @returns
|
|
80
|
-
*/
|
|
81
|
-
const nextStep = (cn, ...cns) => {
|
|
82
|
-
if (cn) {
|
|
83
|
-
next(...cns);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// 结束了
|
|
87
|
-
if (valueI >= files.length) {
|
|
88
|
-
next();
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
// 检查所有
|
|
92
|
-
void calli();
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* 执行 i
|
|
96
|
-
* @returns
|
|
97
|
-
*/
|
|
98
|
-
const calli = async () => {
|
|
99
|
-
// 调用完了
|
|
100
|
-
if (valueI >= files.length) {
|
|
101
|
-
// 开始调用j
|
|
102
|
-
nextStep();
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
valueI++;
|
|
106
|
-
const file = files[valueI - 1];
|
|
107
|
-
if (!file?.path) {
|
|
108
|
-
// 继续
|
|
109
|
-
nextStep();
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
// 调用局部中间件(使用模块级单例,避免每文件创建新实例)
|
|
113
|
-
const currentsAndMiddleware = responseMiddlewareSingleton.find(file.appName, file.stateKey);
|
|
114
|
-
const currents = [];
|
|
115
|
-
// 直接遍历 middleware 数组 + file,避免每文件 spread 创建新数组
|
|
116
|
-
const iterItems = currentsAndMiddleware.length > 0 ? currentsAndMiddleware.concat(file) : [file];
|
|
117
|
-
for (const cm of iterItems) {
|
|
118
|
-
let isBreak = false;
|
|
119
|
-
if (recordCloseMw.has(cm.stateKey)) {
|
|
120
|
-
// 这是一个被关闭的中间件
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* 直接关闭当前循环
|
|
125
|
-
*/
|
|
126
|
-
const close = () => {
|
|
127
|
-
isBreak = true;
|
|
128
|
-
recordCloseMw.add(cm.stateKey);
|
|
129
|
-
};
|
|
130
|
-
await callHandlerFile(valueEvent, select, cm, close, app => {
|
|
131
|
-
const currentsItem = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
|
|
132
|
-
currents.push(...currentsItem);
|
|
133
|
-
});
|
|
134
|
-
// 直接结束了
|
|
135
|
-
if (isBreak) {
|
|
136
|
-
// 进行下一步
|
|
137
|
-
nextStep();
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// 调用当前响应体
|
|
142
|
-
callHandler(currents, nextStep);
|
|
143
|
-
};
|
|
144
|
-
return nextStep;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export { clearModuleCache, createNextStep };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Next, Events, EventKeys, ResponseRoute } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* 创建路由处理调用函数
|
|
4
|
-
* @param valueEvent
|
|
5
|
-
* @param select
|
|
6
|
-
* @param nextCycle
|
|
7
|
-
* @param callHandler
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export declare const createRouteProcessChildren: <T extends EventKeys>(valueEvent: Events[T], select: T, nextCycle: Next, callHandler: (currents: any, nextEvent: any) => void) => (nodes: ResponseRoute[], middleware: any, next: () => Promise<void> | void) => void;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { EventMessageText } from '../../core/variable.js';
|
|
2
|
-
import { getCachedRegExp, showErrorModule } from '../../core/utils.js';
|
|
3
|
-
|
|
4
|
-
// 缓存 AsyncFunction 构造函数 — 避免每次调用创建匿名 async 函数
|
|
5
|
-
const AsyncFunction = (async () => { }).constructor;
|
|
6
|
-
function isAsyncFunction(fn) {
|
|
7
|
-
return fn instanceof AsyncFunction;
|
|
8
|
-
}
|
|
9
|
-
function isFunction(value) {
|
|
10
|
-
return isAsyncFunction(value) || typeof value === 'function' || value instanceof Function;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* 创建路由处理调用函数
|
|
14
|
-
* @param valueEvent
|
|
15
|
-
* @param select
|
|
16
|
-
* @param nextCycle
|
|
17
|
-
* @param callHandler
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
const createRouteProcessChildren = (valueEvent, select, nextCycle, callHandler) => {
|
|
21
|
-
// 开始处理 handler
|
|
22
|
-
const processChildren = (nodes, middleware, next) => {
|
|
23
|
-
if (!nodes || nodes.length === 0) {
|
|
24
|
-
void next();
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
let idx = 0;
|
|
28
|
-
const nextNode = async () => {
|
|
29
|
-
idx++;
|
|
30
|
-
if (idx > nodes.length) {
|
|
31
|
-
void next();
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const node = nodes[idx - 1];
|
|
35
|
-
if (node?.selects) {
|
|
36
|
-
const selects = Array.isArray(node.selects) ? node.selects : [node.selects];
|
|
37
|
-
if (!selects.includes(select)) {
|
|
38
|
-
void nextNode();
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// 文本匹配(按性能从高到低:exact > prefix > regular)
|
|
43
|
-
if (EventMessageText.includes(select)) {
|
|
44
|
-
const text = valueEvent['MessageText'] ?? '';
|
|
45
|
-
// 精确匹配(最快,O(1) 字符串比较)
|
|
46
|
-
if (node.exact !== undefined) {
|
|
47
|
-
if (text !== node.exact) {
|
|
48
|
-
void nextNode();
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
// 前缀匹配(快,O(n) startsWith)
|
|
53
|
-
if (node.prefix !== undefined) {
|
|
54
|
-
if (!text.startsWith(node.prefix)) {
|
|
55
|
-
void nextNode();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// 正则匹配(使用缓存,避免每条消息重编译)
|
|
60
|
-
if (node.regular) {
|
|
61
|
-
if (!getCachedRegExp(node.regular).test(text)) {
|
|
62
|
-
void nextNode();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (!node.handler) {
|
|
68
|
-
void nextNode();
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// 递归:如果有children,继续递归下去
|
|
72
|
-
if (node.children && node.children.length > 0) {
|
|
73
|
-
// push/pop 回溯 — 避免每层递归 spread 创建新数组
|
|
74
|
-
middleware.push(node.handler);
|
|
75
|
-
processChildren(node.children, middleware, () => {
|
|
76
|
-
middleware.pop();
|
|
77
|
-
void nextNode();
|
|
78
|
-
});
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
// 没有children,直接处理handler — 临时拼接,无需 spread
|
|
82
|
-
middleware.push(node.handler);
|
|
83
|
-
const currentsAndMiddleware = middleware;
|
|
84
|
-
// node.handler 是一个异步函数。函数执行的结果是 { current: Current[] | Current, select: xxx }
|
|
85
|
-
try {
|
|
86
|
-
const currents = [];
|
|
87
|
-
for (const item of currentsAndMiddleware) {
|
|
88
|
-
const app = await item();
|
|
89
|
-
// 没有 default。因为是 import x from './';
|
|
90
|
-
if (isFunction(app)) {
|
|
91
|
-
// 纯异步函数
|
|
92
|
-
currents.push(app);
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
// 中间件也有 selects。
|
|
96
|
-
// 如果 发现 和当前要处理的 selects 不匹配。
|
|
97
|
-
// 只要是一个不匹配。则说明处理还不是最终想要执行结果。
|
|
98
|
-
const selects = Array.isArray(app.select) ? app.select : [app.select];
|
|
99
|
-
// 没有匹配到
|
|
100
|
-
if (!selects.includes(select)) {
|
|
101
|
-
// 回溯 pop,避免中间件泄漏
|
|
102
|
-
middleware.pop();
|
|
103
|
-
void nextNode();
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
// 可能是数组。也可能不是数组
|
|
107
|
-
const currentsItem = Array.isArray(app.current) ? app.current : [app.current];
|
|
108
|
-
currents.push(...currentsItem);
|
|
109
|
-
}
|
|
110
|
-
// 回溯 pop 当前 handler
|
|
111
|
-
middleware.pop();
|
|
112
|
-
// 要把二维数组拍平
|
|
113
|
-
callHandler(currents, (cn, ...cns) => {
|
|
114
|
-
if (cn) {
|
|
115
|
-
// 这里的 next 要加 true。
|
|
116
|
-
// 因为下一层是旧版本逻辑。不加一层。会出现处理了没有完全结束周期
|
|
117
|
-
nextCycle(true, ...cns);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
void nextNode();
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
catch (err) {
|
|
124
|
-
middleware.pop();
|
|
125
|
-
showErrorModule(err);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
void nextNode();
|
|
129
|
-
};
|
|
130
|
-
return processChildren;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
export { createRouteProcessChildren };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview 消息处理快
|
|
3
|
-
* 登录模块向核心模块发送数据
|
|
4
|
-
* 核心模块调用模块索引
|
|
5
|
-
* @module processor
|
|
6
|
-
* @author ningmengchongshui
|
|
7
|
-
*/
|
|
8
|
-
import { Next, Events, EventKeys } from '../../types';
|
|
9
|
-
/**
|
|
10
|
-
* todo:
|
|
11
|
-
* 当前的局部中间件算法有问题
|
|
12
|
-
* ****
|
|
13
|
-
* 当前仅仅是简单的记录。被关闭的中间件。
|
|
14
|
-
* ****
|
|
15
|
-
* 在一个指令匹配多个 res 的情况下。
|
|
16
|
-
* 会出现多次计算同一个中间件的结果。即 bad case
|
|
17
|
-
* 需要一个缓存机制。
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* 消息体处理机制
|
|
21
|
-
* @param event
|
|
22
|
-
* @param key
|
|
23
|
-
*/
|
|
24
|
-
export declare const expendEvent: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Response, ResponseRouter } from '../../store/store.js';
|
|
2
|
-
import { createCallHandler } from './event-processor-callHandler.js';
|
|
3
|
-
import { createNextStep } from './event-processor-cycleFiles.js';
|
|
4
|
-
import { createRouteProcessChildren } from './event-processor-cycleRoute.js';
|
|
5
|
-
|
|
6
|
-
// 单例,避免每次事件处理都创建新对象
|
|
7
|
-
const responseSingleton = new Response();
|
|
8
|
-
const responseRouterSingleton = new ResponseRouter();
|
|
9
|
-
/**
|
|
10
|
-
* todo:
|
|
11
|
-
* 当前的局部中间件算法有问题
|
|
12
|
-
* ****
|
|
13
|
-
* 当前仅仅是简单的记录。被关闭的中间件。
|
|
14
|
-
* ****
|
|
15
|
-
* 在一个指令匹配多个 res 的情况下。
|
|
16
|
-
* 会出现多次计算同一个中间件的结果。即 bad case
|
|
17
|
-
* 需要一个缓存机制。
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* 消息体处理机制
|
|
21
|
-
* @param event
|
|
22
|
-
* @param key
|
|
23
|
-
*/
|
|
24
|
-
const expendEvent = (valueEvent, select, next) => {
|
|
25
|
-
// 得到所有响应体(文件)
|
|
26
|
-
const StoreResponse = responseSingleton.value;
|
|
27
|
-
// 创建调用函数(文件)
|
|
28
|
-
const callHandler = createCallHandler(valueEvent);
|
|
29
|
-
// 创建next函数(文件)
|
|
30
|
-
const nextEvent = createNextStep(valueEvent, select, next, StoreResponse, callHandler);
|
|
31
|
-
// 得到所有响应体(路由)
|
|
32
|
-
const routes = responseRouterSingleton.value;
|
|
33
|
-
// 创建调用函数(路由)
|
|
34
|
-
const callRouteHandler = createCallHandler(valueEvent);
|
|
35
|
-
// 创建 children 处理函数(路由)
|
|
36
|
-
const processChildren = createRouteProcessChildren(valueEvent, select, nextEvent, callRouteHandler);
|
|
37
|
-
// 开始先处理 路由系统,再到 文件系统
|
|
38
|
-
void processChildren(routes, [], nextEvent);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { expendEvent };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview 消息处理快
|
|
3
|
-
* 登录模块向核心模块发送数据
|
|
4
|
-
* 核心模块调用模块索引
|
|
5
|
-
* @module processor
|
|
6
|
-
* @author ningmengchongshui
|
|
7
|
-
*/
|
|
8
|
-
import { Next, Events, EventKeys } from '../../types';
|
|
9
|
-
/**
|
|
10
|
-
* 处理中间件
|
|
11
|
-
* @param event
|
|
12
|
-
* @param select
|
|
13
|
-
*/
|
|
14
|
-
export declare const expendMiddleware: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Next) => void;
|