|
|
@ -224,6 +224,12 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { |
|
|
|
emitter.cancel = function cancel() { |
|
|
|
emitter.cancel = function cancel() { |
|
|
|
call.cancel(); |
|
|
|
call.cancel(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
this.updateMetadata(metadata, function(error, metadata) { |
|
|
|
|
|
|
|
if (error) { |
|
|
|
|
|
|
|
call.cancel(); |
|
|
|
|
|
|
|
callback(error); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
var client_batch = {}; |
|
|
|
var client_batch = {}; |
|
|
|
client_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
client_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
client_batch[grpc.opType.SEND_MESSAGE] = serialize(argument); |
|
|
|
client_batch[grpc.opType.SEND_MESSAGE] = serialize(argument); |
|
|
@ -244,6 +250,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { |
|
|
|
emitter.emit('metadata', response.metadata); |
|
|
|
emitter.emit('metadata', response.metadata); |
|
|
|
callback(null, deserialize(response.read)); |
|
|
|
callback(null, deserialize(response.read)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
return emitter; |
|
|
|
return emitter; |
|
|
|
} |
|
|
|
} |
|
|
|
return makeUnaryRequest; |
|
|
|
return makeUnaryRequest; |
|
|
@ -279,6 +286,12 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
metadata = {}; |
|
|
|
metadata = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
var stream = new ClientWritableStream(call, serialize); |
|
|
|
var stream = new ClientWritableStream(call, serialize); |
|
|
|
|
|
|
|
this.updateMetadata(metadata, function(error, metadata) { |
|
|
|
|
|
|
|
if (error) { |
|
|
|
|
|
|
|
call.cancel(); |
|
|
|
|
|
|
|
callback(error); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
var metadata_batch = {}; |
|
|
|
var metadata_batch = {}; |
|
|
|
metadata_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
metadata_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
metadata_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
metadata_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
@ -304,6 +317,7 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
stream.emit('status', response.status); |
|
|
|
stream.emit('status', response.status); |
|
|
|
callback(null, deserialize(response.read)); |
|
|
|
callback(null, deserialize(response.read)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
return stream; |
|
|
|
return stream; |
|
|
|
} |
|
|
|
} |
|
|
|
return makeClientStreamRequest; |
|
|
|
return makeClientStreamRequest; |
|
|
@ -339,6 +353,12 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
metadata = {}; |
|
|
|
metadata = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
var stream = new ClientReadableStream(call, deserialize); |
|
|
|
var stream = new ClientReadableStream(call, deserialize); |
|
|
|
|
|
|
|
this.updateMetadata(metadata, function(error, metadata) { |
|
|
|
|
|
|
|
if (error) { |
|
|
|
|
|
|
|
call.cancel(); |
|
|
|
|
|
|
|
stream.emit('error', error); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
var start_batch = {}; |
|
|
|
var start_batch = {}; |
|
|
|
start_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
start_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
start_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
start_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
@ -358,6 +378,7 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
} |
|
|
|
} |
|
|
|
stream.emit('status', response.status); |
|
|
|
stream.emit('status', response.status); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
return stream; |
|
|
|
return stream; |
|
|
|
} |
|
|
|
} |
|
|
|
return makeServerStreamRequest; |
|
|
|
return makeServerStreamRequest; |
|
|
@ -391,6 +412,12 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
metadata = {}; |
|
|
|
metadata = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
var stream = new ClientDuplexStream(call, serialize, deserialize); |
|
|
|
var stream = new ClientDuplexStream(call, serialize, deserialize); |
|
|
|
|
|
|
|
this.updateMetadata(metadata, function(error, metadata) { |
|
|
|
|
|
|
|
if (error) { |
|
|
|
|
|
|
|
call.cancel(); |
|
|
|
|
|
|
|
stream.emit('error', error); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
var start_batch = {}; |
|
|
|
var start_batch = {}; |
|
|
|
start_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
start_batch[grpc.opType.SEND_INITIAL_METADATA] = metadata; |
|
|
|
start_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
|
start_batch[grpc.opType.RECV_INITIAL_METADATA] = true; |
|
|
@ -408,6 +435,7 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { |
|
|
|
} |
|
|
|
} |
|
|
|
stream.emit('status', response.status); |
|
|
|
stream.emit('status', response.status); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
return stream; |
|
|
|
return stream; |
|
|
|
} |
|
|
|
} |
|
|
|
return makeBidiStreamRequest; |
|
|
|
return makeBidiStreamRequest; |
|
|
@ -438,8 +466,17 @@ function makeClientConstructor(service) { |
|
|
|
* @constructor |
|
|
|
* @constructor |
|
|
|
* @param {string} address The address of the server to connect to |
|
|
|
* @param {string} address The address of the server to connect to |
|
|
|
* @param {Object} options Options to pass to the underlying channel |
|
|
|
* @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); |
|
|
|
this.channel = new grpc.Channel(address, options); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -458,11 +495,13 @@ function makeClientConstructor(service) { |
|
|
|
method_type = 'unary'; |
|
|
|
method_type = 'unary'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Client.prototype[decapitalize(method.name)] = |
|
|
|
var serialize = common.serializeCls(method.resolvedRequestType.build()); |
|
|
|
requester_makers[method_type]( |
|
|
|
var deserialize = common.deserializeCls( |
|
|
|
prefix + capitalize(method.name), |
|
|
|
method.resolvedResponseType.build()); |
|
|
|
common.serializeCls(method.resolvedRequestType.build()), |
|
|
|
Client.prototype[decapitalize(method.name)] = requester_makers[method_type]( |
|
|
|
common.deserializeCls(method.resolvedResponseType.build())); |
|
|
|
prefix + capitalize(method.name), serialize, deserialize); |
|
|
|
|
|
|
|
Client.prototype[decapitalize(method.name)].serialize = serialize; |
|
|
|
|
|
|
|
Client.prototype[decapitalize(method.name)].deserialize = deserialize; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Client.service = service; |
|
|
|
Client.service = service; |
|
|
|