How to use the @google-cloud/common.util 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 / nodejs-compute / src / operation.js View on Github external
this.getMetadata(function(err, metadata, apiResponse) {
      // Parsing the response body will automatically create an ApiError object if
      // the operation failed.
      const parsedHttpRespBody = common.util.parseHttpRespBody(apiResponse);
      err = err || parsedHttpRespBody.err;
      if (err) {
        callback(err);
        return;
      }
      if (metadata.status === 'RUNNING' && !self.status) {
        self.status = metadata.status;
        self.emit('running', metadata);
      }
      if (metadata.status !== 'DONE') {
        callback();
        return;
      }
      self.status = metadata.status;
      callback(null, metadata);
    });
github googleapis / nodejs-storage / src / file.js View on Github external
.on('response', res => {
          throughStream.emit('response', res);
          common.util.handleResp(null, res, null, onResponse);
        })
        .resume();
github firebase / user-privacy / functions / node_modules / @google-cloud / common-grpc / src / operation.js View on Github external
Operation.prototype.cancel = function(callback) {
  var protoOpts = {
    service: 'Operations',
    method: 'cancelOperation',
  };

  var reqOpts = {
    name: this.id,
  };

  this.request(protoOpts, reqOpts, callback || common.util.noop);
};
github googleapis / nodejs-storage / src / bucket.js View on Github external
});
  }
}

/*! 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: ['request', 'file', 'notification'],
});

/**
 * Reference to the {@link Bucket} class.
 * @name module:@google-cloud/storage.Bucket
 * @see Bucket
 */
module.exports = Bucket;
github googleapis / google-cloud-node / packages / compute / src / vm.js View on Github external
return;
    }

    var operation = zone.operation(resp.name);
    operation.metadata = resp;

    callback(null, operation, resp);
  });
};

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
common.util.promisifyAll(VM);

module.exports = VM;
github googleapis / google-cloud-node / packages / datastore / src / index.js View on Github external
function Datastore(options) {
  if (!(this instanceof Datastore)) {
    options = common.util.normalizeArguments(this, options, {
      projectIdRequired: false
    });
    return new Datastore(options);
  }

  this.defaultBaseUrl_ = 'datastore.googleapis.com';
  this.determineBaseUrl_(options.apiEndpoint);

  this.namespace = options.namespace;
  this.projectId = process.env.DATASTORE_PROJECT_ID || options.projectId;

  var config = {
    projectIdRequired: false,
    baseUrl: this.baseUrl_,
    customEndpoint: this.customEndpoint_,
    protosDir: path.resolve(__dirname, '../protos'),
github googleapis / google-cloud-node / packages / storage / src / index.js View on Github external
function Storage(options) {
  if (!(this instanceof Storage)) {
    options = common.util.normalizeArguments(this, options);
    return new Storage(options);
  }

  var config = {
    baseUrl: 'https://www.googleapis.com./storage/v1',
    projectIdRequired: false,
    scopes: [
      'https://www.googleapis.com/auth/devstorage.full_control'
    ],
    packageJson: require('../package.json')
  };

  common.Service.call(this, config, options);
}
github googleapis / google-cloud-node / packages / bigquery / src / index.js View on Github external
this.createJob(reqOpts, callback);
};

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

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

BigQuery.Dataset = Dataset;
BigQuery.Job = Job;
BigQuery.Table = Table;

module.exports = BigQuery;
github googleapis / google-cloud-node / packages / pubsub / src / subscription.js View on Github external
Subscription.prototype.modifyAckDeadline_ = function(ackIds, deadline, connId) {
  var self = this;
  var promise;

  ackIds = arrify(ackIds);

  if (!this.isConnected_()) {
    promise = common.util.promisify(this.request).call(this, {
      client: 'subscriberClient',
      method: 'modifyAckDeadline',
      reqOpts: {
        subscription: self.name,
        ackDeadlineSeconds: deadline,
        ackIds
      }
    });
  } else {
    promise = new Promise(function(resolve, reject) {
      self.connectionPool.acquire(connId, function(err, connection) {
        if (err) {
          reject(err);
          return;
        }
github firebase / user-privacy / functions / node_modules / @google-cloud / common-grpc / src / service.js View on Github external
/*!
 * @module commonGrpc/service
 */

'use strict';

var dotProp = require('dot-prop');
var duplexify = require('duplexify');
var extend = require('extend');
var grpc = require('grpc');
var is = require('is');
var nodeutil = require('util');
var retryRequest = require('retry-request');
var Service = require('@google-cloud/common').Service;
var through = require('through2');
var util = require('@google-cloud/common').util;

/**
 * @const {object} - A map of protobuf codes to HTTP status codes.
 * @private
 */
var GRPC_ERROR_CODE_TO_HTTP = {
  0: {
    code: 200,
    message: 'OK'
  },

  1: {
    code: 499,
    message: 'Client Closed Request'
  },