refactor(bridge): extract BridgeInterface as the OneBot-facing seam
OneBot used to depend on the concrete Bridge class — 778 lines, ~99 public methods including PID management, raw packet dispatch, and cmd handler registration that no external consumer should touch. Add an explicit BridgeInterface (bridge/bridge-interface.ts) enumerating only the surface OneBot actually reads (verified by grepping every bridge.* access in onebot/), and have Bridge `implements BridgeInterface` so the compiler enforces alignment. Net effect at runtime: zero — Bridge's methods, fields, and bodies are unchanged; the interface is a TypeScript-only declaration. Net effect for typing: the OneBot package (instance, instance-context, instance-rkey, manager, media-url-resolver, and the modules under onebot/modules/) now imports `BridgeInterface` instead of `Bridge`, so tests / fakes can satisfy the interface without subclassing or pulling in the SQLite/native bits. In-tree bridge actions (actions/*, bridge-contacts, highway) keep their concrete `Bridge` typing — they legitimately need sendRawPacket and other low-level entry points that intentionally stay off the interface.
This commit is contained in:
11 files changed
+167
-35
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { Bridge } from '../../bridge/bridge';
|
||||
import type { BridgeInterface } from '../../bridge/bridge-interface';
|
||||
import type { ForwardNodePayload, MessageElement } from '../../bridge/events';
|
||||
import { createLogger } from '../../utils/logger';
|
||||
import type { MessageSendResult } from '../api-handler';
|
||||
@@ -63,7 +63,7 @@ export async function getFriendMsgHistory(
|
||||
.map(sanitizeMessageEventForApi);
|
||||
}
|
||||
|
||||
export async function deleteMessage(bridge: Bridge, meta: MessageMeta): Promise<void> {
|
||||
export async function deleteMessage(bridge: BridgeInterface, meta: MessageMeta): Promise<void> {
|
||||
if (meta.isGroup) {
|
||||
await bridge.recallGroupMessage(meta.targetId, meta.sequence);
|
||||
} else {
|
||||
@@ -78,7 +78,7 @@ export async function deleteMessage(bridge: Bridge, meta: MessageMeta): Promise<
|
||||
}
|
||||
|
||||
export async function setEssenceMessage(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeInterface,
|
||||
messageStore: MessageStore,
|
||||
messageId: number,
|
||||
enable: boolean,
|
||||
|
||||
Reference in new issue
Block a user