@zhin.js/core 1.0.13 → 1.0.14

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @zhin.js/core
2
2
 
3
+ ## 1.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 547028f: fix: 优化包结构,优化客户端支持
8
+ - Updated dependencies [547028f]
9
+ - @zhin.js/database@1.0.4
10
+ - @zhin.js/hmr@1.0.7
11
+
3
12
  ## 1.0.13
4
13
 
5
14
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/core",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Zhin机器人核心框架",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -29,8 +29,8 @@
29
29
  "toml": "^3.0.0",
30
30
  "dotenv": "^16.3.1",
31
31
  "cron-parser": "latest",
32
- "@zhin.js/hmr": "1.0.6",
33
- "@zhin.js/database": "1.0.3"
32
+ "@zhin.js/hmr": "1.0.7",
33
+ "@zhin.js/database": "1.0.4"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@zhin.js/logger": "0.1.1"
@@ -38,7 +38,7 @@
38
38
  "devDependencies": {
39
39
  "@types/node": "^24.3.0",
40
40
  "typescript": "^5.3.0",
41
- "@zhin.js/types": "1.0.4"
41
+ "@zhin.js/types": "1.0.5"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsc",
package/tests/bot.test.ts CHANGED
@@ -1,32 +1,42 @@
1
1
  import { describe, it, expect, beforeEach, vi } from 'vitest'
2
2
  import type { Bot } from '../src/bot'
3
- import type { BotConfig, SendOptions } from '../src/types'
3
+ import type {SendOptions } from '../src/types'
4
+ import { Message } from '../src/message'
4
5
 
5
6
  describe('Bot接口测试', () => {
6
7
  // 创建一个测试用的Bot实现类
7
- class TestBot implements Bot {
8
+ class TestBot implements Bot<any, Bot.Config> {
8
9
  connected = false
10
+ $config: Bot.Config
11
+ constructor(public config: Bot.Config) {
12
+ this.$config = config
13
+ }
9
14
 
10
- constructor(public config: BotConfig) {}
11
-
12
- async connect(): Promise<void> {
15
+ async $connect(): Promise<void> {
13
16
  this.connected = true
14
17
  }
15
18
 
16
- async disconnect(): Promise<void> {
19
+ async $disconnect(): Promise<void> {
17
20
  this.connected = false
18
21
  }
19
22
 
20
- async sendMessage(options: SendOptions): Promise<void> {
23
+ async $sendMessage(options: SendOptions): Promise<string> {
21
24
  if (!this.connected) {
22
25
  throw new Error('机器人未连接')
23
26
  }
24
27
  // 模拟发送消息
28
+ return '123'
29
+ }
30
+ async $recallMessage(id: string): Promise<void> {
31
+ // 模拟撤回消息
32
+ }
33
+ $formatMessage(message: any): Message<any> {
34
+ return message
25
35
  }
26
36
  }
27
37
 
28
38
  let bot: TestBot
29
- let testConfig: BotConfig
39
+ let testConfig: Bot.Config
30
40
 
31
41
  beforeEach(() => {
32
42
  testConfig = {
@@ -48,13 +58,13 @@ describe('Bot接口测试', () => {
48
58
 
49
59
  describe('连接管理测试', () => {
50
60
  it('应该正确处理连接', async () => {
51
- await bot.connect()
61
+ await bot.$connect()
52
62
  expect(bot.connected).toBe(true)
53
63
  })
54
64
 
55
65
  it('应该正确处理断开连接', async () => {
56
- await bot.connect()
57
- await bot.disconnect()
66
+ await bot.$connect()
67
+ await bot.$disconnect()
58
68
  expect(bot.connected).toBe(false)
59
69
  })
60
70
  })
@@ -69,7 +79,7 @@ describe('Bot接口测试', () => {
69
79
  content: '测试消息'
70
80
  }
71
81
 
72
- await expect(bot.sendMessage(options)).rejects.toThrow('机器人未连接')
82
+ await expect(bot.$sendMessage(options)).rejects.toThrow('机器人未连接')
73
83
  })
74
84
 
75
85
  it('连接后应该正确发送消息', async () => {
@@ -81,39 +91,48 @@ describe('Bot接口测试', () => {
81
91
  content: '测试消息'
82
92
  }
83
93
 
84
- const sendSpy = vi.spyOn(bot, 'sendMessage')
85
- await bot.connect()
86
- await bot.sendMessage(options)
94
+ const sendSpy = vi.spyOn(bot, '$sendMessage')
95
+ await bot.$connect()
96
+ await bot.$sendMessage(options)
87
97
  expect(sendSpy).toHaveBeenCalledWith(options)
88
98
  })
89
99
  })
90
100
 
91
101
  describe('自定义配置测试', () => {
92
102
  it('应该支持扩展的配置类型', () => {
93
- interface ExtendedConfig extends BotConfig {
103
+ interface ExtendedConfig extends Bot.Config {
94
104
  token: string
95
105
  platform: string
96
106
  }
97
107
 
98
108
  class ExtendedBot implements Bot<ExtendedConfig> {
99
109
  connected = false
110
+ $config: ExtendedConfig
111
+ constructor(public config: ExtendedConfig) {
112
+ this.$config = config
113
+ }
100
114
 
101
- constructor(public config: ExtendedConfig) {}
102
-
103
- async connect(): Promise<void> {
115
+ async $connect(): Promise<void> {
104
116
  this.connected = true
105
117
  }
106
118
 
107
- async disconnect(): Promise<void> {
119
+ async $disconnect(): Promise<void> {
108
120
  this.connected = false
109
121
  }
110
122
 
111
- async sendMessage(options: SendOptions): Promise<void> {
123
+ async $sendMessage(options: SendOptions): Promise<string> {
112
124
  if (!this.connected) {
113
125
  throw new Error('机器人未连接')
114
126
  }
127
+ return '123'
115
128
  // 模拟发送消息
116
129
  }
130
+ async $recallMessage(id: string): Promise<void> {
131
+ // 模拟撤回消息
132
+ }
133
+ $formatMessage(message: any): Message<any> {
134
+ return message
135
+ }
117
136
  }
118
137
 
119
138
  const extendedConfig: ExtendedConfig = {
package/src/jsx.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import { SendContent } from './types.js';
2
- import { Component,ComponentContext } from './component.js';
3
- import { MessageElement } from './types.js';
4
-
5
- declare global {
6
- namespace JSX {
7
- interface Element {
8
- type: string | Component<any>;
9
- data: Record<string, any>;
10
- children?: JSXChildren;
11
- }
12
-
13
- interface ElementClass {
14
- render(props: any, context?: ComponentContext): MaybePromise<SendContent>;
15
- }
16
-
17
- interface ElementAttributesProperty {
18
- data: {};
19
- }
20
-
21
- interface ElementChildrenAttribute {
22
- children: {};
23
- }
24
-
25
- interface IntrinsicElements {
26
- // 简化的组件元素
27
- fetch: JSXFetchElement;
28
- }
29
- }
30
- }
31
-
32
- // 简化的组件属性接口
33
- interface JSXBaseElement {
34
- children?: JSXChildren;
35
- }
36
-
37
- interface JSXFetchElement extends JSXBaseElement {
38
- url?: string;
39
- }
40
-
41
- // JSX 子元素类型
42
- type JSXChildren = MessageElement | string | number | boolean | null | undefined | JSXChildren[];
43
-
44
- // JSX 元素类型
45
- type JSXElement = {
46
- type: string | Component<any>;
47
- data: Record<string, any>;
48
- children?: JSXChildren;
49
- };
50
-
51
- // 类型辅助
52
- type MaybePromise<T> = T | Promise<T>;