refactor(proto-defs): extract wire-protobuf definitions into standalone package
Move `packages/core/src/bridge/proto/proton/*.ts` (13 files, ~3.3k LOC) into a new `@snowluma/proto-defs` workspace package. The proton spike landed in the previous commit means bare-specifier imports (`@snowluma/proto-defs/oidb`, `…/message`, …) now resolve correctly through proton's vite plugin, so call-site replacement still fires. Why --- - Lets downstream consumers share the same wire definitions without copy-pasting them — multiple workspace packages can now depend on `@snowluma/proto-defs` directly. - Trims `@snowluma/core`'s surface: the bridge no longer owns the protocol schema, only its consumers. - Sets up future #5 (`message-parsing perf`) and #6 (`Api-on-ctx refactor`) — both want a thinner core. Layout ------ Per-file subpath exports (mirrors the legacy `proto/proton/<sub>` shape 1:1). The barrel `index.ts` intentionally skips `highway` and `oidb-actions/media` because the two files share six NTV2-prefixed type names — `export *` would silently drop one side. Subpath imports are unambiguous, which is also why every call site in core uses them. Changes ------- - New package `packages/proto-defs/` (package.json, tsconfig.json, src/index.ts). - 13 `.ts` files moved via `git mv` to preserve history. - 44 import sites across 26 source files + 15 tests rewritten via sed from `./[…/]proto/proton/<sub>` → `@snowluma/proto-defs/<sub>`. - `@snowluma/core` depends on `@snowluma/proto-defs` (workspace:*). Verification ------------ - proto-defs typecheck: clean - core typecheck: clean - core test suite: 587 passed (same baseline as before the refactor; one failure is the pre-existing websocket native addon, unrelated) - proton test suite: 99 passed (8 files including the new cross-package.test.ts from the spike) - Full workspace `pnpm -r typecheck`: all 8 projects clean Note: proton's `dist/index.js` MUST be rebuilt for the vite plugin to pick up the bare-specifier resolution. The previous commit's source change is only effective after `pnpm -F @snowluma/proton build`.
This commit is contained in:
1 parent
994633eafa
commit
6c7e56d5a1
59 files changed
+212
-75
No files matched your search
@@ -0,0 +1,98 @@
|
||||
import type { pb, pb_repeated, int_32, uint_32, uint_64, bytes } from '@snowluma/proton';
|
||||
import type { Elem } from './element';
|
||||
|
||||
// ResponseHead.Grp
|
||||
export interface ResponseGrp {
|
||||
groupUin?: pb<1, uint_32>;
|
||||
memberName?: pb<2, string>;
|
||||
groupName?: pb<4, string>;
|
||||
}
|
||||
|
||||
export interface ResponseForward {
|
||||
friendName?: pb<6, string>;
|
||||
}
|
||||
|
||||
// ResponseHead
|
||||
export interface ResponseHead {
|
||||
fromUin?: pb<1, uint_32>;
|
||||
fromUid?: pb<2, string>;
|
||||
type?: pb<3, uint_32>;
|
||||
sigMap?: pb<4, uint_32>;
|
||||
toUin?: pb<5, uint_32>;
|
||||
toUid?: pb<6, string>;
|
||||
forward?: pb<7, ResponseForward>;
|
||||
grp?: pb<8, ResponseGrp>;
|
||||
}
|
||||
|
||||
// ContentHead
|
||||
export interface ContentHead {
|
||||
msgType?: pb<1, uint_32>;
|
||||
subType?: pb<2, uint_32>;
|
||||
divSeq?: pb<3, uint_32>;
|
||||
msgId?: pb<4, uint_32>;
|
||||
sequence?: pb<5, uint_32>;
|
||||
timestamp?: pb<6, uint_32>;
|
||||
field7?: pb<7, uint_64>;
|
||||
newId?: pb<12, uint_64>;
|
||||
}
|
||||
|
||||
// Ptt (voice)
|
||||
export interface Ptt {
|
||||
fileType?: pb<1, uint_32>;
|
||||
fileId?: pb<2, uint_64>;
|
||||
fileUuid?: pb<3, bytes>;
|
||||
fileMd5?: pb<4, bytes>;
|
||||
fileName?: pb<5, string>;
|
||||
fileSize?: pb<6, uint_32>;
|
||||
groupFileKey?: pb<10, string>;
|
||||
fileKey?: pb<14, bytes>;
|
||||
time?: pb<19, uint_32>;
|
||||
format?: pb<29, uint_32>;
|
||||
}
|
||||
|
||||
// C2C 离线文件结构
|
||||
// 1. 发送端必填:字段 9/50/55(subcmd=1, dangerEvel=0, expireTime=当前时间+7天)。
|
||||
// 2. 接收端只读:核心标识槽位(Uuid/Md5/Name/Size/Hash)。
|
||||
export interface NotOnlineFile {
|
||||
fileType?: pb<1, uint_32>;
|
||||
fileUuid?: pb<3, string>;
|
||||
fileMd5?: pb<4, bytes>;
|
||||
fileName?: pb<5, string>;
|
||||
fileSize?: pb<6, uint_64>;
|
||||
subcmd?: pb<9, uint_32>; // 发送必填:固定为 1
|
||||
dangerEvel?: pb<50, uint_32>; // 发送必填:固定为 0
|
||||
expireTime?: pb<55, uint_32>; // 发送必填:过期时间戳(now + 7 days)
|
||||
fileHash?: pb<57, string>;
|
||||
}
|
||||
|
||||
// RichText
|
||||
export interface RichText {
|
||||
elems?: pb_repeated<2, Elem>;
|
||||
notOnlineFile?: pb<3, NotOnlineFile>;
|
||||
ptt?: pb<4, Ptt>;
|
||||
}
|
||||
|
||||
// MessageBody
|
||||
export interface MessageBody {
|
||||
richText?: pb<1, RichText>;
|
||||
msgContent?: pb<2, bytes>;
|
||||
}
|
||||
|
||||
// C2C 文件附加信息
|
||||
// 统一使用与线上数据对齐的 NotOnlineFile 结构,修复收发双向的解析问题。
|
||||
export interface FileExtra {
|
||||
file?: pb<1, NotOnlineFile>;
|
||||
}
|
||||
|
||||
// PushMsgBody
|
||||
export interface PushMsgBody {
|
||||
responseHead?: pb<1, ResponseHead>;
|
||||
contentHead?: pb<2, ContentHead>;
|
||||
body?: pb<3, MessageBody>;
|
||||
}
|
||||
|
||||
// PushMsg (top-level)
|
||||
export interface PushMsg {
|
||||
message?: pb<1, PushMsgBody>;
|
||||
status?: pb<3, int_32>;
|
||||
}
|
||||
Reference in new issue
Block a user