|
|
|
@ -224,25 +224,32 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { |
|
|
|
|
emitter.cancel = function cancel() { |
|
|
|
|
call.cancel(); |
|
|
|
|
}; |
|
|
|
|
var client_batch = {}; |
|
|
|
|
client_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
|
client_batch[grpc.opType.SEND_MESSAGE] = serialize(argument); |
|
|
|
|
client_batch[grpc.opType.SEND_CLOSE_FROM_CLIENT] = true; |
|
|
|
|
client_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
|
client_batch[grpc.opType.RECV_MESSAGE] = true; |
|
|
|
|
client_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; |
|
|
|
|
call.startBatch(client_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
callback(err); |
|
|
|
|
this.updateMetadata(metadata, function(error, metadata) { |
|
|
|
|
if (error) { |
|
|
|
|
call.cancel(); |
|
|
|
|
callback(error); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (response.status.code != grpc.status.OK) { |
|
|
|
|
callback(response.status); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
emitter.emit('status', response.status); |
|
|
|
|
emitter.emit('metadata', response.metadata); |
|
|
|
|
callback(null, deserialize(response.read)); |
|
|
|
|
var client_batch = {}; |
|
|
|
|
client_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
|
client_batch[grpc.opType.SEND_MESSAGE] = serialize(argument); |
|
|
|
|
client_batch[grpc.opType.SEND_CLOSE_FROM_CLIENT] = true; |
|
|
|
|
client_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
|
client_batch[grpc.opType.RECV_MESSAGE] = true; |
|
|
|
|
client_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; |
|
|
|
|
call.startBatch(client_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
callback(err); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (response.status.code != grpc.status.OK) { |
|
|
|
|
callback(response.status); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
emitter.emit('status', response.status); |
|
|
|
|
emitter.emit('metadata', response.metadata); |
|
|
|
|
callback(null, deserialize(response.read)); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
return emitter; |
|
|
|
|
} |
|
|
|
@ -279,30 +286,37 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
|
metadata = {}; |
|
|
|
|
} |
|
|
|
|
var stream = new ClientWritableStream(call, serialize); |
|
|
|
|
var metadata_batch = {}; |
|
|
|
|
metadata_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
|
metadata_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
|
call.startBatch(metadata_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
callback(err); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
stream.emit('metadata', response.metadata); |
|
|
|
|
}); |
|
|
|
|
var client_batch = {}; |
|
|
|
|
client_batch[grpc.opType.RECV_MESSAGE] = true; |
|
|
|
|
client_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; |
|
|
|
|
call.startBatch(client_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
callback(err); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (response.status.code != grpc.status.OK) { |
|
|
|
|
callback(response.status); |
|
|
|
|
this.updateMetadata(metadata, function(error, metadata) { |
|
|
|
|
if (error) { |
|
|
|
|
call.cancel(); |
|
|
|
|
callback(error); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
stream.emit('status', response.status); |
|
|
|
|
callback(null, deserialize(response.read)); |
|
|
|
|
var metadata_batch = {}; |
|
|
|
|
metadata_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
|
metadata_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
|
call.startBatch(metadata_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
callback(err); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
stream.emit('metadata', response.metadata); |
|
|
|
|
}); |
|
|
|
|
var client_batch = {}; |
|
|
|
|
client_batch[grpc.opType.RECV_MESSAGE] = true; |
|
|
|
|
client_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; |
|
|
|
|
call.startBatch(client_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
callback(err); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (response.status.code != grpc.status.OK) { |
|
|
|
|
callback(response.status); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
stream.emit('status', response.status); |
|
|
|
|
callback(null, deserialize(response.read)); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
return stream; |
|
|
|
|
} |
|
|
|
@ -339,24 +353,31 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
|
metadata = {}; |
|
|
|
|
} |
|
|
|
|
var stream = new ClientReadableStream(call, deserialize); |
|
|
|
|
var start_batch = {}; |
|
|
|
|
start_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
|
start_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
|
start_batch[grpc.opType.SEND_MESSAGE] = serialize(argument); |
|
|
|
|
start_batch[grpc.opType.SEND_CLOSE_FROM_CLIENT] = true; |
|
|
|
|
call.startBatch(start_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
throw err; |
|
|
|
|
} |
|
|
|
|
stream.emit('metadata', response.metadata); |
|
|
|
|
}); |
|
|
|
|
var status_batch = {}; |
|
|
|
|
status_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; |
|
|
|
|
call.startBatch(status_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
throw err; |
|
|
|
|
this.updateMetadata(metadata, function(error, metadata) { |
|
|
|
|
if (error) { |
|
|
|
|
call.cancel(); |
|
|
|
|
stream.emit('error', error); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
stream.emit('status', response.status); |
|
|
|
|
var start_batch = {}; |
|
|
|
|
start_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
|
start_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
|
start_batch[grpc.opType.SEND_MESSAGE] = serialize(argument); |
|
|
|
|
start_batch[grpc.opType.SEND_CLOSE_FROM_CLIENT] = true; |
|
|
|
|
call.startBatch(start_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
throw err; |
|
|
|
|
} |
|
|
|
|
stream.emit('metadata', response.metadata); |
|
|
|
|
}); |
|
|
|
|
var status_batch = {}; |
|
|
|
|
status_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; |
|
|
|
|
call.startBatch(status_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
throw err; |
|
|
|
|
} |
|
|
|
|
stream.emit('status', response.status); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
return stream; |
|
|
|
|
} |
|
|
|
@ -391,22 +412,29 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
|
metadata = {}; |
|
|
|
|
} |
|
|
|
|
var stream = new ClientDuplexStream(call, serialize, deserialize); |
|
|
|
|
var start_batch = {}; |
|
|
|
|
start_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
|
start_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
|
call.startBatch(start_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
throw err; |
|
|
|
|
} |
|
|
|
|
stream.emit('metadata', response.metadata); |
|
|
|
|
}); |
|
|
|
|
var status_batch = {}; |
|
|
|
|
status_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; |
|
|
|
|
call.startBatch(status_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
throw err; |
|
|
|
|
this.updateMetadata(metadata, function(error, metadata) { |
|
|
|
|
if (error) { |
|
|
|
|
call.cancel(); |
|
|
|
|
stream.emit('error', error); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
stream.emit('status', response.status); |
|
|
|
|
var start_batch = {}; |
|
|
|
|
start_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
|
start_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
|
call.startBatch(start_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
throw err; |
|
|
|
|
} |
|
|
|
|
stream.emit('metadata', response.metadata); |
|
|
|
|
}); |
|
|
|
|
var status_batch = {}; |
|
|
|
|
status_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true; |
|
|
|
|
call.startBatch(status_batch, function(err, response) { |
|
|
|
|
if (err) { |
|
|
|
|
throw err; |
|
|
|
|
} |
|
|
|
|
stream.emit('status', response.status); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
return stream; |
|
|
|
|
} |
|
|
|
@ -438,8 +466,17 @@ function makeClientConstructor(service) { |
|
|
|
|
* @constructor |
|
|
|
|
* @param {string} address The address of the server to connect to |
|
|
|
|
* @param {Object} options Options to pass to the underlying channel |
|
|
|
|
* @param {function(Object, function)=} updateMetadata function to update the |
|
|
|
|
* metadata for each request |
|
|
|
|
*/ |
|
|
|
|
function Client(address, options) { |
|
|
|
|
function Client(address, options, updateMetadata) { |
|
|
|
|
if (updateMetadata) { |
|
|
|
|
this.updateMetadata = updateMetadata; |
|
|
|
|
} else { |
|
|
|
|
this.updateMetadata = function(metadata, callback) { |
|
|
|
|
callback(null, metadata); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
this.channel = new grpc.Channel(address, options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -458,11 +495,13 @@ function makeClientConstructor(service) { |
|
|
|
|
method_type = 'unary'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Client.prototype[decapitalize(method.name)] = |
|
|
|
|
requester_makers[method_type]( |
|
|
|
|
prefix + capitalize(method.name), |
|
|
|
|
common.serializeCls(method.resolvedRequestType.build()), |
|
|
|
|
common.deserializeCls(method.resolvedResponseType.build())); |
|
|
|
|
var serialize = common.serializeCls(method.resolvedRequestType.build()); |
|
|
|
|
var deserialize = common.deserializeCls( |
|
|
|
|
method.resolvedResponseType.build()); |
|
|
|
|
Client.prototype[decapitalize(method.name)] = requester_makers[method_type]( |
|
|
|
|
prefix + capitalize(method.name), serialize, deserialize); |
|
|
|
|
Client.prototype[decapitalize(method.name)].serialize = serialize; |
|
|
|
|
Client.prototype[decapitalize(method.name)].deserialize = deserialize; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Client.service = service; |
|
|
|
|