Skip to content

Commit

Permalink
Merge pull request #162 from murgatroid99/remove_argue.js
Browse files Browse the repository at this point in the history
Replace argue.js usage with inline argument checking
  • Loading branch information
murgatroid99 authored Jan 24, 2018
2 parents fcba0c1 + a50ba76 commit 8201554
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 53 deletions.
1 change: 0 additions & 1 deletion packages/grpc-native-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
119 changes: 68 additions & 51 deletions packages/grpc-native-core/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
'use strict';

var _ = require('lodash');
var arguejs = require('arguejs');

var grpc = require('./grpc_extension');

Expand Down Expand Up @@ -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] =
Expand All @@ -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 {
Expand All @@ -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);
});
Expand All @@ -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] =
Expand All @@ -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 {
Expand All @@ -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);
});
Expand All @@ -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();
Expand Down Expand Up @@ -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] =
Expand Down
1 change: 0 additions & 1 deletion packages/grpc-native-core/templates/package.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8201554

Please # to comment.