diff --git a/packages/google-cloud-dns/package.json b/packages/google-cloud-dns/package.json index 867d3dd29f7..1c619861ae6 100644 --- a/packages/google-cloud-dns/package.json +++ b/packages/google-cloud-dns/package.json @@ -54,6 +54,8 @@ }, "dependencies": { "@google-cloud/common": "^0.20.0", + "@google-cloud/paginator": "^0.1.0", + "@google-cloud/promisify": "^0.3.0", "arrify": "^1.0.1", "dns-zonefile": "0.2.2", "extend": "^3.0.0", diff --git a/packages/google-cloud-dns/src/change.js b/packages/google-cloud-dns/src/change.js index ef5151bc7e0..83d94679a73 100644 --- a/packages/google-cloud-dns/src/change.js +++ b/packages/google-cloud-dns/src/change.js @@ -16,7 +16,8 @@ 'use strict'; -const common = require('@google-cloud/common'); +const {ServiceObject} = require('@google-cloud/common'); +const {promisifyAll} = require('@google-cloud/promisify'); const util = require('util'); /** @@ -167,7 +168,7 @@ function Change(zone, id) { * @name Change#metadata * @type {object} */ - common.ServiceObject.call(this, { + ServiceObject.call(this, { parent: zone, /** @@ -186,7 +187,7 @@ function Change(zone, id) { }); } -util.inherits(Change, common.ServiceObject); +util.inherits(Change, ServiceObject); /** * Create a change. @@ -243,6 +244,6 @@ Change.prototype.create = function(config, callback) { * All async methods (except for streams) will return a Promise in the event * that a callback is omitted. */ -common.util.promisifyAll(Change); +promisifyAll(Change); module.exports = Change; diff --git a/packages/google-cloud-dns/src/index.js b/packages/google-cloud-dns/src/index.js index 2f41567410f..8a2a2688dd7 100644 --- a/packages/google-cloud-dns/src/index.js +++ b/packages/google-cloud-dns/src/index.js @@ -17,7 +17,9 @@ 'use strict'; const arrify = require('arrify'); -const common = require('@google-cloud/common'); +const {Service} = require('@google-cloud/common'); +const {paginator} = require('@google-cloud/paginator'); +const {promisifyAll} = require('@google-cloud/promisify'); const extend = require('extend'); const is = require('is'); const util = require('util'); @@ -83,7 +85,7 @@ function DNS(options) { return new DNS(options); } - options = common.util.normalizeArguments(this, options); + options = options || {}; const config = { baseUrl: 'https://www.googleapis.com/dns/v1', @@ -94,10 +96,10 @@ function DNS(options) { packageJson: require('../package.json'), }; - common.Service.call(this, config, options); + Service.call(this, config, options); } -util.inherits(DNS, common.Service); +util.inherits(DNS, Service); /** * Config to set for the zone. @@ -304,7 +306,7 @@ DNS.prototype.getZones = function(query, callback) { * this.end(); * }); */ -DNS.prototype.getZonesStream = common.paginator.streamify('getZones'); +DNS.prototype.getZonesStream = paginator.streamify('getZones'); /** * Get a reference to a Zone. @@ -333,14 +335,14 @@ DNS.prototype.zone = function(name) { * * These methods can be auto-paginated. */ -common.paginator.extend(DNS, 'getZones'); +paginator.extend(DNS, 'getZones'); /*! Developer Documentation * * All async methods (except for streams) will return a Promise in the event * that a callback is omitted. */ -common.util.promisifyAll(DNS, { +promisifyAll(DNS, { exclude: ['zone'], }); diff --git a/packages/google-cloud-dns/src/record.js b/packages/google-cloud-dns/src/record.js index b15d68956ee..032fa9a5cba 100644 --- a/packages/google-cloud-dns/src/record.js +++ b/packages/google-cloud-dns/src/record.js @@ -17,7 +17,7 @@ 'use strict'; const arrify = require('arrify'); -const common = require('@google-cloud/common'); +const {promisifyAll} = require('@google-cloud/promisify'); const extend = require('extend'); const format = require('string-format-obj'); @@ -201,7 +201,7 @@ Record.prototype.toString = function() { * All async methods (except for streams) will return a Promise in the event * that a callback is omitted. */ -common.util.promisifyAll(Record, { +promisifyAll(Record, { exclude: ['toJSON', 'toString'], }); diff --git a/packages/google-cloud-dns/src/zone.js b/packages/google-cloud-dns/src/zone.js index 1f588f18380..26f1b64c1a4 100644 --- a/packages/google-cloud-dns/src/zone.js +++ b/packages/google-cloud-dns/src/zone.js @@ -17,7 +17,9 @@ 'use strict'; const arrify = require('arrify'); -const common = require('@google-cloud/common'); +const {ServiceObject} = require('@google-cloud/common'); +const {paginator} = require('@google-cloud/paginator'); +const {promisifyAll} = require('@google-cloud/promisify'); const exec = require('methmeth'); const extend = require('extend'); const flatten = require('lodash.flatten'); @@ -198,7 +200,7 @@ function Zone(dns, name) { * @name Zone#metadata * @type {object} */ - common.ServiceObject.call(this, { + ServiceObject.call(this, { parent: dns, /** @@ -224,7 +226,7 @@ function Zone(dns, name) { this.name = name; } -util.inherits(Zone, common.ServiceObject); +util.inherits(Zone, ServiceObject); /** * @typedef {array} ZoneAddRecordsResponse @@ -463,7 +465,7 @@ Zone.prototype.delete = function(options, callback) { return; } - common.ServiceObject.prototype.delete.call(this, callback); + ServiceObject.prototype.delete.call(this, callback); }; /** @@ -798,7 +800,7 @@ Zone.prototype.getChanges = function(query, callback) { * this.end(); * }); */ -Zone.prototype.getChangesStream = common.paginator.streamify('getChanges'); +Zone.prototype.getChangesStream = paginator.streamify('getChanges'); /** * Query object for listing records. @@ -980,7 +982,7 @@ Zone.prototype.getRecords = function(query, callback) { * this.end(); * }); */ -Zone.prototype.getRecordsStream = common.paginator.streamify('getRecords'); +Zone.prototype.getRecordsStream = paginator.streamify('getRecords'); /** * @typedef {array} ZoneImportResponse @@ -1229,14 +1231,14 @@ Zone.prototype.deleteRecordsByType_ = function(recordTypes, callback) { * * These methods can be auto-paginated. */ -common.paginator.extend(Zone, ['getChanges', 'getRecords']); +paginator.extend(Zone, ['getChanges', 'getRecords']); /*! Developer Documentation * * All async methods (except for streams) will return a Promise in the event * that a callback is omitted. */ -common.util.promisifyAll(Zone, { +promisifyAll(Zone, { exclude: ['change', 'record'], }); diff --git a/packages/google-cloud-dns/test/change.js b/packages/google-cloud-dns/test/change.js index e86c27fc46f..b98b3a0aa12 100644 --- a/packages/google-cloud-dns/test/change.js +++ b/packages/google-cloud-dns/test/change.js @@ -20,11 +20,11 @@ const assert = require('assert'); const extend = require('extend'); const nodeutil = require('util'); const proxyquire = require('proxyquire'); -const ServiceObject = require('@google-cloud/common').ServiceObject; -const util = require('@google-cloud/common').util; +const {ServiceObject} = require('@google-cloud/common'); +const promisify = require('@google-cloud/promisify'); let promisified = false; -const fakeUtil = extend({}, util, { +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class) { if (Class.name === 'Change') { promisified = true; @@ -45,17 +45,17 @@ describe('Change', function() { const ZONE = { name: 'zone-name', - createChange: util.noop, + createChange: function() {}, }; const CHANGE_ID = 'change-id'; before(function() { - Change = proxyquire('../src/change.js', { + Change = proxyquire('../src/change', { '@google-cloud/common': { ServiceObject: FakeServiceObject, - util: fakeUtil, }, + '@google-cloud/promisify': fakePromisify, }); }); diff --git a/packages/google-cloud-dns/test/index.js b/packages/google-cloud-dns/test/index.js index 9b15cf01e22..ceb7497ba26 100644 --- a/packages/google-cloud-dns/test/index.js +++ b/packages/google-cloud-dns/test/index.js @@ -21,23 +21,26 @@ const assert = require('assert'); const extend = require('extend'); const nodeutil = require('util'); const proxyquire = require('proxyquire'); -const Service = require('@google-cloud/common').Service; -const util = require('@google-cloud/common').util; +const {Service} = require('@google-cloud/common'); +const {util} = require('@google-cloud/common'); +const promisify = require('@google-cloud/promisify'); let extended = false; const fakePaginator = { - extend: function(Class, methods) { - if (Class.name !== 'DNS') { - return; - } - - extended = true; - methods = arrify(methods); - assert.strictEqual(Class.name, 'DNS'); - assert.deepStrictEqual(methods, ['getZones']); - }, - streamify: function(methodName) { - return methodName; + paginator: { + extend: function(Class, methods) { + if (Class.name !== 'DNS') { + return; + } + + extended = true; + methods = arrify(methods); + assert.strictEqual(Class.name, 'DNS'); + assert.deepStrictEqual(methods, ['getZones']); + }, + streamify: function(methodName) { + return methodName; + }, }, }; @@ -48,19 +51,21 @@ function FakeService() { nodeutil.inherits(FakeService, Service); -let promisified = false; const fakeUtil = extend({}, util, { - makeAuthenticatedRequestFactory: util.noop, + makeAuthenticatedRequestFactory: function() {}, +}); +const originalFakeUtil = extend(true, {}, fakeUtil); + +let promisified = false; +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class, options) { if (Class.name !== 'DNS') { return; } - promisified = true; assert.deepStrictEqual(options.exclude, ['zone']); }, }); -const originalFakeUtil = extend(true, {}, fakeUtil); function FakeZone() { this.calledWith_ = arguments; @@ -76,10 +81,10 @@ describe('DNS', function() { DNS = proxyquire('../', { '@google-cloud/common': { Service: FakeService, - paginator: fakePaginator, - util: fakeUtil, }, - './zone.js': FakeZone, + '@google-cloud/paginator': fakePaginator, + '@google-cloud/promisify': fakePromisify, + './zone': FakeZone, }); }); @@ -109,20 +114,6 @@ describe('DNS', function() { }); }); - it('should normalize the arguments', function() { - let normalizeArgumentsCalled = false; - const options = {}; - - fakeUtil.normalizeArguments = function(context, options_) { - normalizeArgumentsCalled = true; - assert.strictEqual(options_, options); - return options_; - }; - - new DNS(options); - assert.strictEqual(normalizeArgumentsCalled, true); - }); - it('should inherit from Service', function() { assert(dns instanceof Service); diff --git a/packages/google-cloud-dns/test/record.js b/packages/google-cloud-dns/test/record.js index 0899e3afc70..40d42187101 100644 --- a/packages/google-cloud-dns/test/record.js +++ b/packages/google-cloud-dns/test/record.js @@ -19,15 +19,14 @@ const assert = require('assert'); const extend = require('extend'); const proxyquire = require('proxyquire'); -const util = require('@google-cloud/common').util; +const promisify = require('@google-cloud/promisify'); let promisified = false; -const fakeUtil = extend({}, util, { +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class, options) { if (Class.name !== 'Record') { return; } - promisified = true; assert.deepStrictEqual(options.exclude, ['toJSON', 'toString']); }, @@ -38,7 +37,7 @@ describe('Record', function() { let record; const ZONE = { - deleteRecords: util.noop, + deleteRecords: function() {}, }; const TYPE = 'A'; const METADATA = { @@ -48,10 +47,8 @@ describe('Record', function() { }; before(function() { - Record = proxyquire('../src/record.js', { - '@google-cloud/common': { - util: fakeUtil, - }, + Record = proxyquire('../src/record', { + '@google-cloud/promisify': fakePromisify, }); }); diff --git a/packages/google-cloud-dns/test/zone.js b/packages/google-cloud-dns/test/zone.js index 2f51cd81238..636b3f2bc8d 100644 --- a/packages/google-cloud-dns/test/zone.js +++ b/packages/google-cloud-dns/test/zone.js @@ -24,16 +24,16 @@ const flatten = require('lodash.flatten'); const nodeutil = require('util'); const prop = require('propprop'); const proxyquire = require('proxyquire'); -const {ServiceObject, util} = require('@google-cloud/common'); +const {ServiceObject} = require('@google-cloud/common'); +const promisify = require('@google-cloud/promisify'); const uuid = require('uuid'); let promisified = false; -const fakeUtil = extend({}, util, { +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class, options) { if (Class.name !== 'Zone') { return; } - promisified = true; assert.deepStrictEqual(options.exclude, ['change', 'record']); }, @@ -42,7 +42,7 @@ const fakeUtil = extend({}, util, { let parseOverride; const fakeDnsZonefile = { parse: function() { - return (parseOverride || util.noop).apply(null, arguments); + return (parseOverride || function() {}).apply(null, arguments); }, }; @@ -50,10 +50,10 @@ let writeFileOverride; let readFileOverride; const fakeFs = { readFile: function() { - return (readFileOverride || util.noop).apply(null, arguments); + return (readFileOverride || function() {}).apply(null, arguments); }, writeFile: function() { - return (writeFileOverride || util.noop).apply(null, arguments); + return (writeFileOverride || function() {}).apply(null, arguments); }, }; @@ -79,18 +79,20 @@ nodeutil.inherits(FakeServiceObject, ServiceObject); let extended = false; const fakePaginator = { - extend: function(Class, methods) { - if (Class.name !== 'Zone') { - return; - } - - extended = true; - methods = arrify(methods); - assert.strictEqual(Class.name, 'Zone'); - assert.deepStrictEqual(methods, ['getChanges', 'getRecords']); - }, - streamify: function(methodName) { - return methodName; + paginator: { + extend: function(Class, methods) { + if (Class.name !== 'Zone') { + return; + } + + extended = true; + methods = arrify(methods); + assert.strictEqual(Class.name, 'Zone'); + assert.deepStrictEqual(methods, ['getChanges', 'getRecords']); + }, + streamify: function(methodName) { + return methodName; + }, }, }; @@ -99,7 +101,7 @@ describe('Zone', function() { let zone; const DNS = { - createZone: util.noop, + createZone: function() {}, }; const ZONE_NAME = 'zone-name'; @@ -109,11 +111,11 @@ describe('Zone', function() { fs: fakeFs, '@google-cloud/common': { ServiceObject: FakeServiceObject, - paginator: fakePaginator, - util: fakeUtil, }, - './change.js': FakeChange, - './record.js': FakeRecord, + '@google-cloud/promisify': fakePromisify, + '@google-cloud/paginator': fakePaginator, + './change': FakeChange, + './record': FakeRecord, }); }); @@ -214,7 +216,7 @@ describe('Zone', function() { it('should throw error if add or delete is not provided', function() { assert.throws(function() { - zone.createChange({}, util.noop); + zone.createChange({}, function() {}); }, /Cannot create a change with no additions or deletions/); });