Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ interface ISimpleServiceService extends grpc.ServiceDefinition<grpc.UntypedServi

export const SimpleServiceService: ISimpleServiceService;

export interface ISimpleServiceServer extends grpc.UntypedServiceImplementation {
doUnary(call: grpc.ServerUnaryCall<proto_examplecom_simple_service_pb.UnaryRequest, proto_othercom_external_child_message_pb.ExternalChildMessage>, callback: grpc.sendUnaryData<proto_othercom_external_child_message_pb.ExternalChildMessage>): void;
doServerStream(call: grpc.ServerWritableStream<proto_examplecom_simple_service_pb.StreamRequest, proto_othercom_external_child_message_pb.ExternalChildMessage>): void;
doClientStream(call: grpc.ServerReadableStream<proto_examplecom_simple_service_pb.StreamRequest, google_protobuf_empty_pb.Empty>, callback: grpc.sendUnaryData<google_protobuf_empty_pb.Empty>): void;
doBidiStream(call: grpc.ServerDuplexStream<proto_examplecom_simple_service_pb.StreamRequest, proto_othercom_external_child_message_pb.ExternalChildMessage>): void;
delete(call: grpc.ServerUnaryCall<proto_examplecom_simple_service_pb.UnaryRequest, proto_examplecom_simple_service_pb.UnaryResponse>, callback: grpc.sendUnaryData<proto_examplecom_simple_service_pb.UnaryResponse>): void;
}

export class SimpleServiceClient extends grpc.Client {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
doUnary(argument: proto_examplecom_simple_service_pb.UnaryRequest, callback: grpc.requestCallback<proto_othercom_external_child_message_pb.ExternalChildMessage>): grpc.ClientUnaryCall;
Expand Down
5 changes: 5 additions & 0 deletions examples/generated-grpc-js-node/proto/orphan_grpc_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ interface IOrphanServiceService extends grpc.ServiceDefinition<grpc.UntypedServi

export const OrphanServiceService: IOrphanServiceService;

export interface IOrphanServiceServer extends grpc.UntypedServiceImplementation {
doUnary(call: grpc.ServerUnaryCall<proto_orphan_pb.OrphanUnaryRequest, proto_orphan_pb.OrphanMessage>, callback: grpc.sendUnaryData<proto_orphan_pb.OrphanMessage>): void;
doStream(call: grpc.ServerWritableStream<proto_orphan_pb.OrphanStreamRequest, proto_orphan_pb.OrphanMessage>): void;
}

export class OrphanServiceClient extends grpc.Client {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
doUnary(argument: proto_orphan_pb.OrphanUnaryRequest, callback: grpc.requestCallback<proto_orphan_pb.OrphanMessage>): grpc.ClientUnaryCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ interface ISimpleServiceService extends grpc.ServiceDefinition<grpc.UntypedServi

export const SimpleServiceService: ISimpleServiceService;

export interface ISimpleServiceServer extends grpc.UntypedServiceImplementation {
doUnary(call: grpc.ServerUnaryCall<proto_examplecom_simple_service_pb.UnaryRequest, proto_othercom_external_child_message_pb.ExternalChildMessage>, callback: grpc.sendUnaryData<proto_othercom_external_child_message_pb.ExternalChildMessage>): void;
doServerStream(call: grpc.ServerWritableStream<proto_examplecom_simple_service_pb.StreamRequest, proto_othercom_external_child_message_pb.ExternalChildMessage>): void;
doClientStream(call: grpc.ServerReadableStream<proto_examplecom_simple_service_pb.StreamRequest, google_protobuf_empty_pb.Empty>, callback: grpc.sendUnaryData<google_protobuf_empty_pb.Empty>): void;
doBidiStream(call: grpc.ServerDuplexStream<proto_examplecom_simple_service_pb.StreamRequest, proto_othercom_external_child_message_pb.ExternalChildMessage>): void;
delete(call: grpc.ServerUnaryCall<proto_examplecom_simple_service_pb.UnaryRequest, proto_examplecom_simple_service_pb.UnaryResponse>, callback: grpc.sendUnaryData<proto_examplecom_simple_service_pb.UnaryResponse>): void;
}

export class SimpleServiceClient extends grpc.Client {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
doUnary(argument: proto_examplecom_simple_service_pb.UnaryRequest, callback: grpc.requestCallback<proto_othercom_external_child_message_pb.ExternalChildMessage>): grpc.ClientUnaryCall;
Expand Down
5 changes: 5 additions & 0 deletions examples/generated-grpc-node/proto/orphan_grpc_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ interface IOrphanServiceService extends grpc.ServiceDefinition<grpc.UntypedServi

export const OrphanServiceService: IOrphanServiceService;

export interface IOrphanServiceServer extends grpc.UntypedServiceImplementation {
doUnary(call: grpc.ServerUnaryCall<proto_orphan_pb.OrphanUnaryRequest, proto_orphan_pb.OrphanMessage>, callback: grpc.sendUnaryData<proto_orphan_pb.OrphanMessage>): void;
doStream(call: grpc.ServerWritableStream<proto_orphan_pb.OrphanStreamRequest, proto_orphan_pb.OrphanMessage>): void;
}

export class OrphanServiceClient extends grpc.Client {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
doUnary(argument: proto_orphan_pb.OrphanUnaryRequest, callback: grpc.requestCallback<proto_orphan_pb.OrphanMessage>): grpc.ClientUnaryCall;
Expand Down
20 changes: 20 additions & 0 deletions src/service/grpcnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function generateTypeScriptDefinition(fileDescriptor: FileDescriptorProto, expor
printer.printEmptyLn();
printService(printer, service);
printer.printEmptyLn();
printServer(printer, service);
printer.printEmptyLn();
printClient(printer, service);
});

Expand All @@ -62,6 +64,24 @@ function printService(printer: Printer, service: RPCDescriptor) {
printer.printLn(`export const ${serviceName}: I${serviceName};`);
}

function printServer(printer: Printer, service: RPCDescriptor) {
const serverName = `${service.name}Server`;
printer.printLn(`export interface I${serverName} extends grpc.UntypedServiceImplementation {`);
service.methods
.forEach(method => {
if (!method.requestStream && !method.responseStream) {
printer.printIndentedLn(`${method.nameAsCamelCase}(call: grpc.ServerUnaryCall<${method.requestType}, ${method.responseType}>, callback: grpc.sendUnaryData<${method.responseType}>): void;`);
} else if (!method.requestStream) {
printer.printIndentedLn(`${method.nameAsCamelCase}(call: grpc.ServerWritableStream<${method.requestType}, ${method.responseType}>): void;`);
} else if (!method.responseStream) {
printer.printIndentedLn(`${method.nameAsCamelCase}(call: grpc.ServerReadableStream<${method.requestType}, ${method.responseType}>, callback: grpc.sendUnaryData<${method.responseType}>): void;`);
} else {
printer.printIndentedLn(`${method.nameAsCamelCase}(call: grpc.ServerDuplexStream<${method.requestType}, ${method.responseType}>): void;`);
}
});
printer.printLn("}");
}

function printClient(printer: Printer, service: RPCDescriptor) {
printer.printLn(`export class ${service.name}Client extends grpc.Client {`);
printer.printIndentedLn("constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);");
Expand Down