@yumerijs/core 1.1.0-alpha.5 → 1.1.1

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 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
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Context = void 0;
4
4
  const command_1 = require("./command");
5
5
  class Context {
6
+ core;
7
+ pluginname;
6
8
  constructor(core, pluginname) {
7
9
  this.core = core;
8
10
  this.pluginname = pluginname;
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,110 +150,81 @@ 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
- // 检查 plugins 配置是否存在且是对象类型
143
158
  if (!this.config || typeof this.config.plugins !== 'object' || this.config.plugins === null) {
144
159
  this.logger.info('No plugins configuration found or it is not an object. No plugins to load.');
145
160
  return;
146
161
  }
147
- // 获取所有需要加载的插件名,过滤掉以~开头的插件(禁用的插件)
148
162
  const pluginNamesToLoad = Object.keys(this.config.plugins).filter(name => !name.startsWith('~'));
149
163
  if (pluginNamesToLoad.length === 0) {
150
164
  this.logger.info('No enabled plugins found in configuration. All plugins might be disabled or configuration is empty.');
151
165
  return;
152
166
  }
153
- // 记录被禁用的插件
154
167
  const disabledPlugins = Object.keys(this.config.plugins).filter(name => name.startsWith('~'));
155
168
  if (disabledPlugins.length > 0) {
156
169
  this.logger.info(`Skipping disabled plugins: ${disabledPlugins.join(', ')}`);
157
170
  }
158
171
  const loadedPluginNames = [];
159
- // 使用对象来跟踪尝试加载的插件名
160
172
  let loadAttempted = {};
161
- // 使用插件名数组来管理剩余待加载的插件
162
173
  let remainingPluginNames = [...pluginNamesToLoad];
163
- // 不加载名称以~开头的插件
164
- remainingPluginNames = remainingPluginNames.filter(name => !name.startsWith('~'));
165
- // 多次尝试加载插件,直到所有插件加载完毕或检测到循环依赖
166
174
  while (remainingPluginNames.length > 0) {
167
175
  let loadedInThisPass = false;
168
- // 用于存储下一轮尝试加载的插件名
169
176
  const nextRemainingPluginNames = [];
170
- // 遍历当前剩余待加载的插件名
171
177
  for (const pluginName of remainingPluginNames) {
172
- // 如果插件已经加载或已尝试加载,则跳过
173
- if (loadedPluginNames.includes(pluginName) || loadAttempted[`${pluginName}`]) {
178
+ if (loadedPluginNames.includes(pluginName)) {
174
179
  continue;
175
180
  }
176
- // 标记该插件已尝试加载
177
- loadAttempted[`${pluginName}`] = true;
178
181
  try {
179
- this.logger.info(`Attempting to load plugin: ${pluginName}`);
180
- // 使用插件名加载插件实例和模块
182
+ // this.logger.info(`Attempting to load plugin: ${pluginName}`);
181
183
  const pluginInstance = await this.pluginLoader.load(pluginName);
182
- //const pluginModule = await this.importPluginModule(pluginName);
183
184
  if (pluginInstance) {
184
185
  const depend = pluginInstance.depend;
185
186
  const provide = pluginInstance.provide;
186
- // 检查依赖是否满足 (此处仍然检查 this.components,请确保 this.components 在此阶段已包含必要的基准组件)
187
- const unmetDependencies = depend?.filter(dep => !this.components.hasOwnProperty(dep)) || [];
187
+ // 用 providedComponents 作为依赖判断来源(比 components 更准确)
188
+ const unmetDependencies = depend?.filter(dep => !this.providedComponents.hasOwnProperty(dep)) || [];
188
189
  if (unmetDependencies.length === 0) {
189
- // 将加载成功并满足依赖的插件存储起来
190
- this.plugins[`${pluginName}`] = Object.assign(pluginInstance, { depend, provide });
191
- //this.pluginModules[`${pluginName}`] = pluginModule;
192
- //this.logger.info(`Plugin ${pluginName} loaded.`);
190
+ this.plugins[pluginName] = Object.assign(pluginInstance, { depend, provide });
193
191
  loadedPluginNames.push(pluginName);
194
- loadedInThisPass = true; // 标记本轮有插件加载成功
195
- if (loadedInThisPass && pluginInstance && pluginInstance.apply) {
192
+ loadedInThisPass = true;
193
+ if (pluginInstance.apply) {
196
194
  await pluginInstance.apply(new context_1.Context(this, pluginName), await this.getPluginConfig(pluginName));
197
- // 使用 pluginName
198
195
  this.pluginLoader.logger.info(`apply plugin ${pluginName}`);
199
196
  }
200
- // 记录该插件提供了哪些组件
201
197
  if (provide) {
202
198
  for (const componentName of provide) {
203
199
  if (this.providedComponents.hasOwnProperty(componentName)) {
204
- this.logger.error(`Multiple plugins provide the component "${componentName}". Provided by "${this.providedComponents[`${componentName}`]}" and "${pluginName}". Only the first loaded will be active.`);
200
+ this.logger.error(`Multiple plugins provide the component "${componentName}". Provided by "${this.providedComponents[componentName]}" and "${pluginName}". Only the first loaded will be active.`);
205
201
  }
206
202
  else {
207
- this.providedComponents[`${componentName}`] = pluginName;
203
+ this.providedComponents[componentName] = pluginName;
208
204
  }
209
205
  }
210
206
  }
211
207
  }
212
208
  else {
213
- // 如果存在未满足的依赖,将插件名放回下一轮尝试加载列表
214
209
  nextRemainingPluginNames.push(pluginName);
215
- /*this.logger.warn(
216
- `Plugin ${pluginName} has unmet dependencies: ${unmetDependencies.join(', ')}. Will try again later.`
217
- );*/
210
+ // 不加入 loadAttempted,让下一轮重试
218
211
  }
219
212
  }
220
- else {
221
- //this.logger.warn(`Plugin "${pluginName}" could not be loaded or its module could not be imported.`);
222
- }
223
213
  }
224
214
  catch (err) {
225
215
  this.pluginLoader.logger.error(`Failed to load or process plugin ${pluginName}:`, err);
226
- // 如果加载或处理失败,不将其加入下一轮尝试列表,但也不标记为已加载成功
216
+ loadAttempted[pluginName] = true; // 真正失败才标记
227
217
  }
228
218
  }
229
- // 如果本轮没有插件加载成功,并且剩余插件列表没有变化,则检测到循环或无法解决的依赖
230
219
  if (!loadedInThisPass && nextRemainingPluginNames.length === remainingPluginNames.length && remainingPluginNames.length > 0) {
231
- this.logger.error('Detected circular or unresolvable plugin dependencies. Remaining plugins:', nextRemainingPluginNames.map(name => name) // 映射回插件名
232
- );
233
- break; // 防止无限循环
220
+ this.logger.error('Detected circular or unresolvable plugin dependencies. Remaining plugins:', nextRemainingPluginNames);
221
+ break;
234
222
  }
235
- // 更新剩余待加载插件列表为下一轮的列表
236
223
  remainingPluginNames = nextRemainingPluginNames;
237
224
  }
238
- // 警告未加载成功的插件
239
225
  if (remainingPluginNames.length > 0) {
240
- this.logger.warn('Some plugins could not be fully loaded due to unresolved dependencies or errors:', remainingPluginNames.map(name => name) // 映射回插件名
241
- );
226
+ this.logger.warn('Some plugins could not be fully loaded due to unresolved dependencies or errors:', remainingPluginNames);
242
227
  }
243
- // 开发环境下监听插件变化
244
228
  if (process.env.NODE_ENV === 'development') {
245
229
  this.watchPlugins(this);
246
230
  }
@@ -370,7 +354,12 @@ class Core {
370
354
  this.logger.error(`Failed to unload plugin ${pluginName}:`, error);
371
355
  }
372
356
  }
373
- // 注册组件
357
+ /**
358
+ * 注册组件
359
+ * @param name 组件名称
360
+ * @param component 组件
361
+ * @returns void
362
+ */
374
363
  registerComponent(name, component) {
375
364
  if (this.components.hasOwnProperty(name)) {
376
365
  this.logger.warn(`Component "${name}" already registered by plugin "${this.providedComponents[`${name}`]}".`);
@@ -379,17 +368,28 @@ class Core {
379
368
  this.components[`${name}`] = component;
380
369
  this.logger.info(`Component "${name}" registered.`);
381
370
  }
382
- // 获取组件
371
+ /**
372
+ * 获取组件
373
+ * @param name 组件名称
374
+ * @returns 组件
375
+ */
383
376
  getComponent(name) {
384
377
  return this.components[`${name}`];
385
378
  }
386
- // 取消注册组件
379
+ /**
380
+ * 取消注册组件
381
+ * @param name 组件名称
382
+ */
387
383
  unregisterComponent(name) {
388
384
  delete this.components[`${name}`];
389
385
  delete this.providedComponents[`${name}`];
390
386
  delete this.comtoplu[`${name}`];
391
387
  }
392
- // 事件系统:监听事件
388
+ /**
389
+ * 监听事件
390
+ * @param event 事件名称
391
+ * @param listener 回调函数
392
+ */
393
393
  on(event, listener) {
394
394
  if (!this.eventListeners[`${event}`]) {
395
395
  this.eventListeners[`${event}`] = [];
@@ -397,7 +397,11 @@ class Core {
397
397
  this.eventListeners[`${event}`].push(listener);
398
398
  //this.logger.info(`Listener added for event "${event}".`);
399
399
  }
400
- // 事件系统:触发事件
400
+ /**
401
+ * 触发事件
402
+ * @param event 事件名称
403
+ * @param args 参数
404
+ */
401
405
  async emit(event, ...args) {
402
406
  if (this.eventListeners[`${event}`]) {
403
407
  // this.logger.info(`Emitting event "${event}" with args:`, args);
@@ -414,18 +418,33 @@ class Core {
414
418
  //this.logger.info(`No listeners for event "${event}".`);
415
419
  }
416
420
  }
417
- // 注册全局中间件
421
+ /**
422
+ * 注册全局中间件
423
+ * @param name 中间件名称
424
+ * @param middleware 中间件
425
+ * @returns Core对象
426
+ */
418
427
  use(name, middleware) {
419
428
  this.globalMiddlewares[name] = middleware;
420
429
  return this;
421
430
  }
422
- // 定义指令
431
+ /**
432
+ * 定义指令
433
+ * @param name 指令名称
434
+ * @returns 指令对象
435
+ */
423
436
  command(name) {
424
437
  const command = new command_1.Command(this, name); // 传递 Core 实例
425
438
  this.commands[`${name}`] = command;
426
439
  return command;
427
440
  }
428
- // 执行指令
441
+ /**
442
+ * 执行指令
443
+ * @param name 指令名称
444
+ * @param session 会话
445
+ * @param args 参数
446
+ * @returns 回话/null
447
+ */
429
448
  async executeCommand(name, session, ...args) {
430
449
  const command = this.commands[`${name}`];
431
450
  if (command) {
@@ -453,10 +472,19 @@ class Core {
453
472
  }
454
473
  return null;
455
474
  }
475
+ /**
476
+ * 注册平台
477
+ * @param platform 平台名称
478
+ * @returns 启动结果
479
+ */
456
480
  registerPlatform(platform) {
457
481
  this.platforms.push(platform);
458
482
  return platform.startPlatform(this);
459
483
  }
484
+ /**
485
+ * 取消注册插件
486
+ * @param pluginname 插件名称
487
+ */
460
488
  unregall(pluginname) {
461
489
  let cmdtodel = [];
462
490
  for (const cmd in this.cmdtoplu) {
@@ -504,5 +532,18 @@ class Core {
504
532
  delete this.globalMiddlewares[mdw];
505
533
  }
506
534
  }
535
+ /**
536
+ * 获取指令对象
537
+ * @param name 指令名称
538
+ * @returns null/指令对象
539
+ */
540
+ getCommand(name) {
541
+ if (Object.hasOwn(this.commands, name)) {
542
+ return this.commands[name];
543
+ }
544
+ else {
545
+ return null;
546
+ }
547
+ }
507
548
  }
508
549
  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-alpha.5",
3
+ "version": "1.1.1",
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-alpha.5",
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",