( items: T[], isSkipped: (item: T) => boolean, max: number, alreadyIndexed: number )
| 205 | * that count toward the cap), and whether the cap is now reached |
| 206 | */ |
| 207 | export function takeIndexableWithinCap<T>( |
| 208 | items: T[], |
| 209 | isSkipped: (item: T) => boolean, |
| 210 | max: number, |
| 211 | alreadyIndexed: number |
| 212 | ): { documents: T[]; indexableCount: number; capReached: boolean } { |
| 213 | if (max <= 0) { |
| 214 | let indexableCount = 0 |
| 215 | for (const item of items) { |
| 216 | if (!isSkipped(item)) indexableCount += 1 |
| 217 | } |
| 218 | return { documents: items, indexableCount, capReached: false } |
| 219 | } |
| 220 | |
| 221 | const remaining = max - alreadyIndexed |
| 222 | const documents: T[] = [] |
| 223 | let indexableCount = 0 |
| 224 | for (const item of items) { |
| 225 | if (indexableCount >= remaining) break |
| 226 | documents.push(item) |
| 227 | if (!isSkipped(item)) indexableCount += 1 |
| 228 | } |
| 229 | return { documents, indexableCount, capReached: alreadyIndexed + indexableCount >= max } |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Raised by a connector when a file exceeds its size cap mid-download — i.e. the |
no test coverage detected