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

Method validateFlashcardData

src/storage/DataValidator.ts:168–197  ·  view source on GitHub ↗

* 验证闪卡数据结构 * @param data 闪卡数据 * @returns 验证结果

(data: unknown)

Source from the content-addressed store, hash-verified

166 * @returns 验证结果
167 */
168 static validateFlashcardData(data: unknown): { valid: boolean; errors: string[] } {
169 const errors: string[] = [];
170
171 if (!this.isRecord(data)) {
172 errors.push('闪卡数据必须是对象');
173 return { valid: false, errors };
174 }
175
176 // 验证版本
177 if (!data.version || typeof data.version !== 'string') {
178 errors.push('缺少有效的版本信息');
179 }
180
181 // 验证cards对象
182 if (data.cards && typeof data.cards !== 'object') {
183 errors.push('cards必须是对象');
184 }
185
186 // 验证globalStats
187 if (data.globalStats && typeof data.globalStats !== 'object') {
188 errors.push('globalStats必须是对象');
189 }
190
191 // 验证cardGroups
192 if (data.cardGroups && !Array.isArray(data.cardGroups)) {
193 errors.push('cardGroups必须是数组');
194 }
195
196 return { valid: errors.length === 0, errors };
197 }
198
199 /**
200 * 验证文件映射数据

Callers 1

loadMethod · 0.80

Calls 1

isRecordMethod · 0.95

Tested by

no test coverage detected