Skip to content

Read every page of a list ​

ts
/** Every client, one page at a time. */
export async function* allClients(limit = 200) {
  for (let page = 1; ; page++) {
    const p = await staff.clients.list({ page, limit });
    yield* p.items;
    if (page * limit >= p.total) return;
  }
}

// for await (const c of allClients()) exportRow(c)

total counts every match, so the last page is ceil(total / limit). Logs that grow fast (journal) page by cursor with before instead.