-
Notifications
You must be signed in to change notification settings - Fork 100
feat: add dedicated methods for cursor based pagination [CAPI-2357] #2824
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
base: master
Are you sure you want to change the base?
feat: add dedicated methods for cursor based pagination [CAPI-2357] #2824
Conversation
…ods for entry, asset, and content-type [CAPI-2357] Adds getManyWithCursor as a dedicated cursor based method for entry, asset, and content-type and getPublishedWithCursor for only the asset and entry entities
…response and params and building utilities to do so [CAPI-2357] * fix: getPublished does not currently support cursor based pagination, removing relevant methods for entities * fix: normalize pagination params to filter prevPage and prevNext if falsey * fix: normalize pagination response to parse next, prev tokens if present
… for getManyWithCursor for content-type, asset, and entry entities [CAPI-2357]
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension. |
…console statements, adding cbp to toc in readme [CAPI-2357]
2ac557b to
09e8e07
Compare
…2819) Co-authored-by: Ely Lucas <[email protected]>
…etManyWithCursor methods [CAPI-2357]
| } | ||
|
|
||
| export interface BasicCursorPaginationOptions extends Omit<BasicQueryOptions, 'skip'> { | ||
| skip?: never |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this skip unnecessary given the Omit above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this type used in all the non cursor based functions as signature? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ethan-ozelius-contentful It's there because unless strictly forbidden, the value can still be passed in at runtime. I wanted to make sure to have a type error there just in case.
@marcolink Could you point to where that is the case? I'm not sure I follow right now, apologies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here for example:
(not changed in this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I'm not sure why, but can investigate. I was using the same type to idiomatically match how we were using it elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, changing that now would likely create a breaking change ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, we can make a point to investigate what's happening here and if need be spin up another ticket?
| }, | ||
|
|
||
| /** | ||
| * Gets a collection of Content Types with cursor based pagination |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two URLs listed in this @param should probably point to the follow URL right?
ethan-ozelius-contentful
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left 1-2 non-blocking questions, but otherwise looks good.
| console.log(response.items); // Array of items | ||
| console.log(response.pages?.next); // Cursor for next page | ||
| ``` | ||
| Use the value from `response.pages.next` to fetch the next page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add an example on how to use the pages.next token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do
| } | ||
|
|
||
| export interface BasicCursorPaginationOptions extends Omit<BasicQueryOptions, 'skip'> { | ||
| skip?: never |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this type used in all the non cursor based functions as signature? 🤔
…nation example to readme [CAPI-2357]
Summary
Introduces three dedicated cursor pagination methods, one per each relevant entity:
getAssetsWithCursorgetContentTypesWithCursorgetEntriesWithCursorDescription
These changes expose three new dedicated methods in the plain client for cursor based pagination. These methods map to the
getManyendpoint per each entity and are wrapped accordingly with the appropriate cursor pagination collection. Relevant unit and integration tests are also included.Motivation and Context
Previously we tried to provide correct typing for
cma.jsby checking the cursor parameter to be true. As the type system ofcma.jsis already quite complex, this introduced a bug we were not able to foresee. As a result, this was rolled back and the decision was taken to introduce dedicated methods for cursor-based pagination.PR Checklist
CONTRIBUTING.mdfile