@@ -43,6 +43,11 @@ Instead, it re-exports from a core set of Seam modules:
4343 - [ Personal Access Token] ( #personal-access-token )
4444 - [ Console Session Token] ( #console-session-token )
4545 - [ Action Attempts] ( #action-attempts )
46+ - [ Pagination] ( #pagination )
47+ - [ Manually fetch pages with the nextPageCursor] ( #manually-fetch-pages-with-the-nextpagecursor )
48+ - [ Iterate over all pages] ( #iterate-over-all-pages )
49+ - [ Iterate over all resources] ( #iterate-over-all-resources )
50+ - [ Return all resources across all pages as an array] ( #return-all-resources-across-all-pages-as-an-array )
4651 - [ Interacting with Multiple Workspaces] ( #interacting-with-multiple-workspaces )
4752 - [ Personal Access Token] ( #personal-access-token-1 )
4853 - [ Console Session Token] ( #console-session-token-1 )
@@ -313,6 +318,67 @@ try {
313318
314319[ action attempt ] : https://docs.seam.co/latest/core-concepts/action-attempts
315320
321+ ### Pagination
322+
323+ Some Seam API endpoints that return lists of resources support pagination.
324+ Use the ` SeamPaginator ` class to fetch and process resources across multiple pages.
325+
326+ #### Manually fetch pages with the nextPageCursor
327+
328+ ``` ts
329+ const pages = seam .createPaginator (
330+ seam .devices .list ({
331+ limit: 20 ,
332+ }),
333+ )
334+
335+ const [devices, { hasNextPage, nextPageCursor }] = await pages .firstPage ()
336+
337+ if (hasNextPage ) {
338+ const [moreDevices] = await pages .nextPage (nextPageCursor )
339+ }
340+ ```
341+
342+ #### Iterate over all pages
343+
344+ ``` ts
345+ const pages = seam .createPaginator (
346+ seam .devices .list ({
347+ limit: 20 ,
348+ }),
349+ )
350+
351+ for await (const devices of pages ) {
352+ console .log (` There are ${devices .length } devices on this page. ` )
353+ }
354+ ```
355+
356+ #### Iterate over all resources
357+
358+ ``` ts
359+ const pages = seam .createPaginator (
360+ seam .devices .list ({
361+ limit: 20 ,
362+ }),
363+ )
364+
365+ for await (const device of pages .flatten ()) {
366+ console .log (devices .name )
367+ }
368+ ```
369+
370+ #### Return all resources across all pages as an array
371+
372+ ``` ts
373+ const pages = seam .createPaginator (
374+ seam .devices .list ({
375+ limit: 20 ,
376+ }),
377+ )
378+
379+ const devices = await pages .toArray ()
380+ ```
381+
316382### Interacting with Multiple Workspaces
317383
318384Some Seam API endpoints interact with multiple workspaces.
0 commit comments