Skip to content

Commit

Permalink
chore: split the common module (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Aug 9, 2018
1 parent 964171a commit 1c0ddbd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
2 changes: 2 additions & 0 deletions packages/google-cloud-resourcemanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
},
"dependencies": {
"@google-cloud/common": "^0.20.0",
"@google-cloud/paginator": "^0.1.0",
"@google-cloud/promisify": "^0.3.0",
"extend": "^3.0.0",
"is": "^3.0.1"
},
Expand Down
16 changes: 9 additions & 7 deletions packages/google-cloud-resourcemanager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

'use strict';

import * as common from '@google-cloud/common';
import {Service, Operation} from '@google-cloud/common';
import {paginator} from '@google-cloud/paginator';
import {promisifyAll} from '@google-cloud/promisify';
import * as extend from 'extend';
import * as is from 'is';
import * as util from 'util';
Expand Down Expand Up @@ -91,10 +93,10 @@ function Resource(options) {
packageJson: require('../../package.json'),
};

common.Service.call(this, config, options);
Service.call(this, config, options);
}

util.inherits(Resource, common.Service);
util.inherits(Resource, Service);

/**
* Create a project.
Expand Down Expand Up @@ -304,7 +306,7 @@ Resource.prototype.getProjects = function(options, callback) {
* this.end();
* });
*/
Resource.prototype.getProjectsStream = common.paginator.streamify(
Resource.prototype.getProjectsStream = paginator.streamify(
'getProjects'
);

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

return new common.Operation({
return new Operation({
parent: this,
id: name,
});
Expand Down Expand Up @@ -365,14 +367,14 @@ Resource.prototype.project = function(id) {
*
* These methods can be auto-paginated.
*/
common.paginator.extend(Resource, ['getProjects']);
paginator.extend(Resource, ['getProjects']);

/*! Developer Documentation
*
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Resource, {
promisifyAll(Resource, {
exclude: ['operation', 'project'],
});

Expand Down
3 changes: 2 additions & 1 deletion packages/google-cloud-resourcemanager/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'use strict';

import * as common from '@google-cloud/common';
import {promisifyAll} from '@google-cloud/promisify';
import * as util from 'util';

/**
Expand Down Expand Up @@ -310,7 +311,7 @@ Project.prototype.restore = function(callback) {
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Project);
promisifyAll(Project);

/**
* Reference to the {@link Project} class.
Expand Down
46 changes: 24 additions & 22 deletions packages/google-cloud-resourcemanager/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,41 @@ function FakeService() {

var extended = false;
var fakePaginator = {
extend: function(Class, methods) {
paginator: {
extend: function(Class, methods) {
if (Class.name !== 'Resource') {
return;
}
methods = arrify(methods);
assert.strictEqual(Class.name, 'Resource');
assert.deepStrictEqual(methods, ['getProjects']);
extended = true;
},
streamify: function(methodName) {
return methodName;
},
}
};

var promisified = true;
const fakePromisify = {
promisifyAll: function(Class, options) {
if (Class.name !== 'Resource') {
return;
}

methods = arrify(methods);
assert.strictEqual(Class.name, 'Resource');
assert.deepStrictEqual(methods, ['getProjects']);
extended = true;
},
streamify: function(methodName) {
return methodName;
promisified = true;
assert.deepStrictEqual(options.exclude, ['operation', 'project']);
},
};

var promisified = true;
var makeAuthenticatedRequestFactoryOverride;
var fakeUtil = extend({}, util, {
makeAuthenticatedRequestFactory: function() {
if (makeAuthenticatedRequestFactoryOverride) {
return makeAuthenticatedRequestFactoryOverride.apply(null, arguments);
}

return util.makeAuthenticatedRequestFactory.apply(null, arguments);
},
promisifyAll: function(Class, options) {
if (Class.name !== 'Resource') {
return;
}

promisified = true;
assert.deepStrictEqual(options.exclude, ['operation', 'project']);
},
});
var originalFakeUtil = extend(true, {}, fakeUtil);

Expand All @@ -83,10 +85,10 @@ describe('Resource', function() {
'@google-cloud/common': {
Operation: FakeOperation,
Service: FakeService,
paginator: fakePaginator,
util: fakeUtil,
},
'./project.js': FakeProject,
'@google-cloud/promisify': fakePromisify,
'@google-cloud/paginator': fakePaginator,
'./project': FakeProject,
});
});

Expand Down
10 changes: 5 additions & 5 deletions packages/google-cloud-resourcemanager/test/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

import * as assert from 'assert';
import * as extend from 'extend';
var nodeutil = require('util');
import * as nodeutil from 'util';
import * as proxyquire from 'proxyquire';
var ServiceObject = require('@google-cloud/common').ServiceObject;
var util = require('@google-cloud/common').util;
import {ServiceObject, util} from '@google-cloud/common';
import * as promisify from '@google-cloud/promisify';

var promisified = false;
var fakeUtil = extend({}, util, {
var fakePromisify = extend({}, promisify, {
promisifyAll: function(Class) {
if (Class.name === 'Project') {
promisified = true;
Expand Down Expand Up @@ -52,8 +52,8 @@ describe('Project', function() {
Project = proxyquire('../src/project.js', {
'@google-cloud/common': {
ServiceObject: FakeServiceObject,
util: fakeUtil,
},
'@google-cloud/promisify': fakePromisify
});
});

Expand Down

0 comments on commit 1c0ddbd

Please sign in to comment.