Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental pagination feature #833

Merged
merged 7 commits into from
Feb 6, 2020

Conversation

szmarczak
Copy link
Collaborator

@szmarczak szmarczak commented Jul 15, 2019

Fixes #722

Checklist

  • I have read the documentation.
  • I have included a pull request description of my changes.
  • I have included some tests.
  • If it's a new feature, I have included documentation updates.

IssueHunt Summary

Referenced issues

This pull request has been submitted to:


IssueHunt has been backed by the following sponsors. Become a sponsor

@szmarczak szmarczak changed the title Pagination support [WIP] Pagination support Sep 9, 2019
@sindresorhus
Copy link
Owner

We need an option for itemCount too.

source/index.ts Show resolved Hide resolved
source/index.ts Outdated Show resolved Hide resolved
source/index.ts Outdated Show resolved Hide resolved
source/index.ts Outdated Show resolved Hide resolved
@szmarczak
Copy link
Collaborator Author

We need an option for itemCount too.

Instead of an itemCount option I think it's better to have this:

const results = await got.paginate.all({
	pagination: {
		shouldContinue: allItems => allItems.length !== 3
	}
});

because people may want have custom conditions.

@szmarczak
Copy link
Collaborator Author

szmarczak commented Nov 24, 2019

@rarkins Could you look at the tests and tell if the API looks ok?

@rarkins
Copy link
Contributor

rarkins commented Nov 28, 2019

@rarkins Could you look at the tests and tell if the API looks ok?

I think it looks good so far, thanks

source/as-stream.ts Outdated Show resolved Hide resolved
@szmarczak
Copy link
Collaborator Author

I need to make more tests here

@rarkins
Copy link
Contributor

rarkins commented Nov 29, 2019

@szmarczak one day I would like to see pagination with a limit, e.g. you might want the first 1000 Pull Requests from GitHub's API. Would you anticipate that being an option to got.paginate.all or would it be a new function like got.paginate.some? Also we'd ideally like to combine it with a filter too eventually, e.g. you can get the first X paginated items that match logic Y.

@szmarczak
Copy link
Collaborator Author

A side note for me: There's a missing test for options.pagination.shouldContinue.

@rarkins You can do something like this:

const results = await got.paginate.all({
    pagination: {
        ...,
        shouldContinue: items => items.length < 1000
    }
});

That will give you max 1000 items. But if it's a common use case, then I can make options.pagination.countLimit.

@rarkins
Copy link
Contributor

rarkins commented Nov 29, 2019

But if it's a common use case

I'm pretty sure it would be commonly used

@szmarczak
Copy link
Collaborator Author

I'm pretty sure it would be commonly used

So you have a new countLimit option now :) I just need to update the docs and the PR is good to merge.

@szmarczak szmarczak changed the title [WIP] Pagination support Pagination support Nov 29, 2019
@szmarczak
Copy link
Collaborator Author

I'm gonna write the docs tomorrow.

pmmmwh added a commit to pmmmwh/got that referenced this pull request Nov 29, 2019
pmmmwh added a commit to pmmmwh/got that referenced this pull request Nov 30, 2019
source/index.ts Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

How about we prefix the option with an underscore and document that the option is experimental and that users should lock the Got dependency as it might change in minor releases? This will give users a chance to try it out, but also gives us a chance to improve it without having to do lots of major releases?

@szmarczak
Copy link
Collaborator Author

Sure, will finish this today.

@szmarczak szmarczak requested review from sindresorhus and removed request for sindresorhus February 3, 2020 15:30
readme.md Outdated Show resolved Hide resolved
@szmarczak szmarczak changed the title Pagination support Experimental pagination support Feb 3, 2020
@szmarczak szmarczak mentioned this pull request Feb 6, 2020
18 tasks
@sindresorhus sindresorhus changed the title Experimental pagination support Experimental pagination feature Feb 6, 2020
###### \_pagination.paginate

Type: `Function`\
Default: [`Link` header logic](source/index.ts)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should explain the Link header logic in English prose, not just link to the source.

@sindresorhus
Copy link
Owner

#1053

@sindresorhus sindresorhus merged commit 761c7c6 into sindresorhus:master Feb 6, 2020
@sindresorhus
Copy link
Owner

This is looking great! Nice work, @szmarczak 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pagination support
3 participants