promise array results #2896
Labels
semver: major
Hint for users that this is an API breaking change.
status: won't fix
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
The age old question - why do Promises always resolve with tuples (Arrays)?
There have been a few threads where we receive complaints about Promises resolving with tuples. More often than not the suggestion to resolve with objects is made, but personally I don't see why we would want to do that. With destructuring the end result is the same and tuples are slightly easier to work with.
My overall opinion is that if we want to do away with tuples, we should change all methods to not return the response and if there are use cases for the raw response data, we create an alternate version of the method that exposes it in some way. For some types of methods this is pretty easy, but with others not so much. Here's a possible solution for the various types of methods we have
resource creators
For resource creating methods I think it would be safe to just drop the response completely since it always gets set as the
metadata
property.Before
After
paginated lasts
For paginated lists I think we should split up the functionality into 2 separate methods.
autoPaginate: true
)autoPaginate: false
)This has an added benefit of following the single responsibility principle since the current version changes the response tuple based on an option.
Before
After
convenience methods
We have several convenience methods that essentially wrap other methods (
exists
->getMetadata
). I think we should ditch the response on these kinds of methods and add JSDoc{@link}
tags to whatever is called under the hood.Before
After
operation methods
For resources that require a lro we should separate that logic into 2 different methods (BigQuery already does this).
Since we would be returning 2 resources, each response would be available via
metadata
property.Before
After
queries
Methods that perform a query often contain both data and statistics about the query itself. Unlike paginated lists, I feel like this information should always be returned.
Before
After
The text was updated successfully, but these errors were encountered: