* Applies the optional maxItems cap to a batch, tracking the running total in * syncContext and flagging `listingCapped` when the cap actually truncated the * listing. The sync engine reads `listingCapped` to suppress deletion * reconciliation on a truncated listing — without it, a capped full sy
( documents: ExternalDocument[], maxItems: number, syncContext: Record<string, unknown> | undefined, moreAvailable: boolean )
| 1164 | * documents are still cleaned up. |
| 1165 | */ |
| 1166 | function applyMaxItemsCap( |
| 1167 | documents: ExternalDocument[], |
| 1168 | maxItems: number, |
| 1169 | syncContext: Record<string, unknown> | undefined, |
| 1170 | moreAvailable: boolean |
| 1171 | ): { documents: ExternalDocument[]; capped: boolean } { |
| 1172 | if (maxItems <= 0) return { documents, capped: false } |
| 1173 | const prevTotal = (syncContext?.totalDocsFetched as number) ?? 0 |
| 1174 | const remaining = Math.max(0, maxItems - prevTotal) |
| 1175 | const slicedSome = documents.length > remaining |
| 1176 | const sliced = slicedSome ? documents.slice(0, remaining) : documents |
| 1177 | const newTotal = prevTotal + sliced.length |
| 1178 | if (syncContext) syncContext.totalDocsFetched = newTotal |
| 1179 | const capped = newTotal >= maxItems |
| 1180 | if (capped && (slicedSome || moreAvailable) && syncContext) syncContext.listingCapped = true |
| 1181 | return { documents: sliced, capped } |
| 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * Lists a single batch of wiki pages across the project's wikis (optionally |
no outgoing calls
no test coverage detected