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

feat: allow options to ServiceObject methods #349

Merged
merged 10 commits into from
Jan 23, 2019

Conversation

stephenplusplus
Copy link
Contributor

@stephenplusplus stephenplusplus commented Jan 18, 2019

To Dos

  • Tests

This allows options to be passed to several methods on ServiceObject:

  • delete
  • exists
  • get
  • getMetadata
  • setMetadata

For Storage, in order to support the userProject object, we ended up duplicating many of these methods, so that we could pass extra parameters along with the request as query string parameters. With this change, we will just support that here, where it probably belongs.

Sending this in early for feedback before I carry on with the other methods and tests.

@stephenplusplus stephenplusplus added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jan 18, 2019
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 18, 2019
@@ -42,8 +42,13 @@ export interface Interceptor {
request(opts: r.Options): DecorateRequestOptions;
}

// tslint:disable-next-line:no-any
export type GetMetadataOptions = any;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think maybe it would be better to use object than any here. I think it is safe to assume that we'll only ever allow objects to be passed in (as opposed to strings, numbers, etc.).

// tslint:disable-next-line:no-any
export type Metadata = any;
// tslint:disable-next-line:no-any
export type SetMetadataOptions = any;
Copy link
Contributor

Choose a reason for hiding this comment

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

See comments for GetMetadataOptions.

optionsOrCallback?: GetMetadataOptions|MetadataCallback,
callback?: MetadataCallback): Promise<MetadataResponse>|void {
let options: GetMetadataOptions = {};
if (typeof optionsOrCallback === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using maybeOptionsOrCallback to simplify this logic!

metadata: Metadata,
optionsOrCallback?: SetMetadataOptions|MetadataCallback,
callback?: MetadataCallback): Promise<SetMetadataResponse>|void {
const options =
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using maybeOptionsOrCallback to simplify this logic!

@@ -42,8 +42,13 @@ export interface Interceptor {
request(opts: r.Options): DecorateRequestOptions;
}

// tslint:disable-next-line:no-any
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can get rid of this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😊

Copy link
Contributor

@JustinBeckwith JustinBeckwith left a comment

Choose a reason for hiding this comment

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

This LGTM, as long as we're not causing too much pain breaking our upstream dependencies :)

@@ -122,7 +123,7 @@ export class Operation<T = any> extends ServiceObject<T> {
* @private
*/
protected poll_(callback: MetadataCallback): void {
this.getMetadata((err, body) => {
this.getMetadata((err: ApiError, body: Metadata) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, the compiler should be able to infer the types for the callback. Weird that you had to add this.

@stephenplusplus stephenplusplus removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jan 23, 2019
@stephenplusplus
Copy link
Contributor Author

@JustinBeckwith @callmehiphop -- tests added. PTAfinalL. It would be great to get this in before the next release (#350).

@JustinBeckwith JustinBeckwith merged commit 07af323 into googleapis:master Jan 23, 2019
callmehiphop added a commit that referenced this pull request Jan 23, 2019
@stephenplusplus stephenplusplus deleted the spp--options branch January 24, 2019 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants