Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions packages/common-grpc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "@google-cloud/common-grpc",
"version": "0.0.0",
"author": "Google Inc.",
"description": "Common components for Google Cloud APIs Node.js Client Libraries that require gRPC",
"contributors": [
{
"name": "Burcu Dogan",
"email": "jbd@google.com"
},
{
"name": "Johan Euphrosine",
"email": "proppy@google.com"
},
{
"name": "Patrick Costello",
"email": "pcostell@google.com"
},
{
"name": "Ryan Seys",
"email": "ryan@ryanseys.com"
},
{
"name": "Silvano Luciani",
"email": "silvano@google.com"
},
{
"name": "Stephen Sawchuk",
"email": "sawchuk@gmail.com"
}
],
"main": "./src/index.js",
"files": [
"src",
"AUTHORS",
"CONTRIBUTORS",
"COPYING"
],
"repository": "googlecloudplatform/google-cloud-node",
"dependencies": {
"@google-cloud/common": "^0.11.0",
"dot-prop": "^2.4.0",
"duplexify": "^3.5.0",
"extend": "^3.0.0",
"google-proto-files": "^0.8.6",
"grpc": "^1.0.1",
"is": "^3.2.0",
"retry-request": "^1.3.2",
"through2": "^2.0.3"
},
"devDependencies": {
"mocha": "^3.2.0",
"proxyquire": "^1.7.10",
"sinon": "^1.17.7",
"uuid": "^3.0.1"
},
"scripts": {
"publish-module": "node ../../scripts/publish.js common-grpc",
"test": "mocha test/*.js"
},
"license": "Apache-2.0",
"engines": {
"node": ">=0.12.0"
}
}
36 changes: 36 additions & 0 deletions packages/common-grpc/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*!
* @module commonGrpc
*/

'use strict';

/**
* @type {module:commonGrpc/operation}
*/
exports.Operation = require('./operation.js');

/**
* @type {module:commonGrpc/serviceObject}
*/
exports.ServiceObject = require('./service-object.js');

/**
* @type {module:commonGrpc/service}
*/
exports.Service = require('./service.js');
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,25 @@
*/

/*!
* @module common/grpcOperation
* @module commonGrpc/operation
*/

'use strict';

var common = require('@google-cloud/common');
var modelo = require('modelo');

/**
* @type {module:common/grpcServiceObject}
* @type {module:commonGrpc/serviceObject}
* @private
*/
var GrpcServiceObject = require('./grpc-service-object.js');
var ServiceObject = require('./service-object.js');

/**
* @type {module:common/operation}
* @type {module:commonGrpc/service}
* @private
*/
var Operation = require('./operation.js');

/**
* @type {module:common/util}
* @private
*/
var util = require('./util.js');
var Service = require('./service.js');

// jscs:disable maximumLineLength
/**
Expand All @@ -48,13 +43,13 @@ var util = require('./util.js');
* @constructor
* @alias module:common/grpcOperation
*
* @param {module:common/grpcService|module:common/grpcServiceObject} parent - The
* @param {module:commonGrpc/service|module:commonGrpc/serviceObject} parent - The
* parent object. This should be configured to use the longrunning.operation
* service.
* @param {string} name - The operation name.
*/
// jscs:enable maximumLineLength
function GrpcOperation(parent, name) {
function Operation(parent, name) {
var methods = {

/**
Expand Down Expand Up @@ -100,11 +95,11 @@ function GrpcOperation(parent, name) {
methods: methods
};

Operation.call(this, config);
GrpcServiceObject.call(this, config);
common.Operation.call(this, config);
ServiceObject.call(this, config);
}

modelo.inherits(GrpcOperation, GrpcServiceObject, Operation);
modelo.inherits(Operation, ServiceObject, common.Operation);

/**
* Cancel the operation.
Expand All @@ -114,7 +109,7 @@ modelo.inherits(GrpcOperation, GrpcServiceObject, Operation);
* request.
* @param {object} callback.apiResponse - The full API response.
*/
GrpcOperation.prototype.cancel = function(callback) {
Operation.prototype.cancel = function(callback) {
var protoOpts = {
service: 'Operations',
method: 'cancelOperation'
Expand All @@ -124,7 +119,34 @@ GrpcOperation.prototype.cancel = function(callback) {
name: this.id
};

this.request(protoOpts, reqOpts, callback || util.noop);
this.request(protoOpts, reqOpts, callback || common.util.noop);
};

/**
* Poll for a status update. Execute the callback:
*
* - callback(err): Operation failed
* - callback(): Operation incomplete
* - callback(null, metadata): Operation complete
*
* @private
*
* @param {function} callback
*/
Operation.prototype.poll_ = function(callback) {
this.getMetadata(function(err, resp) {
if (err || resp.error) {
callback(err || Service.decorateGrpcStatus_(resp.error));
return;
}

if (!resp.done) {
callback();
return;
}

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

module.exports = GrpcOperation;
module.exports = Operation;
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,15 @@
*/

/*!
* @module common/grpc-service-object
* @module commonGrpc/serviceObject
*/

'use strict';

var extend = require('extend');
var nodeutil = require('util');

/**
* @type {module:common/service-object}
* @private
*/
var ServiceObject = require('./service-object.js');

/**
* @type {module:common/util}
* @private
*/
var util = require('./util.js');
var ServiceObject = require('@google-cloud/common').ServiceObject;
var util = require('@google-cloud/common').util;

/**
* GrpcServiceObject is a base class, meant to be inherited from by a service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/*!
* @module common/grpc-service
* @module commonGrpc/service
*/

'use strict';
Expand All @@ -29,19 +29,9 @@ var is = require('is');
var nodeutil = require('util');
var path = require('path');
var retryRequest = require('retry-request');
var Service = require('@google-cloud/common').Service;
var through = require('through2');

/**
* @type {module:common/service}
* @private
*/
var Service = require('./service.js');

/**
* @type {module:common/util}
* @private
*/
var util = require('./util.js');
var util = require('@google-cloud/common').util;

/**
* @const {object} - A map of protobuf codes to HTTP status codes.
Expand Down
44 changes: 44 additions & 0 deletions packages/common-grpc/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var assert = require('assert');
var proxyquire = require('proxyquire');

var fakeOperation = {};
var fakeService = {};
var fakeServiceObject = {};

describe('grpc-common', function() {
var grpcCommon;

before(function() {
grpcCommon = proxyquire('../src/index.js', {
'./operation.js': fakeOperation,
'./service.js': fakeService,
'./service-object.js': fakeServiceObject
});
});

it('should correctly export the common modules', function() {
assert.deepEqual(grpcCommon, {
Operation: fakeOperation,
Service: fakeService,
ServiceObject: fakeServiceObject
});
});
});
Loading