* Lists a single batch of repository-file stubs. The full filtered file list is * resolved once and cached on syncContext; the cursor is an offset into that * list, of the form `file|{offset}`.
( accessToken: string, organization: string, project: string, filters: FileFilters, maxItems: number, cursor: string | undefined, syncContext: Record<string, unknown> | undefined )
| 950 | * list, of the form `file|{offset}`. |
| 951 | */ |
| 952 | async function listRepoFiles( |
| 953 | accessToken: string, |
| 954 | organization: string, |
| 955 | project: string, |
| 956 | filters: FileFilters, |
| 957 | maxItems: number, |
| 958 | cursor: string | undefined, |
| 959 | syncContext: Record<string, unknown> | undefined |
| 960 | ): Promise<ExternalDocumentList> { |
| 961 | const entries = await resolveRepoFiles(accessToken, organization, project, filters, syncContext) |
| 962 | |
| 963 | if (entries.length === 0) { |
| 964 | return { documents: [], hasMore: false } |
| 965 | } |
| 966 | |
| 967 | let offset = 0 |
| 968 | if (cursor) { |
| 969 | const parts = cursor.split('|') |
| 970 | offset = Number(parts[1]) || 0 |
| 971 | } |
| 972 | |
| 973 | const chunk = entries.slice(offset, offset + FILE_BATCH_SIZE) |
| 974 | const documents = chunk.map((entry) => fileToStub(organization, project, entry)) |
| 975 | |
| 976 | const nextOffset = offset + FILE_BATCH_SIZE |
| 977 | const { documents: capped, capped: hitLimit } = applyMaxItemsCap( |
| 978 | documents, |
| 979 | maxItems, |
| 980 | syncContext, |
| 981 | nextOffset < entries.length |
| 982 | ) |
| 983 | |
| 984 | const hasMore = !hitLimit && nextOffset < entries.length |
| 985 | |
| 986 | return { |
| 987 | documents: capped, |
| 988 | nextCursor: hasMore ? `file|${nextOffset}` : undefined, |
| 989 | hasMore, |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | /** |
| 994 | * Resolves the branch to fetch a single repository file from in getDocument. Uses |
no test coverage detected