diff --git a/packages/google-cloud-compute/package.json b/packages/google-cloud-compute/package.json index 8323c952de1..c6e8dedc01e 100644 --- a/packages/google-cloud-compute/package.json +++ b/packages/google-cloud-compute/package.json @@ -64,6 +64,7 @@ }, "dependencies": { "@google-cloud/common": "^0.17.0", + "@google-cloud/paginator": "^0.1.1", "@google-cloud/promisify": "^0.3.1", "arrify": "^1.0.1", "async": "^2.6.1", diff --git a/packages/google-cloud-compute/src/index.js b/packages/google-cloud-compute/src/index.js index 23785b66383..8c0952bac35 100644 --- a/packages/google-cloud-compute/src/index.js +++ b/packages/google-cloud-compute/src/index.js @@ -23,6 +23,7 @@ const format = require('string-format-obj'); const is = require('is'); const util = require('util'); const {promisifyAll} = require('@google-cloud/promisify'); +const {paginator} = require('@google-cloud/paginator'); const Firewall = require('./firewall.js'); const HealthCheck = require('./health-check.js'); @@ -809,9 +810,7 @@ Compute.prototype.getAddresses = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getAddressesStream = common.paginator.streamify( - 'getAddresses' -); +Compute.prototype.getAddressesStream = paginator.streamify('getAddresses'); /** * Get a list of autoscalers. For a detailed description of this method's @@ -948,9 +947,7 @@ Compute.prototype.getAutoscalers = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getAutoscalersStream = common.paginator.streamify( - 'getAutoscalers' -); +Compute.prototype.getAutoscalersStream = paginator.streamify('getAutoscalers'); /** * Get a list of disks. @@ -1082,7 +1079,7 @@ Compute.prototype.getDisks = function(options, callback) { * }); */ -Compute.prototype.getDisksStream = common.paginator.streamify('getDisks'); +Compute.prototype.getDisksStream = paginator.streamify('getDisks'); /** * Get a list of instance groups. @@ -1216,7 +1213,7 @@ Compute.prototype.getInstanceGroups = function(options, callback) { * }); */ -Compute.prototype.getInstanceGroupsStream = common.paginator.streamify( +Compute.prototype.getInstanceGroupsStream = paginator.streamify( 'getInstanceGroups' ); @@ -1337,9 +1334,7 @@ Compute.prototype.getFirewalls = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getFirewallsStream = common.paginator.streamify( - 'getFirewalls' -); +Compute.prototype.getFirewallsStream = paginator.streamify('getFirewalls'); /** * Get a list of health checks. @@ -1467,7 +1462,7 @@ Compute.prototype.getHealthChecks = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getHealthChecksStream = common.paginator.streamify( +Compute.prototype.getHealthChecksStream = paginator.streamify( 'getHealthChecks' ); @@ -1587,7 +1582,7 @@ Compute.prototype.getImages = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getImagesStream = common.paginator.streamify('getImages'); +Compute.prototype.getImagesStream = paginator.streamify('getImages'); /** * Get a list of machine types in this project. @@ -1721,7 +1716,7 @@ Compute.prototype.getMachineTypes = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getMachineTypesStream = common.paginator.streamify( +Compute.prototype.getMachineTypesStream = paginator.streamify( 'getMachineTypes' ); @@ -1845,7 +1840,7 @@ Compute.prototype.getNetworks = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getNetworksStream = common.paginator.streamify('getNetworks'); +Compute.prototype.getNetworksStream = paginator.streamify('getNetworks'); /** * Get a list of global operations. @@ -1968,9 +1963,7 @@ Compute.prototype.getOperations = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getOperationsStream = common.paginator.streamify( - 'getOperations' -); +Compute.prototype.getOperationsStream = paginator.streamify('getOperations'); /** * Return the regions available to your project. @@ -2091,7 +2084,7 @@ Compute.prototype.getRegions = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getRegionsStream = common.paginator.streamify('getRegions'); +Compute.prototype.getRegionsStream = paginator.streamify('getRegions'); /** * Get a list of forwarding rules. @@ -2212,7 +2205,7 @@ Compute.prototype.getRules = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getRulesStream = common.paginator.streamify('getRules'); +Compute.prototype.getRulesStream = paginator.streamify('getRules'); /** * Get a list of backend services. @@ -2334,7 +2327,7 @@ Compute.prototype.getServices = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getServicesStream = common.paginator.streamify('getServices'); +Compute.prototype.getServicesStream = paginator.streamify('getServices'); /** * Get a list of snapshots. @@ -2456,9 +2449,7 @@ Compute.prototype.getSnapshots = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getSnapshotsStream = common.paginator.streamify( - 'getSnapshots' -); +Compute.prototype.getSnapshotsStream = paginator.streamify('getSnapshots'); /** * Get a list of subnetworks in this project. @@ -2594,9 +2585,7 @@ Compute.prototype.getSubnetworks = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getSubnetworksStream = common.paginator.streamify( - 'getSubnetworks' -); +Compute.prototype.getSubnetworksStream = paginator.streamify('getSubnetworks'); /** * Get a list of virtual machine instances. @@ -2726,7 +2715,7 @@ Compute.prototype.getVMs = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getVMsStream = common.paginator.streamify('getVMs'); +Compute.prototype.getVMsStream = paginator.streamify('getVMs'); /** * Return the zones available to your project. @@ -2847,7 +2836,7 @@ Compute.prototype.getZones = function(options, callback) { * this.end(); * }); */ -Compute.prototype.getZonesStream = common.paginator.streamify('getZones'); +Compute.prototype.getZonesStream = paginator.streamify('getZones'); /** * Get a reference to a Google Compute Engine health check. @@ -3035,7 +3024,7 @@ Compute.prototype.execAfterOperation_ = function(callback) { * * These methods can be auto-paginated. */ -common.paginator.extend(Compute, [ +paginator.extend(Compute, [ 'getAddresses', 'getAutoscalers', 'getDisks', diff --git a/packages/google-cloud-compute/src/instance-group.js b/packages/google-cloud-compute/src/instance-group.js index bb89ac51872..852d9012887 100644 --- a/packages/google-cloud-compute/src/instance-group.js +++ b/packages/google-cloud-compute/src/instance-group.js @@ -22,6 +22,7 @@ const extend = require('extend'); const is = require('is'); const util = require('util'); const {promisifyAll} = require('@google-cloud/promisify'); +const {paginator} = require('@google-cloud/paginator'); /** * You can create and manage groups of virtual machine instances so that you @@ -466,7 +467,7 @@ InstanceGroup.prototype.getVMs = function(options, callback) { * this.end(); * }); */ -InstanceGroup.prototype.getVMsStream = common.paginator.streamify('getVMs'); +InstanceGroup.prototype.getVMsStream = paginator.streamify('getVMs'); /** * Remove one or more VMs from this instance group. @@ -602,7 +603,7 @@ InstanceGroup.prototype.setPorts = function(ports, callback) { * * These methods can be auto-paginated. */ -common.paginator.extend(InstanceGroup, ['getVMs']); +paginator.extend(InstanceGroup, ['getVMs']); /*! Developer Documentation * diff --git a/packages/google-cloud-compute/src/region.js b/packages/google-cloud-compute/src/region.js index 6db29c97d9e..01115defabd 100644 --- a/packages/google-cloud-compute/src/region.js +++ b/packages/google-cloud-compute/src/region.js @@ -21,6 +21,7 @@ const extend = require('extend'); const is = require('is'); const util = require('util'); const {promisifyAll} = require('@google-cloud/promisify'); +const {paginator} = require('@google-cloud/paginator'); const Address = require('./address.js'); const Network = require('./network.js'); @@ -529,9 +530,7 @@ Region.prototype.getAddresses = function(options, callback) { * this.end(); * }); */ -Region.prototype.getAddressesStream = common.paginator.streamify( - 'getAddresses' -); +Region.prototype.getAddressesStream = paginator.streamify('getAddresses'); /** * Get a list of operations for this region. @@ -661,9 +660,7 @@ Region.prototype.getOperations = function(options, callback) { * this.end(); * }); */ -Region.prototype.getOperationsStream = common.paginator.streamify( - 'getOperations' -); +Region.prototype.getOperationsStream = paginator.streamify('getOperations'); /** * Get a list of forwading rules in this region. @@ -792,7 +789,7 @@ Region.prototype.getRules = function(options, callback) { * this.end(); * }); */ -Region.prototype.getRulesStream = common.paginator.streamify('getRules'); +Region.prototype.getRulesStream = paginator.streamify('getRules'); /** * Get a list of subnetworks in this region. @@ -922,9 +919,7 @@ Region.prototype.getSubnetworks = function(options, callback) { * this.end(); * }); */ -Region.prototype.getSubnetworksStream = common.paginator.streamify( - 'getSubnetworks' -); +Region.prototype.getSubnetworksStream = paginator.streamify('getSubnetworks'); /** * Get a reference to a Google Compute Engine region operation. @@ -985,7 +980,7 @@ Region.prototype.subnetwork = function(name) { * * These methods can be auto-paginated. */ -common.paginator.extend(Region, [ +paginator.extend(Region, [ 'getAddresses', 'getOperations', 'getRules', diff --git a/packages/google-cloud-compute/src/zone.js b/packages/google-cloud-compute/src/zone.js index f44e26f6ce3..d9a1f835f6c 100644 --- a/packages/google-cloud-compute/src/zone.js +++ b/packages/google-cloud-compute/src/zone.js @@ -25,6 +25,7 @@ const gceImages = require('gce-images'); const is = require('is'); const util = require('util'); const {promisifyAll} = require('@google-cloud/promisify'); +const {paginator} = require('@google-cloud/paginator'); const Autoscaler = require('./autoscaler.js'); const Disk = require('./disk.js'); @@ -889,9 +890,7 @@ Zone.prototype.getAutoscalers = function(options, callback) { * this.end(); * }); */ -Zone.prototype.getAutoscalersStream = common.paginator.streamify( - 'getAutoscalers' -); +Zone.prototype.getAutoscalersStream = paginator.streamify('getAutoscalers'); /** * Get a list of disks in this zone. @@ -1020,7 +1019,7 @@ Zone.prototype.getDisks = function(options, callback) { * this.end(); * }); */ -Zone.prototype.getDisksStream = common.paginator.streamify('getDisks'); +Zone.prototype.getDisksStream = paginator.streamify('getDisks'); /** * Get a list of instance groups for this zone. @@ -1151,7 +1150,7 @@ Zone.prototype.getInstanceGroups = function(options, callback) { * this.end(); * }); */ -Zone.prototype.getInstanceGroupsStream = common.paginator.streamify( +Zone.prototype.getInstanceGroupsStream = paginator.streamify( 'getInstanceGroups' ); @@ -1251,9 +1250,7 @@ Zone.prototype.getMachineTypes = function(options, callback) { * this.end(); * }); */ -Zone.prototype.getMachineTypesStream = common.paginator.streamify( - 'getMachineTypes' -); +Zone.prototype.getMachineTypesStream = paginator.streamify('getMachineTypes'); /** * Get a list of operations for this zone. @@ -1383,9 +1380,7 @@ Zone.prototype.getOperations = function(options, callback) { * this.end(); * }); */ -Zone.prototype.getOperationsStream = common.paginator.streamify( - 'getOperations' -); +Zone.prototype.getOperationsStream = paginator.streamify('getOperations'); /** * Get a list of VM instances in this zone. @@ -1512,7 +1507,7 @@ Zone.prototype.getVMs = function(options, callback) { * this.end(); * }); */ -Zone.prototype.getVMsStream = common.paginator.streamify('getVMs'); +Zone.prototype.getVMsStream = paginator.streamify('getVMs'); /** * Get a reference to a Google Compute Engine instance group. @@ -1647,7 +1642,7 @@ Zone.prototype.createHttpsServerFirewall_ = function(callback) { * * These methods can be auto-paginated. */ -common.paginator.extend(Zone, [ +paginator.extend(Zone, [ 'getAutoscalers', 'getDisks', 'getInstanceGroups', diff --git a/packages/google-cloud-compute/test/index.js b/packages/google-cloud-compute/test/index.js index 26c0dce8092..cd45b97a4d8 100644 --- a/packages/google-cloud-compute/test/index.js +++ b/packages/google-cloud-compute/test/index.js @@ -28,17 +28,16 @@ const promisify = require('@google-cloud/promisify'); const slice = Array.prototype.slice; -let promisified = false; const fakeUtil = extend({}, util, { makeAuthenticatedRequestFactory: util.noop, }); +let promisified = false; const fakePromisify = extend({}, promisify, { promisifyAll: function(Class, options) { if (Class.name !== 'Compute') { return; } - promisified = true; assert.deepStrictEqual(options.exclude, [ 'address', @@ -65,34 +64,36 @@ const fakePromisify = extend({}, promisify, { const originalFakeUtil = extend(true, {}, fakeUtil); const fakePaginator = { - extend: function(Class, methods) { - if (Class.name !== 'Compute') { - return; - } + paginator: { + extend: function(Class, methods) { + if (Class.name !== 'Compute') { + return; + } - methods = arrify(methods); - assert.deepStrictEqual(methods, [ - 'getAddresses', - 'getAutoscalers', - 'getDisks', - 'getFirewalls', - 'getImages', - 'getHealthChecks', - 'getInstanceGroups', - 'getMachineTypes', - 'getNetworks', - 'getOperations', - 'getRegions', - 'getRules', - 'getServices', - 'getSnapshots', - 'getSubnetworks', - 'getVMs', - 'getZones', - ]); - }, - streamify: function(methodName) { - return methodName; + methods = arrify(methods); + assert.deepStrictEqual(methods, [ + 'getAddresses', + 'getAutoscalers', + 'getDisks', + 'getFirewalls', + 'getImages', + 'getHealthChecks', + 'getInstanceGroups', + 'getMachineTypes', + 'getNetworks', + 'getOperations', + 'getRegions', + 'getRules', + 'getServices', + 'getSnapshots', + 'getSubnetworks', + 'getVMs', + 'getZones', + ]); + }, + streamify: function(methodName) { + return methodName; + }, }, }; @@ -175,9 +176,9 @@ describe('Compute', function() { Compute = proxyquire('../', { '@google-cloud/common': { Service: FakeService, - paginator: fakePaginator, util: fakeUtil, }, + '@google-cloud/paginator': fakePaginator, '@google-cloud/promisify': fakePromisify, './firewall.js': FakeFirewall, './health-check.js': FakeHealthCheck, diff --git a/packages/google-cloud-compute/test/instance-group.js b/packages/google-cloud-compute/test/instance-group.js index 55e08c87925..3a629cf5e4f 100644 --- a/packages/google-cloud-compute/test/instance-group.js +++ b/packages/google-cloud-compute/test/instance-group.js @@ -42,18 +42,20 @@ nodeutil.inherits(FakeServiceObject, ServiceObject); let extended = false; const fakePaginator = { - extend: function(Class, methods) { - if (Class.name !== 'InstanceGroup') { - return; - } - - extended = true; - methods = arrify(methods); - assert.strictEqual(Class.name, 'InstanceGroup'); - assert.deepStrictEqual(methods, ['getVMs']); - }, - streamify: function(methodName) { - return methodName; + paginator: { + extend: function(Class, methods) { + if (Class.name !== 'InstanceGroup') { + return; + } + + extended = true; + methods = arrify(methods); + assert.strictEqual(Class.name, 'InstanceGroup'); + assert.deepStrictEqual(methods, ['getVMs']); + }, + streamify: function(methodName) { + return methodName; + }, }, }; @@ -73,8 +75,8 @@ describe('InstanceGroup', function() { InstanceGroup = proxyquire('../src/instance-group.js', { '@google-cloud/common': { ServiceObject: FakeServiceObject, - paginator: fakePaginator, }, + '@google-cloud/paginator': fakePaginator, '@google-cloud/promisify': fakePromisify, }); staticMethods.formatPorts_ = InstanceGroup.formatPorts_; diff --git a/packages/google-cloud-compute/test/region.js b/packages/google-cloud-compute/test/region.js index 68fcb68edf7..cbb570e2545 100644 --- a/packages/google-cloud-compute/test/region.js +++ b/packages/google-cloud-compute/test/region.js @@ -70,23 +70,25 @@ nodeutil.inherits(FakeServiceObject, ServiceObject); let extended = false; const fakePaginator = { - extend: function(Class, methods) { - if (Class.name !== 'Region') { - return; - } - - extended = true; - methods = arrify(methods); - assert.strictEqual(Class.name, 'Region'); - assert.deepStrictEqual(methods, [ - 'getAddresses', - 'getOperations', - 'getRules', - 'getSubnetworks', - ]); - }, - streamify: function(methodName) { - return methodName; + paginator: { + extend: function(Class, methods) { + if (Class.name !== 'Region') { + return; + } + + extended = true; + methods = arrify(methods); + assert.strictEqual(Class.name, 'Region'); + assert.deepStrictEqual(methods, [ + 'getAddresses', + 'getOperations', + 'getRules', + 'getSubnetworks', + ]); + }, + streamify: function(methodName) { + return methodName; + }, }, }; @@ -103,8 +105,8 @@ describe('Region', function() { Region = proxyquire('../src/region.js', { '@google-cloud/common': { ServiceObject: FakeServiceObject, - paginator: fakePaginator, }, + '@google-cloud/paginator': fakePaginator, '@google-cloud/promisify': fakePromisify, './address.js': FakeAddress, './network.js': FakeNetwork, diff --git a/packages/google-cloud-compute/test/zone.js b/packages/google-cloud-compute/test/zone.js index 4a80b678489..a648381c8ce 100644 --- a/packages/google-cloud-compute/test/zone.js +++ b/packages/google-cloud-compute/test/zone.js @@ -87,25 +87,27 @@ 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, [ - 'getAutoscalers', - 'getDisks', - 'getInstanceGroups', - 'getMachineTypes', - 'getOperations', - 'getVMs', - ]); - }, - 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, [ + 'getAutoscalers', + 'getDisks', + 'getInstanceGroups', + 'getMachineTypes', + 'getOperations', + 'getVMs', + ]); + }, + streamify: function(methodName) { + return methodName; + }, }, }; @@ -124,8 +126,8 @@ describe('Zone', function() { 'gce-images': fakeGceImages, '@google-cloud/common': { ServiceObject: FakeServiceObject, - paginator: fakePaginator, }, + '@google-cloud/paginator': fakePaginator, '@google-cloud/promisify': fakePromisify, './autoscaler.js': FakeAutoscaler, './disk.js': FakeDisk,