@zhin.js/core 1.0.16 → 1.0.18

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.
Files changed (118) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/REFACTORING_COMPLETE.md +178 -0
  3. package/REFACTORING_STATUS.md +263 -0
  4. package/lib/adapter.d.ts +44 -19
  5. package/lib/adapter.d.ts.map +1 -1
  6. package/lib/adapter.js +81 -50
  7. package/lib/adapter.js.map +1 -1
  8. package/lib/bot.d.ts +7 -12
  9. package/lib/bot.d.ts.map +1 -1
  10. package/lib/built/adapter-process.d.ts +36 -0
  11. package/lib/built/adapter-process.d.ts.map +1 -0
  12. package/lib/built/adapter-process.js +77 -0
  13. package/lib/built/adapter-process.js.map +1 -0
  14. package/lib/built/command.d.ts +46 -0
  15. package/lib/built/command.d.ts.map +1 -0
  16. package/lib/built/command.js +54 -0
  17. package/lib/built/command.js.map +1 -0
  18. package/lib/built/component.d.ts +42 -0
  19. package/lib/built/component.d.ts.map +1 -0
  20. package/lib/built/component.js +66 -0
  21. package/lib/built/component.js.map +1 -0
  22. package/lib/built/config.d.ts +31 -0
  23. package/lib/built/config.d.ts.map +1 -0
  24. package/lib/built/config.js +141 -0
  25. package/lib/built/config.js.map +1 -0
  26. package/lib/built/cron.d.ts +53 -0
  27. package/lib/built/cron.d.ts.map +1 -0
  28. package/lib/built/cron.js +79 -0
  29. package/lib/built/cron.js.map +1 -0
  30. package/lib/built/database.d.ts +17 -0
  31. package/lib/built/database.d.ts.map +1 -0
  32. package/lib/built/database.js +28 -0
  33. package/lib/built/database.js.map +1 -0
  34. package/lib/{permissions.d.ts → built/permission.d.ts} +5 -10
  35. package/lib/built/permission.d.ts.map +1 -0
  36. package/lib/{permissions.js → built/permission.js} +11 -10
  37. package/lib/built/permission.js.map +1 -0
  38. package/lib/command.d.ts +18 -7
  39. package/lib/command.d.ts.map +1 -1
  40. package/lib/command.js +36 -15
  41. package/lib/command.js.map +1 -1
  42. package/lib/component.d.ts +1 -1
  43. package/lib/component.d.ts.map +1 -1
  44. package/lib/component.js.map +1 -1
  45. package/lib/cron.d.ts +4 -12
  46. package/lib/cron.d.ts.map +1 -1
  47. package/lib/cron.js +33 -64
  48. package/lib/cron.js.map +1 -1
  49. package/lib/index.d.ts +11 -3
  50. package/lib/index.d.ts.map +1 -1
  51. package/lib/index.js +14 -4
  52. package/lib/index.js.map +1 -1
  53. package/lib/jsx-runtime.d.ts +2 -2
  54. package/lib/jsx.d.ts +2 -3
  55. package/lib/jsx.d.ts.map +1 -1
  56. package/lib/jsx.js.map +1 -1
  57. package/lib/message.d.ts +4 -7
  58. package/lib/message.d.ts.map +1 -1
  59. package/lib/message.js.map +1 -1
  60. package/lib/plugin.d.ts +164 -51
  61. package/lib/plugin.d.ts.map +1 -1
  62. package/lib/plugin.js +520 -137
  63. package/lib/plugin.js.map +1 -1
  64. package/lib/prompt.d.ts +1 -1
  65. package/lib/prompt.d.ts.map +1 -1
  66. package/lib/prompt.js +2 -1
  67. package/lib/prompt.js.map +1 -1
  68. package/lib/types.d.ts +33 -33
  69. package/lib/types.d.ts.map +1 -1
  70. package/lib/utils.d.ts +16 -1
  71. package/lib/utils.d.ts.map +1 -1
  72. package/lib/utils.js +166 -66
  73. package/lib/utils.js.map +1 -1
  74. package/package.json +17 -11
  75. package/src/adapter.ts +131 -80
  76. package/src/bot.ts +8 -13
  77. package/src/built/adapter-process.ts +77 -0
  78. package/src/built/command.ts +102 -0
  79. package/src/built/component.ts +111 -0
  80. package/src/built/config.ts +126 -0
  81. package/src/built/cron.ts +140 -0
  82. package/src/built/database.ts +38 -0
  83. package/src/{permissions.ts → built/permission.ts} +9 -12
  84. package/src/command.ts +48 -20
  85. package/src/component.ts +2 -3
  86. package/src/cron.ts +35 -70
  87. package/src/index.ts +15 -5
  88. package/src/jsx.ts +2 -3
  89. package/src/message.ts +3 -4
  90. package/src/plugin.ts +671 -184
  91. package/src/prompt.ts +4 -3
  92. package/src/types.ts +41 -35
  93. package/src/utils.ts +418 -296
  94. package/test/minimal-bot.ts +31 -0
  95. package/test/stress-test.ts +123 -0
  96. package/tests/command.test.ts +124 -44
  97. package/ASYNC-JSX-SUPPORT.md +0 -173
  98. package/lib/app.d.ts +0 -191
  99. package/lib/app.d.ts.map +0 -1
  100. package/lib/app.js +0 -604
  101. package/lib/app.js.map +0 -1
  102. package/lib/config.d.ts +0 -54
  103. package/lib/config.d.ts.map +0 -1
  104. package/lib/config.js +0 -308
  105. package/lib/config.js.map +0 -1
  106. package/lib/log-transport.d.ts +0 -37
  107. package/lib/log-transport.d.ts.map +0 -1
  108. package/lib/log-transport.js +0 -136
  109. package/lib/log-transport.js.map +0 -1
  110. package/lib/permissions.d.ts.map +0 -1
  111. package/lib/permissions.js.map +0 -1
  112. package/src/app.ts +0 -772
  113. package/src/config.ts +0 -397
  114. package/src/log-transport.ts +0 -163
  115. package/tests/app.test.ts +0 -265
  116. package/tests/permissions.test.ts +0 -358
  117. package/tests/plugin.test.ts +0 -234
  118. package/tests/prompt.test.ts +0 -223
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Cron Context
3
+ * 管理所有插件注册的定时任务
4
+ */
5
+ import { Cron } from "../cron.js";
6
+ import { Context, Plugin, getPlugin } from "../plugin.js";
7
+
8
+ /**
9
+ * CronContext 扩展方法类型
10
+ */
11
+ export interface CronContextExtensions {
12
+ /** 添加定时任务 */
13
+ addCron(cron: Cron): () => void;
14
+ }
15
+
16
+ // 扩展 Plugin 接口
17
+ declare module "../plugin.js" {
18
+ namespace Plugin {
19
+ interface Extensions extends CronContextExtensions {}
20
+ interface Contexts {
21
+ cron: CronService;
22
+ }
23
+ }
24
+ }
25
+
26
+ /**
27
+ * 定时任务服务数据
28
+ */
29
+ export interface CronService {
30
+ /** 任务列表 */
31
+ readonly items: Cron[];
32
+ /** 按 ID/表达式 索引 */
33
+ readonly byName: Map<string, Cron>;
34
+ /** 添加任务 */
35
+ add(cron: Cron, pluginName: string): () => void;
36
+ /** 移除任务 */
37
+ remove(cron: Cron): boolean;
38
+ /** 按名称获取 */
39
+ get(id: string): Cron | undefined;
40
+ /** 停止所有任务 */
41
+ stopAll(): void;
42
+ /** 启动所有任务 */
43
+ startAll(): void;
44
+ /** 获取状态 */
45
+ getStatus(): Array<{
46
+ expression: string;
47
+ running: boolean;
48
+ nextExecution: Date | null;
49
+ plugin: string;
50
+ }>;
51
+ }
52
+
53
+ /**
54
+ * 创建定时任务 Context
55
+ */
56
+ export function createCronService(): Context<'cron', CronContextExtensions> {
57
+ const items: Cron[] = [];
58
+ const byName = new Map<string, Cron>();
59
+ const pluginMap = new Map<Cron, string>();
60
+
61
+ const value: CronService = {
62
+ items,
63
+ byName,
64
+
65
+ add(cron, pluginName) {
66
+ items.push(cron);
67
+ byName.set(cron.id || cron.cronExpression, cron);
68
+ pluginMap.set(cron, pluginName);
69
+ // 自动启动
70
+ if (!cron.running) {
71
+ cron.run();
72
+ }
73
+ return () => value.remove(cron);
74
+ },
75
+
76
+ remove(cron) {
77
+ const index = items.indexOf(cron);
78
+ if (index !== -1) {
79
+ // 自动停止
80
+ if (cron.running) {
81
+ cron.stop();
82
+ }
83
+ items.splice(index, 1);
84
+ byName.delete(cron.id || cron.cronExpression);
85
+ pluginMap.delete(cron);
86
+ return true;
87
+ }
88
+ return false;
89
+ },
90
+
91
+ get(id) {
92
+ return byName.get(id);
93
+ },
94
+
95
+ stopAll() {
96
+ for (const cron of items) {
97
+ if (cron.running) {
98
+ cron.stop();
99
+ }
100
+ }
101
+ },
102
+
103
+ startAll() {
104
+ for (const cron of items) {
105
+ if (!cron.running && !cron.disposed) {
106
+ cron.run();
107
+ }
108
+ }
109
+ },
110
+
111
+ getStatus() {
112
+ return items.map(cron => ({
113
+ expression: cron.cronExpression,
114
+ running: cron.running,
115
+ nextExecution: cron.running ? cron.getNextExecutionTime() : null,
116
+ plugin: pluginMap.get(cron) || 'unknown',
117
+ }));
118
+ }
119
+ };
120
+
121
+ return {
122
+ name: 'cron',
123
+ description: '定时任务服务',
124
+ value,
125
+
126
+ dispose() {
127
+ value.stopAll();
128
+ },
129
+
130
+ extensions: {
131
+ addCron(cron: Cron) {
132
+ const plugin = getPlugin();
133
+ const dispose = value.add(cron, plugin.name);
134
+ plugin.onDispose(dispose);
135
+ return dispose;
136
+ }
137
+ }
138
+ };
139
+ }
140
+
@@ -0,0 +1,38 @@
1
+ import { Registry,Definition,Databases,Database } from "@zhin.js/database";
2
+ import { DatabaseConfig,Models } from "../types.js";
3
+ import { defineContext,Plugin } from "../plugin.js";
4
+ import { SystemLogDefinition } from "../models/system-log.js";
5
+ import { UserDefinition } from "../models/user.js";
6
+ declare module "../plugin" {
7
+ namespace Plugin {
8
+ interface Extensions {
9
+ defineModel<K extends keyof Models>(name: K, definition: Definition<Models[K]>): void;
10
+ }
11
+ interface Contexts {
12
+ database: Database<any,Models,any>;
13
+ }
14
+ }
15
+ }
16
+ export function defineDatabaseService<K extends keyof Databases>(config: DatabaseConfig<K>) {
17
+ const db = Registry.create<Models,K>(config.dialect, config,{
18
+ SystemLog: SystemLogDefinition,
19
+ User: UserDefinition,
20
+ });
21
+ return defineContext({
22
+ name: 'database',
23
+ description: '数据库服务',
24
+ mounted: async () => {
25
+ await db.start();
26
+ return db;
27
+ },
28
+ dispose: async () => {
29
+ await db.stop();
30
+ },
31
+ extensions: {
32
+ defineModel<K extends keyof Models>(this:Plugin,name: K, definition: Definition<Models[K]>) {
33
+ db.define(name, definition);
34
+ this.logger.debug(`Model "${String(name)}" defined by plugin "${this.name}"`);
35
+ }
36
+ },
37
+ });
38
+ }
@@ -1,15 +1,11 @@
1
- import { MaybePromise } from "@zhin.js/types";
2
- import { RegisteredAdapter } from "./types.js";
3
- import { Message } from "./message.js";
4
- import { AdapterMessage } from "./types.js";
5
- import { App } from "./app.js";
1
+ import { MaybePromise, RegisteredAdapter, Message, AdapterMessage } from "@zhin.js/core";
6
2
  export type PermissionItem<T extends RegisteredAdapter = RegisteredAdapter> = {
7
3
  name: string | RegExp
8
4
  check: PermissionChecker<T>
9
5
  }
10
6
  export type PermissionChecker<T extends RegisteredAdapter = RegisteredAdapter> = (name: string, message: Message<AdapterMessage<T>>) => MaybePromise<boolean>
11
- export class Permissions extends Array<PermissionItem>{
12
- constructor(private readonly app: App) {
7
+ export class PermissionService extends Array<PermissionItem>{
8
+ constructor() {
13
9
  super();
14
10
  this.add(Permissions.define(/^adapter\([^)]+\)$/, (name, message) => {
15
11
  return message.$adapter === name.replace(/^adapter\(([^)]+)\)$/, '$1');
@@ -48,11 +44,12 @@ export class Permissions extends Array<PermissionItem>{
48
44
  add(permission: PermissionItem) {
49
45
  this.push(permission);
50
46
  }
51
- get(name: string): PermissionItem | undefined {
52
- return this.app.dependencyList.reduce((result,dep)=>{
53
- result.push(...dep.permissions)
54
- return result;
55
- },[...this]).find(p => new RegExp(p.name).test(name));
47
+ async check(name: string, message: Message<AdapterMessage<RegisteredAdapter>>):Promise<boolean> {
48
+ for(const permission of this){
49
+ const passed=await permission.check(name,message);
50
+ if(passed) return true;
51
+ }
52
+ return false;
56
53
  }
57
54
  }
58
55
  export namespace Permissions{
package/src/command.ts CHANGED
@@ -1,19 +1,48 @@
1
1
  import {MatchResult, SegmentMatcher} from "segment-matcher";
2
2
  import {AdapterMessage, SendContent} from "./types.js";
3
- import {RegisteredAdapters} from "@zhin.js/types";
3
+ import {RegisteredAdapter} from "./types.js";
4
4
  import type {Message} from "./message.js";
5
- import {MaybePromise} from "@zhin.js/types";
6
- import { ZhinError } from "./errors.js";
7
- import { App } from "./app.js";
5
+ import {MaybePromise} from "./types.js";
6
+ import {Plugin} from "./plugin.js";
8
7
 
9
8
  /**
10
9
  * MessageCommand类:命令系统核心,基于segment-matcher实现。
11
10
  * 支持多平台命令注册、作用域限制、参数解析、异步处理等。
12
11
  */
13
- export class MessageCommand<T extends keyof RegisteredAdapters=keyof RegisteredAdapters> extends SegmentMatcher{
12
+ export class MessageCommand<T extends RegisteredAdapter=RegisteredAdapter> extends SegmentMatcher{
14
13
  #callbacks:MessageCommand.Callback<T>[]=[];
14
+ #desc:string[]=[];
15
+ #usage:string[]=[];
16
+ #examples:string[]=[];
15
17
  #permissions:string[]=[];
16
- #checkers:MessageCommand.Checker<T>[]=[]
18
+ get helpInfo():MessageCommand.HelpInfo{
19
+ return {
20
+ pattern: this.pattern,
21
+ desc: this.#desc,
22
+ usage: this.#usage,
23
+ examples: this.#examples
24
+ }
25
+ }
26
+ get help(){
27
+ return [
28
+ this.pattern,
29
+ ...this.#desc,
30
+ ...this.#usage,
31
+ ...this.#examples
32
+ ].join("\n");
33
+ }
34
+ desc(...desc:string[]){
35
+ this.#desc.push(...desc)
36
+ return this as MessageCommand<T>;
37
+ }
38
+ usage(...usage:string[]){
39
+ this.#usage.push(...usage)
40
+ return this as MessageCommand<T>;
41
+ }
42
+ examples(...examples:string[]){
43
+ this.#examples.push(...examples)
44
+ return this as MessageCommand<T>;
45
+ }
17
46
  /**
18
47
  * 注册命令回调
19
48
  * @param callback 命令处理函数
@@ -32,18 +61,11 @@ export class MessageCommand<T extends keyof RegisteredAdapters=keyof RegisteredA
32
61
  * @param plugin 插件实例
33
62
  * @returns 命令返回内容或undefined
34
63
  */
35
- async handle(message:Message<AdapterMessage<T>>,app:App):Promise<SendContent|undefined>{
36
- for(const permission of this.#permissions){
37
- const permit=app.permissions.get(permission)
38
- if(!permit) {
39
- throw new ZhinError(`权限 ${permission} 不存在`)
40
- }
41
- const result=await permit.check(permission,message)
42
- if(!result) return;
43
- }
44
- for(const check of this.#checkers){
45
- const result=await check(message)
46
- if(!result) return;
64
+ async handle(message:Message<AdapterMessage<T>>,plugin:Plugin):Promise<SendContent|undefined>{
65
+ const auth = plugin.contextIsReady('permission') ? plugin.inject('permission') : null
66
+ for(const permit of this.#permissions){
67
+ const passed=await auth?.check(permit,message)
68
+ if(!passed) return;
47
69
  }
48
70
  const matched=this.match(message.$content);
49
71
  if(!matched) return
@@ -54,6 +76,12 @@ export class MessageCommand<T extends keyof RegisteredAdapters=keyof RegisteredA
54
76
  }
55
77
  }
56
78
  export namespace MessageCommand{
57
- export type Callback<T extends keyof RegisteredAdapters>=(message:Message<AdapterMessage<T>>,result:MatchResult)=>SendContent|undefined|Promise<SendContent|undefined>;
58
- export type Checker<T extends keyof RegisteredAdapters>=(message:Message<AdapterMessage<T>>)=>MaybePromise<boolean>
79
+ export type Callback<T extends RegisteredAdapter>=(message:Message<AdapterMessage<T>>,result:MatchResult)=>SendContent|undefined|Promise<SendContent|undefined>;
80
+ export type Checker<T extends RegisteredAdapter>=(message:Message<AdapterMessage<T>>)=>MaybePromise<boolean>
81
+ export type HelpInfo={
82
+ pattern:string;
83
+ desc:string[];
84
+ usage:string[];
85
+ examples:string[];
86
+ }
59
87
  }
package/src/component.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { getValueWithRuntime, compiler, segment } from './utils.js';
2
2
  import { Dict, SendContent, SendOptions, MessageElement } from './types.js';
3
- import { Message } from "./message.js";
4
3
 
5
4
  // 组件匹配符号
6
5
  export const CapWithChild = Symbol('CapWithChild');
@@ -8,7 +7,7 @@ export const CapWithClose = Symbol('CapWithClose');
8
7
 
9
8
  // 函数式组件类型定义
10
9
  export type Component<P = any> = {
11
- (props: P, context: ComponentContext): Promise<SendContent>;
10
+ (props: P, context: ComponentContext): SendContent | Promise<SendContent>;
12
11
  name: string;
13
12
  }
14
13
 
@@ -562,4 +561,4 @@ export const Fragment = defineComponent(async (props: { children?: SendContent }
562
561
  }, 'Fragment');
563
562
  export const Fetch = defineComponent(async ({ url }) => {
564
563
  return await fetch(url).then((r) => r.text());
565
- }, 'fetch');
564
+ }, 'fetch');
package/src/cron.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { CronExpressionParser, CronExpression } from 'cron-parser';
1
+ import { Cron as Croner } from 'croner';
2
2
 
3
3
  /**
4
4
  * Cron 定时任务类
5
- * 基于 cron-parser 实现的定时任务调度器
5
+ * 基于 croner 实现的定时任务调度器 (无需 Luxon,内存占用更小)
6
6
  */
7
7
  export class Cron {
8
- private expression: CronExpression;
8
+ private job: Croner | null = null;
9
+ id:string = '';
9
10
  private callback: () => void | Promise<void>;
10
- private timeoutId?: NodeJS.Timeout;
11
- private isRunning = false;
12
11
  private isDisposed = false;
12
+ private _cronExpression: string;
13
13
 
14
14
  /**
15
15
  * 创建一个新的 Cron 实例
@@ -17,9 +17,14 @@ export class Cron {
17
17
  * @param callback - 要执行的回调函数
18
18
  */
19
19
  constructor(cronExpression: string, callback: () => void | Promise<void>) {
20
+ this.id=Math.random().toString(36).substring(2, 10);
20
21
  try {
21
- this.expression = CronExpressionParser.parse(cronExpression);
22
+ this._cronExpression = cronExpression;
22
23
  this.callback = callback;
24
+
25
+ // 验证 cron 表达式是否有效 (不启动)
26
+ const testJob = new Croner(cronExpression, { paused: true });
27
+ testJob.stop();
23
28
  } catch (error) {
24
29
  throw new Error(`Invalid cron expression "${cronExpression}": ${(error as Error).message}`);
25
30
  }
@@ -33,23 +38,28 @@ export class Cron {
33
38
  throw new Error('Cannot run a disposed cron job');
34
39
  }
35
40
 
36
- if (this.isRunning) {
41
+ if (this.job) {
37
42
  return; // 已经在运行中
38
43
  }
39
44
 
40
- this.isRunning = true;
41
- this.scheduleNext();
45
+ // 创建并启动任务
46
+ this.job = new Croner(this._cronExpression, async () => {
47
+ try {
48
+ await this.callback();
49
+ } catch (error) {
50
+ console.error(`Error executing cron callback: ${(error as Error).message}`);
51
+ }
52
+ });
42
53
  }
43
54
 
44
55
  /**
45
56
  * 停止定时任务
46
57
  */
47
58
  stop(): void {
48
- if (this.timeoutId) {
49
- clearTimeout(this.timeoutId);
50
- this.timeoutId = undefined;
59
+ if (this.job) {
60
+ this.job.stop();
61
+ this.job = null;
51
62
  }
52
- this.isRunning = false;
53
63
  }
54
64
 
55
65
  /**
@@ -68,16 +78,23 @@ export class Cron {
68
78
  throw new Error('Cannot get next execution time for a disposed cron job');
69
79
  }
70
80
 
71
- // 重置表达式到当前时间
72
- this.expression.reset();
73
- return this.expression.next().toDate();
81
+ // 创建临时任务来获取下次执行时间
82
+ const tempJob = new Croner(this._cronExpression, { paused: true });
83
+ const nextRun = tempJob.nextRun();
84
+ tempJob.stop();
85
+
86
+ if (!nextRun) {
87
+ throw new Error('Cannot determine next execution time');
88
+ }
89
+
90
+ return nextRun;
74
91
  }
75
92
 
76
93
  /**
77
94
  * 检查任务是否正在运行
78
95
  */
79
96
  get running(): boolean {
80
- return this.isRunning;
97
+ return this.job !== null;
81
98
  }
82
99
 
83
100
  /**
@@ -91,59 +108,7 @@ export class Cron {
91
108
  * 获取原始的 cron 表达式字符串
92
109
  */
93
110
  get cronExpression(): string {
94
- return this.expression.stringify();
95
- }
96
-
97
- /**
98
- * 调度下一次执行
99
- */
100
- private scheduleNext(): void {
101
- if (!this.isRunning || this.isDisposed) {
102
- return;
103
- }
104
-
105
- try {
106
- // 重置到当前时间并获取下一次执行时间
107
- this.expression.reset();
108
- const nextDate = this.expression.next().toDate();
109
- const now = new Date();
110
- const delay = nextDate.getTime() - now.getTime();
111
-
112
- // 如果延迟时间为负数或0,说明应该立即执行
113
- if (delay <= 0) {
114
- this.executeCallback();
115
- return;
116
- }
117
-
118
- // 设置定时器
119
- this.timeoutId = setTimeout(() => {
120
- this.executeCallback();
121
- }, delay);
122
-
123
- } catch (error) {
124
- console.error(`Error scheduling next cron execution: ${(error as Error).message}`);
125
- // 如果出错,停止任务
126
- this.stop();
127
- }
128
- }
129
-
130
- /**
131
- * 执行回调函数并调度下一次执行
132
- */
133
- private async executeCallback(): Promise<void> {
134
- if (!this.isRunning || this.isDisposed) {
135
- return;
136
- }
137
-
138
- try {
139
- // 执行回调函数
140
- await this.callback();
141
- } catch (error) {
142
- console.error(`Error executing cron callback: ${(error as Error).message}`);
143
- }
144
-
145
- // 调度下一次执行
146
- this.scheduleNext();
111
+ return this._cronExpression;
147
112
  }
148
113
  }
149
114
 
package/src/index.ts CHANGED
@@ -1,18 +1,28 @@
1
1
  // Core exports
2
- export * from './app.js'
3
2
  export * from './bot.js'
4
3
  export * from './plugin.js'
5
4
  export * from './command.js'
6
5
  export * from './component.js'
7
6
  export * from './adapter.js'
8
- export * from './config.js'
9
7
  export * from './message.js'
10
- // Logger moved to @zhin.js/logger package
8
+ export * from './prompt.js'
9
+ // Models
10
+ export * from './models/system-log.js'
11
+ export * from './models/user.js'
12
+ // Built-in Contexts
13
+ export * from './built/config.js'
14
+ export * from './built/command.js'
15
+ export * from './built/cron.js'
16
+ export * from './built/permission.js'
17
+ export * from './built/adapter-process.js'
18
+ export * from './built/component.js'
19
+ export * from './built/database.js'
20
+
11
21
  export * from './types.js'
12
22
  export * from './utils.js'
13
23
  export * from './errors.js' // 导出错误处理系统
14
24
  export * from './cron.js'
15
25
  export * from '@zhin.js/database'
16
26
  export * from '@zhin.js/logger'
17
-
18
- export { Dependency, Schema } from '@zhin.js/hmr'
27
+ // 只导出 Schema 类,避免与 utils.js 的 isEmpty 冲突
28
+ export { Schema } from '@zhin.js/schema'
package/src/jsx.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { MaybePromise } from '@zhin.js/types';
2
1
  import { SendContent,MessageElement } from './types.js';
3
2
  import { MessageComponent } from './message.js';
4
3
  import { Component, ComponentContext } from './component.js';
@@ -20,9 +19,9 @@ declare global {
20
19
  namespace JSX {
21
20
  // 支持同步和异步组件 - Element 可以是 MessageComponent
22
21
  // TypeScript 会在编译时允许异步组件,运行时会自动 await
23
- type Element = MessageComponent<any> | Promise<MessageComponent<any>> | Promise<SendContent>
22
+ type Element = SendContent | Promise<SendContent>
24
23
  interface ElementClass {
25
- render(props: any, context?: ComponentContext): MaybePromise<SendContent>;
24
+ render(props: any, context?: ComponentContext): Element;
26
25
  }
27
26
  interface ElementAttributesProperty {
28
27
  data: {};
package/src/message.ts CHANGED
@@ -1,12 +1,11 @@
1
- import {MessageElement, MessageSender, SendContent} from "./types";
1
+ import {MessageElement, MessageSender, RegisteredAdapter, SendContent} from "./types";
2
2
  import { Component } from "./component.js";
3
3
 
4
4
  /**
5
5
  * 消息组件类型:用于自定义消息结构
6
- * 支持同步和异步组件
7
6
  */
8
7
  export type MessageComponent<T extends object>={
9
- type:Component<T&{children?:SendContent}> | ((props: T & {children?: SendContent}) => Promise<SendContent>)
8
+ type:Component<T&{children?:SendContent|Promise<SendContent>}>
10
9
  data:T
11
10
  }
12
11
  /**
@@ -25,7 +24,7 @@ export type MessageType = 'group' | 'private' | 'channel'
25
24
  */
26
25
  export interface MessageBase {
27
26
  $id: string;
28
- $adapter:string
27
+ $adapter:RegisteredAdapter
29
28
  $bot:string
30
29
  $content: MessageElement[];
31
30
  $sender: MessageSender;