MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / normalizeNoteComments

Function normalizeNoteComments

apps/desktop/src/main/vault.ts:2697–2714  ·  view source on GitHub ↗
(raw: unknown, notePath: string)

Source from the content-addressed store, hash-verified

2695}
2696
2697function normalizeNoteComments(raw: unknown, notePath: string): NoteComment[] {
2698 const values = Array.isArray(raw)
2699 ? raw
2700 : raw && typeof raw === 'object' && Array.isArray((raw as { comments?: unknown }).comments)
2701 ? (raw as { comments: unknown[] }).comments
2702 : []
2703 const seen = new Set<string>()
2704 const comments: NoteComment[] = []
2705 for (const value of values) {
2706 if (!value || typeof value !== 'object') continue
2707 const comment = normalizeNoteComment(value as NoteCommentInput, notePath)
2708 if (!comment || seen.has(comment.id)) continue
2709 seen.add(comment.id)
2710 comments.push(comment)
2711 }
2712 comments.sort((a, b) => a.createdAt - b.createdAt || a.id.localeCompare(b.id))
2713 return comments
2714}
2715
2716export async function readNoteComments(root: string, rel: string): Promise<NoteComment[]> {
2717 const notePath = toPosix(rel)

Callers 2

readNoteCommentsFunction · 0.85
writeNoteCommentsFunction · 0.85

Calls 1

normalizeNoteCommentFunction · 0.85

Tested by

no test coverage detected