-
|
Pagination parameters (which is extended then) looks like folloowing: interface DefaultPaginationParams {
/** Return results older than this ID. */
readonly maxId?: string | null;
/** Return results newer than this ID. */
readonly sinceId?: string | null;
/** Get a list of items with ID greater than this value excluding this ID */
readonly minId?: string | null;
/** Maximum number of results to return per page. Defaults to 40. NOTE: Pagination is done with the Link header from the response. */
readonly limit?: number | null;
}Also, based on mastodon api docs, we know that parameters like My question is, what is the proper way to implement paging with masto.js? If I use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hello @jibla. As you pointed out, Mastodon returns information related to pagination including the next However, we instead offer a higher level abstraction. All methods named Here's a basic example that favourite all posts on your home feed by using for await (const statuses of masto.v1.timelines.home.list()) {
for (const status of statuses) {
await masto.v1.statuses.$select(status.id).favourite();
}
}or if you want to fetch individual pages, you can use const timeline = masto.v1.timelines.home.list();
const page1 = await timeline.next() // { done: false, value: [post, post, post...] }
const page2 = await timeline.next();
const page3 = await timeline.next();at the same time, you can fetch the first page by const timeline = await masto.v1.timelines.home.list();
// ^^^^^
// It now behaves like a Promise because we used `await`.
// This is a synonym for `(await timelines.home.list().next()).value`Therefore I believe we don't need to expose any HTTP information because you can encapsulate concrete implementation by using the Paginator API. TSDoc comment for the limit property mentions about Link header but this is because we copy-and-pasted all descriptions from the Mastodon docs, which should be improved in the future. I hope this helps |
Beta Was this translation helpful? Give feedback.
Hello @jibla. As you pointed out, Mastodon returns information related to pagination including the next
minIdin the HTTPLinkheader, and Masto.js is currently not offering a API for directly referring response headers.However, we instead offer a higher level abstraction. All methods named
list()actually returns an object that we callPaginatorthat can not only behave like aPromise, but also as aAsyncIterator.Here's a basic example that favourite all posts on your home feed by using
for-await-ofsyntax:or if you want to…