Skip to content

grpc-js: Fix handling of non-service objects in package definitions #704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions packages/grpc-js/src/make-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ export interface ServiceDefinition {
[index: string]: MethodDefinition<object, object>;
}

export interface PackageDefinition { [index: string]: ServiceDefinition; }
export interface ProtobufTypeDefinition {
format: string;
type: object;
fileDescriptorProtos: Buffer[];
}

export interface PackageDefinition {
[index: string]: ServiceDefinition|ProtobufTypeDefinition;
}

/**
* Map with short names for each of the requester maker functions. Used in
Expand Down Expand Up @@ -119,9 +127,15 @@ function partial(
}

export type GrpcObject = {
[index: string]: GrpcObject|ServiceClientConstructor;
[index: string]: GrpcObject|ServiceClientConstructor|ProtobufTypeDefinition;
};

function isProtobufTypeDefinition(
obj: ServiceDefinition|
ProtobufTypeDefinition): obj is ProtobufTypeDefinition {
return 'format' in obj;
}

/**
* Load a gRPC package definition as a gRPC object hierarchy.
* @param packageDef The package definition object.
Expand All @@ -142,7 +156,11 @@ export function loadPackageDefinition(packageDef: PackageDefinition):
}
current = current[packageName] as GrpcObject;
}
current[serviceName] = makeClientConstructor(service, serviceName, {});
if (isProtobufTypeDefinition(service)) {
current[serviceName] = service;
} else {
current[serviceName] = makeClientConstructor(service, serviceName, {});
}
}
}
return result;
Expand Down