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

Support RecordsQuery pagination in Web5 #268

Merged
merged 6 commits into from
Nov 29, 2023
Merged

Conversation

LiranCohen
Copy link
Member

Add paginationMessageCid to the RecordsQueryResponse object, now when providing a limit, if there are additional results this cursor will be returned to be used in subsequent queries.

Example response with additional results:

{
  status: { code: 200, message: '...' },
  records: [...],
  paginationMessageCid: 'bayfreigu....'
}

Example request for additional results:

const results = await dwn.records.query({
  message: {
    filter: {
      schema: 'foo/bar'
    },
    pagination: { limit: 2, messageCid: 'bayfreigu....' }
  }
});

Added a pagination test, as well as a missing sorts test.

@frankhinek I'm not sure if this is the best place to test these particular paths, input would be appreciated.

Copy link

codesandbox bot commented Nov 7, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

github-actions bot commented Nov 7, 2023

TBDocs Report

✅ No errors or warnings

@web5/api

  • Project entry file: packages/api/src/index.ts

Updated @ 2023-11-28T23:17:03.775Z - Commit: f51373f

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Merging #268 (5b81224) into main (34b915d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #268   +/-   ##
=======================================
  Coverage   91.77%   91.77%           
=======================================
  Files          73       73           
  Lines       15758    15764    +6     
  Branches     1448     1448           
=======================================
+ Hits        14462    14468    +6     
  Misses       1270     1270           
  Partials       26       26           
Components Coverage Δ
api 96.69% <100.00%> (+<0.01%) ⬆️
common 95.00% <ø> (ø)
credentials 94.32% <ø> (ø)
crypto 100.00% <ø> (ø)
dids 88.75% <ø> (ø)
agent 88.08% <100.00%> (+<0.01%) ⬆️
identity-agent 56.81% <ø> (ø)
proxy-agent 58.43% <ø> (ø)
user-agent 55.22% <ø> (ø)

Copy link
Contributor

@frankhinek frankhinek left a comment

Choose a reason for hiding this comment

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

@@ -353,7 +356,7 @@ export class DwnApi {
agentResponse = await this.agent.processDwnRequest(agentRequest);
}

const { reply: { entries, status } } = agentResponse;
const { reply: { entries, status, paginationMessageCid } } = agentResponse;
Copy link
Contributor

Choose a reason for hiding this comment

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

@LiranCohen In the hopes of providing the most intuitive developer experience, I was thinking that perhaps we name paginationMessageCid something that alludes to this value being the pagination cursor.

I was reading through the PR that originally introduced the pagination feature. I can understand the reasons for using the messageCid as the token but it seems like providing a more descriptive name to the value returned would have been more intuitive for developers using the feature. Particularly since so many other pagination implementations often return to the value as a token or cursor.

Thoughts?

Copy link
Member Author

@LiranCohen LiranCohen Nov 9, 2023

Choose a reason for hiding this comment

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

@frankhinek

I agree I think what we landed on wrt the cursor objects is less than optimal, especially looking at it again after some time.

I'm leaning towards a more generic naming, and we can define the explicitness of the values within docs/spec/comments.

Example:

// Query pagination object in descriptor
export type Pagination = {
  cursor?: string
  limit?: number
};

export type RecordsQueryResponse = {
  status: UnionMessageReply['status'];
  records?: Record[];
  cursor?: string;
};

If we really want to be explicit about the cursor being a messageCid, which could have some value, maybe something like cursorMessageCid?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. How do we move forward? Is there an update to dwn-sdk-js and then web5-js? Or another approach you prefer?

Copy link
Member Author

Choose a reason for hiding this comment

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

@frankhinek Originally was thinking of making the change here first to get it in, but then realized that it would be a hassle since the pagination object with messageCid is in the descriptor of the request.

I opened a PR in dwn-sdk-js to get this in and bubble it up to here.

@LiranCohen
Copy link
Member Author

@frankhinek updated this PR and added the missing documentation. Although would love some suggestions on the wording, not my strongest suit.

Also, not sure that I saw a pattern anywhere to document enum values like the DateSort enum we expose for sorting. Any suggestions on where/how to call it out or is it ok to just call out the type name like I did?

@frankhinek frankhinek added the enhancement New feature or request label Nov 28, 2023
@frankhinek frankhinek added this to the @web5/api 0.8.3 milestone Nov 28, 2023
Copy link
Contributor

@frankhinek frankhinek left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@frankhinek frankhinek force-pushed the lirancohen/pagination-sort branch from 23f993b to 5b81224 Compare November 28, 2023 23:14
@frankhinek frankhinek merged commit dce370d into main Nov 29, 2023
29 of 30 checks passed
@frankhinek frankhinek deleted the lirancohen/pagination-sort branch November 29, 2023 19:16
finn-block pushed a commit that referenced this pull request Mar 19, 2024
* Add pagination messageCid to RecordsQueryResponse and tests supporting pagination/sort
* cursor instead of paginationsMessagecid

---------

Signed-off-by: Frank Hinek <[email protected]>
Co-authored-by: Frank Hinek <[email protected]>
finn-block pushed a commit that referenced this pull request Mar 19, 2024
* Add pagination messageCid to RecordsQueryResponse and tests supporting pagination/sort
* cursor instead of paginationsMessagecid

---------

Signed-off-by: Frank Hinek <[email protected]>
Co-authored-by: Frank Hinek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants