How to use the @google-cloud/common.paginator function in @google-cloud/common

To help you get started, we’ve selected a few @google-cloud/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / google-cloud-node / packages / compute / src / zone.js View on Github external
protocols: {
      tcp: [443]
    },
    ranges: ['0.0.0.0/0'],
    tags: ['https-server']
  }, function(err) {
    // If it already exists, we're all good.
    callback(err && err.code !== 409 ? err : null);
  });
};

/*! Developer Documentation
 *
 * These methods can be auto-paginated.
 */
common.paginator.extend(Zone, [
  'getAutoscalers',
  'getDisks',
  'getInstanceGroups',
  'getMachineTypes',
  'getOperations',
  'getVMs'
]);

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
common.util.promisifyAll(Zone, {
  exclude: [
    'autoscaler',
github googleapis / google-cloud-node / packages / storage / src / index.js View on Github external
*     // bucket is a Bucket object.
 *   })
 *   .on('end', function() {
 *     // All buckets retrieved.
 *   });
 *
 * //-
 * // If you anticipate many results, you can end a stream early to prevent
 * // unnecessary processing and API requests.
 * //-
 * gcs.getBucketsStream()
 *   .on('data', function(bucket) {
 *     this.end();
 *   });
 */
Storage.prototype.getBucketsStream = common.paginator.streamify('getBuckets');

/*! Developer Documentation
 *
 * These methods can be auto-paginated.
 */
common.paginator.extend(Storage, 'getBuckets');

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
common.util.promisifyAll(Storage, {
  exclude: ['bucket', 'channel']
});
github googleapis / google-cloud-node / packages / pubsub / src / index.js View on Github external
*   })
 *   .on('end', function() {
 *     // All snapshots retrieved.
 *   });
 *
 * //-
 * // If you anticipate many results, you can end a stream early to prevent
 * // unnecessary processing and API requests.
 * //-
 * pubsub.getSnapshotsStream()
 *   .on('data', function(snapshot) {
 *     this.end();
 *   });
 */
PubSub.prototype.getSnapshotsStream =
  common.paginator.streamify('getSnapshots');

/**
 * Get a list of the subscriptions registered to all of your project's topics.
 * You may optionally provide a query object as the first argument to customize
 * the response.
 *
 * Your provided callback will be invoked with an error object if an API error
 * occurred or an array of {module:pubsub/subscription} objects.
 *
 * To get subscriptions for a topic, see {module:pubsub/topic}.
 *
 * @resource [Subscriptions: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/list}
 *
 * @param {object=} options - Configuration object.
 * @param {boolean} options.autoPaginate - Have pagination handled
 *     automatically. Default: true.
github googleapis / google-cloud-node / packages / pubsub / src / index.js View on Github external
*   })
 *   .on('end', function() {
 *     // All subscriptions retrieved.
 *   });
 *
 * //-
 * // If you anticipate many results, you can end a stream early to prevent
 * // unnecessary processing and API requests.
 * //-
 * pubsub.getSubscriptionsStream()
 *   .on('data', function(subscription) {
 *     this.end();
 *   });
 */
PubSub.prototype.getSubscriptionsStream =
  common.paginator.streamify('getSubscriptions');

/**
 * Get a list of the topics registered to your project. You may optionally
 * provide a query object as the first argument to customize the response.
 *
 * @resource [Topics: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/list}
 *
 * @param {object=} query - Query object.
 * @param {boolean} query.autoPaginate - Have pagination handled
 *     automatically. Default: true.
 * @param {object} query.gaxOpts - Request configuration options, outlined
 *     here: https://googleapis.github.io/gax-nodejs/CallSettings.html.
 * @param {number} query.pageSize - Max number of results to return.
 * @param {string} query.pageToken - Page token.
 * @param {function} callback - The callback function.
 * @param {?error} callback.err - An error from the API call, may be null.
github googleapis / google-cloud-node / packages / prediction / src / index.js View on Github external
*     // model is a Model object.
 *   })
 *   .on('end', function() {
 *     // All models retrieved.
 *   });
 *
 * //-
 * // If you anticipate many results, you can end a stream early to prevent
 * // unnecessary processing and API requests.
 * //-
 * prediction.getModelsStream()
 *   .on('data', function(model) {
 *     this.end();
 *   });
 */
Prediction.prototype.getModelsStream = common.paginator.streamify('getModels');

/**
 * Create a model object representing a trained model.
 *
 * @throws {error} If a model ID is not provided.
 *
 * @param {string} id - The unique ID of the trained model.
 * @return {module:prediction/model}
 *
 * @example
 * var model = prediction.model('my-model');
 */
Prediction.prototype.model = function(id) {
  if (!id) {
    throw new Error('A model ID is required.');
  }
github googleapis / google-cloud-node / packages / storage / src / index.js View on Github external
*     // bucket is a Bucket object.
 *   })
 *   .on('end', function() {
 *     // All buckets retrieved.
 *   });
 *
 * //-
 * // If you anticipate many results, you can end a stream early to prevent
 * // unnecessary processing and API requests.
 * //-
 * gcs.getBucketsStream()
 *   .on('data', function(bucket) {
 *     this.end();
 *   });
 */
Storage.prototype.getBucketsStream = common.paginator.streamify('getBuckets');

/*! Developer Documentation
 *
 * These methods can be auto-paginated.
 */
common.paginator.extend(Storage, 'getBuckets');

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
common.util.promisifyAll(Storage, {
  exclude: ['bucket', 'channel']
});
github googleapis / google-cloud-node / packages / storage / src / bucket.js View on Github external
async.eachLimit(files, MAX_PARALLEL_LIMIT, processFile, function(err) {
      if (err || errors.length > 0) {
        callback(err || errors, updatedFiles);
        return;
      }

      callback(null, updatedFiles);
    });
  });
};

/*! Developer Documentation
 *
 * These methods can be auto-paginated.
 */
common.paginator.extend(Bucket, 'getFiles');

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

module.exports = Bucket;
github googleapis / google-cloud-node / packages / dns / src / index.js View on Github external
* @example
 * var zone = dns.zone('my-zone');
 */
DNS.prototype.zone = function(name) {
  if (!name) {
    throw new Error('A zone name is required.');
  }

  return new Zone(this, name);
};

/*! Developer Documentation
 *
 * These methods can be auto-paginated.
 */
common.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, {
  exclude: ['zone']
});

DNS.Zone = Zone;

module.exports = DNS;
github googleapis / google-cloud-node / packages / bigquery / src / dataset.js View on Github external
*
 * @param {string} id - The ID of the table.
 * @return {module:bigquery/table}
 *
 * @example
 * var institutions = dataset.table('institution_data');
 */
Dataset.prototype.table = function(id) {
  return new Table(this, id);
};

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

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

module.exports = Dataset;
github googleapis / google-cloud-node / packages / resource / src / index.js View on Github external
*/
Resource.prototype.project = function(id) {
  id = id || this.projectId;

  if (!id) {
    throw new Error('A project ID is required.');
  }

  return new Project(this, id);
};

/*! Developer Documentation
 *
 * These methods can be auto-paginated.
 */
common.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, {
  exclude: [
    'operation',
    'project'
  ]
});

Resource.Project = Project;

module.exports = Resource;