diff --git a/package.json b/package.json index 453f160fd..c6c2aebe0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/app-profile.js b/src/app-profile.js index d958ab1dd..89aef7c60 100644 --- a/src/app-profile.js +++ b/src/app-profile.js @@ -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'); @@ -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. diff --git a/src/chunktransformer.js b/src/chunktransformer.js index 9733389b3..d899c047d 100644 --- a/src/chunktransformer.js +++ b/src/chunktransformer.js @@ -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) { diff --git a/src/cluster.js b/src/cluster.js index 0d33eb23e..f32cbffd0 100644 --- a/src/cluster.js +++ b/src/cluster.js @@ -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'); /** @@ -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. diff --git a/src/family.js b/src/family.js index 04551f3b3..d7022960d 100644 --- a/src/family.js +++ b/src/family.js @@ -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'); /** @@ -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; diff --git a/src/index.js b/src/index.js index a5f7322a8..84cd7d0cc 100644 --- a/src/index.js +++ b/src/index.js @@ -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; @@ -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. @@ -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( @@ -708,7 +709,7 @@ class Bigtable { currentRetryAttempt: 0, noResponseRetries: 0, objectMode: true, - shouldRetryFn: GrpcService.shouldRetryRequest_, + shouldRetryFn: Service.shouldRetryRequest_, request() { gaxStream = requestFn(); return gaxStream; @@ -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'], }); diff --git a/src/instance.js b/src/instance.js index 8c33f5bfc..35c99ee32 100644 --- a/src/instance.js +++ b/src/instance.js @@ -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'); @@ -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'], }); diff --git a/src/row.js b/src/row.js index 63990a5f0..d03abcdfc 100644 --- a/src/row.js +++ b/src/row.js @@ -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'); @@ -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; diff --git a/src/table.js b/src/table.js index 7d416c9d4..f74ae33bc 100644 --- a/src/table.js +++ b/src/table.js @@ -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'); @@ -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'], }); diff --git a/synth.py b/synth.py index a7852353f..472d344ad 100644 --- a/synth.py +++ b/synth.py @@ -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']) diff --git a/test/app-profile.js b/test/app-profile.js index 4b8600131..482c15bf2 100644 --- a/test/app-profile.js +++ b/test/app-profile.js @@ -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; @@ -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, }); }); diff --git a/test/chunktransformer.js b/test/chunktransformer.js index 656e9f9b4..c4273410a 100644 --- a/test/chunktransformer.js +++ b/test/chunktransformer.js @@ -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, diff --git a/test/cluster.js b/test/cluster.js index dabb72a3d..6a795704f 100644 --- a/test/cluster.js +++ b/test/cluster.js @@ -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; @@ -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, }); }); diff --git a/test/family.js b/test/family.js index 789df966c..3a75f8bf7 100644 --- a/test/family.js +++ b/test/family.js @@ -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; @@ -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}`; @@ -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; diff --git a/test/index.js b/test/index.js index edbae9652..cf5bb6485 100644 --- a/test/index.js +++ b/test/index.js @@ -24,6 +24,8 @@ const grpc = new gax.GrpcClient().grpc; const proxyquire = require('proxyquire'); const sinon = require('sinon').createSandbox(); const through = require('through2'); +const promisify = require('@google-cloud/promisify'); +const projectify = require('@google-cloud/projectify'); const Cluster = require('../src/cluster.js'); const Instance = require('../src/instance.js'); @@ -35,12 +37,11 @@ function fakeV2() {} var promisified = false; var replaceProjectIdTokenOverride; -const fakeUtil = extend({}, common.util, { +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class, options) { if (Class.name !== 'Bigtable') { return; } - promisified = true; assert.deepStrictEqual(options.exclude, [ 'instance', @@ -48,15 +49,15 @@ const fakeUtil = extend({}, common.util, { 'request', ]); }, +}); +const fakeReplaceProjectIdToken = extend({}, projectify, { replaceProjectIdToken: function(reqOpts) { if (replaceProjectIdTokenOverride) { return replaceProjectIdTokenOverride.apply(null, arguments); } - return reqOpts; }, }); -const originalFakeUtil = extend(true, {}, fakeUtil); var googleAuthOverride; function fakeGoogleAuth() { @@ -92,9 +93,8 @@ describe('Bigtable', function() { before(function() { Bigtable = proxyquire('../', { - '@google-cloud/common-grpc': { - util: fakeUtil, - }, + '@google-cloud/promisify': fakePromisify, + '@google-cloud/projectify': fakeReplaceProjectIdToken, 'google-auth-library': { GoogleAuth: fakeGoogleAuth, }, @@ -110,14 +110,10 @@ describe('Bigtable', function() { }); beforeEach(function() { - extend(fakeUtil, originalFakeUtil); - googleAuthOverride = null; retryRequestOverride = null; replaceProjectIdTokenOverride = null; - delete process.env.BIGTABLE_EMULATOR_HOST; - bigtable = new Bigtable({projectId: PROJECT_ID}); }); @@ -146,20 +142,6 @@ describe('Bigtable', function() { assert(bigtable instanceof Bigtable); }); - it('should normalize the arguments', function() { - let normalizeArgumentsCalled = false; - let options = {}; - - fakeUtil.normalizeArguments = function(context, options_) { - normalizeArgumentsCalled = true; - assert.strictEqual(options_, options); - return options_; - }; - - new Bigtable(options); - assert.strictEqual(normalizeArgumentsCalled, true); - }); - it('should initialize the API object', function() { assert.deepStrictEqual(bigtable.api, {}); }); diff --git a/test/instance.js b/test/instance.js index da31d4953..bb9d0dbd5 100644 --- a/test/instance.js +++ b/test/instance.js @@ -17,7 +17,8 @@ 'use strict'; const assert = require('assert'); -const common = require('@google-cloud/common-grpc'); +const promisify = require('@google-cloud/promisify'); +const paginator = require('@google-cloud/paginator'); const extend = require('extend'); const proxyquire = require('proxyquire'); @@ -27,25 +28,26 @@ const Family = require('../src/family.js'); const Table = require('../src/table.js'); var promisified = false; -const fakeUtil = extend({}, common.util, { +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class, options) { if (Class.name !== 'Instance') { return; } - promisified = true; assert.deepStrictEqual(options.exclude, ['appProfile', 'cluster', 'table']); }, }); -const fakePaginator = { - extend: function() { - this.calledWith_ = arguments; - }, - streamify: function(methodName) { - return methodName; +const fakePaginator = extend({}, paginator, { + paginator: { + extend: function() { + this.calledWith_ = arguments; + }, + streamify: function(methodName) { + return methodName; + }, }, -}; +}); function createFake(Class) { return class Fake extends Class { @@ -74,10 +76,8 @@ describe('Bigtable/Instance', function() { before(function() { Instance = proxyquire('../src/instance.js', { - '@google-cloud/common-grpc': { - paginator: fakePaginator, - util: fakeUtil, - }, + '@google-cloud/paginator': fakePaginator, + '@google-cloud/promisify': fakePromisify, './app-profile.js': FakeAppProfile, './cluster.js': FakeCluster, './family.js': FakeFamily, @@ -91,8 +91,7 @@ describe('Bigtable/Instance', function() { describe('instantiation', function() { it('should extend the correct methods', function() { - let args = fakePaginator.calledWith_; - + let args = fakePaginator.paginator.calledWith_; assert.strictEqual(args[0], Instance); assert.deepStrictEqual(args[1], ['getTables']); }); diff --git a/test/row.js b/test/row.js index 8c554f5fd..8afc2965e 100644 --- a/test/row.js +++ b/test/row.js @@ -17,7 +17,7 @@ 'use strict'; const assert = require('assert'); -const common = require('@google-cloud/common-grpc'); +const promisify = require('@google-cloud/promisify'); const extend = require('extend'); const proxyquire = require('proxyquire'); const sinon = require('sinon').createSandbox(); @@ -25,7 +25,7 @@ const sinon = require('sinon').createSandbox(); const Mutation = require('../src/mutation.js'); var promisified = false; -const fakeUtil = extend({}, common.util, { +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class) { if (Class.name === 'Row') { promisified = true; @@ -73,9 +73,7 @@ describe('Bigtable/Row', function() { before(function() { Row = proxyquire('../src/row.js', { - '@google-cloud/common-grpc': { - util: fakeUtil, - }, + '@google-cloud/promisify': fakePromisify, './mutation.js': FakeMutation, './filter.js': FakeFilter, }); diff --git a/test/table.js b/test/table.js index 1f5075320..8bfbe6d42 100644 --- a/test/table.js +++ b/test/table.js @@ -17,7 +17,6 @@ 'use strict'; const assert = require('assert'); -const Buffer = require('buffer').Buffer; const extend = require('extend'); const proxyquire = require('proxyquire'); const pumpify = require('pumpify'); @@ -26,18 +25,18 @@ const Stream = require('stream').PassThrough; const through = require('through2'); const common = require('@google-cloud/common-grpc'); +const promisify = require('@google-cloud/promisify'); const Family = require('../src/family.js'); const Mutation = require('../src/mutation.js'); const Row = require('../src/row.js'); const ChunkTransformer = require('../src/chunktransformer.js'); var promisified = false; -const fakeUtil = extend({}, common.util, { +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class, options) { if (Class.name !== 'Table') { return; } - promisified = true; assert.deepStrictEqual(options.exclude, ['family', 'row']); }, @@ -102,8 +101,8 @@ describe('Bigtable/Table', function() { Table = proxyquire('../src/table.js', { '@google-cloud/common-grpc': { Service: FakeGrpcService, - util: fakeUtil, }, + '@google-cloud/promisify': fakePromisify, './family.js': FakeFamily, './mutation.js': FakeMutation, './filter.js': FakeFilter,