@fantaibao/ws-protocol 1.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gravio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @fantaibao/ws-protocol
2
+
3
+ 万流引力 桌面端(gravio-app) ↔ Web 控制台(wlyl_web) 之间的 WebSocket 协议契约。
4
+
5
+ - **Zod schema**:运行时校验,desktop 服务端用
6
+ - **TS 类型**:通过 `z.infer` 派生,两端都可以 `import type`
7
+ - **WsCodec**:消息编解码(JSON.parse + schema 校验 + 错误处理)
8
+
9
+ ## 使用
10
+
11
+ ```bash
12
+ pnpm add @fantaibao/ws-protocol
13
+ ```
14
+
15
+ ### desktop(带运行时校验)
16
+
17
+ ```ts
18
+ import { WsCodec, WsEnvelopeSchema, type WsEnvelope } from '@fantaibao/ws-protocol'
19
+
20
+ const envelope = WsCodec.decode(rawString) // 自动校验
21
+ ```
22
+
23
+ ### web(仅类型,零运行时开销)
24
+
25
+ ```ts
26
+ import type { WsEnvelope, WsAccountInfo, TaskKind } from '@fantaibao/ws-protocol'
27
+
28
+ const env: WsEnvelope = JSON.parse(rawString) // 不带 zod,自己 trust 服务端
29
+ ```
30
+
31
+ `import type` 在 TS 编译时被擦除,zod 不会进 web bundle。
32
+
33
+ ## 改契约的工作流
34
+
35
+ ```bash
36
+ # 1. 改 src/index.ts
37
+ vim src/index.ts
38
+
39
+ # 2. 自测 + 构建
40
+ pnpm typecheck && pnpm build
41
+
42
+ # 3. 升版本号 + 打 tag
43
+ pnpm version patch # 或 minor / major
44
+ git push --follow-tags
45
+
46
+ # 4. 登录 npm 并发布
47
+ npm login
48
+ npm publish --access public
49
+
50
+ # 5. desktop 端升级
51
+ cd ~/dev/gravio-app
52
+ pnpm up @fantaibao/ws-protocol@1.1.0
53
+
54
+ # 6. web 端同样动作
55
+ cd ~/dev/wlyl_web
56
+ pnpm up @fantaibao/ws-protocol@1.1.0
57
+ ```
58
+
59
+ 任何一端不升版本号就锁在旧版本上,**不会被偷偷漂移**。
60
+
61
+ ## 版本规范
62
+
63
+ 按 [Semantic Versioning](https://semver.org/lang/zh-CN/):
64
+
65
+ - **major**:删消息类型、改字段含义、改 PROTOCOL_VERSION
66
+ - **minor**:新增消息类型、新增可选字段
67
+ - **patch**:注释/JSDoc 改动、不影响行为的内部重构