mirror of https://github.com/grpc/grpc-node.git
Replace Argue.js usage with inline argument checking
This commit is contained in:
parent
fcba0c101c
commit
a50ba76838
|
@ -28,7 +28,6 @@
|
|||
"node-pre-gyp"
|
||||
],
|
||||
"dependencies": {
|
||||
"arguejs": "^0.2.3",
|
||||
"lodash": "^4.15.0",
|
||||
"nan": "^2.0.0",
|
||||
"node-pre-gyp": "^0.6.39",
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var arguejs = require('arguejs');
|
||||
|
||||
var grpc = require('./grpc_extension');
|
||||
|
||||
|
@ -500,21 +499,27 @@ exports.Client = Client;
|
|||
Client.prototype.makeUnaryRequest = function(method, serialize, deserialize,
|
||||
argument, metadata, options,
|
||||
callback) {
|
||||
/* While the arguments are listed in the function signature, those variables
|
||||
* are not used directly. Instead, ArgueJS processes the arguments
|
||||
* object. This allows for simple handling of optional arguments in the
|
||||
* middle of the argument list, and also provides type checking. */
|
||||
var args = arguejs({method: String, serialize: Function,
|
||||
deserialize: Function,
|
||||
argument: null, metadata: [Metadata, new Metadata()],
|
||||
options: [Object], callback: Function}, arguments);
|
||||
var call = getCall(this.$channel, method, args.options);
|
||||
if (!(metadata instanceof Metadata)) {
|
||||
callback = options;
|
||||
options = metadata;
|
||||
metadata = new Metadata();
|
||||
}
|
||||
if (options instanceof Function) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
if (!((metadata instanceof Metadata) &&
|
||||
(options instanceof Object) &&
|
||||
(callback instanceof Function))) {
|
||||
throw new Error("Argument mismatch in makeUnaryRequest");
|
||||
}
|
||||
var call = getCall(this.$channel, method, options);
|
||||
var emitter = new ClientUnaryCall(call);
|
||||
metadata = args.metadata.clone();
|
||||
metadata = metadata.clone();
|
||||
var client_batch = {};
|
||||
var message = serialize(args.argument);
|
||||
if (args.options) {
|
||||
message.grpcWriteFlags = args.options.flags;
|
||||
var message = serialize(argument);
|
||||
if (options) {
|
||||
message.grpcWriteFlags = options.flags;
|
||||
}
|
||||
|
||||
client_batch[grpc.opType.SEND_INITIAL_METADATA] =
|
||||
|
@ -535,7 +540,7 @@ Client.prototype.makeUnaryRequest = function(method, serialize, deserialize,
|
|||
if (status.code === constants.status.OK) {
|
||||
if (err) {
|
||||
// Got a batch error, but OK status. Something went wrong
|
||||
args.callback(err);
|
||||
callback(err);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
|
@ -554,9 +559,9 @@ Client.prototype.makeUnaryRequest = function(method, serialize, deserialize,
|
|||
error = new Error(status.details);
|
||||
error.code = status.code;
|
||||
error.metadata = status.metadata;
|
||||
args.callback(error);
|
||||
callback(error);
|
||||
} else {
|
||||
args.callback(null, deserialized);
|
||||
callback(null, deserialized);
|
||||
}
|
||||
emitter.emit('status', status);
|
||||
});
|
||||
|
@ -582,16 +587,22 @@ Client.prototype.makeUnaryRequest = function(method, serialize, deserialize,
|
|||
Client.prototype.makeClientStreamRequest = function(method, serialize,
|
||||
deserialize, metadata,
|
||||
options, callback) {
|
||||
/* While the arguments are listed in the function signature, those variables
|
||||
* are not used directly. Instead, ArgueJS processes the arguments
|
||||
* object. This allows for simple handling of optional arguments in the
|
||||
* middle of the argument list, and also provides type checking. */
|
||||
var args = arguejs({method:String, serialize: Function,
|
||||
deserialize: Function,
|
||||
metadata: [Metadata, new Metadata()],
|
||||
options: [Object], callback: Function}, arguments);
|
||||
var call = getCall(this.$channel, method, args.options);
|
||||
metadata = args.metadata.clone();
|
||||
if (!(metadata instanceof Metadata)) {
|
||||
callback = options;
|
||||
options = metadata;
|
||||
metadata = new Metadata();
|
||||
}
|
||||
if (options instanceof Function) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
if (!((metadata instanceof Metadata) &&
|
||||
(options instanceof Object) &&
|
||||
(callback instanceof Function))) {
|
||||
throw new Error("Argument mismatch in makeClientStreamRequest");
|
||||
}
|
||||
var call = getCall(this.$channel, method, options);
|
||||
metadata = metadata.clone();
|
||||
var stream = new ClientWritableStream(call, serialize);
|
||||
var metadata_batch = {};
|
||||
metadata_batch[grpc.opType.SEND_INITIAL_METADATA] =
|
||||
|
@ -618,7 +629,7 @@ Client.prototype.makeClientStreamRequest = function(method, serialize,
|
|||
if (status.code === constants.status.OK) {
|
||||
if (err) {
|
||||
// Got a batch error, but OK status. Something went wrong
|
||||
args.callback(err);
|
||||
callback(err);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
|
@ -637,9 +648,9 @@ Client.prototype.makeClientStreamRequest = function(method, serialize,
|
|||
error = new Error(response.status.details);
|
||||
error.code = status.code;
|
||||
error.metadata = status.metadata;
|
||||
args.callback(error);
|
||||
callback(error);
|
||||
} else {
|
||||
args.callback(null, deserialized);
|
||||
callback(null, deserialized);
|
||||
}
|
||||
stream.emit('status', status);
|
||||
});
|
||||
|
@ -664,20 +675,23 @@ Client.prototype.makeClientStreamRequest = function(method, serialize,
|
|||
Client.prototype.makeServerStreamRequest = function(method, serialize,
|
||||
deserialize, argument,
|
||||
metadata, options) {
|
||||
/* While the arguments are listed in the function signature, those variables
|
||||
* are not used directly. Instead, ArgueJS processes the arguments
|
||||
* object. */
|
||||
var args = arguejs({method:String, serialize: Function,
|
||||
deserialize: Function,
|
||||
argument: null, metadata: [Metadata, new Metadata()],
|
||||
options: [Object]}, arguments);
|
||||
var call = getCall(this.$channel, method, args.options);
|
||||
metadata = args.metadata.clone();
|
||||
if (!(metadata instanceof Metadata)) {
|
||||
options = metadata;
|
||||
metadata = new Metadata();
|
||||
}
|
||||
if (!(options instanceof Object)) {
|
||||
options = {};
|
||||
}
|
||||
if (!((metadata instanceof Metadata) && (options instanceof Object))) {
|
||||
throw new Error("Argument mismatch in makeServerStreamRequest");
|
||||
}
|
||||
var call = getCall(this.$channel, method, options);
|
||||
metadata = metadata.clone();
|
||||
var stream = new ClientReadableStream(call, deserialize);
|
||||
var start_batch = {};
|
||||
var message = serialize(args.argument);
|
||||
if (args.options) {
|
||||
message.grpcWriteFlags = args.options.flags;
|
||||
var message = serialize(argument);
|
||||
if (options) {
|
||||
message.grpcWriteFlags = options.flags;
|
||||
}
|
||||
start_batch[grpc.opType.SEND_INITIAL_METADATA] =
|
||||
metadata._getCoreRepresentation();
|
||||
|
@ -722,15 +736,18 @@ Client.prototype.makeServerStreamRequest = function(method, serialize,
|
|||
Client.prototype.makeBidiStreamRequest = function(method, serialize,
|
||||
deserialize, metadata,
|
||||
options) {
|
||||
/* While the arguments are listed in the function signature, those variables
|
||||
* are not used directly. Instead, ArgueJS processes the arguments
|
||||
* object. */
|
||||
var args = arguejs({method:String, serialize: Function,
|
||||
deserialize: Function,
|
||||
metadata: [Metadata, new Metadata()],
|
||||
options: [Object]}, arguments);
|
||||
var call = getCall(this.$channel, method, args.options);
|
||||
metadata = args.metadata.clone();
|
||||
if (!(metadata instanceof Metadata)) {
|
||||
options = metadata;
|
||||
metadata = new Metadata();
|
||||
}
|
||||
if (!(options instanceof Object)) {
|
||||
options = {};
|
||||
}
|
||||
if (!((metadata instanceof Metadata) && (options instanceof Object))) {
|
||||
throw new Error("Argument mismatch in makeBidiStreamRequest");
|
||||
}
|
||||
var call = getCall(this.$channel, method, options);
|
||||
metadata = metadata.clone();
|
||||
var stream = new ClientDuplexStream(call, serialize, deserialize);
|
||||
var start_batch = {};
|
||||
start_batch[grpc.opType.SEND_INITIAL_METADATA] =
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
"node-pre-gyp"
|
||||
],
|
||||
"dependencies": {
|
||||
"arguejs": "^0.2.3",
|
||||
"lodash": "^4.15.0",
|
||||
"nan": "^2.0.0",
|
||||
"node-pre-gyp": "^0.6.39",
|
||||
|
|
Loading…
Reference in New Issue