diff --git a/README.md b/README.md index 676d57f59..1435b3bd7 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ ```javascript // Imports the Google Cloud client library -const PubSub = require('@google-cloud/pubsub'); +const {PubSub} = require('@google-cloud/pubsub'); // Your Google Cloud Platform project ID const projectId = 'YOUR_PROJECT_ID'; diff --git a/package.json b/package.json index 5ff40ccc1..cc975e58c 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "devDependencies": { "@google-cloud/nodejs-repo-tools": "^2.3.3", "@types/arrify": "^1.0.4", + "@types/async": "^2.0.50", "@types/extend": "^3.0.0", "@types/is": "0.0.20", "@types/mocha": "^5.2.5", diff --git a/samples/quickstart.js b/samples/quickstart.js index fbe203857..4ff6d2ef5 100755 --- a/samples/quickstart.js +++ b/samples/quickstart.js @@ -17,7 +17,7 @@ // [START pubsub_quickstart_create_topic] // Imports the Google Cloud client library -const PubSub = require('@google-cloud/pubsub'); +const {PubSub} = require('@google-cloud/pubsub'); // Your Google Cloud Platform project ID const projectId = 'YOUR_PROJECT_ID'; diff --git a/samples/subscriptions.js b/samples/subscriptions.js index b9ba89312..870027393 100755 --- a/samples/subscriptions.js +++ b/samples/subscriptions.js @@ -26,7 +26,7 @@ function listSubscriptions() { // [START pubsub_list_subscriptions] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -49,7 +49,7 @@ function listSubscriptions() { function listTopicSubscriptions(topicName) { // [START pubsub_list_topic_subscriptions] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -78,7 +78,7 @@ function listTopicSubscriptions(topicName) { function createSubscription(topicName, subscriptionName) { // [START pubsub_create_pull_subscription] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -111,7 +111,7 @@ function createFlowControlledSubscription( ) { // [START pubsub_subscriber_flow_settings] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -159,7 +159,7 @@ function createFlowControlledSubscription( function createPushSubscription(topicName, subscriptionName) { // [START pubsub_create_push_subscription] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -195,7 +195,7 @@ function createPushSubscription(topicName, subscriptionName) { function modifyPushConfig(topicName, subscriptionName) { // [START pubsub_update_push_configuration] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -228,7 +228,7 @@ function modifyPushConfig(topicName, subscriptionName) { function deleteSubscription(subscriptionName) { // [START pubsub_delete_subscription] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -253,7 +253,7 @@ function deleteSubscription(subscriptionName) { function getSubscription(subscriptionName) { // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -284,7 +284,7 @@ function listenForMessages(subscriptionName, timeout) { // [START pubsub_subscriber_async_pull] // [START pubsub_quickstart_subscriber] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -441,7 +441,7 @@ const outstandingMessages = {}; function listenForOrderedMessages(subscriptionName, timeout) { // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -504,7 +504,7 @@ function listenForOrderedMessages(subscriptionName, timeout) { function listenForErrors(subscriptionName, timeout) { // [START pubsub_subscriber_error_listener] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -547,7 +547,7 @@ function listenForErrors(subscriptionName, timeout) { function getSubscriptionPolicy(subscriptionName) { // [START pubsub_get_subscription_policy] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -574,7 +574,7 @@ function getSubscriptionPolicy(subscriptionName) { function setSubscriptionPolicy(subscriptionName) { // [START pubsub_set_subscription_policy] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -620,7 +620,7 @@ function setSubscriptionPolicy(subscriptionName) { function testSubscriptionPermissions(subscriptionName) { // [START pubsub_test_subscription_permissions] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); diff --git a/samples/system-test/quickstart.test.js b/samples/system-test/quickstart.test.js index 4166a1ac6..ee6d7453e 100644 --- a/samples/system-test/quickstart.test.js +++ b/samples/system-test/quickstart.test.js @@ -15,12 +15,12 @@ 'use strict'; -const proxyquire = require(`proxyquire`).noPreserveCache(); -const PubSub = proxyquire(`@google-cloud/pubsub`, {}); -const sinon = require(`sinon`); -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); -const uuid = require(`uuid`); +const proxyquire = require('proxyquire').noPreserveCache(); +const {PubSub} = proxyquire('@google-cloud/pubsub', {}); +const sinon = require('sinon'); +const test = require('ava'); +const tools = require('@google-cloud/nodejs-repo-tools'); +const uuid = require('uuid'); const projectId = process.env.GCLOUD_PROJECT; const pubsub = new PubSub({projectId}); @@ -61,6 +61,8 @@ test.cb(`should create a topic`, t => { }; proxyquire(`../quickstart`, { - '@google-cloud/pubsub': sinon.stub().returns(pubsubMock), + '@google-cloud/pubsub': { + PubSub: sinon.stub().returns(pubsubMock), + }, }); }); diff --git a/samples/system-test/subscriptions.test.js b/samples/system-test/subscriptions.test.js index 21c10e08c..c2ba45146 100644 --- a/samples/system-test/subscriptions.test.js +++ b/samples/system-test/subscriptions.test.js @@ -16,7 +16,7 @@ 'use strict'; const path = require(`path`); -const PubSub = require(`@google-cloud/pubsub`); +const {PubSub} = require('@google-cloud/pubsub'); const test = require(`ava`); const tools = require(`@google-cloud/nodejs-repo-tools`); const uuid = require(`uuid`); diff --git a/samples/system-test/topics.test.js b/samples/system-test/topics.test.js index 6ff68516e..413f52174 100644 --- a/samples/system-test/topics.test.js +++ b/samples/system-test/topics.test.js @@ -16,7 +16,7 @@ 'use strict'; const path = require(`path`); -const PubSub = require(`@google-cloud/pubsub`); +const {PubSub} = require('@google-cloud/pubsub'); const test = require(`ava`); const tools = require(`@google-cloud/nodejs-repo-tools`); const uuid = require(`uuid`); diff --git a/samples/topics.js b/samples/topics.js index 4dd70bec8..f4824d073 100755 --- a/samples/topics.js +++ b/samples/topics.js @@ -26,7 +26,7 @@ function listAllTopics() { // [START pubsub_list_topics] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -49,7 +49,7 @@ function listAllTopics() { function createTopic(topicName) { // [START pubsub_create_topic] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -75,7 +75,7 @@ function createTopic(topicName) { function deleteTopic(topicName) { // [START pubsub_delete_topic] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -102,7 +102,7 @@ function publishMessage(topicName, data) { // [START pubsub_publish] // [START pubsub_quickstart_publisher] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -133,7 +133,7 @@ function publishMessage(topicName, data) { function publishMessageWithCustomAttributes(topicName, data) { // [START pubsub_publish_custom_attributes] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -168,7 +168,7 @@ function publishMessageWithCustomAttributes(topicName, data) { function publishBatchedMessages(topicName, data, maxMessages, maxWaitTime) { // [START pubsub_publisher_batch_settings] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -216,7 +216,7 @@ function setPublishCounterValue(value) { function publishOrderedMessage(topicName, data) { // [START pubsub_publish_ordered_message] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -259,7 +259,7 @@ function publishOrderedMessage(topicName, data) { function getTopicPolicy(topicName) { // [START pubsub_get_topic_policy] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -286,7 +286,7 @@ function getTopicPolicy(topicName) { function setTopicPolicy(topicName) { // [START pubsub_set_topic_policy] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); @@ -329,7 +329,7 @@ function setTopicPolicy(topicName) { function testTopicPermissions(topicName) { // [START pubsub_test_topic_permissions] // Imports the Google Cloud client library - const PubSub = require(`@google-cloud/pubsub`); + const {PubSub} = require('@google-cloud/pubsub'); // Creates a client const pubsub = new PubSub(); diff --git a/smoke-test/publisher_smoke_test.ts b/smoke-test/publisher_smoke_test.ts index cae73093e..be3df5a3c 100644 --- a/smoke-test/publisher_smoke_test.ts +++ b/smoke-test/publisher_smoke_test.ts @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -'use strict'; - describe('PublisherSmokeTest', () => { if (!process.env.GCLOUD_PROJECT) { throw new Error('Usage: GCLOUD_PROJECT= node #{$0}'); diff --git a/src/connection-pool.ts b/src/connection-pool.ts index b840ea26d..471d96d72 100644 --- a/src/connection-pool.ts +++ b/src/connection-pool.ts @@ -61,7 +61,7 @@ const RETRY_CODES = [ * @param {number} [options.ackDeadline] The ack deadline to send when * creating a connection. */ -class ConnectionPool extends EventEmitter { +export class ConnectionPool extends EventEmitter { subscription; pubsub; connections; @@ -458,5 +458,3 @@ class ConnectionPool extends EventEmitter { return true; } } - -module.exports = ConnectionPool; diff --git a/src/histogram.ts b/src/histogram.ts index c1c1cfa95..6a058a25a 100644 --- a/src/histogram.ts +++ b/src/histogram.ts @@ -24,11 +24,11 @@ import * as extend from 'extend'; * @private * @class */ -class Histogram { +export class Histogram { options; data; length; - constructor(options) { + constructor(options?) { this.options = extend( { min: 10000, @@ -78,5 +78,3 @@ class Histogram { return this.options.min; } } - -module.exports = Histogram; diff --git a/src/iam.ts b/src/iam.ts index a8ef8342b..2c74842b0 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -18,8 +18,6 @@ * @module pubsub/iam */ -'use strict'; - import * as arrify from 'arrify'; import {promisifyAll} from '@google-cloud/promisify'; import * as is from 'is'; @@ -53,7 +51,7 @@ import * as is from 'is'; * @see [What is Cloud IAM?]{@link https://cloud.google.com/iam/} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -62,7 +60,7 @@ import * as is from 'is'; * const subscription = pubsub.subscription('my-subscription'); * // subscription.iam */ -class IAM { +export class IAM { Promise; pubsub; request; @@ -98,7 +96,7 @@ class IAM { * @see [Subscriptions: getIamPolicy API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/getIamPolicy} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -116,7 +114,7 @@ class IAM { * const apiResponse = data[1]; * }); */ - getPolicy(gaxOpts, callback) { + getPolicy(gaxOpts, callback?) { if (is.fn(gaxOpts)) { callback = gaxOpts; gaxOpts = null; @@ -164,7 +162,7 @@ class IAM { * @see [Policy]{@link https://cloud.google.com/pubsub/docs/reference/rest/Shared.Types/Policy} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -191,7 +189,7 @@ class IAM { * const apiResponse = data[1]; * }); */ - setPolicy(policy, gaxOpts, callback) { + setPolicy(policy, gaxOpts, callback?) { if (!is.object(policy)) { throw new Error('A policy object is required.'); } @@ -242,7 +240,7 @@ class IAM { * @see [Permissions Reference]{@link https://cloud.google.com/pubsub/access_control#permissions} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -284,7 +282,7 @@ class IAM { * const apiResponse = data[1]; * }); */ - testPermissions(permissions, gaxOpts, callback) { + testPermissions(permissions, gaxOpts, callback?) { if (!is.array(permissions) && !is.string(permissions)) { throw new Error('Permissions are required.'); } @@ -325,5 +323,3 @@ class IAM { * that a callback is omitted. */ promisifyAll(IAM); - -module.exports = IAM; diff --git a/src/index.ts b/src/index.ts index 925c859be..579f3f6ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -'use strict'; - import {replaceProjectIdToken} from '@google-cloud/projectify'; import {paginator} from '@google-cloud/paginator'; import {promisifyAll} from '@google-cloud/promisify'; @@ -28,9 +26,10 @@ import * as is from 'is'; const PKG = require('../../package.json'); const v1 = require('./v1'); -const Snapshot = require('./snapshot'); -const Subscription = require('./subscription'); -const Topic = require('./topic'); +import {Snapshot} from './snapshot'; +import {Subscription} from './subscription'; +import {Topic} from './topic'; +import { Readable } from 'stream'; /** * @type {string} - Project ID placeholder. @@ -78,7 +77,7 @@ const PROJECT_ID_PLACEHOLDER = '{{projectId}}'; * @param {ClientConfig} [options] Configuration options. * * @example Import the client library - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * * @example Create a client that uses Application Default Credentials (ADC): * const pubsub = new PubSub(); @@ -93,14 +92,16 @@ const PROJECT_ID_PLACEHOLDER = '{{projectId}}'; * region_tag:pubsub_quickstart_create_topic * Full quickstart example: */ -class PubSub { +export class PubSub { options; - isEmulator; + isEmulator: boolean; api; - auth; - projectId; - Promise; - constructor(options) { + auth: GoogleAuth; + projectId: string; + Promise?: PromiseConstructor; + getSubscriptionsStream = paginator.streamify('getSubscriptions') as () => Readable; + getSnapshotsStream = paginator.streamify('getSnapshots') as () => Readable; + constructor(options?) { options = options || {}; // Determine what scopes are needed. // It is the union of the scopes on both clients. @@ -189,7 +190,7 @@ class PubSub { * @returns {Promise} * * @example Subscribe to a topic. - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = 'messageCenter'; @@ -268,7 +269,7 @@ class PubSub { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * pubsub.createTopic('my-new-topic', function(err, topic, apiResponse) { @@ -285,7 +286,7 @@ class PubSub { * const apiResponse = data[1]; * }); */ - createTopic(name, gaxOpts, callback) { + createTopic(name, gaxOpts, callback?) { const topic = this.topic(name); const reqOpts = { name: topic.name, @@ -366,7 +367,7 @@ class PubSub { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * pubsub.getSnapshots(function(err, snapshots) { @@ -382,7 +383,7 @@ class PubSub { * const snapshots = data[0]; * }); */ - getSnapshots(options, callback) { + getSnapshots(options?, callback?) { const self = this; if (is.fn(options)) { callback = options; @@ -463,7 +464,7 @@ class PubSub { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * pubsub.getSubscriptions(function(err, subscriptions) { @@ -479,7 +480,7 @@ class PubSub { * const subscriptions = data[0]; * }); */ - getSubscriptions(options, callback) { + getSubscriptions(options, callback?) { const self = this; if (is.fn(options)) { callback = options; @@ -555,7 +556,7 @@ class PubSub { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * pubsub.getTopics(function(err, topics) { @@ -578,7 +579,7 @@ class PubSub { * const topics = data[0]; * }); */ - getTopics(options, callback) { + getTopics(options, callback?) { const self = this; if (is.fn(options)) { callback = options; @@ -639,7 +640,7 @@ class PubSub { callback(err); return; } - self.projectId = projectId; + self.projectId = projectId!; self.getClient_(config, callback); }); return; @@ -685,7 +686,7 @@ class PubSub { * @returns {Snapshot} A {@link Snapshot} instance. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const snapshot = pubsub.snapshot('my-snapshot'); @@ -719,7 +720,7 @@ class PubSub { * @returns {Subscription} A {@link Subscription} instance. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const subscription = pubsub.subscription('my-subscription'); @@ -734,7 +735,7 @@ class PubSub { * // message.publishTime = Timestamp when Pub/Sub received the message. * }); */ - subscription(name, options?) { + subscription(name: string, options?) { if (!name) { throw new Error('A name must be specified for a subscription.'); } @@ -749,16 +750,16 @@ class PubSub { * @returns {Topic} A {@link Topic} instance. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); */ - topic(name, options?) { + topic(name: string) { if (!name) { throw new Error('A name must be specified for a topic.'); } - return new Topic(this, name, options); + return new Topic(this, name); } } @@ -771,7 +772,7 @@ class PubSub { * @returns {ReadableStream} A readable stream of {@link Snapshot} instances. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * pubsub.getSnapshotsStream() @@ -792,7 +793,6 @@ class PubSub { * this.end(); * }); */ -(PubSub.prototype as any).getSnapshotsStream = paginator.streamify('getSnapshots'); /** * Get a list of the {@link Subscription} objects registered to all of @@ -804,7 +804,7 @@ class PubSub { * @returns {ReadableStream} A readable stream of {@link Subscription} instances. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * pubsub.getSubscriptionsStream() @@ -825,9 +825,6 @@ class PubSub { * this.end(); * }); */ -(PubSub.prototype as any).getSubscriptionsStream = paginator.streamify( - 'getSubscriptions' -); /** * Get a list of the {module:pubsub/topic} objects registered to your project as @@ -839,7 +836,7 @@ class PubSub { * @returns {ReadableStream} A readable stream of {@link Topic} instances. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * pubsub.getTopicsStream() @@ -877,6 +874,8 @@ promisifyAll(PubSub, { exclude: ['request', 'snapshot', 'subscription', 'topic'], }); +export {Subscription, Topic}; + /** * The default export of the `@google-cloud/pubsub` package is the * {@link PubSub} class. @@ -891,7 +890,7 @@ promisifyAll(PubSub, { * npm install --save @google-cloud/pubsub * * @example Import the client library - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * * @example Create a client that uses Application Default Credentials (ADC): * const pubsub = new PubSub(); @@ -906,7 +905,6 @@ promisifyAll(PubSub, { * region_tag:pubsub_quickstart_create_topic * Full quickstart example: */ -module.exports = PubSub; /** * @name PubSub.v1 diff --git a/src/publisher.ts b/src/publisher.ts index 39c66e40e..abc62ca2b 100644 --- a/src/publisher.ts +++ b/src/publisher.ts @@ -14,13 +14,12 @@ * limitations under the License. */ -'use strict'; - import * as arrify from 'arrify'; import {promisifyAll} from '@google-cloud/promisify'; const each = require('async-each'); import * as extend from 'extend'; import * as is from 'is'; +import { Topic } from './topic'; /** * A Publisher object allows you to publish messages to a specific topic. @@ -42,19 +41,19 @@ import * as is from 'is'; * here: https://googleapis.github.io/gax-nodejs/CallSettings.html. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); * const publisher = topic.publisher(); */ -class Publisher { +export class Publisher { Promise; topic; inventory_; settings; timeoutHandle_; - constructor(topic, options) { + constructor(topic: Topic, options) { if (topic.Promise) { this.Promise = topic.Promise; } @@ -118,7 +117,7 @@ class Publisher { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -149,7 +148,7 @@ class Publisher { * //- * publisher.publish(data).then((messageId) => {}); */ - publish(data, attributes, callback) { + publish(data, attributes, callback?) { if (!(data instanceof Buffer)) { throw new TypeError('Data must be in the form of a Buffer.'); } @@ -252,5 +251,3 @@ class Publisher { promisifyAll(Publisher, { singular: true, }); - -module.exports = Publisher; diff --git a/src/snapshot.ts b/src/snapshot.ts index 6b7fc88ff..5e46116c2 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -'use strict'; - import * as util from './util'; import {promisifyAll} from '@google-cloud/promisify'; import * as is from 'is'; @@ -84,12 +82,13 @@ import * as is from 'is'; * } * }); */ -class Snapshot { +export class Snapshot { parent; name; Promise; create; seek; + metadata; constructor(parent, name) { if (parent.Promise) { this.Promise = parent.Promise; @@ -213,5 +212,3 @@ class Snapshot { * that a callback is omitted. */ promisifyAll(Snapshot); - -module.exports = Snapshot; diff --git a/src/subscriber.ts b/src/subscriber.ts index 4ab422d1a..43d986298 100644 --- a/src/subscriber.ts +++ b/src/subscriber.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -'use strict'; - import * as arrify from 'arrify'; const chunk = require('lodash.chunk'); import * as util from './util'; @@ -26,8 +24,8 @@ import * as extend from 'extend'; import * as is from 'is'; import * as os from 'os'; -const ConnectionPool = require('./connection-pool'); -const Histogram = require('./histogram'); +import {ConnectionPool} from './connection-pool'; +import {Histogram} from './histogram'; /** * @type {number} - The maximum number of ackIds to be sent in acknowledge/modifyAckDeadline @@ -44,23 +42,23 @@ const MAX_ACK_IDS_PER_REQUEST = 3000; * * @param {object} options Configuration object. */ -class Subscriber extends EventEmitter { - histogram; - latency_; - connectionPool; - ackDeadline; - maxConnections; +export class Subscriber extends EventEmitter { + histogram: Histogram; + latency_: Histogram; + connectionPool: ConnectionPool|null; + ackDeadline: number; + maxConnections: number; inventory_; flowControl; batching; flushTimeoutHandle_; leaseTimeoutHandle_; - userClosed_; - isOpen; + userClosed_: boolean; + isOpen: boolean; messageListeners; writeToStreams_; request; - name; + name?: string; constructor(options) { super(); @@ -194,7 +192,7 @@ class Subscriber extends EventEmitter { * //- * Subscriber.close().then(() => {}); */ - close(callback) { + close(callback?) { this.userClosed_ = true; const inventory = this.inventory_; inventory.lease.length = inventory.bytes = 0; @@ -472,7 +470,7 @@ class Subscriber extends EventEmitter { writeTo_(connId, data) { const startTime = Date.now(); return new Promise((resolve, reject) => { - this.connectionPool.acquire(connId, (err, connection) => { + this.connectionPool!.acquire(connId, (err, connection) => { if (err) { reject(err); return; @@ -496,5 +494,3 @@ class Subscriber extends EventEmitter { * that a callback is omitted. */ promisifyAll(Subscriber); - -module.exports = Subscriber; diff --git a/src/subscription.ts b/src/subscription.ts index e2778ae16..8fb23eace 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -14,17 +14,16 @@ * limitations under the License. */ -'use strict'; - import * as util from './util'; import {promisifyAll} from '@google-cloud/promisify'; import * as extend from 'extend'; import * as is from 'is'; const snakeCase = require('lodash.snakecase'); -const IAM = require('./iam'); -const Snapshot = require('./snapshot'); -const Subscriber = require('./subscriber'); +import {IAM} from './iam'; +import {Snapshot} from './snapshot'; +import {Subscriber} from './subscriber'; +import { PubSub } from '.'; /** * A Subscription object will give you access to your Cloud Pub/Sub @@ -77,7 +76,7 @@ const Subscriber = require('./subscriber'); * connections to be used when sending and receiving messages. Default: 5. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * //- @@ -140,7 +139,13 @@ const Subscriber = require('./subscriber'); * // Remove the listener from receiving `message` events. * subscription.removeListener('message', onMessage); */ -class Subscription extends Subscriber { +export class Subscription extends Subscriber { + Promise?: PromiseConstructor; + pubsub: PubSub; + projectId: string; + create!: Function; + iam: IAM; + metadata; constructor(pubsub, name, options) { options = options || {}; super(options); @@ -212,7 +217,7 @@ class Subscription extends Subscriber { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -278,7 +283,7 @@ class Subscription extends Subscriber { * @param {object} callback.apiResponse Raw API response. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -293,7 +298,7 @@ class Subscription extends Subscriber { * const apiResponse = data[0]; * }); */ - delete(gaxOpts, callback) { + delete(gaxOpts, callback?) { if (is.fn(gaxOpts)) { callback = gaxOpts; gaxOpts = {}; @@ -334,7 +339,7 @@ class Subscription extends Subscriber { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -384,7 +389,7 @@ class Subscription extends Subscriber { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -439,7 +444,7 @@ class Subscription extends Subscriber { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -458,7 +463,7 @@ class Subscription extends Subscriber { * const apiResponse = data[0]; * }); */ - getMetadata(gaxOpts, callback?) { + getMetadata(gaxOpts?, callback?) { if (is.fn(gaxOpts)) { callback = gaxOpts; gaxOpts = {}; @@ -503,7 +508,7 @@ class Subscription extends Subscriber { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -645,7 +650,7 @@ class Subscription extends Subscriber { * const apiResponse = data[0]; * }); */ - setMetadata(metadata, gaxOpts, callback) { + setMetadata(metadata, gaxOpts?, callback?) { if (is.fn(gaxOpts)) { callback = gaxOpts; gaxOpts = {}; @@ -729,5 +734,3 @@ class Subscription extends Subscriber { promisifyAll(Subscription, { exclude: ['snapshot'], }); - -module.exports = Subscription; diff --git a/src/topic.ts b/src/topic.ts index 81fca0c61..973022190 100644 --- a/src/topic.ts +++ b/src/topic.ts @@ -14,16 +14,16 @@ * limitations under the License. */ -'use strict'; - import * as util from './util'; import {promisifyAll} from '@google-cloud/promisify'; import {paginator} from '@google-cloud/paginator'; import * as extend from 'extend'; import * as is from 'is'; -const IAM = require('./iam'); -const Publisher = require('./publisher'); +import {IAM} from './iam'; +import {Publisher} from './publisher'; +import { PubSub } from '.'; +import { Readable } from 'stream'; /** * A Topic object allows you to interact with a Cloud Pub/Sub topic. @@ -33,20 +33,21 @@ const Publisher = require('./publisher'); * @param {string} name Name of the topic. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); */ -class Topic { - Promise; - name; +export class Topic { + Promise?: PromiseConstructor; + name: string; parent; - pubsub; + pubsub: PubSub; request; - iam; + iam: IAM; metadata; - constructor(pubsub, name) { + getSubscriptionsStream = paginator.streamify('getSubscriptions') as () => Readable; + constructor(pubsub: PubSub, name: string) { if (pubsub.Promise) { this.Promise = pubsub.Promise; } @@ -88,7 +89,7 @@ class Topic { * @see [What is Cloud IAM?]{@link https://cloud.google.com/iam/} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -119,7 +120,7 @@ class Topic { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -138,7 +139,7 @@ class Topic { * const apiResponse = data[1]; * }); */ - create(gaxOpts, callback) { + create(gaxOpts, callback?) { this.pubsub.createTopic(this.name, gaxOpts, callback); } /** @@ -155,7 +156,7 @@ class Topic { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -177,7 +178,7 @@ class Topic { * const apiResponse = data[1]; * }); */ - createSubscription(name, options, callback) { + createSubscription(name, options, callback?) { this.pubsub.createSubscription(this, name, options, callback); } /** @@ -193,7 +194,7 @@ class Topic { * @param {object} callback.apiResponse Raw API response. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -207,7 +208,7 @@ class Topic { * const apiResponse = data[0]; * }); */ - delete(gaxOpts, callback) { + delete(gaxOpts, callback?) { if (is.fn(gaxOpts)) { callback = gaxOpts; gaxOpts = {}; @@ -242,7 +243,7 @@ class Topic { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -291,7 +292,7 @@ class Topic { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -347,7 +348,7 @@ class Topic { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -398,7 +399,7 @@ class Topic { * @returns {Promise} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -419,7 +420,7 @@ class Topic { * const subscriptions = data[0]; * }); */ - getSubscriptions(options, callback) { + getSubscriptions(options, callback?) { const self = this; if (is.fn(options)) { callback = options; @@ -473,7 +474,7 @@ class Topic { * @return {Publisher} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -485,7 +486,7 @@ class Topic { * } * }); */ - publisher(options) { + publisher(options?) { return new Publisher(this, options); } /** @@ -511,7 +512,7 @@ class Topic { * @return {Subscription} * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -540,7 +541,7 @@ class Topic { * * @return {string} */ - static formatName_(projectId, name) { + static formatName_(projectId: string, name: string) { // Simple check if the name is already formatted. if (name.indexOf('/') > -1) { return name; @@ -559,7 +560,7 @@ class Topic { * @returns {ReadableStream} A readable stream of {@link Subscription} instances. * * @example - * const PubSub = require('@google-cloud/pubsub'); + * const {PubSub} = require('@google-cloud/pubsub'); * const pubsub = new PubSub(); * * const topic = pubsub.topic('my-topic'); @@ -582,9 +583,6 @@ class Topic { * this.end(); * }); */ -(Topic.prototype as any).getSubscriptionsStream = paginator.streamify( - 'getSubscriptions' -); /*! Developer Documentation * @@ -600,5 +598,3 @@ paginator.extend(Topic, ['getSubscriptions']); promisifyAll(Topic, { exclude: ['publisher', 'subscription'], }); - -module.exports = Topic; diff --git a/system-test/pubsub.ts b/system-test/pubsub.ts index 89439fd9a..b28d458c3 100644 --- a/system-test/pubsub.ts +++ b/system-test/pubsub.ts @@ -14,14 +14,11 @@ * limitations under the License. */ -'use strict'; - import * as assert from 'assert'; -const async = require('async'); -const Subscription = require('../src/subscription.js'); +import * as async from 'async'; import * as uuid from 'uuid'; +import {PubSub, Subscription} from '../src'; -const PubSub = require('../src'); const pubsub = new PubSub(); describe('pubsub', function() { @@ -135,9 +132,11 @@ describe('pubsub', function() { }); it('should list topics in a stream', function(done) { + // tslint:disable-next-line no-any const topicsEmitted: any[] = []; - pubsub + // tslint:disable-next-line no-any + (pubsub as any) .getTopicsStream() .on('error', done) .on('data', function(topic) { @@ -332,6 +331,7 @@ describe('pubsub', function() { it('should list all topic subscriptions as a stream', function(done) { const subscriptionsEmitted: {}[] = []; + // tslint:disable-next-line no-any topic .getSubscriptionsStream() .on('error', done) @@ -605,7 +605,8 @@ describe('pubsub', function() { let snapshot; function deleteAllSnapshots() { - return pubsub.getSnapshots().then(function(data) { + // tslint:disable-next-line no-any + return (pubsub.getSnapshots() as any).then(function(data) { return Promise.all( data[0].map(function(snapshot) { return snapshot.delete(); diff --git a/test/connection-pool.ts b/test/connection-pool.ts index 6d450e8cd..67c1cf482 100644 --- a/test/connection-pool.ts +++ b/test/connection-pool.ts @@ -120,7 +120,7 @@ describe('ConnectionPool', function() { }, duplexify: fakeDuplexify, uuid: fakeUuid, - }); + }).ConnectionPool; }); beforeEach(function() { @@ -1028,25 +1028,28 @@ describe('ConnectionPool', function() { describe('getClient', function() { const fakeCreds = {}; - function FakeSubscriber(address, creds, options) { - this.address = address; - this.creds = creds; - this.options = options; - this.closed = false; + class FakeSubscriber { + address; + creds; + options; + closed; + constructor(address, creds, options) { + this.address = address; + this.creds = creds; + this.options = options; + this.closed = false; + } + streamingPull() { + return fakeConnection; + } + getChannel() { + return fakeChannel; + } + close() { + this.closed = true; + } } - FakeSubscriber.prototype.streamingPull = function() { - return fakeConnection; - }; - - FakeSubscriber.prototype.getChannel = function() { - return fakeChannel; - }; - - FakeSubscriber.prototype.close = function() { - this.closed = true; - }; - const fakeClient = new FakeSubscriber('fake-address', fakeCreds, {}); beforeEach(function() { diff --git a/test/gapic-v1.ts b/test/gapic-v1.ts index 513fd15c4..b5db87268 100644 --- a/test/gapic-v1.ts +++ b/test/gapic-v1.ts @@ -12,10 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -'use strict'; - import * as assert from 'assert'; -const through2 = require('through2'); +import * as through2 from 'through2'; const pubsubModule = require('../src'); diff --git a/test/histogram.ts b/test/histogram.ts index 11e48ba29..e72ad2f85 100644 --- a/test/histogram.ts +++ b/test/histogram.ts @@ -14,11 +14,8 @@ * limitations under the License. */ -'use strict'; - import * as assert from 'assert'; - -const Histogram = require('../src/histogram.js'); +import {Histogram} from '../src/histogram.js'; describe('Histogram', function() { let histogram; diff --git a/test/iam.ts b/test/iam.ts index 8d69a9aba..b1c4c6129 100644 --- a/test/iam.ts +++ b/test/iam.ts @@ -14,13 +14,11 @@ * limitations under the License. */ -'use strict'; - import * as assert from 'assert'; import * as extend from 'extend'; -const proxyquire = require('proxyquire'); +import * as proxyquire from 'proxyquire'; import * as util from '../src/util'; -const promisify = require('@google-cloud/promisify'); +import * as promisify from '@google-cloud/promisify'; let promisified = false; const fakePromisify = extend({}, promisify, { @@ -45,7 +43,7 @@ describe('IAM', function() { before(function() { IAM = proxyquire('../src/iam.js', { '@google-cloud/promisify': fakePromisify, - }); + }).IAM; }); beforeEach(function() { diff --git a/test/index.ts b/test/index.ts index 10da3385f..476cc3c2a 100644 --- a/test/index.ts +++ b/test/index.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -'use strict'; - import * as arrify from 'arrify'; import * as assert from 'assert'; import * as extend from 'extend'; @@ -24,6 +22,7 @@ import * as proxyquire from 'proxyquire'; import * as util from '../src/util'; import * as pjy from '@google-cloud/projectify'; import * as promisify from '@google-cloud/promisify'; +import * as subby from '../src/subscription'; const PKG = require('../../package.json'); @@ -43,7 +42,7 @@ const fakeGoogleGax = { }, }; -const SubscriptionCached = require('../src/subscription'); +const SubscriptionCached = subby.Subscription; let SubscriptionOverride; function Subscription(a, b, c) { @@ -70,15 +69,22 @@ const fakePromisify = extend({}, promisify, { let pjyOverride; function fakePjy() { - return (pjyOverride || pjy.replaceProjectIdToken).apply(this, arguments); + return (pjyOverride || pjy.replaceProjectIdToken).apply(null, arguments); } -function FakeSnapshot() { - this.calledWith_ = arguments; +class FakeSnapshot { + calledWith_: IArguments; + constructor() { + this.calledWith_ = arguments; + } } -function FakeTopic() { - this.calledWith_ = arguments; +class FakeTopic { + calledWith_: IArguments; + getSubscriptions?: Function; + constructor() { + this.calledWith_ = arguments; + } } let extended = false; @@ -151,11 +157,11 @@ describe('PubSub', function() { GoogleAuth: fakeGoogleAuth, }, 'google-gax': fakeGoogleGax, - './snapshot': FakeSnapshot, - './subscription': Subscription, - './topic': FakeTopic, + './snapshot': {Snapshot: FakeSnapshot}, + './subscription': {Subscription: Subscription}, + './topic': {Topic: FakeTopic}, './v1': v1Override, - }); + }).PubSub; }); after(function() { diff --git a/test/publisher.ts b/test/publisher.ts index 16d0e8b60..173b1164e 100644 --- a/test/publisher.ts +++ b/test/publisher.ts @@ -14,13 +14,11 @@ * limitations under the License. */ -'use strict'; - import * as assert from 'assert'; import * as util from '../src/util'; -const pfy = require('@google-cloud/promisify'); +import * as pfy from '@google-cloud/promisify'; import * as extend from 'extend'; -const proxyquire = require('proxyquire'); +import * as proxyquire from 'proxyquire'; let promisified = false; const fakePromisify = extend({}, pfy, { @@ -47,7 +45,7 @@ describe('Publisher', function() { before(function() { Publisher = proxyquire('../src/publisher.js', { '@google-cloud/promisify': fakePromisify, - }); + }).Publisher; }); beforeEach(function() { diff --git a/test/snapshot.ts b/test/snapshot.ts index 50ad5064d..d15a44d64 100644 --- a/test/snapshot.ts +++ b/test/snapshot.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -'use strict'; - import * as assert from 'assert'; import * as util from '../src/util'; import * as extend from 'extend'; @@ -55,7 +53,7 @@ describe('Snapshot', function() { before(function() { Snapshot = proxyquire('../src/snapshot', { '@google-cloud/promisify': fakePromisify, - }); + }).Snapshot; }); const sandbox = sinon.createSandbox(); diff --git a/test/subscriber.ts b/test/subscriber.ts index 03be3fdde..25e28075f 100644 --- a/test/subscriber.ts +++ b/test/subscriber.ts @@ -14,16 +14,14 @@ * limitations under the License. */ -'use strict'; - import * as assert from 'assert'; const delay = require('delay'); import {EventEmitter} from 'events'; import * as extend from 'extend'; import * as is from 'is'; -const proxyquire = require('proxyquire'); +import * as proxyquire from 'proxyquire'; import * as util from '../src/util'; -const pfy = require('@google-cloud/promisify'); +import * as pfy from '@google-cloud/promisify'; const fakeUtil = extend({}, util); @@ -54,8 +52,11 @@ class FakeConnectionPool extends EventEmitter { } } -function FakeHistogram() { - this.calledWith_ = [].slice.call(arguments); +class FakeHistogram { + calledWith_: IArguments; + constructor() { + this.calledWith_ = [].slice.call(arguments); + } } let delayOverride: any = null; @@ -79,9 +80,9 @@ describe('Subscriber', function() { }, delay: fakeDelay, os: fakeOs, - './connection-pool.js': FakeConnectionPool, - './histogram.js': FakeHistogram, - }); + './connection-pool.js': {ConnectionPool: FakeConnectionPool}, + './histogram.js': {Histogram: FakeHistogram}, + }).Subscriber; }); beforeEach(function() { diff --git a/test/subscription.ts b/test/subscription.ts index 37b5d082c..e74742b5f 100644 --- a/test/subscription.ts +++ b/test/subscription.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -'use strict'; - import * as assert from 'assert'; import * as util from '../src/util'; import * as extend from 'extend'; @@ -34,8 +32,11 @@ const fakePromisify = extend({}, pfy, { }, }); -function FakeIAM() { - this.calledWith_ = [].slice.call(arguments); +class FakeIAM { + calledWith_: IArguments; + constructor() { + this.calledWith_ = [].slice.call(arguments); + } } class FakeSnapshot { @@ -46,8 +47,11 @@ class FakeSnapshot { } } -function FakeSubscriber() { - this.calledWith_ = [].slice.call(arguments); +class FakeSubscriber { + calledWith_: IArguments; + constructor() { + this.calledWith_ = [].slice.call(arguments); + } } describe('Subscription', function() { @@ -70,10 +74,10 @@ describe('Subscription', function() { before(function() { Subscription = proxyquire('../src/subscription.js', { '@google-cloud/promisify': fakePromisify, - './iam.js': FakeIAM, - './snapshot.js': FakeSnapshot, - './subscriber.js': FakeSubscriber, - }); + './iam.js': {IAM: FakeIAM}, + './snapshot.js': {Snapshot: FakeSnapshot}, + './subscriber.js': {Subscriber: FakeSubscriber}, + }).Subscription; }); const sandbox = sinon.createSandbox(); diff --git a/test/topic.ts b/test/topic.ts index 652d06224..1d5cecff1 100644 --- a/test/topic.ts +++ b/test/topic.ts @@ -14,9 +14,7 @@ * limitations under the License. */ -'use strict'; - -import * as assert from 'assert'; + import * as assert from 'assert'; import * as extend from 'extend'; import * as proxyquire from 'proxyquire'; import * as util from '../src/util'; @@ -34,12 +32,18 @@ const fakePromisify = extend({}, pfy, { }, }); -function FakeIAM() { - this.calledWith_ = [].slice.call(arguments); +class FakeIAM { + calledWith_: IArguments; + constructor() { + this.calledWith_ = [].slice.call(arguments); + } } -function FakePublisher() { - this.calledWith_ = [].slice.call(arguments); +class FakePublisher { + calledWith_: IArguments; + constructor() { + this.calledWith_ = [].slice.call(arguments); + } } let extended = false; @@ -81,9 +85,9 @@ describe('Topic', function() { '@google-cloud/paginator': { paginator: fakePaginator, }, - './iam': FakeIAM, - './publisher': FakePublisher, - }); + './iam': {IAM: FakeIAM}, + './publisher': {Publisher: FakePublisher}, + }).Topic; }); const sandbox = sinon.createSandbox(); diff --git a/tsconfig.json b/tsconfig.json index 2f66e4d86..628b6455f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,8 +3,7 @@ "compilerOptions": { "rootDir": ".", "outDir": "build", - "noImplicitAny": false, - "noImplicitThis": false + "noImplicitAny": false }, "include": [ "src/*.ts",