UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

21 lines (16 loc) 670 B
import {type AnnotationDetails, type Diff, visitDiff} from 'sanity' export function collectLatestAuthorAnnotations(diff: Diff): AnnotationDetails[] { const authorMap = new Map<string, AnnotationDetails>() visitDiff(diff, (child) => { if (child.action === 'unchanged' || !('annotation' in child) || !child.annotation) { return true } const {author, timestamp} = child.annotation const previous = authorMap.get(author) if (!previous || previous.timestamp < timestamp) { authorMap.set(author, child.annotation) } return true }) return Array.from(authorMap.values()).sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1)) }