Skip to content

Commit 1c0ddbd

Browse files
chore: split the common module (#69)
1 parent 964171a commit 1c0ddbd

5 files changed

Lines changed: 42 additions & 35 deletions

File tree

packages/google-cloud-resourcemanager/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
},
6363
"dependencies": {
6464
"@google-cloud/common": "^0.20.0",
65+
"@google-cloud/paginator": "^0.1.0",
66+
"@google-cloud/promisify": "^0.3.0",
6567
"extend": "^3.0.0",
6668
"is": "^3.0.1"
6769
},

packages/google-cloud-resourcemanager/src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
'use strict';
1818

19-
import * as common from '@google-cloud/common';
19+
import {Service, Operation} from '@google-cloud/common';
20+
import {paginator} from '@google-cloud/paginator';
21+
import {promisifyAll} from '@google-cloud/promisify';
2022
import * as extend from 'extend';
2123
import * as is from 'is';
2224
import * as util from 'util';
@@ -91,10 +93,10 @@ function Resource(options) {
9193
packageJson: require('../../package.json'),
9294
};
9395

94-
common.Service.call(this, config, options);
96+
Service.call(this, config, options);
9597
}
9698

97-
util.inherits(Resource, common.Service);
99+
util.inherits(Resource, Service);
98100

99101
/**
100102
* Create a project.
@@ -304,7 +306,7 @@ Resource.prototype.getProjects = function(options, callback) {
304306
* this.end();
305307
* });
306308
*/
307-
Resource.prototype.getProjectsStream = common.paginator.streamify(
309+
Resource.prototype.getProjectsStream = paginator.streamify(
308310
'getProjects'
309311
);
310312

@@ -330,7 +332,7 @@ Resource.prototype.operation = function(name) {
330332
throw new Error('A name must be specified for an operation.');
331333
}
332334

333-
return new common.Operation({
335+
return new Operation({
334336
parent: this,
335337
id: name,
336338
});
@@ -365,14 +367,14 @@ Resource.prototype.project = function(id) {
365367
*
366368
* These methods can be auto-paginated.
367369
*/
368-
common.paginator.extend(Resource, ['getProjects']);
370+
paginator.extend(Resource, ['getProjects']);
369371

370372
/*! Developer Documentation
371373
*
372374
* All async methods (except for streams) will return a Promise in the event
373375
* that a callback is omitted.
374376
*/
375-
common.util.promisifyAll(Resource, {
377+
promisifyAll(Resource, {
376378
exclude: ['operation', 'project'],
377379
});
378380

packages/google-cloud-resourcemanager/src/project.ts

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

1919
import * as common from '@google-cloud/common';
20+
import {promisifyAll} from '@google-cloud/promisify';
2021
import * as util from 'util';
2122

2223
/**
@@ -310,7 +311,7 @@ Project.prototype.restore = function(callback) {
310311
* All async methods (except for streams) will return a Promise in the event
311312
* that a callback is omitted.
312313
*/
313-
common.util.promisifyAll(Project);
314+
promisifyAll(Project);
314315

315316
/**
316317
* Reference to the {@link Project} class.

packages/google-cloud-resourcemanager/test/index.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,41 @@ function FakeService() {
3636

3737
var extended = false;
3838
var fakePaginator = {
39-
extend: function(Class, methods) {
39+
paginator: {
40+
extend: function(Class, methods) {
41+
if (Class.name !== 'Resource') {
42+
return;
43+
}
44+
methods = arrify(methods);
45+
assert.strictEqual(Class.name, 'Resource');
46+
assert.deepStrictEqual(methods, ['getProjects']);
47+
extended = true;
48+
},
49+
streamify: function(methodName) {
50+
return methodName;
51+
},
52+
}
53+
};
54+
55+
var promisified = true;
56+
const fakePromisify = {
57+
promisifyAll: function(Class, options) {
4058
if (Class.name !== 'Resource') {
4159
return;
4260
}
43-
44-
methods = arrify(methods);
45-
assert.strictEqual(Class.name, 'Resource');
46-
assert.deepStrictEqual(methods, ['getProjects']);
47-
extended = true;
48-
},
49-
streamify: function(methodName) {
50-
return methodName;
61+
promisified = true;
62+
assert.deepStrictEqual(options.exclude, ['operation', 'project']);
5163
},
5264
};
5365

54-
var promisified = true;
5566
var makeAuthenticatedRequestFactoryOverride;
5667
var fakeUtil = extend({}, util, {
5768
makeAuthenticatedRequestFactory: function() {
5869
if (makeAuthenticatedRequestFactoryOverride) {
5970
return makeAuthenticatedRequestFactoryOverride.apply(null, arguments);
6071
}
61-
6272
return util.makeAuthenticatedRequestFactory.apply(null, arguments);
6373
},
64-
promisifyAll: function(Class, options) {
65-
if (Class.name !== 'Resource') {
66-
return;
67-
}
68-
69-
promisified = true;
70-
assert.deepStrictEqual(options.exclude, ['operation', 'project']);
71-
},
7274
});
7375
var originalFakeUtil = extend(true, {}, fakeUtil);
7476

@@ -83,10 +85,10 @@ describe('Resource', function() {
8385
'@google-cloud/common': {
8486
Operation: FakeOperation,
8587
Service: FakeService,
86-
paginator: fakePaginator,
87-
util: fakeUtil,
8888
},
89-
'./project.js': FakeProject,
89+
'@google-cloud/promisify': fakePromisify,
90+
'@google-cloud/paginator': fakePaginator,
91+
'./project': FakeProject,
9092
});
9193
});
9294

packages/google-cloud-resourcemanager/test/project.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
import * as assert from 'assert';
2020
import * as extend from 'extend';
21-
var nodeutil = require('util');
21+
import * as nodeutil from 'util';
2222
import * as proxyquire from 'proxyquire';
23-
var ServiceObject = require('@google-cloud/common').ServiceObject;
24-
var util = require('@google-cloud/common').util;
23+
import {ServiceObject, util} from '@google-cloud/common';
24+
import * as promisify from '@google-cloud/promisify';
2525

2626
var promisified = false;
27-
var fakeUtil = extend({}, util, {
27+
var fakePromisify = extend({}, promisify, {
2828
promisifyAll: function(Class) {
2929
if (Class.name === 'Project') {
3030
promisified = true;
@@ -52,8 +52,8 @@ describe('Project', function() {
5252
Project = proxyquire('../src/project.js', {
5353
'@google-cloud/common': {
5454
ServiceObject: FakeServiceObject,
55-
util: fakeUtil,
5655
},
56+
'@google-cloud/promisify': fakePromisify
5757
});
5858
});
5959

0 commit comments

Comments
 (0)