panatgithub_AnkiHeadingSync/src/domain/manual-sync/entities/PluginState.ts
Dusk e2f973dc46 refactor: 切换 manual-sync 主链到 ID noteId / refactor manual-sync mainline to ID noteId
- 将 marker、state、writeback 的 durable identity 改为 noteId
- Switch marker, state, and writeback durable identity to noteId

- 支持满足标题规则的旧 ID 卡片重接进并按当前 renderer 重渲染
- Reconnect legacy ID cards that match heading rules and rerender them with the current renderer

- 补充 schema migration、测试、构建验证与插件同步
- Add schema migration, tests, build verification, and plugin sync
2026-04-19 11:46:37 +08:00

68 lines
No EOL
1.7 KiB
TypeScript

import type { CardType } from "@/domain/card/entities/RenderedFields";
import type { DeckResolutionWarning, DeckResolutionSource } from "@/domain/manual-sync/value-objects/DeckResolution";
export interface FileState {
filePath: string;
fileHash: string;
fileStamp: string;
deckRulesFingerprint?: string;
lastIndexedAt: number;
noteIds: number[];
}
export interface CardState {
noteId: number;
filePath: string;
heading: string;
headingLevel: number;
bodyMarkdown: string;
cardType: CardType;
blockStartOffset: number;
blockEndOffset: number;
blockStartLine: number;
bodyStartLine: number;
blockEndLine: number;
contentEndLine: number;
markerLine?: number;
rawBlockText: string;
rawBlockHash: string;
renderConfigHash: string;
deck: string;
deckHint?: string;
deckHintSource?: Extract<DeckResolutionSource, "frontmatter" | "body">;
deckWarnings: DeckResolutionWarning[];
tagsHint: string[];
lastSyncedAt: number;
orphan: boolean;
}
export interface PendingWriteBackState {
filePath: string;
blockStartLine: number;
expectedFileHash: string;
targetMarker: string;
rawBlockHash: string;
targetNoteId: number;
}
export interface PluginState {
files: Record<string, FileState>;
cards: Record<string, CardState>;
pendingWriteBack: PendingWriteBackState[];
}
export function createEmptyPluginState(): PluginState {
return {
files: {},
cards: {},
pendingWriteBack: [],
};
}
export function toNoteIdKey(noteId: number): string {
return String(noteId);
}
export function createPendingWriteBackKey(filePath: string, blockStartLine: number, rawBlockHash: string): string {
return `${filePath}\u0000${blockStartLine}\u0000${rawBlockHash}`;
}