import type { CatalogPage } from "../contracts/studio/contract.ts"; import type { CatalogQuery, RequestOptions, StudioGateway } from "./ports/studio-gateway.ts"; /** 계약이 정한 한 번의 최대치(`Limit.maximum`). 이보다 크게 부르면 서버가 422 로 거절한다. */ const PAGE_SIZE = 100; /** * 서버가 커서를 계속 주는 경우에 대비한 상한. 100 × 50 이면 5,000건이고, 그 앞에서 화면이 * 영원히 기다리게 두지 않는다. */ const MAX_PAGES = 50; /** * 카탈로그를 끝까지 읽는다. * *

화면들은 `limit: 100` 으로 한 번만 부르고 있었다. 100 은 계약의 상한이라 더 크게 부를 수도 * 없었고, 그래서 기록이 101개가 된 날 101번째부터는 관계 대상 선택에도 작업본 목록의 프로젝트 * 필터에도 나타나지 않았다 — 고를 수 없는 기록이 아무 표시 없이 생겼다. * *

응답에는 `nextCursor` 가 있다. 그것이 빌 때까지 이어 읽는다. */ export async function collectCatalog( gateway: Pick, query: Omit, options?: RequestOptions, ): Promise { const items: CatalogPage["items"][number][] = []; let cursor: string | undefined; for (let page = 0; page < MAX_PAGES; page += 1) { const result: CatalogPage = await gateway.getCatalog( { ...query, limit: PAGE_SIZE, ...(cursor === undefined ? {} : { cursor }) }, options, ); items.push(...result.items); if (!result.nextCursor) return items; cursor = result.nextCursor; } return items; }