-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat: allow options to ServiceObject methods #349
Conversation
src/service-object.ts
Outdated
@@ -42,8 +42,13 @@ export interface Interceptor { | |||
request(opts: r.Options): DecorateRequestOptions; | |||
} | |||
|
|||
// tslint:disable-next-line:no-any | |||
export type GetMetadataOptions = any; |
There was a problem hiding this comment.
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.).
src/service-object.ts
Outdated
// tslint:disable-next-line:no-any | ||
export type Metadata = any; | ||
// tslint:disable-next-line:no-any | ||
export type SetMetadataOptions = any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments for GetMetadataOptions
.
src/service-object.ts
Outdated
optionsOrCallback?: GetMetadataOptions|MetadataCallback, | ||
callback?: MetadataCallback): Promise<MetadataResponse>|void { | ||
let options: GetMetadataOptions = {}; | ||
if (typeof optionsOrCallback === 'function') { |
There was a problem hiding this comment.
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!
src/service-object.ts
Outdated
metadata: Metadata, | ||
optionsOrCallback?: SetMetadataOptions|MetadataCallback, | ||
callback?: MetadataCallback): Promise<SetMetadataResponse>|void { | ||
const options = |
There was a problem hiding this comment.
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!
src/service-object.ts
Outdated
@@ -42,8 +42,13 @@ export interface Interceptor { | |||
request(opts: r.Options): DecorateRequestOptions; | |||
} | |||
|
|||
// tslint:disable-next-line:no-any |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😊
There was a problem hiding this 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) => { |
There was a problem hiding this comment.
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.
@JustinBeckwith @callmehiphop -- tests added. PTAfinalL. It would be great to get this in before the next release (#350). |
To Dos
This allows
options
to be passed to several methods on ServiceObject: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.