diff --git a/packages/grpc-native-core/index.d.ts b/packages/grpc-native-core/index.d.ts index 69c423d8..73a685cd 100644 --- a/packages/grpc-native-core/index.d.ts +++ b/packages/grpc-native-core/index.d.ts @@ -66,7 +66,7 @@ declare module "grpc" { * - Anything else becomes the relevant reflection object that ProtoBuf.js would create */ export interface GrpcObject { - [name: string]: GrpcObject | typeof Client | Message; + [name: string]: GrpcObject | typeof Client | Message; } /** @@ -573,12 +573,12 @@ declare module "grpc" { /** * The server's private key */ - privateKey: Buffer; + private_key: Buffer; /** * The server's certificate chain */ - certChain: Buffer; + cert_chain: Buffer; } /** diff --git a/packages/grpc-native-core/index.js b/packages/grpc-native-core/index.js index 7810b7bf..fa07baeb 100644 --- a/packages/grpc-native-core/index.js +++ b/packages/grpc-native-core/index.js @@ -219,8 +219,8 @@ exports.ServerCredentials = grpc.ServerCredentials; /** * A private key and certificate pair * @typedef {Object} grpc.ServerCredentials~keyCertPair - * @property {Buffer} privateKey The server's private key - * @property {Buffer} certChain The server's certificate chain + * @property {Buffer} private_key The server's private key + * @property {Buffer} cert_chain The server's certificate chain */ /** diff --git a/packages/grpc-native-core/src/client.js b/packages/grpc-native-core/src/client.js index b9de0ab5..a917cbc9 100644 --- a/packages/grpc-native-core/src/client.js +++ b/packages/grpc-native-core/src/client.js @@ -513,13 +513,23 @@ exports.Client = Client; Client.prototype.makeUnaryRequest = function(method, serialize, deserialize, argument, metadata, options, callback) { - if (!(metadata instanceof Metadata)) { - callback = options; - options = metadata; - metadata = new Metadata(); - } if (options instanceof Function) { callback = options; + if (metadata instanceof Metadata) { + options = {}; + } else { + options = metadata; + metadata = new Metadata(); + } + } else if (metadata instanceof Function) { + callback = metadata; + metadata = new Metadata(); + options = {}; + } + if (!metadata) { + metadata = new Metadata(); + } + if (!options) { options = {}; } if (!((metadata instanceof Metadata) && @@ -599,13 +609,23 @@ Client.prototype.makeUnaryRequest = function(method, serialize, deserialize, Client.prototype.makeClientStreamRequest = function(method, serialize, deserialize, metadata, options, callback) { - if (!(metadata instanceof Metadata)) { - callback = options; - options = metadata; - metadata = new Metadata(); - } if (options instanceof Function) { callback = options; + if (metadata instanceof Metadata) { + options = {}; + } else { + options = metadata; + metadata = new Metadata(); + } + } else if (metadata instanceof Function) { + callback = metadata; + metadata = new Metadata(); + options = {}; + } + if (!metadata) { + metadata = new Metadata(); + } + if (!options) { options = {}; } if (!((metadata instanceof Metadata) && diff --git a/packages/grpc-native-core/src/grpc_extension.js b/packages/grpc-native-core/src/grpc_extension.js index 46e2721d..9a023b7c 100644 --- a/packages/grpc-native-core/src/grpc_extension.js +++ b/packages/grpc-native-core/src/grpc_extension.js @@ -31,17 +31,26 @@ var binding; try { binding = require(binding_path); } catch (e) { - var fs = require('fs'); - var searchPath = path.dirname(path.dirname(binding_path)); - var searchName = path.basename(path.dirname(binding_path)); - var foundNames = fs.readdirSync(searchPath); + let fs = require('fs'); + let searchPath = path.dirname(path.dirname(binding_path)); + let searchName = path.basename(path.dirname(binding_path)); + let foundNames; + try { + foundNames = fs.readdirSync(searchPath); + } catch (readDirError) { + let message = `The gRPC binary module was not installed. This may be fixed by running "npm rebuild" +Original error: ${e.message}`; + let error = new Error(message); + error.code = e.code; + throw error; + } if (foundNames.indexOf(searchName) === -1) { - var message = `Failed to load gRPC binary module because it was not installed for the current system + let message = `Failed to load gRPC binary module because it was not installed for the current system Expected directory: ${searchName} Found: [${foundNames.join(', ')}] This problem can often be fixed by running "npm rebuild" on the current system Original error: ${e.message}`; - var error = new Error(message); + let error = new Error(message); error.code = e.code; throw error; } else { diff --git a/test/api/surface_test.js b/test/api/surface_test.js index 3bffaf8e..92802435 100644 --- a/test/api/surface_test.js +++ b/test/api/surface_test.js @@ -506,6 +506,116 @@ describe('Echo metadata', function() { done(); }); }); + describe('Call argument handling', function() { + describe('Unary call', function() { + it('Should handle undefined options', function(done) { + var call = client.unary({}, metadata, undefined, function(err, data) { + assert.ifError(err); + }); + call.on('metadata', function(metadata) { + assert.deepEqual(metadata.get('key'), ['value']); + done(); + }); + }); + it('Should handle two undefined arguments', function(done) { + var call = client.unary({}, undefined, undefined, function(err, data) { + assert.ifError(err); + }); + call.on('metadata', function(metadata) { + done(); + }); + }); + it('Should handle one undefined argument', function(done) { + var call = client.unary({}, undefined, function(err, data) { + assert.ifError(err); + }); + call.on('metadata', function(metadata) { + done(); + }); + }); + }); + describe('Client stream call', function() { + it('Should handle undefined options', function(done) { + var call = client.clientStream(metadata, undefined, function(err, data) { + assert.ifError(err); + }); + call.on('metadata', function(metadata) { + assert.deepEqual(metadata.get('key'), ['value']); + done(); + }); + call.end(); + }); + it('Should handle two undefined arguments', function(done) { + var call = client.clientStream(undefined, undefined, function(err, data) { + assert.ifError(err); + }); + call.on('metadata', function(metadata) { + done(); + }); + call.end(); + }); + it('Should handle one undefined argument', function(done) { + var call = client.clientStream(undefined, function(err, data) { + assert.ifError(err); + }); + call.on('metadata', function(metadata) { + done(); + }); + call.end(); + }); + }); + describe('Server stream call', function() { + it('Should handle undefined options', function(done) { + var call = client.serverStream({}, metadata, undefined); + call.on('data', function() {}); + call.on('metadata', function(metadata) { + assert.deepEqual(metadata.get('key'), ['value']); + done(); + }); + }); + it('Should handle two undefined arguments', function(done) { + var call = client.serverStream({}, undefined, undefined); + call.on('data', function() {}); + call.on('metadata', function(metadata) { + done(); + }); + }); + it('Should handle one undefined argument', function(done) { + var call = client.serverStream({}, undefined); + call.on('data', function() {}); + call.on('metadata', function(metadata) { + done(); + }); + }); + }); + describe('Bidi stream call', function() { + it('Should handle undefined options', function(done) { + var call = client.bidiStream(metadata, undefined); + call.on('data', function() {}); + call.on('metadata', function(metadata) { + assert.deepEqual(metadata.get('key'), ['value']); + done(); + }); + call.end(); + }); + it('Should handle two undefined arguments', function(done) { + var call = client.bidiStream(undefined, undefined); + call.on('data', function() {}); + call.on('metadata', function(metadata) { + done(); + }); + call.end(); + }); + it('Should handle one undefined argument', function(done) { + var call = client.bidiStream(undefined); + call.on('data', function() {}); + call.on('metadata', function(metadata) { + done(); + }); + call.end(); + }); + }); + }); }); describe('Client malformed response handling', function() { var server;