Skip to content

Commit c42f8c0

Browse files
chore: use split common modules (#200)
1 parent bd21911 commit c42f8c0

19 files changed

Lines changed: 150 additions & 139 deletions

handwritten/pubsub/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ out/
77
system-test/secrets.js
88
system-test/*key.json
99
*.lock
10+
.vscode

handwritten/pubsub/package-lock.json

Lines changed: 32 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

handwritten/pubsub/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
},
6666
"dependencies": {
6767
"@google-cloud/common": "^0.20.0",
68+
"@google-cloud/paginator": "^0.1.0",
69+
"@google-cloud/projectify": "^0.3.0",
70+
"@google-cloud/promisify": "^0.3.0",
6871
"arrify": "^1.0.0",
6972
"async-each": "^1.0.1",
7073
"delay": "^3.0.0",

handwritten/pubsub/src/connection-pool.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'use strict';
1818

1919
var common = require('@google-cloud/common');
20+
const {replaceProjectIdToken} = require('@google-cloud/projectify');
2021
var duplexify = require('duplexify');
2122
var each = require('async-each');
2223
var events = require('events');
@@ -233,7 +234,7 @@ ConnectionPool.prototype.createConnection = function() {
233234
.on('error', onConnectionError)
234235
.on('data', onConnectionData)
235236
.write({
236-
subscription: common.util.replaceProjectIdToken(
237+
subscription: replaceProjectIdToken(
237238
self.subscription.name,
238239
self.pubsub.projectId
239240
),

handwritten/pubsub/src/iam.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'use strict';
2222

2323
var arrify = require('arrify');
24-
var common = require('@google-cloud/common');
24+
const {promisifyAll} = require('@google-cloud/promisify');
2525
var is = require('is');
2626

2727
/**
@@ -332,6 +332,6 @@ IAM.prototype.testPermissions = function(permissions, gaxOpts, callback) {
332332
* All async methods (except for streams) will return a Promise in the event
333333
* that a callback is omitted.
334334
*/
335-
common.util.promisifyAll(IAM);
335+
promisifyAll(IAM);
336336

337337
module.exports = IAM;

handwritten/pubsub/src/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
'use strict';
1818

19-
var common = require('@google-cloud/common');
19+
const {replaceProjectIdToken} = require('@google-cloud/projectify');
20+
const {paginator} = require('@google-cloud/paginator');
21+
const {promisifyAll} = require('@google-cloud/promisify');
2022
var extend = require('extend');
2123
var {GoogleAuth} = require('google-auth-library');
2224
var gax = require('google-gax');
23-
var grpc = new gax.GrpcClient().grpc;
25+
var {grpc} = new gax.GrpcClient();
2426
var is = require('is');
2527

2628
var PKG = require('../package.json');
@@ -97,7 +99,7 @@ function PubSub(options) {
9799
return new PubSub(options);
98100
}
99101

100-
options = common.util.normalizeArguments(this, options);
102+
options = options || {};
101103

102104
// Determine what scopes are needed.
103105
// It is the union of the scopes on both clients.
@@ -483,9 +485,7 @@ PubSub.prototype.getSnapshots = function(options, callback) {
483485
* this.end();
484486
* });
485487
*/
486-
PubSub.prototype.getSnapshotsStream = common.paginator.streamify(
487-
'getSnapshots'
488-
);
488+
PubSub.prototype.getSnapshotsStream = paginator.streamify('getSnapshots');
489489

490490
/**
491491
* Query object for listing subscriptions.
@@ -629,7 +629,7 @@ PubSub.prototype.getSubscriptions = function(options, callback) {
629629
* this.end();
630630
* });
631631
*/
632-
PubSub.prototype.getSubscriptionsStream = common.paginator.streamify(
632+
PubSub.prototype.getSubscriptionsStream = paginator.streamify(
633633
'getSubscriptions'
634634
);
635635

@@ -768,7 +768,7 @@ PubSub.prototype.getTopics = function(options, callback) {
768768
* this.end();
769769
* });
770770
*/
771-
PubSub.prototype.getTopicsStream = common.paginator.streamify('getTopics');
771+
PubSub.prototype.getTopicsStream = paginator.streamify('getTopics');
772772

773773
/**
774774
* Get the PubSub client object.
@@ -832,7 +832,7 @@ PubSub.prototype.request = function(config, callback) {
832832
}
833833

834834
var reqOpts = extend(true, {}, config.reqOpts);
835-
reqOpts = common.util.replaceProjectIdToken(reqOpts, self.projectId);
835+
reqOpts = replaceProjectIdToken(reqOpts, self.projectId);
836836

837837
client[config.method](reqOpts, config.gaxOpts, callback);
838838
});
@@ -933,18 +933,14 @@ PubSub.prototype.topic = function(name, options) {
933933
*
934934
* These methods can be agto-paginated.
935935
*/
936-
common.paginator.extend(PubSub, [
937-
'getSnapshots',
938-
'getSubscriptions',
939-
'getTopics',
940-
]);
936+
paginator.extend(PubSub, ['getSnapshots', 'getSubscriptions', 'getTopics']);
941937

942938
/*! Developer Documentation
943939
*
944940
* All async methods (except for streams) will return a Promise in the event
945941
* that a callback is omitted.
946942
*/
947-
common.util.promisifyAll(PubSub, {
943+
promisifyAll(PubSub, {
948944
exclude: ['request', 'snapshot', 'subscription', 'topic'],
949945
});
950946

handwritten/pubsub/src/publisher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'use strict';
1818

1919
var arrify = require('arrify');
20-
var common = require('@google-cloud/common');
20+
const {promisifyAll} = require('@google-cloud/promisify');
2121
var each = require('async-each');
2222
var extend = require('extend');
2323
var is = require('is');
@@ -263,7 +263,7 @@ Publisher.prototype.queue_ = function(data, attrs, callback) {
263263
* All async methods (except for streams) will return a Promise in the event
264264
* that a callback is omitted.
265265
*/
266-
common.util.promisifyAll(Publisher, {
266+
promisifyAll(Publisher, {
267267
singular: true,
268268
});
269269

handwritten/pubsub/src/snapshot.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'use strict';
1818

1919
var common = require('@google-cloud/common');
20+
const {promisifyAll} = require('@google-cloud/promisify');
2021
var is = require('is');
2122

2223
/**
@@ -211,6 +212,6 @@ Snapshot.prototype.delete = function(callback) {
211212
* All async methods (except for streams) will return a Promise in the event
212213
* that a callback is omitted.
213214
*/
214-
common.util.promisifyAll(Snapshot);
215+
promisifyAll(Snapshot);
215216

216217
module.exports = Snapshot;

handwritten/pubsub/src/subscriber.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
var arrify = require('arrify');
2020
var chunk = require('lodash.chunk');
2121
var common = require('@google-cloud/common');
22+
const {promisify} = require('@google-cloud/promisify');
2223
var delay = require('delay');
2324
var events = require('events');
2425
var extend = require('extend');
@@ -138,7 +139,7 @@ Subscriber.prototype.acknowledge_ = function(ackIds, connId) {
138139
return self.writeTo_(connId, {ackIds: ackIdChunk});
139140
}
140141

141-
return common.util.promisify(self.request).call(self, {
142+
return promisify(self.request).call(self, {
142143
client: 'SubscriberClient',
143144
method: 'acknowledge',
144145
reqOpts: {
@@ -396,7 +397,7 @@ Subscriber.prototype.modifyAckDeadline_ = function(ackIds, deadline, connId) {
396397
});
397398
}
398399

399-
return common.util.promisify(self.request).call(self, {
400+
return promisify(self.request).call(self, {
400401
client: 'SubscriberClient',
401402
method: 'modifyAckDeadline',
402403
reqOpts: {

0 commit comments

Comments
 (0)