-
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. |
lib/adapters/REST/make-request.ts
Outdated
| // @ts-ignore | ||
| endpoints[entityType]?.[action] | ||
|
|
||
| console.debug(endpoint) |
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.
Any specific reason for keeping this debug log?
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.
Good catch, not at all
| const queryIndex = url.indexOf('?') | ||
| if (queryIndex === -1) return | ||
|
|
||
| const queryString = url.slice(queryIndex + 1) | ||
| return new URLSearchParams(queryString).get(key) ?? undefined |
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.
| const queryIndex = url.indexOf('?') | |
| if (queryIndex === -1) return | |
| const queryString = url.slice(queryIndex + 1) | |
| return new URLSearchParams(queryString).get(key) ?? undefined | |
| const parsedURL = new URL(url) | |
| return parsedURL.searchParams.get(key) ?? undefined |
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.
The url we are parsing from the response is a relative url
pagePrev: "/spaces/segpl12szpe6/environments/master/assets?pageNext=SMK3D8KEZk..."
so we couldn't use URL here unless we mocked an appropriate base domain. Thoughts?
| { entityType, mockToReturn, methodToTest, wrapperSuffix = '' }, | ||
| ) { | ||
| const { api, entitiesMock } = setup(Promise.resolve(mockToReturn)) | ||
| console.debug('HERE', entitiesMock[entityType]) |
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.
Extra?
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.
Sorry! Yes, definitely need to remove
lib/common-utils.ts
Outdated
|
|
||
| return { | ||
| ...data, | ||
| ...(Object.keys(pages).length && { pages }), |
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 believe API always returns pages object, even if it's empty. Maybe we can do the same here, what do you think?
| - The ability to scope CMA client instance to a specific `spaceId`, `environmentId`, and `organizationId` when initializing the client. | ||
| - You can pass a concrete values to `defaults` and omit specifying these params in actual CMA methods calls. | ||
|
|
||
| ## 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.
Can we also add the title in TOC?
| }) | ||
|
|
||
| test('returns [limit] number of items', async () => { | ||
| const response = await environment.getAssetsWithCursor({ limit: 3 }) |
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.
…console statements, adding cbp to toc in readme [CAPI-2357]
2ac557b to
09e8e07
Compare
…2819) Co-authored-by: Ely Lucas <ely.lucas@contentful.com>
…etManyWithCursor methods [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