Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split usage of common module #297

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "eslint src/ samples/ system-test/ test/",
"prettier": "prettier --write src/*.js src/*/*.js samples/*.js samples/*/*.js test/*.js test/*/*.js system-test/*.js system-test/*/*.js",
"publish-module": "node ../../scripts/publish.js bigtable",
"system-test": "mocha system-test/*.js --timeout 600000",
"snippet-test": "mocha samples/document-snippets/test.js --timeout 600000"
},
"dependencies": {
"@google-cloud/common-grpc": "^0.7.1",
"@google-cloud/paginator": "^0.1.0",
"@google-cloud/projectify": "^0.3.0",
"@google-cloud/promisify": "^0.3.0",
"arrify": "^1.0.0",
"concat-stream": "^1.5.0",
"create-error-class": "^3.0.2",
"dot-prop": "^4.2.0",
"escape-string-regexp": "^1.0.5",
"extend": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/app-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const common = require('@google-cloud/common-grpc');
const {promisifyAll} = require('@google-cloud/promisify');
const is = require('is');
const snakeCase = require('lodash.snakecase');

Expand Down Expand Up @@ -400,7 +400,7 @@ Please use the format 'my-app-profile' or '${
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(AppProfile);
promisifyAll(AppProfile);

/**
* Reference to the {@link AppProfile} class.
Expand Down
3 changes: 1 addition & 2 deletions src/chunktransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* limitations under the License.
*/
const Mutation = require('./mutation');
const stream = require('stream');
const Transform = stream.Transform;
const {Transform} = require('stream');

class TransformError extends Error {
constructor(props) {
Expand Down
4 changes: 2 additions & 2 deletions src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const common = require('@google-cloud/common-grpc');
const {promisifyAll} = require('@google-cloud/promisify');
const is = require('is');

/**
Expand Down Expand Up @@ -400,7 +400,7 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Cluster);
promisifyAll(Cluster);

/**
* Reference to the {@link Cluster} class.
Expand Down
4 changes: 2 additions & 2 deletions src/family.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const common = require('@google-cloud/common-grpc');
const {promisifyAll} = require('@google-cloud/promisify');
const is = require('is');

/**
Expand Down Expand Up @@ -436,7 +436,7 @@ Please use the format 'follows' or '${table.name}/columnFamilies/my-family'.`
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Family);
promisifyAll(Family);

module.exports = Family;
module.exports.FamilyError = FamilyError;
13 changes: 7 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/

const arrify = require('arrify');
const common = require('@google-cloud/common-grpc');
const {replaceProjectIdToken} = require('@google-cloud/projectify');
const {promisifyAll} = require('@google-cloud/promisify');
const extend = require('extend');
const GrpcService = require('@google-cloud/common-grpc').Service;
const {Service} = require('@google-cloud/common-grpc');
const {GoogleAuth} = require('google-auth-library');
const gax = require('google-gax');
const grpc = new gax.GrpcClient().grpc;
Expand Down Expand Up @@ -337,7 +338,7 @@ const v2 = require('./v2');
*/
class Bigtable {
constructor(options) {
options = common.util.normalizeArguments(this, options);
options = options || {};

// Determine what scopes are needed.
// It is the union of the scopes on all three clients.
Expand Down Expand Up @@ -654,7 +655,7 @@ class Bigtable {
let reqOpts = extend(true, {}, config.reqOpts);

if (this.shouldReplaceProjectIdToken && projectId !== '{{projectId}}') {
reqOpts = common.util.replaceProjectIdToken(reqOpts, projectId);
reqOpts = replaceProjectIdToken(reqOpts, projectId);
}

const requestFn = gaxClient[config.method].bind(
Expand Down Expand Up @@ -708,7 +709,7 @@ class Bigtable {
currentRetryAttempt: 0,
noResponseRetries: 0,
objectMode: true,
shouldRetryFn: GrpcService.shouldRetryRequest_,
shouldRetryFn: Service.shouldRetryRequest_,
request() {
gaxStream = requestFn();
return gaxStream;
Expand Down Expand Up @@ -762,7 +763,7 @@ class Bigtable {
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Bigtable, {
promisifyAll(Bigtable, {
exclude: ['instance', 'operation', 'request'],
});

Expand Down
9 changes: 5 additions & 4 deletions src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

const common = require('@google-cloud/common-grpc');
const {paginator} = require('@google-cloud/paginator');
const {promisifyAll} = require('@google-cloud/promisify');
const extend = require('extend');
const is = require('is');
const snakeCase = require('lodash.snakecase');
Expand Down Expand Up @@ -749,20 +750,20 @@ Please use the format 'my-instance' or '${
* this.end();
* });
*/
Instance.prototype.getTablesStream = common.paginator.streamify('getTables');
Instance.prototype.getTablesStream = paginator.streamify('getTables');

/*! Developer Documentation
*
* These methods can be auto-paginated.
*/
common.paginator.extend(Instance, ['getTables']);
paginator.extend(Instance, ['getTables']);

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

Expand Down
4 changes: 2 additions & 2 deletions src/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

const arrify = require('arrify');
const common = require('@google-cloud/common-grpc');
const {promisifyAll} = require('@google-cloud/promisify');
const dotProp = require('dot-prop');
const extend = require('extend');
const flatten = require('lodash.flatten');
Expand Down Expand Up @@ -921,7 +921,7 @@ class Row {
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Row);
promisifyAll(Row);

module.exports = Row;
module.exports.RowError = RowError;
3 changes: 2 additions & 1 deletion src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

const arrify = require('arrify');
const common = require('@google-cloud/common-grpc');
const {promisifyAll} = require('@google-cloud/promisify');
const concat = require('concat-stream');
const flatten = require('lodash.flatten');
const is = require('is');
Expand Down Expand Up @@ -1513,7 +1514,7 @@ Table.VIEWS = {
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Table, {
promisifyAll(Table, {
exclude: ['family', 'row'],
});

Expand Down
13 changes: 2 additions & 11 deletions synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,15 @@
logging.basicConfig(level=logging.DEBUG)

gapic = gcp.GAPICGenerator()
common_templates = gcp.CommonTemplates()

v2_library = gapic.node_library(
'bigtable', 'v2', config_path='/google/bigtable/artman_bigtable.yaml')

# Copy all files except for 'README.md' and 'package.json'
s.copy(
v2_library,
excludes=['package.json', 'README.md', 'src/index.js', 'src/v2/index.js'])

templates = common_templates.node_library(
package_name="@google-cloud/bigtable",
repo_name="googleapis/nodejs-bigtable")
common_templates = gcp.CommonTemplates()
templates = common_templates.node_library()
s.copy(templates)

#
# Node.js specific cleanup
#
subprocess.run(['npm', 'install'])
subprocess.run(['npm', 'run', 'prettier'])
subprocess.run(['npm', 'run', 'lint'])
8 changes: 3 additions & 5 deletions test/app-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
const assert = require('assert');
const extend = require('extend');
const proxyquire = require('proxyquire');
const common = require('@google-cloud/common-grpc');
const promisify = require('@google-cloud/promisify');

var promisified = false;
var fakeUtil = extend({}, common.util, {
var fakePromisify = extend({}, promisify, {
promisifyAll: function(Class) {
if (Class.name === 'AppProfile') {
promisified = true;
Expand Down Expand Up @@ -51,9 +51,7 @@ describe('Bigtable/AppProfile', function() {
before(function() {
AppProfile = proxyquire('../src/app-profile.js', {
'../src/cluster.js': FakeCluster,
'@google-cloud/common-grpc': {
util: fakeUtil,
},
'@google-cloud/promisify': fakePromisify,
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/chunktransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Mutation = require('../src/mutation.js');
const Long = require('long');
const ROW_ID = 'my-row';
const CONVERTED_ROW_ID = 'my-converted-row';
const RowStateEnum = require('../src/chunktransformer.js').RowStateEnum;
const {RowStateEnum} = require('../src/chunktransformer.js');

const FakeMutation = {
methods: Mutation.methods,
Expand Down
9 changes: 3 additions & 6 deletions test/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
const assert = require('assert');
const extend = require('extend');
const proxyquire = require('proxyquire');

const common = require('@google-cloud/common-grpc');
const promisify = require('@google-cloud/promisify');

var promisified = false;
const fakeUtil = extend({}, common.util, {
const fakePromisify = extend({}, promisify, {
promisifyAll: function(Class) {
if (Class.name === 'Cluster') {
promisified = true;
Expand All @@ -46,9 +45,7 @@ describe('Bigtable/Cluster', function() {

before(function() {
Cluster = proxyquire('../src/cluster.js', {
'@google-cloud/common-grpc': {
util: fakeUtil,
},
'@google-cloud/promisify': fakePromisify,
});
});

Expand Down
12 changes: 5 additions & 7 deletions test/family.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
const assert = require('assert');
const extend = require('extend');
const proxyquire = require('proxyquire');
const {util} = require('@google-cloud/common-grpc');
const promisify = require('@google-cloud/promisify');

var promisified = false;
const fakeUtil = extend({}, util, {
const fakePromisify = extend({}, promisify, {
promisifyAll: function(Class) {
if (Class.name === 'Family') {
promisified = true;
Expand All @@ -36,8 +36,8 @@ describe('Bigtable/Family', function() {
bigtable: {},
id: 'my-table',
name: 'projects/my-project/instances/my-inststance/tables/my-table',
getFamilies: util.noop,
createFamily: util.noop,
getFamilies: () => {},
createFamily: () => {},
};

const FAMILY_NAME = `${TABLE.name}/columnFamilies/${FAMILY_ID}`;
Expand All @@ -47,9 +47,7 @@ describe('Bigtable/Family', function() {

before(function() {
Family = proxyquire('../src/family.js', {
'@google-cloud/common-grpc': {
util: fakeUtil,
},
'@google-cloud/promisify': fakePromisify,
});

FamilyError = Family.FamilyError;
Expand Down
Loading