( workspaceId: string, req?: WorkspaceBuildsRequest, )
| 40 | ]; |
| 41 | |
| 42 | export const infiniteWorkspaceBuilds = ( |
| 43 | workspaceId: string, |
| 44 | req?: WorkspaceBuildsRequest, |
| 45 | ) => { |
| 46 | const limit = req?.limit ?? 25; |
| 47 | |
| 48 | return { |
| 49 | queryKey: [...workspaceBuildsKey(workspaceId), req], |
| 50 | getNextPageParam: (lastPage, pages) => { |
| 51 | if (lastPage.length < limit) { |
| 52 | return undefined; |
| 53 | } |
| 54 | return pages.length + 1; |
| 55 | }, |
| 56 | initialPageParam: 0, |
| 57 | queryFn: ({ pageParam }) => { |
| 58 | if (typeof pageParam !== "number") { |
| 59 | throw new Error("pageParam must be a number"); |
| 60 | } |
| 61 | return API.getWorkspaceBuilds(workspaceId, { |
| 62 | limit, |
| 63 | offset: pageParam <= 0 ? 0 : (pageParam - 1) * limit, |
| 64 | }); |
| 65 | }, |
| 66 | } satisfies UseInfiniteQueryOptions<WorkspaceBuild[]>; |
| 67 | }; |
| 68 | |
| 69 | function workspaceBuildLogsKey(workspaceBuildId: string) { |
| 70 | return ["workspaceBuilds", workspaceBuildId, "logs"] as const; |
no test coverage detected