alemonjs 2.1.0-alpha.36 → 2.1.0-alpha.38
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/event-processor-cycle.d.ts +19 -0
- package/lib/app/event-processor-event.d.ts +11 -0
- package/lib/app/event-processor-middleware.d.ts +11 -0
- package/lib/app/event-processor-subscribe.d.ts +41 -0
- package/lib/cbp/hello.html.js +47 -0
- package/lib/cbp/router.js +6 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/main.js +11 -7
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventKeys, Events } from '../typing/event/map.js';
|
|
2
|
+
import '../global.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview 消息处理快
|
|
6
|
+
* 登录模块向核心模块发送数据
|
|
7
|
+
* 核心模块调用模块索引
|
|
8
|
+
* @module processor
|
|
9
|
+
* @author ningmengchongshui
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 消息体处理机制
|
|
14
|
+
* @param event
|
|
15
|
+
* @param key
|
|
16
|
+
*/
|
|
17
|
+
declare const expendCycle: <T extends EventKeys>(valueEvent: Events[T], select: T) => Promise<void>;
|
|
18
|
+
|
|
19
|
+
export { expendCycle };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventKeys, Events } from '../typing/event/map.js';
|
|
2
|
+
import '../global.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 消息体处理机制
|
|
6
|
+
* @param event
|
|
7
|
+
* @param key
|
|
8
|
+
*/
|
|
9
|
+
declare const expendEvent: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
|
|
10
|
+
|
|
11
|
+
export { expendEvent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventKeys, Events } from '../typing/event/map.js';
|
|
2
|
+
import '../global.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 处理中间件
|
|
6
|
+
* @param event
|
|
7
|
+
* @param select
|
|
8
|
+
*/
|
|
9
|
+
declare const expendMiddleware: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
|
|
10
|
+
|
|
11
|
+
export { expendMiddleware };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { EventCycleEnum } from '../typing/cycle/index.js';
|
|
2
|
+
import '../global.js';
|
|
3
|
+
import { EventKeys, Events } from '../typing/event/map.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview 观察者
|
|
7
|
+
* @module processor
|
|
8
|
+
* @author ningmengchongshui
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 处理订阅
|
|
13
|
+
* @param valueEvent
|
|
14
|
+
* @param select
|
|
15
|
+
* @param next
|
|
16
|
+
* @param chioce
|
|
17
|
+
*/
|
|
18
|
+
declare const expendSubscribe: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function, chioce: EventCycleEnum) => Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param valueEvent
|
|
22
|
+
* @param select
|
|
23
|
+
* @param next
|
|
24
|
+
*/
|
|
25
|
+
declare const expendSubscribeCreate: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param valueEvent
|
|
29
|
+
* @param select
|
|
30
|
+
* @param next
|
|
31
|
+
*/
|
|
32
|
+
declare const expendSubscribeMount: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param valueEvent
|
|
36
|
+
* @param select
|
|
37
|
+
* @param next
|
|
38
|
+
*/
|
|
39
|
+
declare const expendSubscribeUnmount: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
|
|
40
|
+
|
|
41
|
+
export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const html = `
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>欢迎使用 AlemonJS!</title>
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
width: 35em;
|
|
9
|
+
margin: 0 auto;
|
|
10
|
+
font-family: Tahoma, Verdana, Arial, sans-serif;
|
|
11
|
+
background-color: #f8f8f8;
|
|
12
|
+
color: #333;
|
|
13
|
+
}
|
|
14
|
+
h1 {
|
|
15
|
+
color: #0099cc;
|
|
16
|
+
margin-top: 2em;
|
|
17
|
+
}
|
|
18
|
+
.footer {
|
|
19
|
+
margin-top: 3em;
|
|
20
|
+
font-size: 0.9em;
|
|
21
|
+
color: #888;
|
|
22
|
+
}
|
|
23
|
+
a {
|
|
24
|
+
color: #0099cc;
|
|
25
|
+
}
|
|
26
|
+
</style>
|
|
27
|
+
</head>
|
|
28
|
+
<body>
|
|
29
|
+
<h1>AlemonJS 启动成功!</h1>
|
|
30
|
+
<p>
|
|
31
|
+
恭喜,您的服务已成功通过 <a href="https://alemonjs.com" target="_blank">AlemonJS 框架</a> 启动。
|
|
32
|
+
</p>
|
|
33
|
+
<p>
|
|
34
|
+
如果想访问主应用,请访问, <a href="/app" target="_blank">/app</a>(对应根目录index.html)
|
|
35
|
+
</p>
|
|
36
|
+
<p>
|
|
37
|
+
如果想访问其他应用,请访问 /apps/[package-name]</a>。(对应/packages/[package-name]/index.html)
|
|
38
|
+
</p>
|
|
39
|
+
<div class="footer">
|
|
40
|
+
<p>感谢选择 AlemonJS。</p>
|
|
41
|
+
</div>
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
44
|
+
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
export { html };
|
package/lib/cbp/router.js
CHANGED
|
@@ -3,6 +3,7 @@ import fs, { existsSync } from 'fs';
|
|
|
3
3
|
import path, { join, dirname } from 'path';
|
|
4
4
|
import mime from 'mime-types';
|
|
5
5
|
import { createRequire } from 'module';
|
|
6
|
+
import { html } from './hello.html.js';
|
|
6
7
|
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
8
9
|
const mainDirMap = new Map();
|
|
@@ -45,6 +46,11 @@ const getModuelFile = (dir) => {
|
|
|
45
46
|
const router = new KoaRouter({
|
|
46
47
|
prefix: '/'
|
|
47
48
|
});
|
|
49
|
+
router.get('/', ctx => {
|
|
50
|
+
ctx.status = 200;
|
|
51
|
+
ctx.set('Content-Type', 'text/html; charset=utf-8');
|
|
52
|
+
ctx.body = html;
|
|
53
|
+
});
|
|
48
54
|
// 响应服务在线
|
|
49
55
|
router.get('api/online', ctx => {
|
|
50
56
|
ctx.status = 200;
|
package/lib/index.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export { defineChildren } from './app/define-chidren.js';
|
|
|
24
24
|
export { onGroup } from './app/event-group.js';
|
|
25
25
|
export { OnMiddleware, onMiddleware } from './app/event-middleware.js';
|
|
26
26
|
export { OnProcessor, onProcessor } from './app/event-processor.js';
|
|
27
|
+
export { expendCycle } from './app/event-processor-cycle.js';
|
|
28
|
+
export { expendEvent } from './app/event-processor-event.js';
|
|
29
|
+
export { expendMiddleware } from './app/event-processor-middleware.js';
|
|
30
|
+
export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './app/event-processor-subscribe.js';
|
|
27
31
|
export { OnResponse, onResponse } from './app/event-response.js';
|
|
28
32
|
export { createSelects, onSelects, unChildren, useChannel, useClient, useMenber, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
|
|
29
33
|
export { onState, unState, useState } from './app/hook-use-state.js';
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,10 @@ export { defineChildren } from './app/define-chidren.js';
|
|
|
5
5
|
export { onGroup } from './app/event-group.js';
|
|
6
6
|
export { OnMiddleware, onMiddleware } from './app/event-middleware.js';
|
|
7
7
|
export { OnProcessor, onProcessor } from './app/event-processor.js';
|
|
8
|
+
export { expendCycle } from './app/event-processor-cycle.js';
|
|
9
|
+
export { expendEvent } from './app/event-processor-event.js';
|
|
10
|
+
export { expendMiddleware } from './app/event-processor-middleware.js';
|
|
11
|
+
export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount } from './app/event-processor-subscribe.js';
|
|
8
12
|
export { OnResponse, onResponse } from './app/event-response.js';
|
|
9
13
|
export { createSelects, onSelects, unChildren, useChannel, useClient, useMenber, useMention, useMessage, useSend, useSends } from './app/hook-use-api.js';
|
|
10
14
|
export { onState, unState, useState } from './app/hook-use-state.js';
|
package/lib/main.js
CHANGED
|
@@ -5,12 +5,14 @@ import './app/define-chidren.js';
|
|
|
5
5
|
import './app/event-group.js';
|
|
6
6
|
import './app/event-middleware.js';
|
|
7
7
|
import './app/event-processor.js';
|
|
8
|
-
import './app/event-response.js';
|
|
9
|
-
import './app/hook-use-api.js';
|
|
10
|
-
import { useState } from './app/hook-use-state.js';
|
|
11
8
|
import { ResultCode } from './core/code.js';
|
|
9
|
+
import 'util/types';
|
|
10
|
+
import { useState } from './app/hook-use-state.js';
|
|
12
11
|
import 'node:fs';
|
|
13
12
|
import 'log4js';
|
|
13
|
+
import './app/hook-use-api.js';
|
|
14
|
+
import { default_port, file_prefix_common, default_platform_common_prefix } from './core/variable.js';
|
|
15
|
+
import './app/event-response.js';
|
|
14
16
|
import './app/message-api.js';
|
|
15
17
|
import './app/message-format.js';
|
|
16
18
|
import { cbpClient } from './cbp/client.js';
|
|
@@ -20,7 +22,6 @@ import './cbp/config.js';
|
|
|
20
22
|
import 'flatted';
|
|
21
23
|
import { join } from 'path';
|
|
22
24
|
import { existsSync } from 'fs';
|
|
23
|
-
import { default_port, file_prefix_common, default_platform_common_prefix } from './core/variable.js';
|
|
24
25
|
|
|
25
26
|
const loadState = () => {
|
|
26
27
|
const value = getConfigValue() ?? {};
|
|
@@ -72,6 +73,7 @@ const start = async (options = {}) => {
|
|
|
72
73
|
const url = options?.url || cfg.argv?.url || cfg.value?.url;
|
|
73
74
|
// 连接到 CBP 服务器
|
|
74
75
|
if (url) {
|
|
76
|
+
logger.info(`[Connecting to CBP server at ${url}]`);
|
|
75
77
|
cbpClient(url);
|
|
76
78
|
}
|
|
77
79
|
else {
|
|
@@ -80,10 +82,12 @@ const start = async (options = {}) => {
|
|
|
80
82
|
// 设置环境变量
|
|
81
83
|
process.env.port = port;
|
|
82
84
|
cbpServer(port, async () => {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
+
const httpURL = `http://127.0.0.1:${port}`;
|
|
86
|
+
const wsURL = `ws://127.0.0.1:${port}`;
|
|
87
|
+
logger.info(`[CBP server started at ${httpURL}]`);
|
|
88
|
+
logger.info(`[CBP server started at ${wsURL}]`);
|
|
85
89
|
const isFullReceive = options?.is_full_receive || cfg.argv?.is_full_receive || cfg.value?.is_full_receive || true;
|
|
86
|
-
cbpClient(
|
|
90
|
+
cbpClient(httpURL, { isFullReceive });
|
|
87
91
|
// 加载平台服务
|
|
88
92
|
const platform = options?.platform || cfg.argv?.platform || cfg.value?.platform;
|
|
89
93
|
const login = options?.login || cfg.argv?.login || cfg.value?.login;
|