MCPcopy Create free account
hub / github.com/CatMuse/HiNote / validateHighlightData

Method validateHighlightData

src/storage/DataValidator.ts:26–57  ·  view source on GitHub ↗

* 验证高亮数据结构 * @param data 高亮数据 * @returns 验证结果

(data: unknown)

Source from the content-addressed store, hash-verified

24 * @returns 验证结果
25 */
26 static validateHighlightData(data: unknown): { valid: boolean; errors: string[] } {
27 const errors: string[] = [];
28
29 if (!this.isRecord(data)) {
30 errors.push('数据必须是对象');
31 return { valid: false, errors };
32 }
33
34 // 验证版本
35 if (!data.version || typeof data.version !== 'string') {
36 errors.push('缺少有效的版本信息');
37 }
38
39 // 验证lastModified
40 if (data.lastModified && typeof data.lastModified !== 'number') {
41 errors.push('lastModified必须是数字');
42 }
43
44 // 验证highlights对象
45 if (!this.isRecord(data.highlights)) {
46 errors.push('缺少highlights对象');
47 return { valid: false, errors };
48 }
49
50 // 验证每个高亮
51 for (const [id, highlight] of Object.entries(data.highlights)) {
52 const highlightErrors = this.validateHighlight(id, highlight);
53 errors.push(...highlightErrors);
54 }
55
56 return { valid: errors.length === 0, errors };
57 }
58
59 /**
60 * 验证单个高亮

Callers 1

getFileHighlightsMethod · 0.80

Calls 2

isRecordMethod · 0.95
validateHighlightMethod · 0.95

Tested by

no test coverage detected