MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / getAllNotes

Function getAllNotes

shared-edge/tests/getNotes.test.ts:73–105  ·  view source on GitHub ↗
(sortState: SortState)

Source from the content-addressed store, hash-verified

71}
72
73async function getAllNotes(sortState: SortState) {
74 const paginatedNotes = [] as Note[]
75 let count = 0
76 do {
77 count++
78 if (count > 1000) throwExp(`loop count is ${count}, did you screw up?`)
79 const last = paginatedNotes.at(-1)
80 const cursor =
81 last == null
82 ? undefined
83 : ({
84 noteEdited: dateToEpoch(last.noteEdited),
85 subscribers: last.subscribers,
86 comments: last.comments,
87 til: maybeDateToEpoch(last.til) ?? undefined,
88 'note.id': last.id,
89 } satisfies NoteCursor)
90 const page = await getNotes(
91 {
92 nook,
93 sortState: cloneDeep(sortState), // getNotes mutates this, which is fine in prod but not for testing
94 cursor,
95 },
96 userId,
97 )
98 if (page.length === 0) {
99 break
100 } else {
101 paginatedNotes.push(...page)
102 }
103 } while (true as boolean)
104 return paginatedNotes
105}
106
107test('cursor/keyset pagination works for getNotes', async () => {
108 const sortState = fc

Callers 1

getNotes.test.tsFile · 0.85

Calls 4

throwExpFunction · 0.90
dateToEpochFunction · 0.90
maybeDateToEpochFunction · 0.90
getNotesFunction · 0.90

Tested by

no test coverage detected