@yumerijs/core 1.1.0-alpha.5 → 1.1.0
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/dist/command.d.ts +96 -0
- package/dist/command.js +120 -3
- package/dist/config.js +40 -8
- package/dist/context.js +2 -0
- package/dist/core.d.ts +75 -0
- package/dist/core.js +99 -26
- package/dist/logger.js +4 -2
- package/dist/platform.js +10 -10
- package/dist/session.js +11 -5
- package/package.json +2 -2
package/dist/command.d.ts
CHANGED
|
@@ -6,14 +6,74 @@
|
|
|
6
6
|
import { Core } from './core';
|
|
7
7
|
import { Session } from './session';
|
|
8
8
|
import { Middleware } from './middleware';
|
|
9
|
+
/**
|
|
10
|
+
* 命令处理函数接口
|
|
11
|
+
* @param session 会话对象
|
|
12
|
+
* @param args 其他参数
|
|
13
|
+
* @returns Promise<any>
|
|
14
|
+
*/
|
|
9
15
|
interface ActionFn {
|
|
10
16
|
(session: any, ...args: any[]): Promise<any>;
|
|
11
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* 支持的协议类型
|
|
20
|
+
* @enum {string}
|
|
21
|
+
*/
|
|
22
|
+
export declare enum ProtocolType {
|
|
23
|
+
/** HTTP 协议 */
|
|
24
|
+
HTTP = "http",
|
|
25
|
+
/** WebSocket 协议 */
|
|
26
|
+
WS = "ws",
|
|
27
|
+
/** 所有协议 */
|
|
28
|
+
ALL = "all"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 支持的 HTTP 方法
|
|
32
|
+
* @enum {string}
|
|
33
|
+
*/
|
|
34
|
+
export declare enum HttpMethod {
|
|
35
|
+
/** GET 请求方法 */
|
|
36
|
+
GET = "get",
|
|
37
|
+
/** POST 请求方法 */
|
|
38
|
+
POST = "post",
|
|
39
|
+
/** PUT 请求方法 */
|
|
40
|
+
PUT = "put",
|
|
41
|
+
/** DELETE 请求方法 */
|
|
42
|
+
DELETE = "delete",
|
|
43
|
+
/** PATCH 请求方法 */
|
|
44
|
+
PATCH = "patch",
|
|
45
|
+
/** HEAD 请求方法 */
|
|
46
|
+
HEAD = "head",
|
|
47
|
+
/** OPTIONS 请求方法 */
|
|
48
|
+
OPTIONS = "options",
|
|
49
|
+
/** 所有 HTTP 方法 */
|
|
50
|
+
ALL = "all"
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 命令类,用于注册和执行命令
|
|
54
|
+
*/
|
|
12
55
|
export declare class Command {
|
|
56
|
+
/** 命令名称 */
|
|
13
57
|
name: string;
|
|
58
|
+
/** 命令处理函数 */
|
|
14
59
|
actionFn: ActionFn | null;
|
|
60
|
+
/** WebSocket 连接处理函数 */
|
|
61
|
+
connectFn: ActionFn | null;
|
|
62
|
+
/** WebSocket 关闭处理函数 */
|
|
63
|
+
closeFn: ActionFn | null;
|
|
64
|
+
/** 核心实例 */
|
|
15
65
|
core: Core;
|
|
66
|
+
/** 命令特定的中间件数组 */
|
|
16
67
|
middlewares: Middleware[];
|
|
68
|
+
/** 支持的协议类型,默认为所有协议 */
|
|
69
|
+
protocol: ProtocolType;
|
|
70
|
+
/** 支持的 HTTP 方法,默认为所有方法 */
|
|
71
|
+
httpMethods: HttpMethod[];
|
|
72
|
+
/**
|
|
73
|
+
* 创建命令实例
|
|
74
|
+
* @param core 核心实例
|
|
75
|
+
* @param name 命令名称
|
|
76
|
+
*/
|
|
17
77
|
constructor(core: Core, name: string);
|
|
18
78
|
/**
|
|
19
79
|
* 注册命令处理函数
|
|
@@ -21,6 +81,42 @@ export declare class Command {
|
|
|
21
81
|
* @returns this 支持链式调用
|
|
22
82
|
*/
|
|
23
83
|
action(fn: ActionFn): this;
|
|
84
|
+
/**
|
|
85
|
+
* 注册 WebSocket 关闭处理函数
|
|
86
|
+
* @param fn 处理函数
|
|
87
|
+
* @returns this 支持链式调用
|
|
88
|
+
*/
|
|
89
|
+
close(fn: ActionFn): this;
|
|
90
|
+
/**
|
|
91
|
+
* 注册 WebSocket 连接处理函数
|
|
92
|
+
* @param fn 处理函数
|
|
93
|
+
* @returns this 支持链式调用
|
|
94
|
+
*/
|
|
95
|
+
connect(fn: ActionFn): this;
|
|
96
|
+
/**
|
|
97
|
+
* 设置命令支持的协议类型
|
|
98
|
+
* @param protocol 协议类型
|
|
99
|
+
* @returns this 支持链式调用
|
|
100
|
+
*/
|
|
101
|
+
setProtocol(protocol: ProtocolType): this;
|
|
102
|
+
/**
|
|
103
|
+
* 设置命令支持的 HTTP 方法
|
|
104
|
+
* @param methods 单个 HTTP 方法或 HTTP 方法数组
|
|
105
|
+
* @returns this 支持链式调用
|
|
106
|
+
*/
|
|
107
|
+
setHttpMethods(methods: HttpMethod | HttpMethod[]): this;
|
|
108
|
+
/**
|
|
109
|
+
* 检查命令是否支持指定的协议类型
|
|
110
|
+
* @param protocol 协议类型
|
|
111
|
+
* @returns 是否支持
|
|
112
|
+
*/
|
|
113
|
+
supportsProtocol(protocol: ProtocolType): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* 检查命令是否支持指定的 HTTP 方法
|
|
116
|
+
* @param method HTTP 方法
|
|
117
|
+
* @returns 是否支持
|
|
118
|
+
*/
|
|
119
|
+
supportsHttpMethod(method: string): boolean;
|
|
24
120
|
/**
|
|
25
121
|
* 注册命令特定的中间件
|
|
26
122
|
* @param middleware 中间件函数
|
package/dist/command.js
CHANGED
|
@@ -5,11 +5,69 @@
|
|
|
5
5
|
* WindyPear-Team All right reserved
|
|
6
6
|
**/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.Command = void 0;
|
|
8
|
+
exports.Command = exports.HttpMethod = exports.ProtocolType = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* 支持的协议类型
|
|
11
|
+
* @enum {string}
|
|
12
|
+
*/
|
|
13
|
+
var ProtocolType;
|
|
14
|
+
(function (ProtocolType) {
|
|
15
|
+
/** HTTP 协议 */
|
|
16
|
+
ProtocolType["HTTP"] = "http";
|
|
17
|
+
/** WebSocket 协议 */
|
|
18
|
+
ProtocolType["WS"] = "ws";
|
|
19
|
+
/** 所有协议 */
|
|
20
|
+
ProtocolType["ALL"] = "all";
|
|
21
|
+
})(ProtocolType || (exports.ProtocolType = ProtocolType = {}));
|
|
22
|
+
/**
|
|
23
|
+
* 支持的 HTTP 方法
|
|
24
|
+
* @enum {string}
|
|
25
|
+
*/
|
|
26
|
+
var HttpMethod;
|
|
27
|
+
(function (HttpMethod) {
|
|
28
|
+
/** GET 请求方法 */
|
|
29
|
+
HttpMethod["GET"] = "get";
|
|
30
|
+
/** POST 请求方法 */
|
|
31
|
+
HttpMethod["POST"] = "post";
|
|
32
|
+
/** PUT 请求方法 */
|
|
33
|
+
HttpMethod["PUT"] = "put";
|
|
34
|
+
/** DELETE 请求方法 */
|
|
35
|
+
HttpMethod["DELETE"] = "delete";
|
|
36
|
+
/** PATCH 请求方法 */
|
|
37
|
+
HttpMethod["PATCH"] = "patch";
|
|
38
|
+
/** HEAD 请求方法 */
|
|
39
|
+
HttpMethod["HEAD"] = "head";
|
|
40
|
+
/** OPTIONS 请求方法 */
|
|
41
|
+
HttpMethod["OPTIONS"] = "options";
|
|
42
|
+
/** 所有 HTTP 方法 */
|
|
43
|
+
HttpMethod["ALL"] = "all";
|
|
44
|
+
})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
|
|
45
|
+
/**
|
|
46
|
+
* 命令类,用于注册和执行命令
|
|
47
|
+
*/
|
|
9
48
|
class Command {
|
|
49
|
+
/** 命令名称 */
|
|
50
|
+
name;
|
|
51
|
+
/** 命令处理函数 */
|
|
52
|
+
actionFn = null;
|
|
53
|
+
/** WebSocket 连接处理函数 */
|
|
54
|
+
connectFn = null;
|
|
55
|
+
/** WebSocket 关闭处理函数 */
|
|
56
|
+
closeFn = null;
|
|
57
|
+
/** 核心实例 */
|
|
58
|
+
core;
|
|
59
|
+
/** 命令特定的中间件数组 */
|
|
60
|
+
middlewares = [];
|
|
61
|
+
/** 支持的协议类型,默认为所有协议 */
|
|
62
|
+
protocol = ProtocolType.ALL;
|
|
63
|
+
/** 支持的 HTTP 方法,默认为所有方法 */
|
|
64
|
+
httpMethods = [HttpMethod.ALL];
|
|
65
|
+
/**
|
|
66
|
+
* 创建命令实例
|
|
67
|
+
* @param core 核心实例
|
|
68
|
+
* @param name 命令名称
|
|
69
|
+
*/
|
|
10
70
|
constructor(core, name) {
|
|
11
|
-
this.actionFn = null;
|
|
12
|
-
this.middlewares = []; // 存储命令特定的中间件
|
|
13
71
|
this.core = core;
|
|
14
72
|
this.name = name;
|
|
15
73
|
}
|
|
@@ -22,6 +80,65 @@ class Command {
|
|
|
22
80
|
this.actionFn = fn;
|
|
23
81
|
return this;
|
|
24
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* 注册 WebSocket 关闭处理函数
|
|
85
|
+
* @param fn 处理函数
|
|
86
|
+
* @returns this 支持链式调用
|
|
87
|
+
*/
|
|
88
|
+
close(fn) {
|
|
89
|
+
this.closeFn = fn;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 注册 WebSocket 连接处理函数
|
|
94
|
+
* @param fn 处理函数
|
|
95
|
+
* @returns this 支持链式调用
|
|
96
|
+
*/
|
|
97
|
+
connect(fn) {
|
|
98
|
+
this.connectFn = fn;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 设置命令支持的协议类型
|
|
103
|
+
* @param protocol 协议类型
|
|
104
|
+
* @returns this 支持链式调用
|
|
105
|
+
*/
|
|
106
|
+
setProtocol(protocol) {
|
|
107
|
+
this.protocol = protocol;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 设置命令支持的 HTTP 方法
|
|
112
|
+
* @param methods 单个 HTTP 方法或 HTTP 方法数组
|
|
113
|
+
* @returns this 支持链式调用
|
|
114
|
+
*/
|
|
115
|
+
setHttpMethods(methods) {
|
|
116
|
+
if (Array.isArray(methods)) {
|
|
117
|
+
this.httpMethods = methods;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.httpMethods = [methods];
|
|
121
|
+
}
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 检查命令是否支持指定的协议类型
|
|
126
|
+
* @param protocol 协议类型
|
|
127
|
+
* @returns 是否支持
|
|
128
|
+
*/
|
|
129
|
+
supportsProtocol(protocol) {
|
|
130
|
+
return this.protocol === ProtocolType.ALL || this.protocol === protocol;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 检查命令是否支持指定的 HTTP 方法
|
|
134
|
+
* @param method HTTP 方法
|
|
135
|
+
* @returns 是否支持
|
|
136
|
+
*/
|
|
137
|
+
supportsHttpMethod(method) {
|
|
138
|
+
const lowerMethod = method.toLowerCase();
|
|
139
|
+
return this.httpMethods.includes(HttpMethod.ALL) ||
|
|
140
|
+
this.httpMethods.some(m => m.toLowerCase() === lowerMethod);
|
|
141
|
+
}
|
|
25
142
|
/**
|
|
26
143
|
* 注册命令特定的中间件
|
|
27
144
|
* @param middleware 中间件函数
|
package/dist/config.js
CHANGED
|
@@ -11,6 +11,34 @@ exports.Config = exports.ConfigSchema = void 0;
|
|
|
11
11
|
* 用于描述插件配置项的类型、默认值、描述等信息
|
|
12
12
|
*/
|
|
13
13
|
class ConfigSchema {
|
|
14
|
+
/**
|
|
15
|
+
* 配置项类型
|
|
16
|
+
*/
|
|
17
|
+
type;
|
|
18
|
+
/**
|
|
19
|
+
* 默认值
|
|
20
|
+
*/
|
|
21
|
+
default;
|
|
22
|
+
/**
|
|
23
|
+
* 配置项描述
|
|
24
|
+
*/
|
|
25
|
+
description;
|
|
26
|
+
/**
|
|
27
|
+
* 是否必需
|
|
28
|
+
*/
|
|
29
|
+
required;
|
|
30
|
+
/**
|
|
31
|
+
* 枚举值列表(可选项)
|
|
32
|
+
*/
|
|
33
|
+
enum;
|
|
34
|
+
/**
|
|
35
|
+
* 数组项类型定义(当type为array时使用)
|
|
36
|
+
*/
|
|
37
|
+
items;
|
|
38
|
+
/**
|
|
39
|
+
* 对象属性定义(当type为object时使用)
|
|
40
|
+
*/
|
|
41
|
+
properties;
|
|
14
42
|
/**
|
|
15
43
|
* 创建配置模式对象
|
|
16
44
|
* @param type 配置项类型
|
|
@@ -72,6 +100,18 @@ class ConfigSchema {
|
|
|
72
100
|
}
|
|
73
101
|
exports.ConfigSchema = ConfigSchema;
|
|
74
102
|
class Config {
|
|
103
|
+
/**
|
|
104
|
+
* 配置名称
|
|
105
|
+
*/
|
|
106
|
+
name = '';
|
|
107
|
+
/**
|
|
108
|
+
* 配置内容
|
|
109
|
+
*/
|
|
110
|
+
content = {};
|
|
111
|
+
/**
|
|
112
|
+
* 配置模式
|
|
113
|
+
*/
|
|
114
|
+
schema;
|
|
75
115
|
/**
|
|
76
116
|
* 创建配置对象
|
|
77
117
|
* @param name 配置名称
|
|
@@ -79,14 +119,6 @@ class Config {
|
|
|
79
119
|
* @param schema 配置模式
|
|
80
120
|
*/
|
|
81
121
|
constructor(name, content, schema) {
|
|
82
|
-
/**
|
|
83
|
-
* 配置名称
|
|
84
|
-
*/
|
|
85
|
-
this.name = '';
|
|
86
|
-
/**
|
|
87
|
-
* 配置内容
|
|
88
|
-
*/
|
|
89
|
-
this.content = {};
|
|
90
122
|
this.name = name;
|
|
91
123
|
this.content = content || {}; // 如果 content 是 undefined,则赋值为空对象
|
|
92
124
|
this.schema = schema;
|
package/dist/context.js
CHANGED
package/dist/core.d.ts
CHANGED
|
@@ -45,14 +45,31 @@ export declare class Core {
|
|
|
45
45
|
evttoplu: Record<string, Record<string, ((...args: any[]) => Promise<void>)[]>>;
|
|
46
46
|
mdwtoplu: Record<string, string>;
|
|
47
47
|
plftoplu: Record<string, string>;
|
|
48
|
+
/**
|
|
49
|
+
* 创建Core实例
|
|
50
|
+
* @param pluginLoader 插件加载器
|
|
51
|
+
*/
|
|
48
52
|
constructor(pluginLoader: PluginLoader);
|
|
53
|
+
/**
|
|
54
|
+
* 加载配置文件
|
|
55
|
+
* @param configPath 配置文件路径
|
|
56
|
+
*/
|
|
49
57
|
loadConfig(configPath: string): Promise<void>;
|
|
50
58
|
/**
|
|
51
59
|
* 监听配置文件变化
|
|
52
60
|
* @param configPath 配置文件路径
|
|
53
61
|
*/
|
|
54
62
|
private watchConfig;
|
|
63
|
+
/**
|
|
64
|
+
* 获取插件配置
|
|
65
|
+
* @param pluginName 插件名称
|
|
66
|
+
* @returns 配置
|
|
67
|
+
*/
|
|
55
68
|
getPluginConfig(pluginName: string): Promise<Config>;
|
|
69
|
+
/**
|
|
70
|
+
* 加载插件
|
|
71
|
+
* @returns Promise<void>
|
|
72
|
+
*/
|
|
56
73
|
loadPlugins(): Promise<void>;
|
|
57
74
|
/**
|
|
58
75
|
* 监听插件目录,实现热重载
|
|
@@ -72,15 +89,73 @@ export declare class Core {
|
|
|
72
89
|
* @param core Core实例
|
|
73
90
|
*/
|
|
74
91
|
unloadPluginAndEmit(pluginName: string, core: Core): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* 注册组件
|
|
94
|
+
* @param name 组件名称
|
|
95
|
+
* @param component 组件
|
|
96
|
+
* @returns void
|
|
97
|
+
*/
|
|
75
98
|
registerComponent(name: string, component: any): void;
|
|
99
|
+
/**
|
|
100
|
+
* 获取组件
|
|
101
|
+
* @param name 组件名称
|
|
102
|
+
* @returns 组件
|
|
103
|
+
*/
|
|
76
104
|
getComponent(name: string): any;
|
|
105
|
+
/**
|
|
106
|
+
* 取消注册组件
|
|
107
|
+
* @param name 组件名称
|
|
108
|
+
*/
|
|
77
109
|
unregisterComponent(name: string): void;
|
|
110
|
+
/**
|
|
111
|
+
* 监听事件
|
|
112
|
+
* @param event 事件名称
|
|
113
|
+
* @param listener 回调函数
|
|
114
|
+
*/
|
|
78
115
|
on(event: string, listener: (...args: any[]) => Promise<void>): void;
|
|
116
|
+
/**
|
|
117
|
+
* 触发事件
|
|
118
|
+
* @param event 事件名称
|
|
119
|
+
* @param args 参数
|
|
120
|
+
*/
|
|
79
121
|
emit(event: string, ...args: any[]): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* 注册全局中间件
|
|
124
|
+
* @param name 中间件名称
|
|
125
|
+
* @param middleware 中间件
|
|
126
|
+
* @returns Core对象
|
|
127
|
+
*/
|
|
80
128
|
use(name: string, middleware: Middleware): Core;
|
|
129
|
+
/**
|
|
130
|
+
* 定义指令
|
|
131
|
+
* @param name 指令名称
|
|
132
|
+
* @returns 指令对象
|
|
133
|
+
*/
|
|
81
134
|
command(name: string): Command;
|
|
135
|
+
/**
|
|
136
|
+
* 执行指令
|
|
137
|
+
* @param name 指令名称
|
|
138
|
+
* @param session 会话
|
|
139
|
+
* @param args 参数
|
|
140
|
+
* @returns 回话/null
|
|
141
|
+
*/
|
|
82
142
|
executeCommand(name: string, session: any, ...args: any[]): Promise<Session | null>;
|
|
143
|
+
/**
|
|
144
|
+
* 注册平台
|
|
145
|
+
* @param platform 平台名称
|
|
146
|
+
* @returns 启动结果
|
|
147
|
+
*/
|
|
83
148
|
registerPlatform(platform: Platform): any;
|
|
149
|
+
/**
|
|
150
|
+
* 取消注册插件
|
|
151
|
+
* @param pluginname 插件名称
|
|
152
|
+
*/
|
|
84
153
|
unregall(pluginname: string): void;
|
|
154
|
+
/**
|
|
155
|
+
* 获取指令对象
|
|
156
|
+
* @param name 指令名称
|
|
157
|
+
* @returns null/指令对象
|
|
158
|
+
*/
|
|
159
|
+
getCommand(name: string): Command | null;
|
|
85
160
|
}
|
|
86
161
|
export {};
|
package/dist/core.js
CHANGED
|
@@ -51,26 +51,34 @@ const command_1 = require("./command");
|
|
|
51
51
|
const chokidar_1 = __importDefault(require("chokidar"));
|
|
52
52
|
const context_1 = require("./context");
|
|
53
53
|
class Core {
|
|
54
|
+
plugins = {};
|
|
55
|
+
config = null;
|
|
56
|
+
platforms = [];
|
|
57
|
+
eventListeners = {};
|
|
58
|
+
components = {};
|
|
59
|
+
commands = {};
|
|
60
|
+
pluginLoader;
|
|
61
|
+
logger = new logger_1.Logger('core');
|
|
62
|
+
providedComponents = {};
|
|
63
|
+
pluginModules = {};
|
|
64
|
+
configPath = ''; // 存储配置文件路径
|
|
65
|
+
globalMiddlewares = {}; // 全局中间件数组
|
|
66
|
+
cmdtoplu = {}; // 存储命令与插件名的映射关系
|
|
67
|
+
comtoplu = {}; // 存储组件与插件名的映射关系
|
|
68
|
+
evttoplu = {}; // 存储事件与插件名的映射关系
|
|
69
|
+
mdwtoplu = {}; // 存储中间件与插件名的映射关系
|
|
70
|
+
plftoplu = {}; // 存储平台与插件名的映射关系
|
|
71
|
+
/**
|
|
72
|
+
* 创建Core实例
|
|
73
|
+
* @param pluginLoader 插件加载器
|
|
74
|
+
*/
|
|
54
75
|
constructor(pluginLoader) {
|
|
55
|
-
this.plugins = {};
|
|
56
|
-
this.config = null;
|
|
57
|
-
this.platforms = [];
|
|
58
|
-
this.eventListeners = {};
|
|
59
|
-
this.components = {};
|
|
60
|
-
this.commands = {};
|
|
61
|
-
this.logger = new logger_1.Logger('core');
|
|
62
|
-
this.providedComponents = {};
|
|
63
|
-
this.pluginModules = {};
|
|
64
|
-
this.configPath = ''; // 存储配置文件路径
|
|
65
|
-
this.globalMiddlewares = {}; // 全局中间件数组
|
|
66
|
-
this.cmdtoplu = {}; // 存储命令与插件名的映射关系
|
|
67
|
-
this.comtoplu = {}; // 存储组件与插件名的映射关系
|
|
68
|
-
this.evttoplu = {}; // 存储事件与插件名的映射关系
|
|
69
|
-
this.mdwtoplu = {}; // 存储中间件与插件名的映射关系
|
|
70
|
-
this.plftoplu = {}; // 存储平台与插件名的映射关系
|
|
71
76
|
this.pluginLoader = pluginLoader;
|
|
72
77
|
}
|
|
73
|
-
|
|
78
|
+
/**
|
|
79
|
+
* 加载配置文件
|
|
80
|
+
* @param configPath 配置文件路径
|
|
81
|
+
*/
|
|
74
82
|
async loadConfig(configPath) {
|
|
75
83
|
try {
|
|
76
84
|
this.configPath = configPath; // 保存配置文件路径
|
|
@@ -116,6 +124,11 @@ class Core {
|
|
|
116
124
|
});
|
|
117
125
|
this.logger.info(`Watching for config changes at ${configPath}`);
|
|
118
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* 获取插件配置
|
|
129
|
+
* @param pluginName 插件名称
|
|
130
|
+
* @returns 配置
|
|
131
|
+
*/
|
|
119
132
|
async getPluginConfig(pluginName) {
|
|
120
133
|
// 如果插件名以~开头,则去掉~前缀获取配置
|
|
121
134
|
const actualPluginName = pluginName.startsWith('~') ? pluginName.substring(1) : pluginName;
|
|
@@ -137,7 +150,10 @@ class Core {
|
|
|
137
150
|
const config = new config_1.Config(actualPluginName, this.config.plugins[actualPluginName]);
|
|
138
151
|
return config;
|
|
139
152
|
}
|
|
140
|
-
|
|
153
|
+
/**
|
|
154
|
+
* 加载插件
|
|
155
|
+
* @returns Promise<void>
|
|
156
|
+
*/
|
|
141
157
|
async loadPlugins() {
|
|
142
158
|
// 检查 plugins 配置是否存在且是对象类型
|
|
143
159
|
if (!this.config || typeof this.config.plugins !== 'object' || this.config.plugins === null) {
|
|
@@ -370,7 +386,12 @@ class Core {
|
|
|
370
386
|
this.logger.error(`Failed to unload plugin ${pluginName}:`, error);
|
|
371
387
|
}
|
|
372
388
|
}
|
|
373
|
-
|
|
389
|
+
/**
|
|
390
|
+
* 注册组件
|
|
391
|
+
* @param name 组件名称
|
|
392
|
+
* @param component 组件
|
|
393
|
+
* @returns void
|
|
394
|
+
*/
|
|
374
395
|
registerComponent(name, component) {
|
|
375
396
|
if (this.components.hasOwnProperty(name)) {
|
|
376
397
|
this.logger.warn(`Component "${name}" already registered by plugin "${this.providedComponents[`${name}`]}".`);
|
|
@@ -379,17 +400,28 @@ class Core {
|
|
|
379
400
|
this.components[`${name}`] = component;
|
|
380
401
|
this.logger.info(`Component "${name}" registered.`);
|
|
381
402
|
}
|
|
382
|
-
|
|
403
|
+
/**
|
|
404
|
+
* 获取组件
|
|
405
|
+
* @param name 组件名称
|
|
406
|
+
* @returns 组件
|
|
407
|
+
*/
|
|
383
408
|
getComponent(name) {
|
|
384
409
|
return this.components[`${name}`];
|
|
385
410
|
}
|
|
386
|
-
|
|
411
|
+
/**
|
|
412
|
+
* 取消注册组件
|
|
413
|
+
* @param name 组件名称
|
|
414
|
+
*/
|
|
387
415
|
unregisterComponent(name) {
|
|
388
416
|
delete this.components[`${name}`];
|
|
389
417
|
delete this.providedComponents[`${name}`];
|
|
390
418
|
delete this.comtoplu[`${name}`];
|
|
391
419
|
}
|
|
392
|
-
|
|
420
|
+
/**
|
|
421
|
+
* 监听事件
|
|
422
|
+
* @param event 事件名称
|
|
423
|
+
* @param listener 回调函数
|
|
424
|
+
*/
|
|
393
425
|
on(event, listener) {
|
|
394
426
|
if (!this.eventListeners[`${event}`]) {
|
|
395
427
|
this.eventListeners[`${event}`] = [];
|
|
@@ -397,7 +429,11 @@ class Core {
|
|
|
397
429
|
this.eventListeners[`${event}`].push(listener);
|
|
398
430
|
//this.logger.info(`Listener added for event "${event}".`);
|
|
399
431
|
}
|
|
400
|
-
|
|
432
|
+
/**
|
|
433
|
+
* 触发事件
|
|
434
|
+
* @param event 事件名称
|
|
435
|
+
* @param args 参数
|
|
436
|
+
*/
|
|
401
437
|
async emit(event, ...args) {
|
|
402
438
|
if (this.eventListeners[`${event}`]) {
|
|
403
439
|
// this.logger.info(`Emitting event "${event}" with args:`, args);
|
|
@@ -414,18 +450,33 @@ class Core {
|
|
|
414
450
|
//this.logger.info(`No listeners for event "${event}".`);
|
|
415
451
|
}
|
|
416
452
|
}
|
|
417
|
-
|
|
453
|
+
/**
|
|
454
|
+
* 注册全局中间件
|
|
455
|
+
* @param name 中间件名称
|
|
456
|
+
* @param middleware 中间件
|
|
457
|
+
* @returns Core对象
|
|
458
|
+
*/
|
|
418
459
|
use(name, middleware) {
|
|
419
460
|
this.globalMiddlewares[name] = middleware;
|
|
420
461
|
return this;
|
|
421
462
|
}
|
|
422
|
-
|
|
463
|
+
/**
|
|
464
|
+
* 定义指令
|
|
465
|
+
* @param name 指令名称
|
|
466
|
+
* @returns 指令对象
|
|
467
|
+
*/
|
|
423
468
|
command(name) {
|
|
424
469
|
const command = new command_1.Command(this, name); // 传递 Core 实例
|
|
425
470
|
this.commands[`${name}`] = command;
|
|
426
471
|
return command;
|
|
427
472
|
}
|
|
428
|
-
|
|
473
|
+
/**
|
|
474
|
+
* 执行指令
|
|
475
|
+
* @param name 指令名称
|
|
476
|
+
* @param session 会话
|
|
477
|
+
* @param args 参数
|
|
478
|
+
* @returns 回话/null
|
|
479
|
+
*/
|
|
429
480
|
async executeCommand(name, session, ...args) {
|
|
430
481
|
const command = this.commands[`${name}`];
|
|
431
482
|
if (command) {
|
|
@@ -453,10 +504,19 @@ class Core {
|
|
|
453
504
|
}
|
|
454
505
|
return null;
|
|
455
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* 注册平台
|
|
509
|
+
* @param platform 平台名称
|
|
510
|
+
* @returns 启动结果
|
|
511
|
+
*/
|
|
456
512
|
registerPlatform(platform) {
|
|
457
513
|
this.platforms.push(platform);
|
|
458
514
|
return platform.startPlatform(this);
|
|
459
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* 取消注册插件
|
|
518
|
+
* @param pluginname 插件名称
|
|
519
|
+
*/
|
|
460
520
|
unregall(pluginname) {
|
|
461
521
|
let cmdtodel = [];
|
|
462
522
|
for (const cmd in this.cmdtoplu) {
|
|
@@ -504,5 +564,18 @@ class Core {
|
|
|
504
564
|
delete this.globalMiddlewares[mdw];
|
|
505
565
|
}
|
|
506
566
|
}
|
|
567
|
+
/**
|
|
568
|
+
* 获取指令对象
|
|
569
|
+
* @param name 指令名称
|
|
570
|
+
* @returns null/指令对象
|
|
571
|
+
*/
|
|
572
|
+
getCommand(name) {
|
|
573
|
+
if (Object.hasOwn(this.commands, name)) {
|
|
574
|
+
return this.commands[name];
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
507
580
|
}
|
|
508
581
|
exports.Core = Core;
|
package/dist/logger.js
CHANGED
|
@@ -11,6 +11,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.Logger = void 0;
|
|
12
12
|
const ansi_colors_1 = __importDefault(require("ansi-colors")); // 引入 ansi-colors
|
|
13
13
|
class Logger {
|
|
14
|
+
title;
|
|
15
|
+
titleColor;
|
|
16
|
+
static coreInstance = null;
|
|
17
|
+
static logs = [];
|
|
14
18
|
static setCore(core) {
|
|
15
19
|
if (Logger.coreInstance !== null) {
|
|
16
20
|
const logger = new Logger('Logger');
|
|
@@ -44,8 +48,6 @@ class Logger {
|
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
exports.Logger = Logger;
|
|
47
|
-
Logger.coreInstance = null;
|
|
48
|
-
Logger.logs = [];
|
|
49
51
|
function stringifyDebug(value, seen = new WeakSet(), depth = 0, indent = 2, maxDepth = 5) {
|
|
50
52
|
const pad = ' '.repeat(depth * indent);
|
|
51
53
|
const nextPad = ' '.repeat((depth + 1) * indent);
|
package/dist/platform.js
CHANGED
|
@@ -8,21 +8,21 @@ const session_1 = require("./session");
|
|
|
8
8
|
* 各平台实现类需继承此类并实现所有抽象方法
|
|
9
9
|
*/
|
|
10
10
|
class Platform {
|
|
11
|
+
// 平台状态
|
|
12
|
+
status = 'idle';
|
|
13
|
+
// 平台错误信息
|
|
14
|
+
errorMessage = null;
|
|
15
|
+
// 平台配置
|
|
16
|
+
config = {};
|
|
17
|
+
// 平台实例ID
|
|
18
|
+
instanceId = '';
|
|
19
|
+
// 平台事件监听器
|
|
20
|
+
eventListeners = {};
|
|
11
21
|
/**
|
|
12
22
|
* 构造函数
|
|
13
23
|
* @param config 平台配置
|
|
14
24
|
*/
|
|
15
25
|
constructor(config) {
|
|
16
|
-
// 平台状态
|
|
17
|
-
this.status = 'idle';
|
|
18
|
-
// 平台错误信息
|
|
19
|
-
this.errorMessage = null;
|
|
20
|
-
// 平台配置
|
|
21
|
-
this.config = {};
|
|
22
|
-
// 平台实例ID
|
|
23
|
-
this.instanceId = '';
|
|
24
|
-
// 平台事件监听器
|
|
25
|
-
this.eventListeners = {};
|
|
26
26
|
if (config) {
|
|
27
27
|
this.config = { ...config };
|
|
28
28
|
}
|
package/dist/session.js
CHANGED
|
@@ -11,17 +11,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.Session = void 0;
|
|
12
12
|
const crypto_1 = __importDefault(require("crypto"));
|
|
13
13
|
class Session {
|
|
14
|
+
ip;
|
|
15
|
+
cookie;
|
|
16
|
+
query;
|
|
17
|
+
sessionid;
|
|
18
|
+
data = {};
|
|
19
|
+
newCookie = {};
|
|
20
|
+
head = {};
|
|
21
|
+
status = 200;
|
|
22
|
+
body;
|
|
23
|
+
platform;
|
|
24
|
+
properties = {};
|
|
14
25
|
/*
|
|
15
26
|
* @ip: string,用户IP
|
|
16
27
|
* @cookie: string,会话cookie
|
|
17
28
|
* @query: string,请求字符串
|
|
18
29
|
*/
|
|
19
30
|
constructor(ip, cookie, platform, query) {
|
|
20
|
-
this.data = {};
|
|
21
|
-
this.newCookie = {};
|
|
22
|
-
this.head = {};
|
|
23
|
-
this.status = 200;
|
|
24
|
-
this.properties = {};
|
|
25
31
|
this.ip = ip;
|
|
26
32
|
this.cookie = cookie;
|
|
27
33
|
this.query = query;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yumerijs/core",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Core module for yumeri",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@types/chalk": "^2.2.4",
|
|
35
|
-
"@yumerijs/loader": "1.1.0
|
|
35
|
+
"@yumerijs/loader": "1.1.0",
|
|
36
36
|
"ansi-colors": "^4.1.3",
|
|
37
37
|
"chalk": "^5.4.1",
|
|
38
38
|
"chokidar": "^4.0.3",
|