mirror of https://github.com/grpc/grpc-node.git
client library integration: adjust options
This commit is contained in:
parent
5b0f7b1faf
commit
94906e4122
|
@ -97,14 +97,14 @@ function createMethodDefinition(method: Protobuf.Method, serviceName: string, op
|
|||
responseSerialize: createSerializer(method.resolvedResponseType as Protobuf.Type),
|
||||
responseDeserialize: createDeserializer(method.resolvedResponseType as Protobuf.Type, options),
|
||||
// TODO(murgatroid99): Find a better way to handle this
|
||||
originalName: _.camelCase(method.name)
|
||||
originalName: method.name
|
||||
};
|
||||
}
|
||||
|
||||
function createServiceDefinition(service: Protobuf.Service, name: string, options: Options): ServiceDefinition {
|
||||
const def: ServiceDefinition = {};
|
||||
for (const method of service.methodsArray) {
|
||||
def[method.name] = createMethodDefinition(method, name, options);
|
||||
def[_.camelCase(method.name)] = createMethodDefinition(method, name, options);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
|
|
@ -28,10 +28,19 @@ if (!process.env.USE_GRPC_NATIVE) {
|
|||
options = filename[2];
|
||||
filename = filename[0];
|
||||
}
|
||||
options = Object.assign({
|
||||
convertFieldsToCamelCase: true, // gax load uses hardcoded convertFieldsToCamelCase = true if it's not specified.
|
||||
binaryAsBase64: false, // gRPC default option
|
||||
longsAsStrings: true, // gRPC default option
|
||||
enumsAsStrings: true, // gRPC default option
|
||||
}, options);
|
||||
const packageDef = grpcProtobuf.loadSync(filename.file, {
|
||||
keepCase: false,
|
||||
keepCase: !options.convertFieldsToCamelCase,
|
||||
defaults: true,
|
||||
enums: String,
|
||||
bytes: options.binaryAsBase64 ? String : Buffer,
|
||||
longs: options.longsAsString ? String : null,
|
||||
enums: options.enumsAsStrings ? String : null,
|
||||
oneofs: true,
|
||||
include: [filename.root]
|
||||
});
|
||||
return grpcImpl.loadPackageDefinition(packageDef);
|
||||
|
@ -42,12 +51,16 @@ if (!process.env.USE_GRPC_NATIVE) {
|
|||
shimmer.wrap(result.grpc.prototype, 'loadProto', (gaxLoadProto) => {
|
||||
const path = require('path');
|
||||
const googleProtoFilesDir = require('google-proto-files')('..');
|
||||
|
||||
return function (protoPath, filename) {
|
||||
// loadProto does not accept options, so the options passed
|
||||
// here correspond to defaultGrpcOptions.
|
||||
const packageDef = grpcProtobuf.loadSync(filename, {
|
||||
keepCase: false,
|
||||
defaults: true,
|
||||
bytes: Buffer,
|
||||
longs: String,
|
||||
enums: String,
|
||||
oneofs: true,
|
||||
include: [protoPath, googleProtoFilesDir]
|
||||
});
|
||||
return grpcImpl.loadPackageDefinition(packageDef);
|
||||
|
@ -75,10 +88,12 @@ if (!process.env.USE_GRPC_NATIVE) {
|
|||
|
||||
if (!protoObjectCache[protoObjectCacheKey]) {
|
||||
const services = grpcProtobuf.loadSync(protoConfig.path, {
|
||||
keepCase: false,
|
||||
bytes: 'string',
|
||||
keepCase: false, // loadProtoFile_ uses hardcoded convertFieldsToCamelCase = true
|
||||
defaults: true,
|
||||
bytes: String, // loadProtoFile_ uses hardcoded binaryAsBase64 = true
|
||||
longs: String,
|
||||
enums: String,
|
||||
oneofs: true,
|
||||
include: [config.protosDir]
|
||||
});
|
||||
const service = dotProp.get(services.google, protoConfig.service);
|
||||
|
|
Loading…
Reference in New Issue