Skip to content

Commit

Permalink
refactor: clean up unused packages (#517)
Browse files Browse the repository at this point in the history
* refactor: clean up unused packages

* fix system test
  • Loading branch information
JustinBeckwith authored Mar 3, 2019
1 parent c0f3147 commit d5806be
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 83 deletions.
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion src/message-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions src/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
6 changes: 2 additions & 4 deletions src/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -697,7 +695,7 @@ export class PubSub {
});
}

getTopics(options: PageOptions): Promise<GetTopicsResponse>;
getTopics(options?: PageOptions): Promise<GetTopicsResponse>;
getTopics(callback: GetTopicsCallback): void;
getTopics(options: PageOptions, callback: GetTopicsCallback): void;
/**
Expand Down
7 changes: 3 additions & 4 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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;

Expand Down
6 changes: 2 additions & 4 deletions src/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down
61 changes: 21 additions & 40 deletions system-test/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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<Message>((resolve, reject) => {
subscription.on('error', reject);
subscription.once('message', resolve);
});
Expand All @@ -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<Topic>();
pubsub.getTopicsStream()
.on('error', done)
.on('data',
topic => {
Expand All @@ -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 => {
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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<Snapshot>();
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);
Expand Down
28 changes: 10 additions & 18 deletions test/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
},
Expand Down

0 comments on commit d5806be

Please sign in to comment.