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

Add pagination to get_exchange_ids() function #110

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

KendallWeihe
Copy link
Contributor

This adds tbdex pagination for the get_exchange_ids() function from-APID-all-the-way-through-the-example app

Reference https://github.com/TBD54566975/tbdex/tree/main/specs/http-api#pagination

let service_endpoint = get_service_endpoint(pfi_did)?;
let get_exchanges_endpoint = format!("{}/exchanges", service_endpoint);

let get_exchanges_endpoint = if let Some(params) = query_params {
add_pagination(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can improve this in due time, but for now this is the most efficient way. namely, we may consider using a dedicated Url type, but which will require additional considerations (namely it may require adding a new dependency which must pass licensing considerations)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw we need to add pagination to other functions too, so we can improve DRY and the like at such time

pub fn get_exchange_ids(
pfi_did_uri: String,
bearer_did: Arc<BearerDid>,
query_params: Option<GetExchangeIdsQueryParams>,
Copy link
Member

Choose a reason for hiding this comment

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

if the query_param is absent, does it return the full list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that would be logic implemented on the PFI-side, but yes if not included then the expectation would be the full set of exchange IDs

perhaps we should add that language to the spec, or perhaps we should have a maximum as the default and include pagination on the response (@jiyoontbd @mistermoe)

Choose a reason for hiding this comment

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

if there's a million exchange between Alice and PFI already, it might be just a tad bit difficult for PFI to return all that in one response

so i agree with the idea of having a max. we could have it paginated by default showing the last X exchange... i don't really know what X should be. 50? 100?

Choose a reason for hiding this comment

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

this is just a list of ids tho, right, and not the full list of messages (which is an Exchange)?

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

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

I'm no rust expert but LGTM!

pfi_did: &str,
requestor_did: &BearerDid,
query_params: Option<GetExchangeIdsQueryParams>,
) -> Result<Vec<String>> {
let service_endpoint = get_service_endpoint(pfi_did)?;
Copy link
Member

Choose a reason for hiding this comment

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

What happens with multiple services?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. The get_service_endpoint is not something exposed internally, so just an internal function for the sake of DRY, and it specifically searched for the service with the type equal to PFI which is the only applicable DID service method in the context of the tbdex::http_client module.

Copy link
Member

Choose a reason for hiding this comment

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

there could still be multiple 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very fair point! #108 (comment)

crates/tbdex/src/http_client/exchanges.rs Show resolved Hide resolved
@@ -628,5 +629,16 @@ CLASS Exchange
## `get_exchange_ids()`

```pseudocode!
FUNCTION get_exchange_ids(pfi_did_uri: string, bearer_did: BearerDid): []string
FUNCTION get_exchange_ids(
pfi_did_uri: string,
Copy link
Member

Choose a reason for hiding this comment

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

Non blocking but is it worth having a DID type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's an idea worthy of consideration. I default to primitive types (strings) where possible, because I like to minimize cross-dependency usage (a DID type would originate, and in fact already exists, inside of web5-rs), but that's my bias.

@KendallWeihe KendallWeihe merged commit a10c268 into main Aug 9, 2024
10 checks passed
@KendallWeihe KendallWeihe deleted the kendall/get-exchange-ids-paginations branch August 9, 2024 16:23
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.

4 participants