Skip to content

feat: allow options to ServiceObject methods#349

Merged
JustinBeckwith merged 10 commits intogoogleapis:masterfrom
stephenplusplus:spp--options
Jan 23, 2019
Merged

feat: allow options to ServiceObject methods#349
JustinBeckwith merged 10 commits intogoogleapis:masterfrom
stephenplusplus:spp--options

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
}

// 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!

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 :)

*/
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