From d755a4a3442fc64c6057d919027f1808869fbd8b Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Wed, 6 Mar 2019 15:45:28 -0500 Subject: [PATCH 1/2] refactor: type fixes and some light housekeeping --- src/iam.ts | 24 +++++-------- src/index.ts | 2 +- src/pubsub.ts | 55 ++++++++++++++---------------- src/snapshot.ts | 16 ++++----- src/subscription.ts | 78 ++++++++++++++++++------------------------ src/topic.ts | 80 ++++++++++++++++++-------------------------- test/snapshot.ts | 9 ----- test/subscription.ts | 9 ----- test/topic.ts | 10 ------ 9 files changed, 108 insertions(+), 175 deletions(-) diff --git a/src/iam.ts b/src/iam.ts index a797bf003..39988e722 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -147,12 +147,10 @@ export class IAM { * }); */ getPolicy( - gaxOptsOrCallback?: CallOptions|GetPolicyCallback, + optsOrCallback?: CallOptions|GetPolicyCallback, callback?: GetPolicyCallback): Promise|void { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const reqOpts = { resource: this.id, @@ -230,16 +228,14 @@ export class IAM { * }); */ setPolicy( - policy: Policy, gaxOptsOrCallback?: CallOptions|SetPolicyCallback, + policy: Policy, optsOrCallback?: CallOptions|SetPolicyCallback, callback?: SetPolicyCallback): Promise|void { if (!(typeof policy === 'object')) { throw new Error('A policy object is required.'); } - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const reqOpts = { resource: this.id, @@ -341,17 +337,15 @@ export class IAM { */ testPermissions( permissions: string|string[], - gaxOptsOrCallback?: CallOptions|TestIamPermissionsCallback, + optsOrCallback?: CallOptions|TestIamPermissionsCallback, callback?: TestIamPermissionsCallback): Promise|void { if (!Array.isArray(permissions) && !(typeof permissions === 'string')) { throw new Error('Permissions are required.'); } - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const reqOpts = { resource: this.id, diff --git a/src/index.ts b/src/index.ts index 479d6cb57..1756689bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,5 +83,5 @@ export {Attributes, PublishCallback} from './publisher'; export {PageOptions, GetSnapshotsCallback, GetSnapshotsResponse, GetSubscriptionsCallback, GetSubscriptionsResponse, GetTopicsCallback, GetTopicsResponse, EmptyCallback, EmptyResponse, ExistsCallback, ExistsResponse, PubSub} from './pubsub'; export {CreateSnapshotCallback, CreateSnapshotResponse, SeekCallback, SeekResponse, Snapshot} from './snapshot'; export {Message} from './subscriber'; -export {SubscriptionMetadata, SubscriptionOptions, SubscriptionCloseCallback, CreateSubscriptionOptions, CreateSubscriptionCallback, CreateSubscriptionResponse, GetSubscriptionOptions, GetSubscriptionCallback, GetSubscriptionResponse, GetSubscriptionMetadataCallback, GetSubscriptionMetadataResponse, SetSubscriptionMetadataCallback, SetSubscriptionMetadataResponse, Subscription} from './subscription'; +export {PushConfig, SubscriptionMetadata, SubscriptionOptions, SubscriptionCloseCallback, CreateSubscriptionOptions, CreateSubscriptionCallback, CreateSubscriptionResponse, GetSubscriptionOptions, GetSubscriptionCallback, GetSubscriptionResponse, GetSubscriptionMetadataCallback, GetSubscriptionMetadataResponse, SetSubscriptionMetadataCallback, SetSubscriptionMetadataResponse, Subscription} from './subscription'; export {CreateTopicCallback, CreateTopicResponse, GetTopicCallback, GetTopicResponse, GetTopicOptions, GetTopicMetadataCallback, GetTopicMetadataResponse, GetTopicSubscriptionsCallback, GetTopicSubscriptionsResponse, Topic} from './topic'; diff --git a/src/pubsub.ts b/src/pubsub.ts index 63d7e3ea0..d0c8247fd 100644 --- a/src/pubsub.ts +++ b/src/pubsub.ts @@ -432,17 +432,15 @@ export class PubSub { * }); */ createTopic( - name: string, gaxOptsOrCallback?: CallOptions|CreateTopicCallback, + name: string, optsOrCallback?: CallOptions|CreateTopicCallback, callback?: CreateTopicCallback): Promise|void { const topic = this.topic(name); const reqOpts = { name: topic.name, }; - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; this.request( { @@ -535,25 +533,26 @@ export class PubSub { * }); */ getSnapshots( - optionsOrCallback?: PageOptions|GetSnapshotsCallback, + optsOrCallback?: PageOptions|GetSnapshotsCallback, callback?: GetSnapshotsCallback): void|Promise { - const self = this; - const options = - typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; - callback = - typeof optionsOrCallback === 'function' ? optionsOrCallback : callback; + const options = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; + const reqOpts = Object.assign( { project: 'projects/' + this.projectId, }, options); + delete reqOpts.gaxOpts; delete reqOpts.autoPaginate; + const gaxOpts = Object.assign( { autoPaginate: options.autoPaginate, }, options.gaxOpts); + this.request< google.pubsub.v1.ISnapshot, google.pubsub.v1.IListSnapshotsResponse>( { @@ -567,7 +566,7 @@ export class PubSub { if (rawSnapshots) { snapshots = rawSnapshots.map(snapshot => { - const snapshotInstance = self.snapshot(snapshot.name!); + const snapshotInstance = this.snapshot(snapshot.name!); snapshotInstance.metadata = snapshot; return snapshotInstance; }); @@ -578,7 +577,7 @@ export class PubSub { } getSubscriptions(options?: GetSubscriptionsOptions): - Promise; + Promise; getSubscriptions(callback: GetSubscriptionsCallback): void; getSubscriptions( options: GetSubscriptionsOptions, @@ -641,14 +640,11 @@ export class PubSub { * }); */ getSubscriptions( - optionsOrCallback?: GetSubscriptionsOptions|GetSubscriptionsCallback, + optsOrCallback?: GetSubscriptionsOptions|GetSubscriptionsCallback, callback?: GetSubscriptionsCallback): - void|Promise { - const self = this; - const options = - typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; - callback = - typeof optionsOrCallback === 'function' ? optionsOrCallback : callback; + void|Promise { + const options = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; let topic = options.topic; if (topic) { @@ -685,7 +681,7 @@ export class PubSub { if (rawSubs) { subscriptions = rawSubs.map(sub => { - const subscriptionInstance = self.subscription(sub.name!); + const subscriptionInstance = this.subscription(sub.name!); subscriptionInstance.metadata = sub; return subscriptionInstance; }); @@ -756,26 +752,26 @@ export class PubSub { * }); */ getTopics( - optionsOrCallback?: PageOptions|GetTopicsCallback, + optsOrCallback?: PageOptions|GetTopicsCallback, callback?: GetTopicsCallback): void|Promise { - const self = this; - const options = - typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; - callback = - typeof optionsOrCallback === 'function' ? optionsOrCallback : callback; + const options = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const reqOpts = Object.assign( { project: 'projects/' + this.projectId, }, options); + delete reqOpts.gaxOpts; delete reqOpts.autoPaginate; + const gaxOpts = Object.assign( { autoPaginate: options.autoPaginate, }, options.gaxOpts); + this.request( { client: 'PublisherClient', @@ -788,7 +784,7 @@ export class PubSub { if (rawTopics) { topics = rawTopics.map(topic => { - const topicInstance = self.topic(topic.name); + const topicInstance = this.topic(topic.name); topicInstance.metadata = topic; return topicInstance; }); @@ -853,14 +849,13 @@ export class PubSub { * @param {function} [callback] The callback function. */ request(config: RequestConfig, callback: RequestCallback) { - const self = this; this.getClient_(config, (err, client) => { if (err) { callback(err); return; } let reqOpts = extend(true, {}, config.reqOpts); - reqOpts = replaceProjectIdToken(reqOpts, self.projectId); + reqOpts = replaceProjectIdToken(reqOpts, this.projectId); client![config.method](reqOpts, config.gaxOpts, callback); }); } diff --git a/src/snapshot.ts b/src/snapshot.ts index cfacb29ac..36ebe9a42 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -28,8 +28,8 @@ export type CreateSnapshotCallback = ResourceCallback; export type CreateSnapshotResponse = [Snapshot, google.pubsub.v1.ISnapshot]; -export type SeekCallback = RequestCallback; -export type SeekResponse = [google.pubsub.v1.ISnapshot]; +export type SeekCallback = RequestCallback; +export type SeekResponse = [google.pubsub.v1.ISeekResponse]; /** * A Snapshot object will give you access to your Cloud Pub/Sub snapshot. @@ -134,14 +134,14 @@ export class Snapshot { const reqOpts = { snapshot: this.name, }; - callback = callback || util.noop; + this.parent.request( { client: 'SubscriberClient', method: 'deleteSnapshot', reqOpts, }, - callback); + callback!); } /*@ @@ -193,18 +193,18 @@ export class Snapshot { * }); */ create( - gaxOpts?: CallOptions|CreateSnapshotCallback, + optsOrCallback?: CallOptions|CreateSnapshotCallback, callback?: CreateSnapshotCallback): void|Promise { if (!(this.parent instanceof Subscription)) { throw new Error( `This is only available if you accessed this object through Subscription#snapshot`); } - const options = typeof gaxOpts === 'function' ? {} : gaxOpts; - callback = typeof gaxOpts === 'function' ? gaxOpts : callback; + const options = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; return this.parent.createSnapshot( - this.name, gaxOpts! as CallOptions, (err, snapshot, resp) => { + this.name, options, (err, snapshot, resp) => { if (err) { callback!(err, null, resp); return; diff --git a/src/subscription.ts b/src/subscription.ts index fedbc10ce..858ed40ec 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -31,6 +31,8 @@ import {Subscriber, SubscriberOptions} from './subscriber'; import {Topic} from './topic'; import {noop} from './util'; +export type PushConfig = google.pubsub.v1.IPushConfig; + export type SubscriptionMetadata = { messageRetentionDuration?: google.protobuf.IDuration|number; pushEndpoint?: string; @@ -405,15 +407,13 @@ export class Subscription extends EventEmitter { * }); */ createSnapshot( - name: string, gaxOptsOrCallback?: CallOptions|CreateSnapshotCallback, + name: string, optsOrCallback?: CallOptions|CreateSnapshotCallback, callback?: CreateSnapshotCallback): void|Promise { if (!is.string(name)) { throw new Error('A name is required to create a snapshot.'); } - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const snapshot = this.snapshot(name); const reqOpts = { @@ -469,16 +469,11 @@ export class Subscription extends EventEmitter { * const apiResponse = data[0]; * }); */ - delete( - gaxOptsOrCallback?: CallOptions|EmptyCallback, - callback?: EmptyCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; - + delete(optsOrCallback?: CallOptions|EmptyCallback, callback?: EmptyCallback): + void|Promise { + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; - callback = callback || noop; const reqOpts = { subscription: this.name, }; @@ -588,15 +583,15 @@ export class Subscription extends EventEmitter { * const apiResponse = data[1]; * }); */ - get(gaxOptsOrCallback?: GetSubscriptionOptions|GetSubscriptionCallback, + get(optsOrCallback?: GetSubscriptionOptions|GetSubscriptionCallback, callback?: GetSubscriptionCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; + const autoCreate = !!gaxOpts.autoCreate && this.topic; delete gaxOpts.autoCreate; + this.getMetadata(gaxOpts, (err, apiResponse) => { if (!err) { callback!(null, this, apiResponse!); @@ -654,16 +649,16 @@ export class Subscription extends EventEmitter { * }); */ getMetadata( - gaxOptsOrCallback?: CallOptions|GetSubscriptionMetadataCallback, + optsOrCallback?: CallOptions|GetSubscriptionMetadataCallback, callback?: GetSubscriptionMetadataCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; + const reqOpts = { subscription: this.name, }; + this.request( { client: 'SubscriberClient', @@ -679,13 +674,11 @@ export class Subscription extends EventEmitter { }); } - modifyPushConfig(config: google.pubsub.v1.IPushConfig, gaxOpts?: CallOptions): + modifyPushConfig(config: PushConfig, gaxOpts?: CallOptions): Promise; + modifyPushConfig(config: PushConfig, callback: EmptyCallback): void; modifyPushConfig( - config: google.pubsub.v1.IPushConfig, callback: EmptyCallback): void; - modifyPushConfig( - config: google.pubsub.v1.IPushConfig, gaxOpts: CallOptions, - callback: EmptyCallback): void; + config: PushConfig, gaxOpts: CallOptions, callback: EmptyCallback): void; /** * @typedef {array} ModifyPushConfigResponse * @property {object} 0 The full API response. @@ -735,17 +728,16 @@ export class Subscription extends EventEmitter { * }); */ modifyPushConfig( - config: google.pubsub.v1.IPushConfig, - gaxOptsOrCallback?: CallOptions|EmptyCallback, + config: PushConfig, optsOrCallback?: CallOptions|EmptyCallback, callback?: EmptyCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; + const reqOpts = { subscription: this.name, pushConfig: config, }; + this.request( { client: 'SubscriberClient', @@ -825,12 +817,10 @@ export class Subscription extends EventEmitter { * subscription.seek(date, callback); */ seek( - snapshot: string|Date, gaxOptsOrCallback?: CallOptions|SeekCallback, + snapshot: string|Date, optsOrCallback?: CallOptions|SeekCallback, callback?: SeekCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const reqOpts: google.pubsub.v1.ISeekRequest = { subscription: this.name, @@ -900,13 +890,11 @@ export class Subscription extends EventEmitter { */ setMetadata( metadata: SubscriptionMetadata, - gaxOptsOrCallback?: CallOptions|SetSubscriptionMetadataCallback, + optsOrCallback?: CallOptions|SetSubscriptionMetadataCallback, callback?: SetSubscriptionMetadataCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const subscription = Subscription.formatMetadata_(metadata); const fields = Object.keys(subscription).map(snakeCase); diff --git a/src/topic.ts b/src/topic.ts index 4c943814c..5b42bacbe 100644 --- a/src/topic.ts +++ b/src/topic.ts @@ -171,12 +171,10 @@ export class Topic { * }); */ create( - gaxOptsOrCallback?: CallOptions|CreateTopicCallback, + optsOrCallback?: CallOptions|CreateTopicCallback, callback?: CreateTopicCallback): Promise|void { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; this.pubsub.createTopic(this.name, gaxOpts, callback!); } @@ -226,13 +224,11 @@ export class Topic { */ createSubscription( name: string, - optionsOrCallback?: CreateSubscriptionOptions|CreateSubscriptionCallback, + optsOrCallback?: CreateSubscriptionOptions|CreateSubscriptionCallback, callback?: CreateSubscriptionCallback): void|Promise { - const options = - typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; - callback = - typeof optionsOrCallback === 'function' ? optionsOrCallback : callback; + const options = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; this.pubsub.createSubscription( this, name, options as CreateSubscriptionOptions, callback!); @@ -268,18 +264,15 @@ export class Topic { * const apiResponse = data[0]; * }); */ - delete( - gaxOptsOrCallback?: CallOptions|EmptyCallback, - callback?: EmptyCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; - - callback = callback || util.noop; + delete(optsOrCallback?: CallOptions|EmptyCallback, callback?: EmptyCallback): + void|Promise { + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; + const reqOpts = { topic: this.name, }; + this.request( { client: 'PublisherClient', @@ -287,7 +280,7 @@ export class Topic { reqOpts, gaxOpts: gaxOpts as CallOptions, }, - callback); + callback!); } exists(): Promise; @@ -378,14 +371,14 @@ export class Topic { * const apiResponse = data[1]; * }); */ - get(gaxOptsOrCallback?: GetTopicOptions|GetTopicCallback, + get(optsOrCallback?: GetTopicOptions|GetTopicCallback, callback?: GetTopicCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; + const autoCreate = !!gaxOpts.autoCreate; delete gaxOpts.autoCreate; + this.getMetadata(gaxOpts, (err, apiResponse) => { if (!err) { callback!(null, this, apiResponse!); @@ -437,16 +430,16 @@ export class Topic { * }); */ getMetadata( - gaxOptsOrCallback?: CallOptions|GetTopicMetadataCallback, + optsOrCallback?: CallOptions|GetTopicMetadataCallback, callback?: GetTopicMetadataCallback): void|Promise { - const gaxOpts = - typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {}; - callback = - typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback; + const gaxOpts = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; + const reqOpts = { topic: this.name, }; + this.request( { client: 'PublisherClient', @@ -504,14 +497,11 @@ export class Topic { * }); */ getSubscriptions( - optionsOrCallback?: PageOptions|GetTopicSubscriptionsCallback, + optsOrCallback?: PageOptions|GetTopicSubscriptionsCallback, callback?: GetTopicSubscriptionsCallback): void|Promise { - const self = this; - const options = - typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; - callback = - typeof optionsOrCallback === 'function' ? optionsOrCallback : callback; + const options = typeof optsOrCallback === 'object' ? optsOrCallback : {}; + callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; const reqOpts: google.pubsub.v1.IListTopicSubscriptionsRequest = Object.assign( @@ -594,13 +584,10 @@ export class Topic { * topic.publish(data).then((messageId) => {}); */ publish( - data: Buffer, attributesOrCallback?: Attributes|PublishCallback, + data: Buffer, attrsOrCb?: Attributes|PublishCallback, callback?: PublishCallback): Promise|void { - const attributes = - typeof attributesOrCallback === 'object' ? attributesOrCallback : {}; - callback = typeof attributesOrCallback === 'function' ? - attributesOrCallback : - callback; + const attributes = typeof attrsOrCb === 'object' ? attrsOrCb : {}; + callback = typeof attrsOrCb === 'function' ? attrsOrCb : callback; return this.publisher.publish(data, attributes, callback!); } @@ -657,16 +644,13 @@ export class Topic { * topic.publishJSON(data).then((messageId) => {}); */ publishJSON( - json: object, attributesOrCallback?: Attributes|PublishCallback, + json: object, attrsOrCb?: Attributes|PublishCallback, callback?: PublishCallback): Promise|void { if (!is.object(json)) { throw new Error('First parameter should be an object.'); } - const attributes = - typeof attributesOrCallback === 'object' ? attributesOrCallback : {}; - callback = typeof attributesOrCallback === 'function' ? - attributesOrCallback : - callback; + const attributes = typeof attrsOrCb === 'object' ? attrsOrCb : {}; + callback = typeof attrsOrCb === 'function' ? attrsOrCb : callback; const data = Buffer.from(JSON.stringify(json)); return this.publish(data, attributes, callback!); diff --git a/test/snapshot.ts b/test/snapshot.ts index 1f6e5c84c..098da790e 100644 --- a/test/snapshot.ts +++ b/test/snapshot.ts @@ -233,14 +233,5 @@ describe('Snapshot', () => { snapshot.delete(done); }); - - it('should optionally accept a callback', done => { - sandbox.stub(util, 'noop').callsFake(done); - - snapshot.parent.request = (config: RequestConfig, callback: Function) => { - callback(); // the done fn - }; - snapshot.delete(); - }); }); }); diff --git a/test/subscription.ts b/test/subscription.ts index 61a860c89..eafcfcb65 100644 --- a/test/subscription.ts +++ b/test/subscription.ts @@ -491,15 +491,6 @@ describe('Subscription', () => { }; }); - it('should optionally accept a callback', done => { - sandbox.stub(util, 'noop').callsFake((err?, resp?) => { - assert.ifError(err); - assert.strictEqual(resp, apiResponse); - done(); - }); - subscription.delete(); - }); - it('should return the api response', done => { subscription.delete((err: Error, resp: google.protobuf.Empty) => { assert.ifError(err); diff --git a/test/topic.ts b/test/topic.ts index e8cd65330..abd8ad9c2 100644 --- a/test/topic.ts +++ b/test/topic.ts @@ -241,16 +241,6 @@ describe('Topic', () => { topic.delete(options, assert.ifError); }); - - it('should optionally accept a callback', done => { - topic.request = - (config: RequestConfig, - callback: RequestCallback) => { - assert.strictEqual(typeof callback, 'function'); - done(); - }; - topic.delete(); - }); }); describe('get', () => { From 4b62b70d467584d5ea5679bf6869fc74f5162562 Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Wed, 6 Mar 2019 15:48:19 -0500 Subject: [PATCH 2/2] import long module in generated types --- package.json | 4 ++-- proto/iam.d.ts | 1 + proto/pubsub.d.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 20b4c9559..4e592587d 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,8 @@ "prepare": "npm run compile", "pretest": "npm run compile", "proto": "npm run proto:pubsub", - "proto:pubsub": "pbjs -t static-module -w commonjs -p protos google/pubsub/v1/pubsub.proto | pbts -o proto/pubsub.d.ts -", - "proto:iam": "pbjs -t static-module -w commonjs -p protos google/iam/v1/iam_policy.proto | pbts -o proto/iam.d.ts -", + "proto:pubsub": "pbjs -t static-module -w commonjs -p protos google/pubsub/v1/pubsub.proto | pbts -i long -o proto/pubsub.d.ts -", + "proto:iam": "pbjs -t static-module -w commonjs -p protos google/iam/v1/iam_policy.proto | pbts -i long -o proto/iam.d.ts -", "proto-types": "mkdir -p proto && npm run proto:pubsub && npm run proto:iam", "docs-test": "linkinator docs -r --skip www.googleapis.com", "predocs-test": "npm run docs" diff --git a/proto/iam.d.ts b/proto/iam.d.ts index 92ecb2096..79818b502 100644 --- a/proto/iam.d.ts +++ b/proto/iam.d.ts @@ -1,4 +1,5 @@ import * as $protobuf from "protobufjs"; +import * as long from "long"; /** Namespace google. */ export namespace google { diff --git a/proto/pubsub.d.ts b/proto/pubsub.d.ts index 572388ae9..fe2ce1632 100644 --- a/proto/pubsub.d.ts +++ b/proto/pubsub.d.ts @@ -1,4 +1,5 @@ import * as $protobuf from "protobufjs"; +import * as long from "long"; /** Namespace google. */ export namespace google {