@google-cloud/common
Advanced tools
Comparing version 0.4.0 to 0.5.0
{ | ||
"name": "@google-cloud/common", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"author": "Google Inc.", | ||
@@ -44,3 +44,3 @@ "description": "Common components for Google Cloud APIs Node.js Client Libraries", | ||
"concat-stream": "^1.5.0", | ||
"create-error-class": "^2.0.1", | ||
"create-error-class": "^3.0.2", | ||
"dot-prop": "^2.4.0", | ||
@@ -64,3 +64,2 @@ "duplexify": "^3.2.0", | ||
"devDependencies": { | ||
"methmeth": "^1.0.0", | ||
"mocha": "^3.0.1", | ||
@@ -67,0 +66,0 @@ "node-uuid": "^1.4.3", |
@@ -112,4 +112,4 @@ /*! | ||
*/ | ||
GrpcServiceObject.prototype.request = function(protoOpts, reqOpts, callback) { | ||
return this.parent.request(protoOpts, reqOpts, callback); | ||
GrpcServiceObject.prototype.request = function() { | ||
return this.parent.request.apply(this.parent, arguments); | ||
}; | ||
@@ -122,6 +122,15 @@ | ||
*/ | ||
GrpcServiceObject.prototype.requestStream = function(protoOpts, reqOpts) { | ||
return this.parent.requestStream(protoOpts, reqOpts); | ||
GrpcServiceObject.prototype.requestStream = function() { | ||
return this.parent.requestStream.apply(this.parent, arguments); | ||
}; | ||
/** | ||
* Patch a writable streaming request to the GrpcService object. | ||
* | ||
* @private | ||
*/ | ||
GrpcServiceObject.prototype.requestWritableStream = function() { | ||
return this.parent.requestWritableStream.apply(this.parent, arguments); | ||
}; | ||
module.exports = GrpcServiceObject; |
@@ -24,2 +24,3 @@ /*! | ||
var dotProp = require('dot-prop'); | ||
var duplexify = require('duplexify'); | ||
var extend = require('extend'); | ||
@@ -41,2 +42,8 @@ var googleProtoFiles = require('google-proto-files'); | ||
/** | ||
* @type {module:common/util} | ||
* @private | ||
*/ | ||
var util = require('./util.js'); | ||
/** | ||
* @const {object} - A map of protobuf codes to HTTP status codes. | ||
@@ -175,2 +182,3 @@ * @private | ||
this.maxRetries = options.maxRetries; | ||
this.userAgent = util.getUserAgentFromPackageJson(config.packageJson); | ||
@@ -299,3 +307,3 @@ var apiVersion = config.apiVersion; | ||
* @param {object} protoOpts - The proto options. | ||
* @param {string} protoOpts.service - The service git stat. | ||
* @param {string} protoOpts.service - The service. | ||
* @param {string} protoOpts.method - The method name. | ||
@@ -375,2 +383,59 @@ * @param {number=} protoOpts.timeout - After how many milliseconds should the | ||
/** | ||
* Make an authenticated writable streaming request with gRPC. | ||
* | ||
* @param {object} protoOpts - The proto options. | ||
* @param {string} protoOpts.service - The service. | ||
* @param {string} protoOpts.method - The method name. | ||
* @param {number=} protoOpts.timeout - After how many milliseconds should the | ||
* request cancel. | ||
* @param {object} reqOpts - The request options. | ||
*/ | ||
GrpcService.prototype.requestWritableStream = function(protoOpts, reqOpts) { | ||
var stream = protoOpts.stream = protoOpts.stream || duplexify.obj(); | ||
if (global.GCLOUD_SANDBOX_ENV) { | ||
return stream; | ||
} | ||
var self = this; | ||
if (!this.grpcCredentials) { | ||
// We must establish an authClient to give to grpc. | ||
this.getGrpcCredentials_(function(err, credentials) { | ||
if (err) { | ||
stream.destroy(err); | ||
return; | ||
} | ||
self.grpcCredentials = credentials; | ||
self.requestWritableStream(protoOpts, reqOpts); | ||
}); | ||
return stream; | ||
} | ||
var service = this.getService_(protoOpts); | ||
var grpcOpts = {}; | ||
if (is.number(protoOpts.timeout)) { | ||
grpcOpts.deadline = GrpcService.createDeadline_(protoOpts.timeout); | ||
} | ||
var grpcStream = service[protoOpts.method](reqOpts, grpcOpts) | ||
.on('status', function(status) { | ||
var grcpStatus = GrpcService.decorateStatus_(status); | ||
stream.emit('response', grcpStatus || status); | ||
}) | ||
.on('error', function(err) { | ||
var grpcError = GrpcService.decorateError_(err); | ||
stream.destroy(grpcError || err); | ||
}); | ||
stream.setReadable(grpcStream); | ||
stream.setWritable(grpcStream); | ||
return stream; | ||
}; | ||
/** | ||
* Decode a protobuf Struct's value. | ||
@@ -740,3 +805,4 @@ * | ||
proto.baseUrl || this.baseUrl, | ||
this.grpcCredentials | ||
this.grpcCredentials, | ||
{ 'grpc.primary_user_agent': this.userAgent } | ||
); | ||
@@ -743,0 +809,0 @@ |
@@ -60,2 +60,3 @@ /*! | ||
this.interceptors = []; | ||
this.packageJson = config.packageJson; | ||
this.projectId = options.projectId; | ||
@@ -118,2 +119,6 @@ this.projectIdRequired = config.projectIdRequired !== false; | ||
reqOpts.headers = extend({}, reqOpts.headers, { | ||
'User-Agent': util.getUserAgentFromPackageJson(this.packageJson) | ||
}); | ||
return this.makeAuthenticatedRequest(reqOpts, callback); | ||
@@ -120,0 +125,0 @@ }; |
@@ -41,8 +41,2 @@ /** | ||
/** @const {object} @google-cloud/common's package.json file. */ | ||
var PKG = require('../package.json'); | ||
/** @const {string} User agent. */ | ||
var USER_AGENT = PKG.name + '/' + PKG.version; | ||
var util = module.exports; | ||
@@ -470,8 +464,3 @@ | ||
config = config || {}; | ||
reqOpts.headers = reqOpts.headers || {}; | ||
var headers = reqOpts.headers; | ||
var userAgent = headers['User-Agent'] || headers['user-agent']; | ||
headers['User-Agent'] = userAgent || config.userAgent || USER_AGENT; | ||
if (is.object(reqOpts.qs)) { | ||
@@ -630,1 +619,17 @@ delete reqOpts.qs.autoPaginate; | ||
util.isCustomType = isCustomType; | ||
/** | ||
* Create a properly-formatted User-Agent string from a package.json file. | ||
* | ||
* @param {object} packageJson - A module's package.json file. | ||
* @return {string} userAgent - The formatted User-Agent string. | ||
*/ | ||
function getUserAgentFromPackageJson(packageJson) { | ||
var hyphenatedPackageName = packageJson.name | ||
.replace('@google-cloud', 'gcloud-node') // For legacy purposes. | ||
.replace('/', '-'); // For UA spec-compliance purposes. | ||
return hyphenatedPackageName + '/' + packageJson.version; | ||
} | ||
util.getUserAgentFromPackageJson = getUserAgentFromPackageJson; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68928
4
2130
+ Addedcreate-error-class@3.0.2(transitive)
- Removedcreate-error-class@2.0.1(transitive)
Updatedcreate-error-class@^3.0.2