diff --git a/package.json b/package.json index 7df205eca..2f8d2d5fa 100644 --- a/package.json +++ b/package.json @@ -56,28 +56,22 @@ "@google-cloud/precise-date": "^0.1.0", "@google-cloud/projectify": "^0.3.0", "@google-cloud/promisify": "^0.4.0", + "@sindresorhus/is": "^0.15.0", "arrify": "^1.0.0", "async-each": "^1.0.1", - "delay": "^4.0.0", - "duplexify": "^4.0.0", "extend": "^3.0.1", "google-auth-library": "^3.0.0", "google-gax": "^0.25.0", - "is": "^3.0.1", "is-stream-ended": "^0.1.4", - "lodash.chunk": "^4.2.0", "lodash.merge": "^4.6.0", "lodash.snakecase": "^4.1.1", "p-defer": "^1.0.0", - "protobufjs": "^6.8.1", - "through2": "^3.0.0" + "protobufjs": "^6.8.1" }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.0.0", "@types/arrify": "^1.0.4", - "@types/duplexify": "^3.6.0", "@types/extend": "^3.0.0", - "@types/is": "0.0.21", "@types/mocha": "^5.2.5", "@types/p-defer": "^1.0.3", "@types/proxyquire": "^1.3.28", @@ -100,6 +94,7 @@ "proxyquire": "^2.0.0", "sinon": "^7.1.1", "source-map-support": "^0.5.9", + "through2": "^3.0.0", "typescript": "~3.3.0", "uuid": "^3.1.0", "linkinator": "^1.1.2" diff --git a/src/iam.ts b/src/iam.ts index b9bef871f..a797bf003 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -100,8 +100,7 @@ export class IAM { this.Promise = pubsub.Promise; } this.pubsub = pubsub; - // tslint:disable-next-line no-any - this.request = pubsub.request.bind(pubsub) as any; + this.request = pubsub.request.bind(pubsub); this.id = id; } diff --git a/src/message-stream.ts b/src/message-stream.ts index 96cfa4d4a..c52400a35 100644 --- a/src/message-stream.ts +++ b/src/message-stream.ts @@ -15,7 +15,6 @@ */ import {promisify} from '@google-cloud/promisify'; -import {Gaxios} from 'gaxios'; import {ClientStub} from 'google-gax'; import {ClientDuplexStream, Metadata, ServiceError, status, StatusObject} from 'grpc'; import * as isStreamEnded from 'is-stream-ended'; diff --git a/src/publisher.ts b/src/publisher.ts index bdeecd072..7e2a1fd57 100644 --- a/src/publisher.ts +++ b/src/publisher.ts @@ -21,10 +21,9 @@ import {google} from '../proto/pubsub'; const each = require('async-each'); import * as extend from 'extend'; -import * as is from 'is'; +import is from '@sindresorhus/is'; import {Topic} from './topic'; import {RequestCallback} from './pubsub'; -import {ServiceError} from 'grpc'; interface Inventory { callbacks: PublishCallback[]; diff --git a/src/pubsub.ts b/src/pubsub.ts index 136134aac..ffc87b5b8 100644 --- a/src/pubsub.ts +++ b/src/pubsub.ts @@ -18,10 +18,10 @@ import {paginator} from '@google-cloud/paginator'; import {replaceProjectIdToken} from '@google-cloud/projectify'; import {promisifyAll} from '@google-cloud/promisify'; +import is from '@sindresorhus/is'; import * as extend from 'extend'; import {GoogleAuth} from 'google-auth-library'; import * as gax from 'google-gax'; -import * as is from 'is'; const PKG = require('../../package.json'); const v1 = require('./v1'); @@ -34,8 +34,6 @@ import {CallOptions} from 'google-gax'; import {Transform} from 'stream'; import {google} from '../proto/pubsub'; import {ServiceError, ChannelCredentials} from 'grpc'; -import {FlowControlOptions} from './lease-manager'; -import {BatchPublishOptions} from './publisher'; const opts = {} as gax.GrpcClientOptions; const {grpc} = new gax.GrpcClient(opts); @@ -697,7 +695,7 @@ export class PubSub { }); } - getTopics(options: PageOptions): Promise; + getTopics(options?: PageOptions): Promise; getTopics(callback: GetTopicsCallback): void; getTopics(options: PageOptions, callback: GetTopicsCallback): void; /** diff --git a/src/subscription.ts b/src/subscription.ts index 838e38e35..0b0e4d325 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -15,10 +15,10 @@ */ import {promisifyAll} from '@google-cloud/promisify'; +import is from '@sindresorhus/is'; import {EventEmitter} from 'events'; import * as extend from 'extend'; import {CallOptions} from 'google-gax'; -import * as is from 'is'; import * as snakeCase from 'lodash.snakecase'; import {google} from '../proto/pubsub'; @@ -27,7 +27,7 @@ import {IAM} from './iam'; import {FlowControlOptions} from './lease-manager'; import {EmptyCallback, EmptyResponse, ExistsCallback, ExistsResponse, Omit, PubSub, RequestCallback, ResourceCallback} from './pubsub'; import {CreateSnapshotCallback, CreateSnapshotResponse, SeekCallback, SeekResponse, Snapshot} from './snapshot'; -import {Message, Subscriber, SubscriberOptions} from './subscriber'; +import {Subscriber, SubscriberOptions} from './subscriber'; import {Topic} from './topic'; import {noop} from './util'; @@ -202,8 +202,7 @@ export class Subscription extends EventEmitter { options = options || {}; this.pubsub = pubsub; - // tslint:disable-next-line no-any - this.request = pubsub.request.bind(pubsub) as any; + this.request = pubsub.request.bind(pubsub); this.name = Subscription.formatName_(this.projectId, name); this.topic = options.topic; diff --git a/src/topic.ts b/src/topic.ts index 9f625b9b1..bd5277d56 100644 --- a/src/topic.ts +++ b/src/topic.ts @@ -16,9 +16,8 @@ import {paginator} from '@google-cloud/paginator'; import {promisifyAll} from '@google-cloud/promisify'; +import is from '@sindresorhus/is'; import {CallOptions} from 'google-gax'; -import * as is from 'is'; -import {Readable} from 'stream'; import {google} from '../proto/pubsub'; @@ -95,8 +94,7 @@ export class Topic { * @type {PubSub} */ this.parent = this.pubsub = pubsub; - // tslint:disable-next-line no-any - this.request = pubsub.request.bind(pubsub) as any; + this.request = pubsub.request.bind(pubsub); /** * [IAM (Identity and Access * Management)](https://cloud.google.com/pubsub/access_control) allows you diff --git a/system-test/pubsub.ts b/system-test/pubsub.ts index 5b75e3a79..742b0f16a 100644 --- a/system-test/pubsub.ts +++ b/system-test/pubsub.ts @@ -17,7 +17,8 @@ import * as assert from 'assert'; import * as defer from 'p-defer'; import * as uuid from 'uuid'; -import {PubSub, Subscription, Topic} from '../src'; + +import {Message, PubSub, Snapshot, Subscription, Topic} from '../src'; const pubsub = new PubSub(); @@ -60,7 +61,7 @@ describe('pubsub', () => { for (let i = 0; i < 6; i++) { await topic.publish(Buffer.from(message), options); } - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { subscription.on('error', reject); subscription.once('message', resolve); }); @@ -77,28 +78,19 @@ describe('pubsub', () => { }); describe('Topic', () => { - it('should be listed', done => { - pubsub.getTopics((err, topics) => { - assert.ifError(err); - - const results = topics!.filter(topic => { - const name = getTopicName(topic); - return TOPIC_FULL_NAMES.indexOf(name) !== -1; - }); - - // get all topics in list of known names - assert.strictEqual(results.length, TOPIC_NAMES.length); - done(); + it('should be listed', async () => { + const [topics] = await pubsub.getTopics(); + const results = topics.filter(topic => { + const name = getTopicName(topic); + return TOPIC_FULL_NAMES.indexOf(name) !== -1; }); + // get all topics in list of known names + assert.strictEqual(results.length, TOPIC_NAMES.length); }); it('should list topics in a stream', done => { - // tslint:disable-next-line no-any - const topicsEmitted: any[] = []; - - // tslint:disable-next-line no-any - (pubsub as any) - .getTopicsStream() + const topicsEmitted = new Array(); + pubsub.getTopicsStream() .on('error', done) .on('data', topic => { @@ -115,17 +107,12 @@ describe('pubsub', () => { }); }); - it('should allow manual paging', done => { - pubsub.getTopics( - { - pageSize: TOPIC_NAMES.length - 1, - gaxOpts: {autoPaginate: false}, - }, - (err, topics) => { - assert.ifError(err); - assert.strictEqual(topics!.length, TOPIC_NAMES.length - 1); - done(); - }); + it('should allow manual paging', async () => { + const [topics] = await pubsub.getTopics({ + pageSize: TOPIC_NAMES.length - 1, + gaxOpts: {autoPaginate: false}, + }); + assert.strictEqual(topics.length, TOPIC_NAMES.length - 1); }); it('should be created and deleted', done => { @@ -178,8 +165,7 @@ describe('pubsub', () => { const attrs = { customAttribute: 'value', }; - // tslint:disable-next-line no-any - const message: any = await publishPop(data, attrs); + const message = await publishPop(data, attrs); assert.deepStrictEqual(message.data, data); assert.deepStrictEqual(message.attributes, attrs); }); @@ -610,15 +596,10 @@ describe('pubsub', () => { }); it('should get a list of snapshots as a stream', done => { - // tslint:disable-next-line no-any - const snapshots: any[] = []; - + const snapshots = new Array(); pubsub.getSnapshotsStream() .on('error', done) - .on('data', - snapshot => { - snapshots.push(snapshot); - }) + .on('data', snapshot => snapshots.push(snapshot)) .on('end', () => { assert(snapshots.length > 0); const names = snapshots.map(getSnapshotName); diff --git a/test/topic.ts b/test/topic.ts index b35f4919a..e8cd65330 100644 --- a/test/topic.ts +++ b/test/topic.ts @@ -23,8 +23,8 @@ import * as sinon from 'sinon'; import {google} from '../proto/pubsub'; import {ExistsCallback, RequestCallback, RequestConfig} from '../src/pubsub'; -import {CreateSubscriptionCallback, CreateSubscriptionOptions, Subscription, SubscriptionOptions} from '../src/subscription'; -import {CreateTopicCallback, GetTopicMetadataCallback, Topic} from '../src/topic'; +import {CreateSubscriptionOptions, Subscription, SubscriptionOptions} from '../src/subscription'; +import {GetTopicMetadataCallback, Topic} from '../src/topic'; import * as util from '../src/util'; let promisified = false; @@ -41,26 +41,20 @@ const fakePromisify = Object.assign({}, pfy, { }); class FakeIAM { - // tslint:disable-next-line no-any - calledWith_: any[]; - // tslint:disable-next-line no-any - constructor(...args: any[]) { + calledWith_: Array<{}>; + constructor(...args: Array<{}>) { this.calledWith_ = args; } } class FakePublisher { - // tslint:disable-next-line no-any - calledWith_: any[]; - // tslint:disable-next-line no-any - published_!: any[]; + calledWith_: Array<{}>; + published_!: Array<{}>; options_!: object; - // tslint:disable-next-line no-any - constructor(...args: any[]) { + constructor(...args: Array<{}>) { this.calledWith_ = args; } - // tslint:disable-next-line no-any - publish(...args: any[]) { + publish(...args: Array<{}>) { this.published_ = args; } setOptions(options: object) { @@ -70,12 +64,10 @@ class FakePublisher { let extended = false; const fakePaginator = { - // tslint:disable-next-line variable-name - extend(Class: Function, methods: string[]) { - if (Class.name !== 'Topic') { + extend(klass: Function, methods: string[]) { + if (klass.name !== 'Topic') { return; } - assert.deepStrictEqual(methods, ['getSubscriptions']); extended = true; },