@hile/message-ws 1.0.0 → 1.0.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/README.md CHANGED
@@ -39,6 +39,10 @@ class AppWs extends MessageWs {
39
39
  return data;
40
40
  }
41
41
  }
42
+
43
+ public request<T = any>(data: T, timeout?: number) {
44
+ return this._send(data, timeout);
45
+ }
42
46
  }
43
47
  ```
44
48
 
@@ -79,10 +83,11 @@ ws.on('open', () => {
79
83
  |------|------|------|
80
84
  | `constructor` | `new SubClass(ws: WebSocket)` | 传入已连接的 WebSocket 实例 |
81
85
  | `exec` | `protected abstract exec(data: any): Promise<any>` | 子类实现:处理对端请求 |
82
- | `request` | `request<T>(data: T, timeout?: number)` | 向对端发送请求,返回 `{ abort, response }` |
86
+ | `_send` | `protected _send<T>(data: T, timeout?: number)` | 发送双向请求(`twoway: true`),返回 `{ abort, response }`。子类自行暴露为 public |
87
+ | `_push` | `protected _push<T>(data: T, timeout?: number)` | 发送单向推送(`twoway: false`),接收方不回复 RESPONSE |
83
88
  | `dispose` | `dispose(): void` | 移除消息监听,释放资源 |
84
89
 
85
- ### `request` 返回值
90
+ ### `_send` 返回值
86
91
 
87
92
  | 属性 | 类型 | 说明 |
88
93
  |------|------|------|
package/SKILL.md CHANGED
@@ -38,7 +38,14 @@ abstract class MessageWs extends MessageModem {
38
38
 
39
39
  protected abstract exec(data: any): Promise<any>;
40
40
 
41
- public request<T = any>(data: T, timeout?: number): {
41
+ // 发送双向请求(protected,子类自行暴露)
42
+ protected _send<T = any>(data: T, timeout?: number): {
43
+ abort: () => void;
44
+ response: <U = any>() => Promise<U>;
45
+ };
46
+
47
+ // 发送单向推送(protected,子类自行暴露)
48
+ protected _push<T = any>(data: T, timeout?: number): {
42
49
  abort: () => void;
43
50
  response: <U = any>() => Promise<U>;
44
51
  };
@@ -63,6 +70,10 @@ class MyWs extends MessageWs {
63
70
  default: return data;
64
71
  }
65
72
  }
73
+
74
+ public request<T = any>(data: T, timeout?: number) {
75
+ return this._send(data, timeout);
76
+ }
66
77
  }
67
78
  ```
68
79
 
@@ -120,8 +131,11 @@ ws.on('open', () => {
120
131
  // ❌ 不能直接实例化
121
132
  const modem = new MessageWs(ws); // abstract
122
133
 
123
- // ✅ 继承并实现 exec
124
- class MyWs extends MessageWs { ... }
134
+ // ✅ 继承并实现 exec,自行暴露 _send
135
+ class MyWs extends MessageWs {
136
+ protected async exec(data: any) { return data; }
137
+ public request<T = any>(data: T, timeout?: number) { return this._send(data, timeout); }
138
+ }
125
139
 
126
140
  // ❌ 传输非 JSON 安全的数据
127
141
  modem.request(new Map()); // Map 序列化会丢失
package/dist/index.d.ts CHANGED
@@ -25,13 +25,6 @@ export declare abstract class MessageWs extends MessageModem {
25
25
  private readonly listener;
26
26
  constructor(ws: WebSocket);
27
27
  protected post<T = any>(data: MessageTransferFormat<T>): void;
28
- /**
29
- * 向对端发送请求
30
- */
31
- request<T = any>(data: T, timeout?: number): {
32
- abort: () => void;
33
- response: <U = any>() => Promise<U>;
34
- };
35
28
  /**
36
29
  * 移除消息监听,释放资源
37
30
  */
package/dist/index.js CHANGED
@@ -40,12 +40,6 @@ export class MessageWs extends MessageModem {
40
40
  }
41
41
  this.ws.send(JSON.stringify(data));
42
42
  }
43
- /**
44
- * 向对端发送请求
45
- */
46
- request(data, timeout) {
47
- return this.send(data, timeout);
48
- }
49
43
  /**
50
44
  * 移除消息监听,释放资源
51
45
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hile/message-ws",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -23,8 +23,8 @@
23
23
  "vitest": "^4.0.18"
24
24
  },
25
25
  "dependencies": {
26
- "@hile/message-modem": "^1.0.1",
26
+ "@hile/message-modem": "^1.0.2",
27
27
  "ws": "^8.19.0"
28
28
  },
29
- "gitHead": "8f802f24910712571463865ddbe856d2cfba0786"
29
+ "gitHead": "86b1ce38e9eeb069acb2188834a0ff5b466a050a"
30
30
  }