Skip to content

Commit 044102d

Browse files
authored
Merge pull request #191 from murgatroid99/v1.9.x_upmerge
V1.9.x upmerge
2 parents 153501d + eb1db93 commit 044102d

File tree

5 files changed

+158
-19
lines changed

5 files changed

+158
-19
lines changed

packages/grpc-native-core/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ declare module "grpc" {
6666
* - Anything else becomes the relevant reflection object that ProtoBuf.js would create
6767
*/
6868
export interface GrpcObject {
69-
[name: string]: GrpcObject | typeof Client | Message;
69+
[name: string]: GrpcObject | typeof Client | Message<any>;
7070
}
7171

7272
/**
@@ -573,12 +573,12 @@ declare module "grpc" {
573573
/**
574574
* The server's private key
575575
*/
576-
privateKey: Buffer;
576+
private_key: Buffer;
577577

578578
/**
579579
* The server's certificate chain
580580
*/
581-
certChain: Buffer;
581+
cert_chain: Buffer;
582582
}
583583

584584
/**

packages/grpc-native-core/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ exports.ServerCredentials = grpc.ServerCredentials;
219219
/**
220220
* A private key and certificate pair
221221
* @typedef {Object} grpc.ServerCredentials~keyCertPair
222-
* @property {Buffer} privateKey The server's private key
223-
* @property {Buffer} certChain The server's certificate chain
222+
* @property {Buffer} private_key The server's private key
223+
* @property {Buffer} cert_chain The server's certificate chain
224224
*/
225225

226226
/**

packages/grpc-native-core/src/client.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,23 @@ exports.Client = Client;
513513
Client.prototype.makeUnaryRequest = function(method, serialize, deserialize,
514514
argument, metadata, options,
515515
callback) {
516-
if (!(metadata instanceof Metadata)) {
516+
if (options instanceof Function) {
517517
callback = options;
518-
options = metadata;
518+
if (metadata instanceof Metadata) {
519+
options = {};
520+
} else {
521+
options = metadata;
522+
metadata = new Metadata();
523+
}
524+
} else if (metadata instanceof Function) {
525+
callback = metadata;
519526
metadata = new Metadata();
527+
options = {};
520528
}
521-
if (options instanceof Function) {
522-
callback = options;
529+
if (!metadata) {
530+
metadata = new Metadata();
531+
}
532+
if (!options) {
523533
options = {};
524534
}
525535
if (!((metadata instanceof Metadata) &&
@@ -599,13 +609,23 @@ Client.prototype.makeUnaryRequest = function(method, serialize, deserialize,
599609
Client.prototype.makeClientStreamRequest = function(method, serialize,
600610
deserialize, metadata,
601611
options, callback) {
602-
if (!(metadata instanceof Metadata)) {
612+
if (options instanceof Function) {
603613
callback = options;
604-
options = metadata;
614+
if (metadata instanceof Metadata) {
615+
options = {};
616+
} else {
617+
options = metadata;
618+
metadata = new Metadata();
619+
}
620+
} else if (metadata instanceof Function) {
621+
callback = metadata;
605622
metadata = new Metadata();
623+
options = {};
606624
}
607-
if (options instanceof Function) {
608-
callback = options;
625+
if (!metadata) {
626+
metadata = new Metadata();
627+
}
628+
if (!options) {
609629
options = {};
610630
}
611631
if (!((metadata instanceof Metadata) &&

packages/grpc-native-core/src/grpc_extension.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,26 @@ var binding;
3131
try {
3232
binding = require(binding_path);
3333
} catch (e) {
34-
var fs = require('fs');
35-
var searchPath = path.dirname(path.dirname(binding_path));
36-
var searchName = path.basename(path.dirname(binding_path));
37-
var foundNames = fs.readdirSync(searchPath);
34+
let fs = require('fs');
35+
let searchPath = path.dirname(path.dirname(binding_path));
36+
let searchName = path.basename(path.dirname(binding_path));
37+
let foundNames;
38+
try {
39+
foundNames = fs.readdirSync(searchPath);
40+
} catch (readDirError) {
41+
let message = `The gRPC binary module was not installed. This may be fixed by running "npm rebuild"
42+
Original error: ${e.message}`;
43+
let error = new Error(message);
44+
error.code = e.code;
45+
throw error;
46+
}
3847
if (foundNames.indexOf(searchName) === -1) {
39-
var message = `Failed to load gRPC binary module because it was not installed for the current system
48+
let message = `Failed to load gRPC binary module because it was not installed for the current system
4049
Expected directory: ${searchName}
4150
Found: [${foundNames.join(', ')}]
4251
This problem can often be fixed by running "npm rebuild" on the current system
4352
Original error: ${e.message}`;
44-
var error = new Error(message);
53+
let error = new Error(message);
4554
error.code = e.code;
4655
throw error;
4756
} else {

test/api/surface_test.js

+110
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,116 @@ describe('Echo metadata', function() {
506506
done();
507507
});
508508
});
509+
describe('Call argument handling', function() {
510+
describe('Unary call', function() {
511+
it('Should handle undefined options', function(done) {
512+
var call = client.unary({}, metadata, undefined, function(err, data) {
513+
assert.ifError(err);
514+
});
515+
call.on('metadata', function(metadata) {
516+
assert.deepEqual(metadata.get('key'), ['value']);
517+
done();
518+
});
519+
});
520+
it('Should handle two undefined arguments', function(done) {
521+
var call = client.unary({}, undefined, undefined, function(err, data) {
522+
assert.ifError(err);
523+
});
524+
call.on('metadata', function(metadata) {
525+
done();
526+
});
527+
});
528+
it('Should handle one undefined argument', function(done) {
529+
var call = client.unary({}, undefined, function(err, data) {
530+
assert.ifError(err);
531+
});
532+
call.on('metadata', function(metadata) {
533+
done();
534+
});
535+
});
536+
});
537+
describe('Client stream call', function() {
538+
it('Should handle undefined options', function(done) {
539+
var call = client.clientStream(metadata, undefined, function(err, data) {
540+
assert.ifError(err);
541+
});
542+
call.on('metadata', function(metadata) {
543+
assert.deepEqual(metadata.get('key'), ['value']);
544+
done();
545+
});
546+
call.end();
547+
});
548+
it('Should handle two undefined arguments', function(done) {
549+
var call = client.clientStream(undefined, undefined, function(err, data) {
550+
assert.ifError(err);
551+
});
552+
call.on('metadata', function(metadata) {
553+
done();
554+
});
555+
call.end();
556+
});
557+
it('Should handle one undefined argument', function(done) {
558+
var call = client.clientStream(undefined, function(err, data) {
559+
assert.ifError(err);
560+
});
561+
call.on('metadata', function(metadata) {
562+
done();
563+
});
564+
call.end();
565+
});
566+
});
567+
describe('Server stream call', function() {
568+
it('Should handle undefined options', function(done) {
569+
var call = client.serverStream({}, metadata, undefined);
570+
call.on('data', function() {});
571+
call.on('metadata', function(metadata) {
572+
assert.deepEqual(metadata.get('key'), ['value']);
573+
done();
574+
});
575+
});
576+
it('Should handle two undefined arguments', function(done) {
577+
var call = client.serverStream({}, undefined, undefined);
578+
call.on('data', function() {});
579+
call.on('metadata', function(metadata) {
580+
done();
581+
});
582+
});
583+
it('Should handle one undefined argument', function(done) {
584+
var call = client.serverStream({}, undefined);
585+
call.on('data', function() {});
586+
call.on('metadata', function(metadata) {
587+
done();
588+
});
589+
});
590+
});
591+
describe('Bidi stream call', function() {
592+
it('Should handle undefined options', function(done) {
593+
var call = client.bidiStream(metadata, undefined);
594+
call.on('data', function() {});
595+
call.on('metadata', function(metadata) {
596+
assert.deepEqual(metadata.get('key'), ['value']);
597+
done();
598+
});
599+
call.end();
600+
});
601+
it('Should handle two undefined arguments', function(done) {
602+
var call = client.bidiStream(undefined, undefined);
603+
call.on('data', function() {});
604+
call.on('metadata', function(metadata) {
605+
done();
606+
});
607+
call.end();
608+
});
609+
it('Should handle one undefined argument', function(done) {
610+
var call = client.bidiStream(undefined);
611+
call.on('data', function() {});
612+
call.on('metadata', function(metadata) {
613+
done();
614+
});
615+
call.end();
616+
});
617+
});
618+
});
509619
});
510620
describe('Client malformed response handling', function() {
511621
var server;

0 commit comments

Comments
 (0)