(raw: unknown, notePath: string)
| 2695 | } |
| 2696 | |
| 2697 | function 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 | |
| 2716 | export async function readNoteComments(root: string, rel: string): Promise<NoteComment[]> { |
| 2717 | const notePath = toPosix(rel) |
no test coverage detected