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 support for SearchResult. #1198

Merged
merged 5 commits into from
Aug 30, 2021
Merged

Conversation

dcr-stripe
Copy link
Contributor

@dcr-stripe dcr-stripe commented Jul 26, 2021

Notify

r? @richardm-stripe

Summary

Adds support for search methods and search_result objects returned by the Stripe API. This requires updating auto pagination to support this. These paginate similarly to lists, however they rely on a next_page token included in the response rather than using object IDs + starting_before/ending_after. Thus, only forward pagination is supported

Test plan

Added unit tests. We'll want to add some more rigorous tests once a resource is using this.

this.createResourcePathWithSymbols(spec.path || '')
);
spec.urlParams = !!spec.fullPath
? []
Copy link
Contributor

Choose a reason for hiding this comment

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

fullPath is guaranteed not to have url params?

Copy link
Contributor Author

@dcr-stripe dcr-stripe Jul 27, 2021

Choose a reason for hiding this comment

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

Fixed! If we're moving everything to full paths, definitely doesn't make sense to exclude these.

@richardm-stripe
Copy link
Contributor

richardm-stripe commented Jul 26, 2021

This looks good, but I wonder - would the code be simpler if we removed all relative paths and used fullPath everywhere? I don't think there is any virtue to relative paths.

[reverseIteration ? 'ending_before' : 'starting_after']: lastId,
});
return listPromise.then(iterate);
if (spec.methodType === 'search') {
Copy link
Contributor

@richardm-stripe richardm-stripe Jul 26, 2021

Choose a reason for hiding this comment

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

supernit: this code would feel slightly better to me if the spec.methodType check was done once, top-level in makeAutoPaginationMethods, rather than each time within iterate.

Either something like

let getNextPagePromise;
if (spec.methodType === 'search') {
  getNextPagePromise = ...
} else {
  getNextPagePromise = ...
}
function iterate(pageResult) {
  ...
  return getPagePromise(...).then(iterate)
}

or

let iterate;
if (spec.methodType === 'search') {
  iterate = function (pageResult) {
    ...
  };
} else {
  iterate = ...
}

(the second would likely require factoring out a couple helper methods to keep it DRY)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - good call!

Copy link
Contributor

@richardm-stripe richardm-stripe left a comment

Choose a reason for hiding this comment

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

Nothing strictly blocking, though I'm curious what you think about fullPath everywhere

@dcr-stripe dcr-stripe force-pushed the dcr-search-result-infra branch 3 times, most recently from 54c3f13 to e39e26d Compare July 27, 2021 15:30
@dcr-stripe
Copy link
Contributor Author

Thanks for the comments!

For full paths, I'll lay down the ground work in this PR and then in a follow up can update the other methods to use it as it depends on basic methods.

r? @richardm-stripe

@dcr-stripe
Copy link
Contributor Author

Removing reviews for a second. I think it'd be good to split our the fullPath logic of this PR into its own PR.

@dcr-stripe dcr-stripe changed the base branch from master to dcr-full-path-support July 27, 2021 16:02
@dcr-stripe
Copy link
Contributor Author

I split out https://github.com/stripe/stripe-node/pull/1200/files for full path support. This should be good to go now.

r? @richardm-stripe

Base automatically changed from dcr-full-path-support to master July 28, 2021 17:55
@dcr-stripe dcr-stripe changed the title Add infrastructure for search. Add support for SearchResult. Jul 28, 2021
@richardm-stripe
Copy link
Contributor

I am merging this. Despite the fact that this functionality is part of a private beta, this will not affect the public interface of the library and can be safely removed/changed.

@richardm-stripe richardm-stripe merged commit a1f8c57 into master Aug 30, 2021
@richardm-stripe richardm-stripe deleted the dcr-search-result-infra branch August 30, 2021 17:11
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.

2 participants