@yumerijs/core 1.2.0 → 1.2.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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @time: 2025/03/25 23:53
2
+ * @time: 2025/08/14 09:48
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
5
  **/
package/dist/command.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * @time: 2025/03/25 23:53
3
+ * @time: 2025/08/14 09:48
4
4
  * @author: FireGuo
5
5
  * WindyPear-Team All right reserved
6
6
  **/
package/dist/context.d.ts CHANGED
@@ -1,8 +1,26 @@
1
+ /**
2
+ * @time: 2025/08/14 19:10
3
+ * @author: FireGuo
4
+ * WindyPear-Team All right reserved
5
+ **/
1
6
  import { Core } from './core';
2
7
  import { Command } from './command';
3
8
  import { Route } from './route';
9
+ import { HookHandler } from './hook';
10
+ /**
11
+ * 插件上下文对象
12
+ * 每个插件一个 Context,用于管理插件注册的命令、路由、事件、组件和中间件
13
+ */
4
14
  export declare class Context {
5
15
  private core;
16
+ private routes;
17
+ private eventlisteners;
18
+ private components;
19
+ private middlewares;
20
+ private hooks;
21
+ /**
22
+ * 插件名称
23
+ */
6
24
  pluginname: string;
7
25
  /**
8
26
  * 创建 Context 实例
@@ -12,12 +30,13 @@ export declare class Context {
12
30
  constructor(core: Core, pluginname: string);
13
31
  /**
14
32
  * @deprecated Use route() instead.
33
+ * 尝试注册命令,如果命令已存在则警告
15
34
  */
16
35
  command(name: string): Command;
17
36
  /**
18
37
  * 注册路由
19
38
  * @param path 路由路径
20
- * @returns Route
39
+ * @returns Route 实例
21
40
  */
22
41
  route(path: string): Route;
23
42
  /**
@@ -33,8 +52,23 @@ export declare class Context {
33
52
  */
34
53
  use(name: string, callback: Function): void;
35
54
  /**
36
- * Unless nessesary, do not use core directly
37
- */
55
+ * 注册 Hook 钩子
56
+ * @param name Hook 点名称
57
+ * @param hookname 钩子名称
58
+ * @param callback 钩子回调函数
59
+ */
60
+ hook(name: string, hookname: string, callback: HookHandler): void;
61
+ /**
62
+ * 执行 Hook 钩子
63
+ * @param name Hook 点名称
64
+ * @param args Hook 参数
65
+ * @returns Promise<any[]>
66
+ */
67
+ executeHook(name: string, ...args: any[]): Promise<any[]>;
68
+ /**
69
+ * 获取 Core 实例
70
+ * @returns Core
71
+ */
38
72
  getCore(): Core;
39
73
  /**
40
74
  * 触发事件
@@ -45,7 +79,7 @@ export declare class Context {
45
79
  emit(event: string, ...args: any[]): Promise<void>;
46
80
  /**
47
81
  * 获取组件实例
48
- * @param name 组件名称
82
+ * @param name 组件名称
49
83
  * @returns 组件实例
50
84
  */
51
85
  getComponent(name: string): any;
@@ -53,7 +87,11 @@ export declare class Context {
53
87
  * 注册组件
54
88
  * @param name 组件名称
55
89
  * @param component 组件实例
56
- * @returns void
57
90
  */
58
91
  registerComponent(name: string, component: any): void;
92
+ /**
93
+ * 卸载插件时清理注册的所有资源
94
+ * 包括组件、路由、中间件和事件监听器
95
+ */
96
+ dispose(): void;
59
97
  }
package/dist/context.js CHANGED
@@ -2,8 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Context = void 0;
4
4
  const command_1 = require("./command");
5
+ const route_1 = require("./route");
6
+ /**
7
+ * 插件上下文对象
8
+ * 每个插件一个 Context,用于管理插件注册的命令、路由、事件、组件和中间件
9
+ */
5
10
  class Context {
6
11
  core;
12
+ routes = [];
13
+ eventlisteners = [];
14
+ components = [];
15
+ middlewares = [];
16
+ hooks = {};
17
+ /**
18
+ * 插件名称
19
+ */
7
20
  pluginname;
8
21
  /**
9
22
  * 创建 Context 实例
@@ -16,31 +29,27 @@ class Context {
16
29
  }
17
30
  /**
18
31
  * @deprecated Use route() instead.
32
+ * 尝试注册命令,如果命令已存在则警告
19
33
  */
20
34
  command(name) {
21
35
  if (this.core.commands[name]) {
22
- this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register command "${name}", but it has been registered by plugin "${this.core.cmdtoplu[name]}."`);
36
+ this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register command "${name}", but it has already been registered.`);
23
37
  return new command_1.Command(this.core, name);
24
38
  }
25
- else {
26
- this.core.cmdtoplu[name] = this.pluginname;
27
- return this.core.command(name);
28
- }
39
+ return this.core.command(name);
29
40
  }
30
41
  /**
31
42
  * 注册路由
32
43
  * @param path 路由路径
33
- * @returns Route
44
+ * @returns Route 实例
34
45
  */
35
46
  route(path) {
36
47
  if (this.core.routes[path]) {
37
- this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register route "${path}", but it has been registered by plugin "${this.core.routetoplu[path]}."`);
38
- return this.core.routes[path];
39
- }
40
- else {
41
- this.core.routetoplu[path] = this.pluginname;
42
- return this.core.route(path);
48
+ this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register route "${path}", but it has already been registered.`);
49
+ return new route_1.Route(path);
43
50
  }
51
+ this.routes.push(path);
52
+ return this.core.route(path);
44
53
  }
45
54
  /**
46
55
  * 注册事件
@@ -48,14 +57,9 @@ class Context {
48
57
  * @param listener 事件监听器
49
58
  */
50
59
  on(name, listener) {
51
- // 存储该插件监听的事件,需要注意的是一个事件可由多个插件监听
52
- if (!this.core.evttoplu[name]) {
53
- this.core.evttoplu[name] = {};
54
- }
55
- if (!this.core.evttoplu[name][this.pluginname]) {
56
- this.core.evttoplu[name][this.pluginname] = [];
57
- }
58
- this.core.evttoplu[name][this.pluginname].push(listener);
60
+ // 记录插件自己的事件监听器
61
+ this.eventlisteners.push({ name, listener });
62
+ // 注册到 core 的全局事件监听器中
59
63
  this.core.on(name, listener);
60
64
  }
61
65
  /**
@@ -64,14 +68,32 @@ class Context {
64
68
  * @param callback 中间件回调函数
65
69
  */
66
70
  use(name, callback) {
67
- this.core.mdwtoplu[name] = this.pluginname;
68
- this.core.use(name, async (...args) => {
69
- return callback(...args);
70
- });
71
+ this.middlewares.push(name);
72
+ this.core.use(name, async (...args) => callback(...args));
73
+ }
74
+ /**
75
+ * 注册 Hook 钩子
76
+ * @param name Hook 点名称
77
+ * @param hookname 钩子名称
78
+ * @param callback 钩子回调函数
79
+ */
80
+ hook(name, hookname, callback) {
81
+ this.core.hook(name, hookname, callback);
82
+ this.hooks[name].push(hookname);
71
83
  }
72
84
  /**
73
- * Unless nessesary, do not use core directly
74
- */
85
+ * 执行 Hook 钩子
86
+ * @param name Hook 点名称
87
+ * @param args Hook 参数
88
+ * @returns Promise<any[]>
89
+ */
90
+ async executeHook(name, ...args) {
91
+ return await this.core.hookExecute(name, ...args);
92
+ }
93
+ /**
94
+ * 获取 Core 实例
95
+ * @returns Core
96
+ */
75
97
  getCore() {
76
98
  return this.core;
77
99
  }
@@ -86,7 +108,7 @@ class Context {
86
108
  }
87
109
  /**
88
110
  * 获取组件实例
89
- * @param name 组件名称
111
+ * @param name 组件名称
90
112
  * @returns 组件实例
91
113
  */
92
114
  getComponent(name) {
@@ -96,16 +118,50 @@ class Context {
96
118
  * 注册组件
97
119
  * @param name 组件名称
98
120
  * @param component 组件实例
99
- * @returns void
100
121
  */
101
122
  registerComponent(name, component) {
102
123
  if (this.core.components[name]) {
103
- this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register component "${name}", but it has been registered by plugin "${this.core.comtoplu[name]}."`);
124
+ this.core.logger.warn(`Plugin "${this.pluginname}" attempt to register component "${name}", but it has already been registered.`);
104
125
  return;
105
126
  }
106
- this.core.comtoplu[name] = this.pluginname;
107
127
  this.core.components[name] = component;
108
- return;
128
+ this.components.push(name);
129
+ }
130
+ /**
131
+ * 卸载插件时清理注册的所有资源
132
+ * 包括组件、路由、中间件和事件监听器
133
+ */
134
+ dispose() {
135
+ // 删除组件
136
+ this.components.forEach((name) => {
137
+ delete this.core.components[name];
138
+ });
139
+ // 删除路由
140
+ this.routes.forEach((route) => {
141
+ delete this.core.routes[route];
142
+ });
143
+ // 删除中间件
144
+ this.middlewares.forEach((middleware) => {
145
+ delete this.core.globalMiddlewares[middleware];
146
+ });
147
+ // 删除事件监听器
148
+ this.eventlisteners.forEach(({ name, listener }) => {
149
+ if (this.core.eventListeners?.[name]) {
150
+ this.core.eventListeners[name] =
151
+ this.core.eventListeners[name].filter((l) => l !== listener);
152
+ }
153
+ });
154
+ // 删除钩子
155
+ for (const hook in this.hooks) {
156
+ this.hooks.hook.forEach((hookname) => {
157
+ this.core.unhook(hook, hookname);
158
+ });
159
+ }
160
+ // 清空 Context 内部记录,避免内存泄漏
161
+ this.components = [];
162
+ this.routes = [];
163
+ this.middlewares = [];
164
+ this.eventlisteners = [];
109
165
  }
110
166
  }
111
167
  exports.Context = Context;
package/dist/core.d.ts CHANGED
@@ -6,6 +6,7 @@ import { Platform } from './platform';
6
6
  import { Middleware } from './middleware';
7
7
  import { Route } from './route';
8
8
  import { Context } from './context';
9
+ import { HookHandler, Hook } from './hook';
9
10
  interface Plugin {
10
11
  apply: (ctx: Context, config: Config) => Promise<void>;
11
12
  disable: (ctx: Context) => Promise<void>;
@@ -36,7 +37,9 @@ export declare class Core {
36
37
  };
37
38
  config: any;
38
39
  platforms: Platform[];
39
- private eventListeners;
40
+ eventListeners: {
41
+ [event: string]: ((...args: any[]) => Promise<void>)[];
42
+ };
40
43
  components: {
41
44
  [name: string]: any;
42
45
  };
@@ -47,43 +50,25 @@ export declare class Core {
47
50
  providedComponents: {
48
51
  [name: string]: string;
49
52
  };
53
+ globalMiddlewares: Record<string, Middleware>;
54
+ pluginStatus: Record<string, PluginStatus>;
55
+ hooks: Record<string, Hook>;
56
+ private pluginWatchers;
50
57
  private pluginModules;
51
58
  private configPath;
52
- private globalMiddlewares;
53
- /**
54
- * @deprecated 命令与插件对应关系
55
- */
56
- cmdtoplu: Record<string, string>;
57
- /**
58
- * 路由与插件对应关系
59
- */
60
- routetoplu: Record<string, string>;
61
59
  /**
62
- * 组件与插件对应关系
60
+ * 插件名 -> Context 映射
63
61
  */
64
- comtoplu: Record<string, string>;
65
- /**
66
- * 事件监听器与插件对应关系
67
- */
68
- evttoplu: Record<string, Record<string, ((...args: any[]) => Promise<void>)[]>>;
69
- /**
70
- * 中间件与插件对应关系
71
- */
72
- mdwtoplu: Record<string, string>;
73
- plftoplu: Record<string, string>;
74
- /**
75
- * 插件状态
76
- */
77
- pluginStatus: Record<string, PluginStatus>;
62
+ private pluginContexts;
63
+ constructor(pluginLoader: PluginLoader);
78
64
  /**
79
- * 插件监听器
65
+ * 获取或创建插件对应 Context
80
66
  */
81
- private pluginWatchers;
67
+ getContext(pluginName: string): Context;
82
68
  /**
83
- * 初始化核心
84
- * @param pluginLoader 插件加载器
69
+ * 清理指定插件注册的所有内容
85
70
  */
86
- constructor(pluginLoader: PluginLoader);
71
+ unregall(pluginName: string): void;
87
72
  /**
88
73
  * 加载配置文件
89
74
  * @param configPath 配置文件的路径
@@ -185,6 +170,24 @@ export declare class Core {
185
170
  * @returns Route 实例
186
171
  */
187
172
  route(path: string): Route;
173
+ /**
174
+ * 注册 Hook 钩子
175
+ * @param name Hook 点名称
176
+ * @param hookname 钩子名称
177
+ * @param callback 钩子函数
178
+ */
179
+ hook(name: string, hookname: string, callback: HookHandler): any;
180
+ /**
181
+ * 消除 Hook 钩子
182
+ */
183
+ unhook(name: string, hookname: string): any;
184
+ /**
185
+ * 执行 Hook 钩子
186
+ * @param name Hook 点名称
187
+ * @param args 参数
188
+ * @return Promise<any[]>
189
+ */
190
+ hookExecute(name: string, ...args: any[]): Promise<any[]>;
188
191
  /**
189
192
  * 执行命令
190
193
  * @deprecated
@@ -204,11 +207,6 @@ export declare class Core {
204
207
  * @returns 平台启动结果
205
208
  */
206
209
  registerPlatform(platform: Platform): any;
207
- /**
208
- * 清理指定插件注册的所有内容
209
- * @param pluginname 插件名称
210
- */
211
- unregall(pluginname: string): void;
212
210
  /**
213
211
  * 获取命令
214
212
  * @param name 命令名称
package/dist/core.js CHANGED
@@ -35,8 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Core = void 0;
37
37
  /**
38
- * @time: 2025/07/12 18:14
39
- * @author: FireGuo & Manus
38
+ * @time: 2025/08/14 09:48
39
+ * @author: FireGuo
40
40
  * WindyPear-Team All right reserved
41
41
  **/
42
42
  const yaml = __importStar(require("js-yaml"));
@@ -48,6 +48,7 @@ const command_1 = require("./command");
48
48
  const chokidar = __importStar(require("chokidar"));
49
49
  const route_1 = require("./route");
50
50
  const context_1 = require("./context");
51
+ const hook_1 = require("./hook");
51
52
  class Core {
52
53
  plugins = {};
53
54
  config = null;
@@ -59,44 +60,37 @@ class Core {
59
60
  pluginLoader;
60
61
  logger = new logger_1.Logger('core');
61
62
  providedComponents = {};
63
+ globalMiddlewares = {};
64
+ pluginStatus = {};
65
+ hooks = {};
66
+ pluginWatchers = {};
62
67
  pluginModules = {};
63
68
  configPath = '';
64
- globalMiddlewares = {};
65
- /**
66
- * @deprecated 命令与插件对应关系
67
- */
68
- cmdtoplu = {};
69
- /**
70
- * 路由与插件对应关系
71
- */
72
- routetoplu = {};
73
- /**
74
- * 组件与插件对应关系
75
- */
76
- comtoplu = {};
77
- /**
78
- * 事件监听器与插件对应关系
79
- */
80
- evttoplu = {};
81
- /**
82
- * 中间件与插件对应关系
83
- */
84
- mdwtoplu = {};
85
- plftoplu = {};
86
69
  /**
87
- * 插件状态
70
+ * 插件名 -> Context 映射
88
71
  */
89
- pluginStatus = {};
72
+ pluginContexts = {};
73
+ constructor(pluginLoader) {
74
+ this.pluginLoader = pluginLoader;
75
+ }
90
76
  /**
91
- * 插件监听器
77
+ * 获取或创建插件对应 Context
92
78
  */
93
- pluginWatchers = {};
79
+ getContext(pluginName) {
80
+ if (!this.pluginContexts[pluginName]) {
81
+ this.pluginContexts[pluginName] = new context_1.Context(this, pluginName);
82
+ }
83
+ return this.pluginContexts[pluginName];
84
+ }
94
85
  /**
95
- * 初始化核心
96
- * @param pluginLoader 插件加载器
86
+ * 清理指定插件注册的所有内容
97
87
  */
98
- constructor(pluginLoader) {
99
- this.pluginLoader = pluginLoader;
88
+ unregall(pluginName) {
89
+ const ctx = this.pluginContexts[pluginName];
90
+ if (ctx) {
91
+ ctx.dispose();
92
+ delete this.pluginContexts[pluginName];
93
+ }
100
94
  }
101
95
  /**
102
96
  * 加载配置文件
@@ -255,7 +249,7 @@ class Core {
255
249
  this.plugins[pluginName] = pluginInstance;
256
250
  if (pluginInstance.apply) {
257
251
  this.pluginLoader.logger.info(`Apply plugin "${pluginName}"`);
258
- await pluginInstance.apply(new context_1.Context(this, pluginName), await this.getPluginConfig(pluginName));
252
+ await pluginInstance.apply(this.getContext(pluginName), await this.getPluginConfig(pluginName));
259
253
  }
260
254
  // 注册提供的组件
261
255
  if (pluginInstance.provide) {
@@ -365,9 +359,8 @@ class Core {
365
359
  this.logger.info(`Unloading plugin "${pluginName}"...`);
366
360
  try {
367
361
  const plugin = this.plugins[pluginName];
368
- if (plugin && plugin.disable) {
369
- await plugin.disable(new context_1.Context(this, pluginName));
370
- }
362
+ if (plugin && plugin.disable)
363
+ await plugin.disable(this.getContext(pluginName));
371
364
  await this.pluginLoader.unloadPlugin(pluginName);
372
365
  this.unregall(pluginName); // 清理该插件注册的所有内容
373
366
  delete this.plugins[pluginName];
@@ -465,7 +458,6 @@ class Core {
465
458
  unregisterComponent(name) {
466
459
  delete this.components[name];
467
460
  delete this.providedComponents[name];
468
- delete this.comtoplu[name];
469
461
  }
470
462
  /**
471
463
  * 注册事件监听器
@@ -523,6 +515,38 @@ class Core {
523
515
  this.routes[path] = route;
524
516
  return route;
525
517
  }
518
+ /**
519
+ * 注册 Hook 钩子
520
+ * @param name Hook 点名称
521
+ * @param hookname 钩子名称
522
+ * @param callback 钩子函数
523
+ */
524
+ hook(name, hookname, callback) {
525
+ if (!this.hooks[name]) {
526
+ this.hooks[name] = new hook_1.Hook(name);
527
+ }
528
+ this.hooks[name].add(hookname, callback);
529
+ }
530
+ /**
531
+ * 消除 Hook 钩子
532
+ */
533
+ unhook(name, hookname) {
534
+ if (this.hooks[name]) {
535
+ this.hooks[name].remove(hookname);
536
+ }
537
+ }
538
+ /**
539
+ * 执行 Hook 钩子
540
+ * @param name Hook 点名称
541
+ * @param args 参数
542
+ * @return Promise<any[]>
543
+ */
544
+ async hookExecute(name, ...args) {
545
+ if (this.hooks[name]) {
546
+ return await this.hooks[name].trigger(...args);
547
+ }
548
+ return [];
549
+ }
526
550
  /**
527
551
  * 执行命令
528
552
  * @deprecated
@@ -530,18 +554,13 @@ class Core {
530
554
  async executeCommand(name, session, ...args) {
531
555
  const command = this.commands[name];
532
556
  if (command) {
533
- const globalMiddlewareList = Object.values(this.globalMiddlewares || {});
534
- const commandMiddlewareList = command.middlewares || [];
535
- const middlewares = [...globalMiddlewareList, ...commandMiddlewareList];
557
+ const middlewares = [...Object.values(this.globalMiddlewares), ...(command.middlewares || [])];
536
558
  let index = 0;
537
559
  const runner = async () => {
538
- if (index < middlewares.length) {
539
- const middleware = middlewares[index++];
540
- await middleware(session, runner);
541
- }
542
- else {
560
+ if (index < middlewares.length)
561
+ await middlewares[index++](session, runner);
562
+ else
543
563
  await command.executeHandler(session, ...args);
544
- }
545
564
  };
546
565
  await runner();
547
566
  return session;
@@ -560,18 +579,13 @@ class Core {
560
579
  const route = this.routes[routePath];
561
580
  const result = route.match(pathname);
562
581
  if (result) {
563
- const globalMiddlewareList = Object.values(this.globalMiddlewares || {});
564
- const routeMiddlewareList = route.middlewares || [];
565
- const middlewares = [...globalMiddlewareList, ...routeMiddlewareList];
582
+ const middlewares = [...Object.values(this.globalMiddlewares), ...(route.middlewares || [])];
566
583
  let index = 0;
567
584
  const runner = async () => {
568
- if (index < middlewares.length) {
569
- const middleware = middlewares[index++];
570
- await middleware(session, runner);
571
- }
572
- else {
585
+ if (index < middlewares.length)
586
+ await middlewares[index++](session, runner);
587
+ else
573
588
  await route.executeHandler(session, queryParams, result.pathParams);
574
- }
575
589
  };
576
590
  await runner();
577
591
  return true;
@@ -588,57 +602,6 @@ class Core {
588
602
  this.platforms.push(platform);
589
603
  return platform.startPlatform(this);
590
604
  }
591
- /**
592
- * 清理指定插件注册的所有内容
593
- * @param pluginname 插件名称
594
- */
595
- unregall(pluginname) {
596
- // 清理 commands
597
- Object.keys(this.cmdtoplu)
598
- .filter(cmd => this.cmdtoplu[cmd] === pluginname)
599
- .forEach(cmd => {
600
- delete this.cmdtoplu[cmd];
601
- delete this.commands[cmd];
602
- });
603
- // 清理 routes
604
- Object.keys(this.routetoplu)
605
- .filter(path => this.routetoplu[path] === pluginname)
606
- .forEach(path => {
607
- delete this.routetoplu[path];
608
- delete this.routes[path];
609
- });
610
- // 清理 components 和 providedComponents
611
- Object.keys(this.comtoplu)
612
- .filter(comp => this.comtoplu[comp] === pluginname)
613
- .forEach(comp => {
614
- delete this.comtoplu[comp];
615
- delete this.components[comp];
616
- delete this.providedComponents[comp];
617
- });
618
- // 清理由 provide 声明的组件提供关系
619
- Object.keys(this.providedComponents)
620
- .filter(prov => this.providedComponents[prov] === pluginname)
621
- .forEach(prov => {
622
- delete this.providedComponents[prov];
623
- });
624
- // 清理 event listeners
625
- for (const evt in this.evttoplu) {
626
- if (this.evttoplu[evt][pluginname]) {
627
- const pluginListeners = this.evttoplu[evt][pluginname] || [];
628
- if (this.eventListeners[evt]) {
629
- this.eventListeners[evt] = this.eventListeners[evt].filter(l => !pluginListeners.includes(l));
630
- }
631
- delete this.evttoplu[evt][pluginname];
632
- }
633
- }
634
- // 清理 middlewares
635
- Object.keys(this.mdwtoplu)
636
- .filter(mdw => this.mdwtoplu[mdw] === pluginname)
637
- .forEach(mdw => {
638
- delete this.mdwtoplu[mdw];
639
- delete this.globalMiddlewares[mdw];
640
- });
641
- }
642
605
  /**
643
606
  * 获取命令
644
607
  * @param name 命令名称
package/dist/hook.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @time: 2025/08/14 18:33
3
+ * @author: FireGuo
4
+ * WindyPear-Team All right reserved
5
+ **/
6
+ /**
7
+ * Hook 处理器
8
+ */
9
+ export type HookHandler = (...args: any[]) => Promise<any>;
10
+ /**
11
+ * Hook 类
12
+ */
13
+ export declare class Hook {
14
+ name: string;
15
+ handlers: Record<string, HookHandler>;
16
+ /**
17
+ * 创建 Hook 实例
18
+ * @param name Hook 名称
19
+ */
20
+ constructor(name: string);
21
+ /**
22
+ * 添加 Hook 函数
23
+ * @param name Hook 函数名称
24
+ * @param handler Hook 函数
25
+ */
26
+ add(name: string, handler: HookHandler): void;
27
+ /**
28
+ * 删除 Hook 函数
29
+ * @param name Hook 函数名称
30
+ */
31
+ remove(name: string): void;
32
+ /**
33
+ * 触发 Hook 函数
34
+ * @param session 会话
35
+ * @param args 参数
36
+ * @returns 执行结果
37
+ */
38
+ trigger(...args: any[]): Promise<any[]>;
39
+ }
package/dist/hook.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * @time: 2025/08/14 18:33
4
+ * @author: FireGuo
5
+ * WindyPear-Team All right reserved
6
+ **/
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Hook = void 0;
9
+ /**
10
+ * Hook 类
11
+ */
12
+ class Hook {
13
+ name;
14
+ handlers = {};
15
+ /**
16
+ * 创建 Hook 实例
17
+ * @param name Hook 名称
18
+ */
19
+ constructor(name) {
20
+ this.name = name;
21
+ }
22
+ /**
23
+ * 添加 Hook 函数
24
+ * @param name Hook 函数名称
25
+ * @param handler Hook 函数
26
+ */
27
+ add(name, handler) {
28
+ this.handlers[name] = handler;
29
+ }
30
+ /**
31
+ * 删除 Hook 函数
32
+ * @param name Hook 函数名称
33
+ */
34
+ remove(name) {
35
+ delete this.handlers[name];
36
+ }
37
+ /**
38
+ * 触发 Hook 函数
39
+ * @param session 会话
40
+ * @param args 参数
41
+ * @returns 执行结果
42
+ */
43
+ async trigger(...args) {
44
+ let result;
45
+ for (const handler of Object.values(this.handlers)) {
46
+ result.push(handler(...args));
47
+ }
48
+ return result;
49
+ }
50
+ }
51
+ exports.Hook = Hook;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @time: 2025/03/24 12:26
2
+ * @time: 2025/08/14 09:48
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
5
  **/
@@ -11,3 +11,4 @@ export * from './config';
11
11
  export * from './logger';
12
12
  export * from './platform';
13
13
  export * from './context';
14
+ export * from './hook';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * @time: 2025/03/24 12:26
3
+ * @time: 2025/08/14 09:48
4
4
  * @author: FireGuo
5
5
  * WindyPear-Team All right reserved
6
6
  **/
@@ -27,3 +27,4 @@ __exportStar(require("./config"), exports);
27
27
  __exportStar(require("./logger"), exports);
28
28
  __exportStar(require("./platform"), exports);
29
29
  __exportStar(require("./context"), exports);
30
+ __exportStar(require("./hook"), exports);
package/dist/logger.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @time: 2025/03/25 18:01
2
+ * @time: 2025/08/14 09:48
3
3
  * @author: FireGuo
4
4
  * WindyPear-Team All right reserved
5
- */
5
+ **/
6
6
  import { Core } from './core';
7
7
  export declare class Logger {
8
8
  private title;
package/dist/logger.js CHANGED
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  /**
3
- * @time: 2025/03/25 18:01
3
+ * @time: 2025/08/14 09:48
4
4
  * @author: FireGuo
5
5
  * WindyPear-Team All right reserved
6
- */
6
+ **/
7
7
  var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.Logger = void 0;
12
- const picocolors_1 = __importDefault(require("picocolors")); // 轻量颜色库
12
+ const picocolors_1 = __importDefault(require("picocolors"));
13
13
  class Logger {
14
14
  title;
15
15
  titleColor;
@@ -1,2 +1,7 @@
1
+ /**
2
+ * @time: 2025/08/14 09:48
3
+ * @author: FireGuo
4
+ * WindyPear-Team All right reserved
5
+ **/
1
6
  import { Session } from './session';
2
7
  export type Middleware = (session: Session, next: () => Promise<void>) => Promise<void>;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @time: 2025/08/14 09:48
3
+ * @author: FireGuo
4
+ * WindyPear-Team All right reserved
5
+ **/
1
6
  import { Session } from './session';
2
7
  import { Core } from './core';
3
8
  import { ConfigSchema } from './config';
package/dist/platform.js CHANGED
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Platform = void 0;
4
+ /**
5
+ * @time: 2025/08/14 09:48
6
+ * @author: FireGuo
7
+ * WindyPear-Team All right reserved
8
+ **/
4
9
  const session_1 = require("./session");
5
10
  /**
6
11
  * Platform 基类
package/dist/route.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @time: 2025/08/14 09:48
3
+ * @author: FireGuo
4
+ * WindyPear-Team All right reserved
5
+ **/
1
6
  import { Session } from './session';
2
7
  import { Middleware } from './middleware';
3
8
  export type RouteHandler = (session: Session, queryParams: URLSearchParams, ...pathParams: string[]) => Promise<void> | void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yumerijs/core",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Core module for yumeri",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -33,7 +33,6 @@
33
33
  "dependencies": {
34
34
  "@yumerijs/loader": "^1.2.0",
35
35
  "chokidar": "^4.0.3",
36
- "js-sha256": "^0.11.0",
37
36
  "js-yaml": "^4.1.0",
38
37
  "picocolors": "^1.1.1"
39
38
  },